add tysc handlers to kontor-gin
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user