Small tables rework
This commit is contained in:
parent
b1f701d307
commit
97f8569178
|
@ -25,7 +25,7 @@ func NewAttribute(key string, value interface{}) *Attribute {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func FromDatabaseAttribute(db *storage.DB_PAttribute) *Attribute {
|
func FromDatabaseAttribute(db *storage.DB_Attribute) *Attribute {
|
||||||
return &Attribute{
|
return &Attribute{
|
||||||
ID: db.ID,
|
ID: db.ID,
|
||||||
ProfileID: db.ProfileID,
|
ProfileID: db.ProfileID,
|
||||||
|
@ -35,8 +35,8 @@ func FromDatabaseAttribute(db *storage.DB_PAttribute) *Attribute {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Attribute) ToDatabase(profileId string) *storage.DB_PAttribute {
|
func (a *Attribute) ToDatabase(profileId string) *storage.DB_Attribute {
|
||||||
return &storage.DB_PAttribute{
|
return &storage.DB_Attribute{
|
||||||
ID: a.ID,
|
ID: a.ID,
|
||||||
ProfileID: profileId,
|
ProfileID: profileId,
|
||||||
Key: a.Key,
|
Key: a.Key,
|
||||||
|
|
|
@ -96,7 +96,7 @@ func (g *Gift) Delete() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *Gift) ToDatabase(profileId string) *storage.DB_Gift {
|
func (g *Gift) ToDatabase(profileId string) *storage.DB_Gift {
|
||||||
profileLoot := []storage.DB_Loot{}
|
profileLoot := []storage.DB_GiftLoot{}
|
||||||
|
|
||||||
for _, item := range g.Loot {
|
for _, item := range g.Loot {
|
||||||
profileLoot = append(profileLoot, *item.ToLootDatabase(g.ID))
|
profileLoot = append(profileLoot, *item.ToLootDatabase(g.ID))
|
||||||
|
|
|
@ -58,7 +58,7 @@ func FromDatabaseItem(item *storage.DB_Item) *Item {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func FromDatabaseLoot(item *storage.DB_Loot) *Item {
|
func FromDatabaseLoot(item *storage.DB_GiftLoot) *Item {
|
||||||
return &Item{
|
return &Item{
|
||||||
ID: item.ID,
|
ID: item.ID,
|
||||||
TemplateID: item.TemplateID,
|
TemplateID: item.TemplateID,
|
||||||
|
@ -202,8 +202,8 @@ func (i *Item) Save() {
|
||||||
storage.Repo.SaveItem(i.ToDatabase(i.ProfileID))
|
storage.Repo.SaveItem(i.ToDatabase(i.ProfileID))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *Item) ToLootDatabase(giftId string) *storage.DB_Loot {
|
func (i *Item) ToLootDatabase(giftId string) *storage.DB_GiftLoot {
|
||||||
return &storage.DB_Loot{
|
return &storage.DB_GiftLoot{
|
||||||
GiftID: giftId,
|
GiftID: giftId,
|
||||||
ProfileType: i.ProfileType,
|
ProfileType: i.ProfileType,
|
||||||
ID: i.ID,
|
ID: i.ID,
|
||||||
|
|
|
@ -330,7 +330,7 @@ func (p *Person) ToDatabase() *storage.DB_Person {
|
||||||
Gifts: []storage.DB_Gift{},
|
Gifts: []storage.DB_Gift{},
|
||||||
Quests: []storage.DB_Quest{},
|
Quests: []storage.DB_Quest{},
|
||||||
Loadouts: []storage.DB_Loadout{},
|
Loadouts: []storage.DB_Loadout{},
|
||||||
Attributes: []storage.DB_PAttribute{},
|
Attributes: []storage.DB_Attribute{},
|
||||||
Revision: profile.Revision,
|
Revision: profile.Revision,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -437,7 +437,7 @@ func (p *Profile) ToDatabase() *storage.DB_Profile {
|
||||||
Gifts: []storage.DB_Gift{},
|
Gifts: []storage.DB_Gift{},
|
||||||
Quests: []storage.DB_Quest{},
|
Quests: []storage.DB_Quest{},
|
||||||
Loadouts: []storage.DB_Loadout{},
|
Loadouts: []storage.DB_Loadout{},
|
||||||
Attributes: []storage.DB_PAttribute{},
|
Attributes: []storage.DB_Attribute{},
|
||||||
Revision: p.Revision,
|
Revision: p.Revision,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,17 +35,19 @@ func (s *PostgresStorage) Migrate(table interface{}, tableName string) {
|
||||||
|
|
||||||
func (s *PostgresStorage) MigrateAll() {
|
func (s *PostgresStorage) MigrateAll() {
|
||||||
s.Migrate(&DB_Person{}, "Persons")
|
s.Migrate(&DB_Person{}, "Persons")
|
||||||
|
s.Migrate(&DB_Relationship{}, "Relationships")
|
||||||
s.Migrate(&DB_Profile{}, "Profiles")
|
s.Migrate(&DB_Profile{}, "Profiles")
|
||||||
s.Migrate(&DB_Item{}, "Items")
|
s.Migrate(&DB_Attribute{}, "Attributes")
|
||||||
s.Migrate(&DB_Gift{}, "Gifts")
|
|
||||||
s.Migrate(&DB_Quest{}, "Quests")
|
|
||||||
s.Migrate(&DB_Loadout{}, "Loadouts")
|
s.Migrate(&DB_Loadout{}, "Loadouts")
|
||||||
s.Migrate(&DB_Loot{}, "Loot")
|
s.Migrate(&DB_Item{}, "Items")
|
||||||
|
s.Migrate(&DB_Purchase{}, "Purchases")
|
||||||
|
s.Migrate(&DB_PurchaseLoot{}, "PurchaseLoot")
|
||||||
s.Migrate(&DB_VariantChannel{}, "Variants")
|
s.Migrate(&DB_VariantChannel{}, "Variants")
|
||||||
s.Migrate(&DB_PAttribute{}, "Attributes")
|
s.Migrate(&DB_Quest{}, "Quests")
|
||||||
|
s.Migrate(&DB_Gift{}, "Gifts")
|
||||||
|
s.Migrate(&DB_GiftLoot{}, "GiftLoot")
|
||||||
s.Migrate(&DB_DiscordPerson{}, "Discords")
|
s.Migrate(&DB_DiscordPerson{}, "Discords")
|
||||||
s.Migrate(&DB_SeasonStat{}, "Stats")
|
s.Migrate(&DB_SeasonStat{}, "Stats")
|
||||||
s.Migrate(&DB_Relationship{}, "Relationships")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *PostgresStorage) DropTables() {
|
func (s *PostgresStorage) DropTables() {
|
||||||
|
@ -242,12 +244,12 @@ func (s *PostgresStorage) DeleteQuest(questId string) {
|
||||||
s.Postgres.Delete(&DB_Quest{}, "id = ?", questId)
|
s.Postgres.Delete(&DB_Quest{}, "id = ?", questId)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *PostgresStorage) SaveLoot(loot *DB_Loot) {
|
func (s *PostgresStorage) SaveLoot(loot *DB_GiftLoot) {
|
||||||
s.Postgres.Save(loot)
|
s.Postgres.Save(loot)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *PostgresStorage) DeleteLoot(lootId string) {
|
func (s *PostgresStorage) DeleteLoot(lootId string) {
|
||||||
s.Postgres.Delete(&DB_Loot{}, "id = ?", lootId)
|
s.Postgres.Delete(&DB_GiftLoot{}, "id = ?", lootId)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *PostgresStorage) SaveGift(gift *DB_Gift) {
|
func (s *PostgresStorage) SaveGift(gift *DB_Gift) {
|
||||||
|
@ -258,12 +260,12 @@ func (s *PostgresStorage) DeleteGift(giftId string) {
|
||||||
s.Postgres.Delete(&DB_Gift{}, "id = ?", giftId)
|
s.Postgres.Delete(&DB_Gift{}, "id = ?", giftId)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *PostgresStorage) SaveAttribute(attribute *DB_PAttribute) {
|
func (s *PostgresStorage) SaveAttribute(attribute *DB_Attribute) {
|
||||||
s.Postgres.Save(attribute)
|
s.Postgres.Save(attribute)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *PostgresStorage) DeleteAttribute(attributeId string) {
|
func (s *PostgresStorage) DeleteAttribute(attributeId string) {
|
||||||
s.Postgres.Delete(&DB_PAttribute{}, "id = ?", attributeId)
|
s.Postgres.Delete(&DB_Attribute{}, "id = ?", attributeId)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *PostgresStorage) SaveLoadout(loadout *DB_Loadout) {
|
func (s *PostgresStorage) SaveLoadout(loadout *DB_Loadout) {
|
||||||
|
|
|
@ -37,13 +37,13 @@ type Storage interface {
|
||||||
SaveQuest(quest *DB_Quest)
|
SaveQuest(quest *DB_Quest)
|
||||||
DeleteQuest(questId string)
|
DeleteQuest(questId string)
|
||||||
|
|
||||||
SaveLoot(loot *DB_Loot)
|
SaveLoot(loot *DB_GiftLoot)
|
||||||
DeleteLoot(lootId string)
|
DeleteLoot(lootId string)
|
||||||
|
|
||||||
SaveGift(gift *DB_Gift)
|
SaveGift(gift *DB_Gift)
|
||||||
DeleteGift(giftId string)
|
DeleteGift(giftId string)
|
||||||
|
|
||||||
SaveAttribute(attribute *DB_PAttribute)
|
SaveAttribute(attribute *DB_Attribute)
|
||||||
DeleteAttribute(attributeId string)
|
DeleteAttribute(attributeId string)
|
||||||
|
|
||||||
SaveLoadout(loadout *DB_Loadout)
|
SaveLoadout(loadout *DB_Loadout)
|
||||||
|
@ -175,7 +175,7 @@ func (r *Repository) DeleteQuest(questId string) {
|
||||||
r.Storage.DeleteQuest(questId)
|
r.Storage.DeleteQuest(questId)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Repository) SaveLoot(loot *DB_Loot) {
|
func (r *Repository) SaveLoot(loot *DB_GiftLoot) {
|
||||||
r.Storage.SaveLoot(loot)
|
r.Storage.SaveLoot(loot)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -191,7 +191,7 @@ func (r *Repository) DeleteGift(giftId string) {
|
||||||
r.Storage.DeleteGift(giftId)
|
r.Storage.DeleteGift(giftId)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Repository) SaveAttribute(attribute *DB_PAttribute) {
|
func (r *Repository) SaveAttribute(attribute *DB_Attribute) {
|
||||||
r.Storage.SaveAttribute(attribute)
|
r.Storage.SaveAttribute(attribute)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ type DB_Profile struct {
|
||||||
Items []DB_Item `gorm:"foreignkey:ProfileID"`
|
Items []DB_Item `gorm:"foreignkey:ProfileID"`
|
||||||
Gifts []DB_Gift `gorm:"foreignkey:ProfileID"`
|
Gifts []DB_Gift `gorm:"foreignkey:ProfileID"`
|
||||||
Quests []DB_Quest `gorm:"foreignkey:ProfileID"`
|
Quests []DB_Quest `gorm:"foreignkey:ProfileID"`
|
||||||
Attributes []DB_PAttribute `gorm:"foreignkey:ProfileID"`
|
Attributes []DB_Attribute `gorm:"foreignkey:ProfileID"`
|
||||||
Loadouts []DB_Loadout `gorm:"foreignkey:ProfileID"`
|
Loadouts []DB_Loadout `gorm:"foreignkey:ProfileID"`
|
||||||
Type string
|
Type string
|
||||||
Revision int
|
Revision int
|
||||||
|
@ -46,7 +46,7 @@ func (DB_Profile) TableName() string {
|
||||||
return "Profiles"
|
return "Profiles"
|
||||||
}
|
}
|
||||||
|
|
||||||
type DB_PAttribute struct {
|
type DB_Attribute struct {
|
||||||
ID string `gorm:"primary_key"`
|
ID string `gorm:"primary_key"`
|
||||||
ProfileID string
|
ProfileID string
|
||||||
Key string
|
Key string
|
||||||
|
@ -54,7 +54,7 @@ type DB_PAttribute struct {
|
||||||
Type string
|
Type string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (DB_PAttribute) TableName() string {
|
func (DB_Attribute) TableName() string {
|
||||||
return "Attributes"
|
return "Attributes"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,6 +94,34 @@ func (DB_Item) TableName() string {
|
||||||
return "Items"
|
return "Items"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type DB_Purchase struct {
|
||||||
|
ID string `gorm:"primary_key"`
|
||||||
|
ProfileID string `gorm:"index"`
|
||||||
|
Loot []DB_PurchaseLoot `gorm:"foreignkey:PurchaseID"`
|
||||||
|
OfferID string
|
||||||
|
PurchaseDate int64
|
||||||
|
FreeRefundExpiry int64
|
||||||
|
RefundExpiry int64
|
||||||
|
Refundable bool
|
||||||
|
Refunded bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func (DB_Purchase) TableName() string {
|
||||||
|
return "Purchases"
|
||||||
|
}
|
||||||
|
|
||||||
|
type DB_PurchaseLoot struct {
|
||||||
|
ID string `gorm:"primary_key"`
|
||||||
|
PurchaseID string `gorm:"index"`
|
||||||
|
TemplateID string
|
||||||
|
Quantity int
|
||||||
|
ProfileType string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (DB_PurchaseLoot) TableName() string {
|
||||||
|
return "PurchaseLoot"
|
||||||
|
}
|
||||||
|
|
||||||
type DB_VariantChannel struct {
|
type DB_VariantChannel struct {
|
||||||
ID string `gorm:"primary_key"`
|
ID string `gorm:"primary_key"`
|
||||||
ItemID string `gorm:"index"`
|
ItemID string `gorm:"index"`
|
||||||
|
@ -129,14 +157,14 @@ type DB_Gift struct {
|
||||||
FromID string
|
FromID string
|
||||||
GiftedAt int64
|
GiftedAt int64
|
||||||
Message string
|
Message string
|
||||||
Loot []DB_Loot `gorm:"foreignkey:GiftID"`
|
Loot []DB_GiftLoot `gorm:"foreignkey:GiftID"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (DB_Gift) TableName() string {
|
func (DB_Gift) TableName() string {
|
||||||
return "Gifts"
|
return "Gifts"
|
||||||
}
|
}
|
||||||
|
|
||||||
type DB_Loot struct {
|
type DB_GiftLoot struct {
|
||||||
ID string `gorm:"primary_key"`
|
ID string `gorm:"primary_key"`
|
||||||
GiftID string `gorm:"index"`
|
GiftID string `gorm:"index"`
|
||||||
TemplateID string
|
TemplateID string
|
||||||
|
@ -144,8 +172,8 @@ type DB_Loot struct {
|
||||||
ProfileType string
|
ProfileType string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (DB_Loot) TableName() string {
|
func (DB_GiftLoot) TableName() string {
|
||||||
return "Loot"
|
return "GiftLoot"
|
||||||
}
|
}
|
||||||
|
|
||||||
type DB_DiscordPerson struct {
|
type DB_DiscordPerson struct {
|
||||||
|
@ -166,12 +194,10 @@ type DB_SeasonStat struct {
|
||||||
ID string `gorm:"primary_key"`
|
ID string `gorm:"primary_key"`
|
||||||
PersonID string
|
PersonID string
|
||||||
Build string
|
Build string
|
||||||
XP int
|
SeasonXP int
|
||||||
Level int
|
SeasonalLevel int
|
||||||
LevelClaimed int
|
SeasonalTier int
|
||||||
Stars int
|
BattleStars int
|
||||||
Tier int
|
|
||||||
TierClaimed int
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (DB_SeasonStat) TableName() string {
|
func (DB_SeasonStat) TableName() string {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user