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 PositionHandler struct { Service *service.PositionService } func (handler *PositionHandler) List(c *gin.Context) { positions, err := handler.Service.List(c.Request.Context()) if err != nil { c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) return } dtos := models.ConvertPositionsToDtos(positions) c.JSON(http.StatusOK, dtos) } func (handler *PositionHandler) Get(c *gin.Context) { id := c.Param("id") position, err := handler.Service.Get(c.Request.Context(), id) if err != nil { c.JSON(http.StatusNotFound, gin.H{"error": "position not found"}) return } c.JSON(http.StatusOK, position) } func NewPositionHandler(db *gorm.DB) *PositionHandler { handler := &PositionHandler{Service: service.NewPositionService(repository.NewPositionRepository(db))} return handler }