add tysc handlers to kontor-gin
This commit is contained in:
@@ -1,12 +1,37 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"kontor-api-gin/internal/globals"
|
||||
"kontor-api-gin/internal/models"
|
||||
"kontor-api-gin/internal/repository"
|
||||
"kontor-api-gin/internal/service"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-contrib/sessions"
|
||||
"github.com/gin-gonic/gin"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type ComicsHandler struct {
|
||||
ComicHandler *ComicHandler
|
||||
PublisherHandler *PublisherHandler
|
||||
// ArtistHandler *ArtistHandler
|
||||
// IssueHandler *IssueHandler
|
||||
// WorktypeHandler *WorktypeHandler
|
||||
// VolumeHandler *VolumeHandler
|
||||
// StoryarcHandler *StoryarcHandler
|
||||
// ComicworkHandler *ComicworkHandler
|
||||
// IssueworkHandler *IssueworkHandler
|
||||
}
|
||||
|
||||
func NewComicsHandler(db *gorm.DB) *ComicsHandler {
|
||||
comicsHandler := &ComicsHandler{
|
||||
ComicHandler: &ComicHandler{Service: service.NewComicService(repository.NewComicRepository(db))},
|
||||
PublisherHandler: &PublisherHandler{Service: service.NewPublisherService(repository.NewPublisherRepository(db))},
|
||||
}
|
||||
return comicsHandler
|
||||
}
|
||||
|
||||
type ComicHandler struct {
|
||||
Service *service.ComicService
|
||||
}
|
||||
@@ -17,5 +42,23 @@ func (handler *ComicHandler) List(c *gin.Context) {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, comics)
|
||||
dtos := models.ConvertComicsToDtos(comics)
|
||||
c.JSON(http.StatusOK, dtos)
|
||||
}
|
||||
|
||||
func (handler *ComicHandler) ListPage(c *gin.Context) {
|
||||
session := sessions.Default(c)
|
||||
user := session.Get(globals.UserKey)
|
||||
comics, err := handler.Service.List(c.Request.Context())
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.HTML(http.StatusOK, "comics", gin.H{
|
||||
"title": "Kontor Comics",
|
||||
"version": "0.4.0",
|
||||
"message": "Comics...",
|
||||
"comics": comics,
|
||||
"user": user,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user