Files
kontor/kontor-gin/internal/handlers/assignment.go
T
Thomas Peetz 4aaf580735
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 5s
WIP: Export Kontor DB
2026-10-01 17:40:17 +02:00

31 lines
758 B
Go

package handlers
import (
"kontor-api-gin/internal/models"
"kontor-api-gin/internal/repository"
"kontor-api-gin/internal/service"
"net/http"
"github.com/gin-gonic/gin"
"gorm.io/gorm"
)
type AssignmentHandler struct {
Service *service.AssignmentService
}
func NewAssignmentHandler(db *gorm.DB) *AssignmentHandler {
handler := &AssignmentHandler{Service: service.NewAssignmentService(repository.NewAssignmentRepository(db))}
return handler
}
func (handler *AssignmentHandler) List(c *gin.Context) {
assignments, err := handler.Service.List(c.Request.Context())
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
dtos := models.ConvertAssignmentsToDtos(assignments)
c.JSON(http.StatusOK, dtos)
}