Files
kontor/kontor-gin/internal/handlers/article.go
T
tpeetz d9007ba0e4
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 5s
add missing models
2026-10-04 01:56:25 +02:00

31 lines
725 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 ArticleHandler struct {
Service *service.ArticleService
}
func NewArticleHandler(db *gorm.DB) *ArticleHandler {
handler := &ArticleHandler{Service: service.NewArticleService(repository.NewArticleRepository(db))}
return handler
}
func (handler *ArticleHandler) List(c *gin.Context) {
articles, err := handler.Service.List(c.Request.Context())
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
dtos := models.ConvertArticlesToDtos(articles)
c.JSON(http.StatusOK, dtos)
}