38 lines
921 B
Go
38 lines
921 B
Go
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
|
|
}
|