add filtering and base repository

This commit is contained in:
Fran Jurmanović
2025-05-28 19:55:11 +02:00
parent 56ef5e1484
commit 0ced45ce55
17 changed files with 567 additions and 246 deletions

View File

@@ -3,6 +3,7 @@ package service
import (
"acc-server-manager/local/model"
"acc-server-manager/local/repository"
"log"
"github.com/gofiber/fiber/v2"
)
@@ -24,6 +25,19 @@ func NewStateHistoryService(repository *repository.StateHistoryRepository) *Stat
// context.Context: Application context
// Returns:
// string: Application version
func (as StateHistoryService) GetAll(ctx *fiber.Ctx, id int) *[]model.StateHistory {
return as.repository.GetAll(ctx.UserContext(), id)
func (s *StateHistoryService) GetAll(ctx *fiber.Ctx, filter *model.StateHistoryFilter) (*[]model.StateHistory, error) {
result, err := s.repository.GetAll(ctx.UserContext(), filter)
if err != nil {
log.Printf("Error getting state history: %v", err)
return nil, err
}
return result, nil
}
func (s *StateHistoryService) Insert(ctx *fiber.Ctx, model *model.StateHistory) error {
if err := s.repository.Insert(ctx.UserContext(), model); err != nil {
log.Printf("Error inserting state history: %v", err)
return err
}
return nil
}