Files
kontor/kontor-gin/internal/repository/player.go
T

38 lines
883 B
Go

package repository
import (
"context"
"kontor-api-gin/internal/models"
"log/slog"
"gorm.io/gorm"
)
type PlayerRepository struct {
db *gorm.DB
}
func NewPlayerRepository(db *gorm.DB) *PlayerRepository {
repo := &PlayerRepository{db: db}
return repo
}
func (repository *PlayerRepository) FindAll(context context.Context) ([]models.Player, error) {
var players []models.Player
result := repository.db.Find(&players)
slog.Info("PlayerRepository#FindAll", "count", result.RowsAffected)
return players, nil
}
func (repository *PlayerRepository) GetById(context context.Context, id string) (models.Player, error) {
var player = models.Player{ID: id}
slog.Info("PlayerRepository#GetById", "id", id)
result := repository.db.First(&player)
if result.Error != nil {
slog.Info("PlayerRepository#GetById", "error", result.Error.Error())
}
return player, result.Error
}