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 IssueHandler struct {
|
||||
Service *service.IssueService
|
||||
}
|
||||
|
||||
func NewIssueHandler(db *gorm.DB) *IssueHandler {
|
||||
handler := &IssueHandler{Service: service.NewIssueService(repository.NewIssueRepository(db))}
|
||||
return handler
|
||||
}
|
||||
|
||||
func (handler *IssueHandler) List(c *gin.Context) {
|
||||
issues, err := handler.Service.List(c.Request.Context())
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
dtos := models.ConvertIssuesToDtos(issues)
|
||||
c.JSON(http.StatusOK, dtos)
|
||||
}
|
||||
|
||||
func (handler *IssueHandler) ListPage(c *gin.Context) {
|
||||
session := sessions.Default(c)
|
||||
user := session.Get(globals.UserKey)
|
||||
issues, 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...",
|
||||
"issues": issues,
|
||||
"user": user,
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user