31 lines
777 B
Go
31 lines
777 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 ArticleAuthorHandler struct {
|
|
Service *service.ArticleAuthorService
|
|
}
|
|
|
|
func NewArticleAuthorHandler(db *gorm.DB) *ArticleAuthorHandler {
|
|
handler := &ArticleAuthorHandler{Service: service.NewArticleAuthorService(repository.NewArticleAuthorRepository(db))}
|
|
return handler
|
|
}
|
|
|
|
func (handler *ArticleAuthorHandler) List(c *gin.Context) {
|
|
authors, err := handler.Service.List(c.Request.Context())
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
dtos := models.ConvertArticleAuthorsToDtos(authors)
|
|
c.JSON(http.StatusOK, dtos)
|
|
}
|