add tysc handlers to kontor-gin
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"kontor-api-gin/internal/repository"
|
||||
"kontor-api-gin/internal/service"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type AdminHandler struct {
|
||||
AuthHandler *AuthHandler
|
||||
PermissionHandler *PermissionHandler
|
||||
Secret []byte
|
||||
}
|
||||
|
||||
func NewAdminHandler(db *gorm.DB, secret []byte) *AdminHandler {
|
||||
adminHandler := &AdminHandler{
|
||||
AuthHandler: &AuthHandler{Service: service.NewAuthService(repository.NewProfileRepository(db), secret)},
|
||||
PermissionHandler: &PermissionHandler{Service: service.NewPermissionService(repository.NewPermissionRepository(db))},
|
||||
Secret: secret,
|
||||
}
|
||||
return adminHandler
|
||||
}
|
||||
@@ -1,23 +1,128 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"kontor-api-gin/internal/globals"
|
||||
"kontor-api-gin/internal/helpers"
|
||||
"kontor-api-gin/internal/models"
|
||||
"kontor-api-gin/internal/service"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-contrib/sessions"
|
||||
"github.com/gin-contrib/slog"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type AuthHandler struct {
|
||||
Service *service.AuthService
|
||||
Secret []byte
|
||||
}
|
||||
|
||||
func (handler *AuthHandler) Login(c *gin.Context) {
|
||||
token, err := helpers.GenerateToken("bla")
|
||||
var input models.LoginInput
|
||||
|
||||
if err := c.ShouldBindJSON(&input); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
proile_id, err := handler.Service.LoginCheck(input.Email, input.Password)
|
||||
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "username or password is incorrect."})
|
||||
return
|
||||
}
|
||||
|
||||
token, err := helpers.GenerateToken(proile_id)
|
||||
logger := slog.Get(c)
|
||||
if err != nil {
|
||||
logger.Info("Login", "GenerateToken error", err.Error())
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"token": token})
|
||||
}
|
||||
|
||||
func (handler *AuthHandler) LoginPage(c *gin.Context) {
|
||||
session := sessions.Default(c)
|
||||
user := session.Get(globals.UserKey)
|
||||
logger := slog.Get(c)
|
||||
logger.Info("LoginPage", globals.UserKey, user)
|
||||
if user != nil {
|
||||
c.HTML(http.StatusBadRequest, "login", gin.H{
|
||||
"title": "Kontor Gin",
|
||||
"version": "0.4.0",
|
||||
"message": "Please logout first",
|
||||
"user": user,
|
||||
})
|
||||
return
|
||||
}
|
||||
c.HTML(http.StatusOK, "login", gin.H{
|
||||
"title": "Kontor Gin",
|
||||
"version": "0.4.0",
|
||||
"message": "",
|
||||
"user": user,
|
||||
})
|
||||
}
|
||||
|
||||
func (handler *AuthHandler) LoginPost(c *gin.Context) {
|
||||
session := sessions.Default(c)
|
||||
user := session.Get(globals.UserKey)
|
||||
logger := slog.Get(c)
|
||||
logger.Info("LoginPost", "user", user)
|
||||
if user != nil {
|
||||
c.HTML(http.StatusBadRequest, "login", gin.H{
|
||||
"title": "Kontor Gin",
|
||||
"version": "0.4.0",
|
||||
"message": "Please logout first",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
username := c.PostForm("username")
|
||||
password := c.PostForm("password")
|
||||
|
||||
if helpers.EmptyUserPass(username, password) {
|
||||
c.HTML(http.StatusBadRequest, "login", gin.H{
|
||||
"title": "Kontor Gin",
|
||||
"version": "0.4.0",
|
||||
"message": "Parameters can't be empty",
|
||||
})
|
||||
}
|
||||
|
||||
proile_id, err := handler.Service.LoginCheck(username, password)
|
||||
if err != nil {
|
||||
c.HTML(http.StatusUnauthorized, "login", gin.H{
|
||||
"title": "Kontor Gin",
|
||||
"version": "0.4.0",
|
||||
"message": "Incorrect username or password",
|
||||
})
|
||||
}
|
||||
|
||||
session.Set(globals.UserKey, proile_id)
|
||||
if err := session.Save(); err != nil {
|
||||
c.HTML(http.StatusInternalServerError, "login", gin.H{
|
||||
"title": "Kontor Gin",
|
||||
"version": "0.4.0",
|
||||
"message": "Failed to save session",
|
||||
})
|
||||
return
|
||||
}
|
||||
logger.Info("LoginPost: redirect to index")
|
||||
c.Redirect(http.StatusMovedPermanently, "/")
|
||||
}
|
||||
|
||||
func (handler *AuthHandler) LogoutPage(c *gin.Context) {
|
||||
session := sessions.Default(c)
|
||||
user := session.Get(globals.UserKey)
|
||||
logger := slog.Get(c)
|
||||
logger.Info("LogoutPage", globals.UserKey, user)
|
||||
if user == nil {
|
||||
logger.Info("Invalid session token")
|
||||
return
|
||||
}
|
||||
session.Delete(globals.UserKey)
|
||||
if err := session.Save(); err != nil {
|
||||
logger.Info("Failed to save session", "error", err)
|
||||
return
|
||||
}
|
||||
logger.Info("LogoutPage: redirect to index page")
|
||||
c.Redirect(http.StatusMovedPermanently, "/")
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"kontor-api-gin/internal/globals"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/gin-contrib/sessions"
|
||||
"github.com/gin-contrib/slog"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func Health(c *gin.Context) {
|
||||
c.JSON(200, gin.H{
|
||||
"ok": true,
|
||||
"status": "healthy",
|
||||
"version": globals.Version,
|
||||
"time": time.Now().UTC().Format(time.RFC3339),
|
||||
})
|
||||
}
|
||||
|
||||
func Index(c *gin.Context) {
|
||||
session := sessions.Default(c)
|
||||
user := session.Get(globals.UserKey)
|
||||
logger := slog.Get(c)
|
||||
logger.Info("IndexGetHandler", globals.UserKey, user)
|
||||
c.HTML(http.StatusOK, "home", gin.H{
|
||||
"title": "Kontor Gin",
|
||||
"version": "0.4.0",
|
||||
"message": "This is an index page...",
|
||||
"user": user,
|
||||
})
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"kontor-api-gin/internal/repository"
|
||||
"kontor-api-gin/internal/service"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type MediaHandler struct {
|
||||
MediaActorHandler *MediaActorHandler
|
||||
MediaFileHandler *MediaFileHandler
|
||||
MediaLoFiHandler *MediaLoFiHandler
|
||||
}
|
||||
|
||||
func NewMediaHandler(db *gorm.DB) *MediaHandler {
|
||||
mediaHandler := &MediaHandler{
|
||||
MediaActorHandler: &MediaActorHandler{Service: service.NewMediaActorService(repository.NewMediaActorRepository(db))},
|
||||
MediaFileHandler: &MediaFileHandler{Service: service.NewMediaFileService(repository.NewMediaFileRepository(db))},
|
||||
MediaLoFiHandler: &MediaLoFiHandler{Service: service.NewMediaLoFiService(repository.NewMediaLoFiRepository(db))},
|
||||
}
|
||||
return mediaHandler
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
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 MediaActorHandler struct {
|
||||
Service *service.MediaActorService
|
||||
}
|
||||
|
||||
func NewMediaActorHandler(db *gorm.DB) *MediaActorHandler {
|
||||
mediaActorHandler := &MediaActorHandler{
|
||||
Service: service.NewMediaActorService(repository.NewMediaActorRepository(db)),
|
||||
}
|
||||
return mediaActorHandler
|
||||
}
|
||||
|
||||
func (handler *MediaActorHandler) List(c *gin.Context) {
|
||||
lofis, err := handler.Service.List(c.Request.Context())
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
dtos := models.ConvertMediaActorsToDtos(lofis)
|
||||
c.JSON(http.StatusOK, dtos)
|
||||
}
|
||||
|
||||
func (handler *MediaActorHandler) ListPage(c *gin.Context) {
|
||||
session := sessions.Default(c)
|
||||
user := session.Get(globals.UserKey)
|
||||
actors, err := handler.Service.List(c.Request.Context())
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.HTML(http.StatusOK, "mediaactors", gin.H{
|
||||
"title": "Kontor MediaActors",
|
||||
"version": "0.4.0",
|
||||
"message": "MediaActors...",
|
||||
"actors": actors,
|
||||
"user": user,
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
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-contrib/slog"
|
||||
"github.com/gin-gonic/gin"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type MediaFileHandler struct {
|
||||
Service *service.MediaFileService
|
||||
}
|
||||
|
||||
func NewMediaFileHandler(db *gorm.DB) *MediaFileHandler {
|
||||
mediaFileHandler := &MediaFileHandler{
|
||||
Service: service.NewMediaFileService(repository.NewMediaFileRepository(db)),
|
||||
}
|
||||
return mediaFileHandler
|
||||
}
|
||||
|
||||
func (handler *MediaFileHandler) List(c *gin.Context) {
|
||||
logger := slog.Get(c)
|
||||
logger.Info("MediaFileHandler#List")
|
||||
files, err := handler.Service.List(c.Request.Context())
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
dtos := models.ConvertMediaFilesToDtos(files)
|
||||
c.JSON(http.StatusOK, dtos)
|
||||
}
|
||||
|
||||
func (handler *MediaFileHandler) ListPage(c *gin.Context) {
|
||||
session := sessions.Default(c)
|
||||
user := session.Get(globals.UserKey)
|
||||
files, err := handler.Service.List(c.Request.Context())
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.HTML(http.StatusOK, "mediafiles", gin.H{
|
||||
"title": "Kontor MediaFiles",
|
||||
"version": "0.4.0",
|
||||
"message": "MediaFiles...",
|
||||
"mediafiles": files,
|
||||
"user": user,
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
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 MediaLoFiHandler struct {
|
||||
Service *service.MediaLoFiService
|
||||
}
|
||||
|
||||
func NewMediaLoFiHandler(db *gorm.DB) *MediaLoFiHandler {
|
||||
mediaLoFiHandler := &MediaLoFiHandler{
|
||||
Service: service.NewMediaLoFiService(repository.NewMediaLoFiRepository(db)),
|
||||
}
|
||||
return mediaLoFiHandler
|
||||
}
|
||||
|
||||
func (handler *MediaLoFiHandler) List(c *gin.Context) {
|
||||
lofis, err := handler.Service.List(c.Request.Context())
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
dtos := models.ConvertMediaLoFisToDtos(lofis)
|
||||
c.JSON(http.StatusOK, dtos)
|
||||
}
|
||||
|
||||
func (handler *MediaLoFiHandler) ListPage(c *gin.Context) {
|
||||
session := sessions.Default(c)
|
||||
user := session.Get(globals.UserKey)
|
||||
lofis, err := handler.Service.List(c.Request.Context())
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.HTML(http.StatusOK, "lofi", gin.H{
|
||||
"title": "Kontor MediaFiles",
|
||||
"version": "0.4.0",
|
||||
"message": "MediaFiles...",
|
||||
"lofis": lofis,
|
||||
"user": user,
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"kontor-api-gin/internal/service"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type PermissionHandler struct {
|
||||
Service *service.PermissionService
|
||||
}
|
||||
|
||||
func (handler *PermissionHandler) List(c *gin.Context) {
|
||||
permissions, err := handler.Service.List(c.Request.Context())
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, permissions)
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"kontor-api-gin/internal/models"
|
||||
"kontor-api-gin/internal/service"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type PlayerHandler struct {
|
||||
Service *service.PlayerService
|
||||
}
|
||||
|
||||
func (handler *PlayerHandler) List(c *gin.Context) {
|
||||
players, err := handler.Service.List(c.Request.Context())
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
dtos := models.ConvertPlayersToDtos(players)
|
||||
c.JSON(http.StatusOK, dtos)
|
||||
}
|
||||
|
||||
func (handler *PlayerHandler) Get(c *gin.Context) {
|
||||
id := c.Param("id")
|
||||
player, err := handler.Service.Get(c.Request.Context(), id)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "player not found"})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, player)
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"kontor-api-gin/internal/models"
|
||||
"kontor-api-gin/internal/service"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type PositionHandler struct {
|
||||
Service *service.PositionService
|
||||
}
|
||||
|
||||
func (handler *PositionHandler) List(c *gin.Context) {
|
||||
positions, err := handler.Service.List(c.Request.Context())
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
dtos := models.ConvertPositionsToDtos(positions)
|
||||
c.JSON(http.StatusOK, dtos)
|
||||
}
|
||||
|
||||
func (handler *PositionHandler) Get(c *gin.Context) {
|
||||
id := c.Param("id")
|
||||
position, err := handler.Service.Get(c.Request.Context(), id)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "position not found"})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, position)
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"kontor-api-gin/internal/models"
|
||||
"kontor-api-gin/internal/service"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type PublisherHandler struct {
|
||||
Service *service.PublisherService
|
||||
}
|
||||
|
||||
func (handler *PublisherHandler) List(c *gin.Context) {
|
||||
comics, err := handler.Service.List(c.Request.Context())
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
dtos := models.ConvertPublishersToDtos(comics)
|
||||
c.JSON(http.StatusOK, dtos)
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"kontor-api-gin/internal/models"
|
||||
"kontor-api-gin/internal/service"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type SportHandler struct {
|
||||
Service *service.SportService
|
||||
}
|
||||
|
||||
func (handler *SportHandler) List(c *gin.Context) {
|
||||
sports, err := handler.Service.List(c.Request.Context())
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
dtos := models.ConvertSportsToDtos(sports)
|
||||
c.JSON(http.StatusOK, dtos)
|
||||
}
|
||||
|
||||
func (handler *SportHandler) Get(c *gin.Context) {
|
||||
id := c.Param("id")
|
||||
sport, err := handler.Service.Get(c.Request.Context(), id)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "sport not found"})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, sport)
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"kontor-api-gin/internal/models"
|
||||
"kontor-api-gin/internal/service"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type TeamHandler struct {
|
||||
Service *service.TeamService
|
||||
}
|
||||
|
||||
func (handler *TeamHandler) List(c *gin.Context) {
|
||||
teams, err := handler.Service.List(c.Request.Context())
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
dtos := models.ConvertTeamsToDtos(teams)
|
||||
c.JSON(http.StatusOK, dtos)
|
||||
}
|
||||
|
||||
func (handler *TeamHandler) Get(c *gin.Context) {
|
||||
id := c.Param("id")
|
||||
team, err := handler.Service.Get(c.Request.Context(), id)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "team not found"})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, team)
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"kontor-api-gin/internal/repository"
|
||||
"kontor-api-gin/internal/service"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type TyscHandler struct {
|
||||
SportHandler *SportHandler
|
||||
PlayerHandler *PlayerHandler
|
||||
TeamHandler *TeamHandler
|
||||
PositionHandler *PositionHandler
|
||||
// RoosterHandler *RoosterHandler
|
||||
// VendorHandler *VendorHandler
|
||||
// CardSetHandler *CardSetHandler
|
||||
// CardHandler *CardHandler
|
||||
}
|
||||
|
||||
func NewTyscHandler(db *gorm.DB) *TyscHandler {
|
||||
handlerMap := &TyscHandler{
|
||||
SportHandler: &SportHandler{Service: service.NewSportService(repository.NewSportRepository(db))},
|
||||
PlayerHandler: &PlayerHandler{Service: service.NewPlayerService(repository.NewPlayerRepository(db))},
|
||||
TeamHandler: &TeamHandler{Service: service.NewTeamService(repository.NewTeamRepository(db))},
|
||||
PositionHandler: &PositionHandler{Service: service.NewPositionService(repository.NewPositionRepository(db))},
|
||||
}
|
||||
return handlerMap
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"kontor-api-gin/internal/repository"
|
||||
"kontor-api-gin/internal/service"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type WebAppHandler struct {
|
||||
AuthHandler *AuthHandler
|
||||
ComicHandler *ComicHandler
|
||||
}
|
||||
|
||||
func NewWebAppHandler(db *gorm.DB, secret []byte) *WebAppHandler {
|
||||
webapp := &WebAppHandler{
|
||||
AuthHandler: &AuthHandler{Service: service.NewAuthService(repository.NewProfileRepository(db), secret)},
|
||||
ComicHandler: &ComicHandler{Service: service.NewComicService(repository.NewComicRepository(db))},
|
||||
}
|
||||
return webapp
|
||||
}
|
||||
Reference in New Issue
Block a user