Files
kontor/kontor-echo/internal/handlers/token.go
T
Thomas Peetz debdf3d0b0
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 6s
Gitea Actions Demo / build-and-test (push) Failing after 11s
kontor-echo: setup project to show homepage
2026-11-09 17:02:59 +01:00

31 lines
730 B
Go

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)
}