The backend for the project formerly known as signet, now known as beignet.
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

context.go 2.2 KiB

há 2 anos
há 2 anos
há 2 anos
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package data
  2. import (
  3. "fmt"
  4. "github.com/spf13/viper"
  5. "gorm.io/driver/postgres"
  6. "gorm.io/gorm"
  7. )
  8. type Bonus struct {
  9. Goal float64 `json:"goal"`
  10. Percent float64 `json:"percent"`
  11. RewardFundID uint `json:"rewardFundID"`
  12. }
  13. type RewardFund struct {
  14. gorm.Model
  15. Asset string `json:"asset"`
  16. FundWallet string `json:"fundWallet"`
  17. SellingWallet string `json:"sellingWallet"`
  18. IssuerWallet string `json:"issuerWallet"`
  19. Memo string `json:"memo"`
  20. Price float64 `json:"price"`
  21. AmountAvailable float64 `gorm:"type:decimal(19,7)" json:"amountAvailable"`
  22. MinContribution float64 `gorm:"type:decimal(19,7)" json:"minContribution"`
  23. Contributions []Contribution `json:"contributions"`
  24. Title string `gorm:"type:varchar(50)" json:"title"`
  25. Description string `gorm:"type:text" json:"description"`
  26. Bonuses []Bonus `json:"bonuses"`
  27. }
  28. type Contribution struct {
  29. gorm.Model
  30. Wallet string `json:"wallet"`
  31. Amount float64 `gorm:"type:decimal(19,7)" json:"amount"`
  32. TransactionID string `json:"transactionID"`
  33. RewardFundID uint `json:"rewardFundID"`
  34. Tags []AppliedTag `json:"tags"`
  35. }
  36. type Tag struct {
  37. gorm.Model
  38. Description string `json:"description"`
  39. Active bool `json:"active"`
  40. Contribution AppliedTag `json:"contribution"`
  41. }
  42. type AppliedTag struct {
  43. gorm.Model
  44. TagID uint `json:"tagID"`
  45. ContributionID uint `json:"contributionID"`
  46. }
  47. type User struct {
  48. gorm.Model
  49. Username string `json:"username"`
  50. Password string `json:"password"`
  51. Privileges uint `json:"admin"`
  52. }
  53. var Db *gorm.DB
  54. func InitializeDatabase() {
  55. var err error
  56. dcs := fmt.Sprintf("host=%s user=%s password=%s dbname=%s port=%d sslmode=%s",
  57. viper.GetString("database.host"),
  58. viper.GetString("database.user"),
  59. viper.GetString("database.password"),
  60. viper.GetString("database.name"),
  61. viper.GetInt("database.port"),
  62. viper.GetString("database.ssl"))
  63. Db, err = gorm.Open(postgres.Open(dcs), &gorm.Config{})
  64. err = Db.AutoMigrate(User{}, RewardFund{}, Contribution{}, Bonus{})
  65. if err != nil {
  66. panic("Could not migrate database")
  67. }
  68. }