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