The backend for the project formerly known as signet, now known as beignet.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
2.5 KiB

  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. gorm.Model
  10. Goal float64 `json:"goal"`
  11. Percent float64 `json:"percent"`
  12. RewardFundID uint `json:"rewardFundID"`
  13. }
  14. type Queue struct {
  15. gorm.Model
  16. Name string `json:"name"`
  17. Funds []RewardFund `json:"funds"`
  18. }
  19. type RewardFund struct {
  20. gorm.Model
  21. Asset string `json:"asset"`
  22. FundWallet string `json:"fundWallet"`
  23. SellingWallet string `json:"sellingWallet"`
  24. IssuerWallet string `json:"issuerWallet"`
  25. Memo string `json:"memo"`
  26. Price float64 `json:"price"`
  27. AmountAvailable float64 `gorm:"type:decimal(19,7)" json:"amountAvailable"`
  28. MinContribution float64 `gorm:"type:decimal(19,7)" json:"minContribution"`
  29. Contributions []Contribution `json:"contributions"`
  30. Title string `gorm:"type:varchar(50)" json:"title"`
  31. Description string `gorm:"type:text" json:"description"`
  32. QueueID uint `json:"queueID"`
  33. Bonuses []Bonus `json:"bonuses"`
  34. }
  35. type QueueRewardFund struct {
  36. }
  37. type Contribution struct {
  38. gorm.Model
  39. Wallet string `json:"wallet"`
  40. Amount float64 `gorm:"type:decimal(19,7)" json:"amount"`
  41. TransactionID string `json:"transactionID"`
  42. RewardFundID uint `json:"rewardFundID"`
  43. Tags []AppliedTag `json:"tags"`
  44. }
  45. type Tag struct {
  46. gorm.Model
  47. Description string `json:"description"`
  48. Active bool `json:"active"`
  49. Contribution AppliedTag `json:"contribution"`
  50. }
  51. type AppliedTag struct {
  52. gorm.Model
  53. TagID uint `json:"tagID"`
  54. ContributionID uint `json:"contributionID"`
  55. }
  56. type User struct {
  57. gorm.Model
  58. Username string `json:"username"`
  59. Password string `json:"password"`
  60. Privileges uint `json:"admin"`
  61. }
  62. var Db *gorm.DB
  63. func InitializeDatabase() {
  64. var err error
  65. dcs := fmt.Sprintf("host=%s user=%s password=%s dbname=%s port=%d sslmode=%s",
  66. viper.GetString("database.host"),
  67. viper.GetString("database.user"),
  68. viper.GetString("database.password"),
  69. viper.GetString("database.name"),
  70. viper.GetInt("database.port"),
  71. viper.GetString("database.ssl"))
  72. Db, err = gorm.Open(postgres.Open(dcs), &gorm.Config{})
  73. if err != nil {
  74. panic("Could not open database")
  75. }
  76. err = Db.AutoMigrate(User{}, Queue{}, RewardFund{}, Contribution{}, Bonus{})
  77. if err != nil {
  78. panic("Could not migrate database")
  79. }
  80. }