|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- package data
-
- import (
- "fmt"
- "github.com/spf13/viper"
- "gorm.io/driver/postgres"
- "gorm.io/gorm"
- )
-
- type Bonus struct {
- Goal float64 `json:"goal"`
- Percent float64 `json:"percent"`
- RewardFundID uint `json:"rewardFundID"`
- }
-
- type RewardFund struct {
- gorm.Model
- Asset string `json:"asset"`
- FundWallet string `json:"fundWallet"`
- SellingWallet string `json:"sellingWallet"`
- IssuerWallet string `json:"issuerWallet"`
- Memo string `json:"memo"`
- Price float64 `json:"price"`
- AmountAvailable float64 `gorm:"type:decimal(19,7)" json:"amountAvailable"`
- MinContribution float64 `gorm:"type:decimal(19,7)" json:"minContribution"`
- Contributions []Contribution `json:"contributions"`
- Title string `gorm:"type:varchar(50)" json:"title"`
- Description string `gorm:"type:text" json:"description"`
- Bonuses []Bonus `json:"bonuses"`
- }
-
- type Contribution struct {
- gorm.Model
- Wallet string `json:"wallet"`
- Amount float64 `gorm:"type:decimal(19,7)" json:"amount"`
- TransactionID string `json:"transactionID"`
- RewardFundID uint `json:"rewardFundID"`
- Tags []AppliedTag `json:"tags"`
- }
-
- type Tag struct {
- gorm.Model
- Description string `json:"description"`
- Active bool `json:"active"`
- Contribution AppliedTag `json:"contribution"`
- }
-
- type AppliedTag struct {
- gorm.Model
- TagID uint `json:"tagID"`
- ContributionID uint `json:"contributionID"`
- }
-
- type User struct {
- gorm.Model
- Username string `json:"username"`
- Password string `json:"password"`
- Privileges uint `json:"admin"`
- }
-
- var Db *gorm.DB
-
- func InitializeDatabase() {
- var err error
- dcs := fmt.Sprintf("host=%s user=%s password=%s dbname=%s port=%d sslmode=%s",
- viper.GetString("database.host"),
- viper.GetString("database.user"),
- viper.GetString("database.password"),
- viper.GetString("database.name"),
- viper.GetInt("database.port"),
- viper.GetString("database.ssl"))
- Db, err = gorm.Open(postgres.Open(dcs), &gorm.Config{})
- err = Db.AutoMigrate(User{}, RewardFund{}, Contribution{}, Bonus{})
- if err != nil {
- panic("Could not migrate database")
- }
- }
|