31 lines
703 B
Go
31 lines
703 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 TokenHandler struct {
|
|
Service *service.TokenService
|
|
}
|
|
|
|
func NewTokenHandler(db *gorm.DB) *TokenHandler {
|
|
handler := &TokenHandler{Service: service.NewTokenService(repository.NewTokenRepository(db))}
|
|
return handler
|
|
}
|
|
|
|
func (handler *TokenHandler) List(c *gin.Context) {
|
|
tokens, err := handler.Service.List(c.Request.Context())
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
dtos := models.ConvertTokensToDtos(tokens)
|
|
c.JSON(http.StatusOK, dtos)
|
|
}
|