feat: initial commit
This commit is contained in:
28
internal/store/player.go
Normal file
28
internal/store/player.go
Normal file
@ -0,0 +1,28 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func (s *Store) UpsertPlayer(ctx context.Context, player *Player) error {
|
||||
return errors.WithStack(s.Do(ctx, func(db *gorm.DB) error {
|
||||
var existing *Player
|
||||
err := db.Find(&existing, "user_id = ? and user_provider = ?", player.UserID, player.UserProvider).Error
|
||||
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
if existing != nil {
|
||||
player.Model = existing.Model
|
||||
}
|
||||
|
||||
if err := db.Save(player).Error; err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}))
|
||||
}
|
Reference in New Issue
Block a user