diff --git a/src/app/controller/events_controller.go b/src/app/controller/events_controller.go index ce69001..bcd4a98 100644 --- a/src/app/controller/events_controller.go +++ b/src/app/controller/events_controller.go @@ -4,6 +4,7 @@ import ( "strconv" "github.com/gofiber/fiber/v2" + "github.com/jinzhu/copier" "ulmer-furs.de/pretix-proxy/v2/app/service" "ulmer-furs.de/pretix-proxy/v2/app/util" "ulmer-furs.de/pretix-proxy/v2/entities" @@ -32,6 +33,20 @@ func ReturnAllEvents(c *fiber.Ctx) error { return c.SendStatus(200) } +func ReturnAllEventsPublic(c *fiber.Ctx) error { + events, err := service.Get_all_db_event() + if err != nil { + return c.Status(500).SendString("Internal Server Error") + } + publicEvets := new([]entities.Db_Event_Public) + err = copier.Copy(publicEvets, events) + if err != nil { + return c.Status(500).SendString("Internal Server Error") + } + c.JSON(publicEvets) + return c.SendStatus(fiber.StatusOK) +} + func ReturnEventById(c *fiber.Ctx) error { id := c.Params("id") id_int, err := strconv.Atoi(id) diff --git a/src/app/routes/public_routes.go b/src/app/routes/public_routes.go index 503c485..157df84 100644 --- a/src/app/routes/public_routes.go +++ b/src/app/routes/public_routes.go @@ -6,9 +6,10 @@ import ( ) func PublicRoutes(app *fiber.App) { - apiv1 := app.Group("/api/v1") + apiv1 := app.Group("/api/v1/public") attendies := apiv1.Group("/attendies") apiv1.Post("/login", controller.LoginUser) + apiv1.Get("/event", controller.ReturnAllEventsPublic) apiv1.Get("/ping", controller.Ping) attendies.Get("/:name", controller.GetAttendiesByEvent) } diff --git a/src/entities/db_event.go b/src/entities/db_event.go index e0c9509..d386ab6 100644 --- a/src/entities/db_event.go +++ b/src/entities/db_event.go @@ -19,3 +19,9 @@ type Db_Event struct { OptionIdSpecialAnimal string `gorm:"column:option_id_special_animal;not null" validate:"required_if=EnforceRequired true"` EnforceRequired bool `gorm:"-"` } + +type Db_Event_Public struct { + Name string + Organizer string + Event string +} diff --git a/src/go.mod b/src/go.mod index 97013c2..c6ac959 100644 --- a/src/go.mod +++ b/src/go.mod @@ -17,6 +17,7 @@ require ( github.com/go-playground/universal-translator v0.18.1 // indirect github.com/gofiber/contrib/jwt v1.0.7 // indirect github.com/golang-jwt/jwt/v5 v5.1.0 // indirect + github.com/jinzhu/copier v0.4.0 // indirect github.com/leodido/go-urn v1.2.4 // indirect golang.org/x/crypto v0.15.0 // indirect golang.org/x/net v0.10.0 // indirect