This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
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 StoryArcHandler struct {
|
||||
Service *service.StoryArcService
|
||||
}
|
||||
|
||||
func NewStoryArcHandler(db *gorm.DB) *StoryArcHandler {
|
||||
handler := &StoryArcHandler{Service: service.NewStoryArcService(repository.NewStoryArcRepository(db))}
|
||||
return handler
|
||||
}
|
||||
|
||||
func (handler *StoryArcHandler) List(c *gin.Context) {
|
||||
storyArcs, err := handler.Service.List(c.Request.Context())
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
dtos := models.ConvertStoryArcsToDtos(storyArcs)
|
||||
c.JSON(http.StatusOK, dtos)
|
||||
}
|
||||
|
||||
func (handler *StoryArcHandler) ListPage(c *gin.Context) {
|
||||
session := sessions.Default(c)
|
||||
user := session.Get(globals.UserKey)
|
||||
storyArcs, err := handler.Service.List(c.Request.Context())
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.HTML(http.StatusOK, "StoryArcs", gin.H{
|
||||
"title": "Kontor StoryArcs",
|
||||
"version": "0.4.0",
|
||||
"message": "StoryArcs...",
|
||||
"storyArcs": storyArcs,
|
||||
"user": user,
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user