Files
kontor/kontor-gin/internal/handlers/cardset.go
T
Thomas Peetz f5abb44466
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 4s
WIP: Export Kontor DB
2026-09-30 18:55:59 +02:00

41 lines
992 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 CardSetHandler struct {
Service *service.CardSetService
}
func (handler *CardSetHandler) List(c *gin.Context) {
cardsets, err := handler.Service.List(c.Request.Context())
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
dtos := models.ConvertCardSetsToDtos(cardsets)
c.JSON(http.StatusOK, dtos)
}
func (handler *CardSetHandler) Get(c *gin.Context) {
id := c.Param("id")
cardset, err := handler.Service.Get(c.Request.Context(), id)
if err != nil {
c.JSON(http.StatusNotFound, gin.H{"error": "cardset not found"})
return
}
c.JSON(http.StatusOK, cardset)
}
func NewCardSetHandler(db *gorm.DB) *CardSetHandler {
handler := &CardSetHandler{Service: service.NewCardSetService(repository.NewCardSetRepository(db))}
return handler
}