38 lines
971 B
Go
38 lines
971 B
Go
package repository
|
|
|
|
import (
|
|
"context"
|
|
"kontor-api-gin/internal/models"
|
|
"log/slog"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
type AssignmentRepository struct {
|
|
db *gorm.DB
|
|
}
|
|
|
|
func NewAssignmentRepository(db *gorm.DB) *AssignmentRepository {
|
|
repository := &AssignmentRepository{db: db}
|
|
return repository
|
|
}
|
|
|
|
func (repository *AssignmentRepository) FindAll(context context.Context) ([]models.Assignment, error) {
|
|
var assignments []models.Assignment
|
|
|
|
result := repository.db.Find(&assignments)
|
|
slog.Info("AssignmentRepository#FindAll", "count", result.RowsAffected)
|
|
|
|
return assignments, nil
|
|
}
|
|
|
|
func (repository *AssignmentRepository) GetById(context context.Context, id string) (models.Assignment, error) {
|
|
var assignment = models.Assignment{ID: id}
|
|
slog.Info("AssignmentRepository#GetById", "id", id)
|
|
result := repository.db.First(&assignment)
|
|
if result.Error != nil {
|
|
slog.Info("AssignmentRepository#GetById", "error", result.Error.Error())
|
|
}
|
|
return assignment, result.Error
|
|
}
|