This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
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 ComicworkHandler struct {
|
||||
Service *service.ComicworkService
|
||||
}
|
||||
|
||||
func NewComicworkHandler(db *gorm.DB) *ComicworkHandler {
|
||||
handler := &ComicworkHandler{Service: service.NewComicworkService(repository.NewComicworkRepository(db))}
|
||||
return handler
|
||||
}
|
||||
|
||||
func (handler *ComicworkHandler) List(c *gin.Context) {
|
||||
comicworks, err := handler.Service.List(c.Request.Context())
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
dtos := models.ConvertComicworksToDtos(comicworks)
|
||||
c.JSON(http.StatusOK, dtos)
|
||||
}
|
||||
Reference in New Issue
Block a user