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 TeamRepository struct {
|
||||
db *gorm.DB
|
||||
}
|
||||
|
||||
func NewTeamRepository(db *gorm.DB) *TeamRepository {
|
||||
repo := &TeamRepository{db: db}
|
||||
return repo
|
||||
}
|
||||
|
||||
func (repository *TeamRepository) FindAll(context context.Context) ([]models.Team, error) {
|
||||
var teams []models.Team
|
||||
|
||||
result := repository.db.Find(&teams)
|
||||
slog.Info("TeamRepository#FindAll", "count", result.RowsAffected)
|
||||
|
||||
return teams, nil
|
||||
}
|
||||
|
||||
func (repository *TeamRepository) GetById(context context.Context, id string) (models.Team, error) {
|
||||
var team = models.Team{ID: id}
|
||||
slog.Info("TeamRepository#GetById", "id", id)
|
||||
result := repository.db.First(&team)
|
||||
if result.Error != nil {
|
||||
slog.Info("TeamRepository#GetById", "error", result.Error.Error())
|
||||
}
|
||||
return team, result.Error
|
||||
}
|
||||
Reference in New Issue
Block a user