Files
Thomas Peetz f5abb44466
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 4s
WIP: Export Kontor DB
2026-09-30 18:55:59 +02:00

50 lines
1.3 KiB
Go

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 IssueworkHandler struct {
Service *service.IssueworkService
}
func NewIssueworkHandler(db *gorm.DB) *IssueworkHandler {
handler := &IssueworkHandler{Service: service.NewIssueworkService(repository.NewIssueworkRepository(db))}
return handler
}
func (handler *IssueworkHandler) List(c *gin.Context) {
issueworks, err := handler.Service.List(c.Request.Context())
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
dtos := models.ConvertIssueworksToDtos(issueworks)
c.JSON(http.StatusOK, dtos)
}
func (handler *IssueworkHandler) ListPage(c *gin.Context) {
session := sessions.Default(c)
user := session.Get(globals.UserKey)
issueworks, err := handler.Service.List(c.Request.Context())
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
c.HTML(http.StatusOK, "Issues", gin.H{
"title": "Kontor Issues",
"version": "0.4.0",
"message": "Issues...",
"issueworks": issueworks,
"user": user,
})
}