This commit is contained in:
Fran Jurmanović
2024-09-30 22:00:15 +02:00
parent 518ce27d7c
commit 14a689ad76
19 changed files with 968 additions and 0 deletions

View File

@@ -0,0 +1,51 @@
package controller
import (
"encoding/json"
"rockhu-bot/local/service"
"rockhu-bot/local/utl/common"
"github.com/gofiber/fiber/v2"
)
type ConcertController struct {
service *service.ConcertService
}
// NewConcertController
// Initializes ConcertController.
//
// Args:
// *services.ConcertService: Concert service
// *Fiber.RouterGroup: Fiber Router Group
// Returns:
// *ConcertController: Controller for "Concert" interactions
func NewConcertController(as *service.ConcertService, routeGroups *common.RouteGroups) *ConcertController {
ac := &ConcertController{
service: as,
}
routeGroups.Concert.Get("/", ac.getAll)
return ac
}
// getAll returns Concert
//
// @Summary Return Concert
// @Description Return Concert
// @Tags Concert
// @Success 200 {array} string
// @Router /v1/Concert [get]
func (ac *ConcertController) getAll(c *fiber.Ctx) error {
ConcertModel := ac.service.GetAll(c.UserContext())
model, err := json.Marshal(ConcertModel)
if err != nil {
return c.SendStatus(400)
}
return c.Send(model)
}
type Service struct {
Name string `json:"name" xml:"name" form:"name"`
}

View File

@@ -0,0 +1,21 @@
package controller
import (
"rockhu-bot/local/service"
"go.uber.org/dig"
)
// InitializeControllers
// Initializes Dependency Injection modules and registers controllers
//
// Args:
// *dig.Container: Dig Container
func InitializeControllers(c *dig.Container) {
service.InitializeServices(c)
err := c.Invoke(NewConcertController)
if err != nil {
panic("unable to initialize Concert controller")
}
}