Skip to content

Commit

Permalink
function passed using references
Browse files Browse the repository at this point in the history
  • Loading branch information
iamananya committed Jun 2, 2023
1 parent 15c2cb5 commit 7ff97ec
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
16 changes: 16 additions & 0 deletions pkg/controllers/gacha-controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,22 @@ func HandleGachaDraw(w http.ResponseWriter, r *http.Request) {
Rarity: character.Rarity,
}
response.Results[i] = characterResponse
// Store the character in the database for the user
userCharacter := models.UserCharacter{
UserID: user.ID,
CharacterID: character.ID,
AttackPower: character.AttackPower,
Defense: character.Defense,
Speed: character.Speed,
HitPoints: character.HitPoints,
CriticalHitRate: character.CriticalHitRate,
ElementalAffinity: character.ElementalAffinity,
Rarity: character.Rarity,
Synergy: character.Synergy,
Evolution: character.Evolution,
}
userCharacter.CreateUserCharacter()

}

respBody, err := json.Marshal(response)
Expand Down
10 changes: 6 additions & 4 deletions pkg/models/gacha.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,13 @@ func GetAllCharacters() ([]Character, error) {
}
return characters, nil
}
func (uc *UserCharacter) CreateUserCharacter() *UserCharacter {
db.Create(&uc)
return uc
func (uc *UserCharacter) CreateUserCharacter() error {
db := config.GetDB()
if err := db.Create(uc).Error; err != nil {
return err
}
return nil
}

func (gr *GachaResult) SaveGachaResult() error {
db := config.GetDB()
err := db.Create(gr).Error
Expand Down

0 comments on commit 7ff97ec

Please sign in to comment.