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 TokenHandler struct { Service *service.TokenService } func NewTokenHandler(db *bun.DB) *TokenHandler { handler := &TokenHandler{Service: service.NewTokenService(repository.NewTokenRepository(db))} return handler } func (handler *TokenHandler) List(c *echo.Context) { tokens, err := handler.Service.List(c.Request().Context()) if err != nil { c.JSON(http.StatusInternalServerError, map[string]any{"error": err.Error()}) return } dtos := models.ConvertTokensToDtos(tokens) c.JSON(http.StatusOK, dtos) }