package handlers import ( "kontor-api-echo/internal/models" "kontor-api-echo/internal/repository" "kontor-api-echo/internal/service" "net/http" "github.com/labstack/echo/v5" "github.com/uptrace/bun" ) type MailHandler struct { Service *service.MailService } func NewMailHandler(db *bun.DB) *MailHandler { handler := &MailHandler{Service: service.NewMailService(repository.NewMailRepository(db))} return handler } func (handler *MailHandler) List(c *echo.Context) { mails, err := handler.Service.List(c.Request().Context()) if err != nil { c.JSON(http.StatusInternalServerError, map[string]any{"error": err.Error()}) return } dtos := models.ConvertMailsToDtos(mails) c.JSON(http.StatusOK, dtos) }