Skip to content

Commit

Permalink
bandaid fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
garrettladley committed Feb 13, 2024
1 parent 51feb45 commit 1a5eebf
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 29 deletions.
5 changes: 5 additions & 0 deletions backend/src/server/routes/club.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,10 @@ func Club(router fiber.Router, clubService services.ClubServiceInterface, middle
clubsID.Patch("/", middlewareService.Authorize(types.ClubWrite), clubController.UpdateClub)
clubsID.Delete("/", middlewareService.Authorize(types.ClubDelete), clubController.DeleteClub)

// TODO: refactor into club_event vertical (controller <-> service <-> model)
// api/v1/clubs/:clubID/events/*
events := clubsID.Group("/events")
events.Get("/", clubController.GetClubEvents)

return clubsID
}
21 changes: 21 additions & 0 deletions backend/src/server/routes/event.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package routes

import (
"github.com/GenerateNU/sac/backend/src/controllers"
"github.com/GenerateNU/sac/backend/src/services"
"github.com/gofiber/fiber/v2"
)

func Event(router fiber.Router, eventService services.EventServiceInterface) {
eventController := controllers.NewEventController(eventService)

events := router.Group("/events")

events.Get("/:id", eventController.GetEvent)
events.Get("/:id/series", eventController.GetSeriesByEventId)
events.Get("/", eventController.GetAllEvents)
events.Post("/", eventController.CreateEvent)
events.Patch("/:id", eventController.UpdateEvent)
events.Delete("/:id", eventController.DeleteEvent)
events.Delete("/:id/series", eventController.DeleteEventSeries)
}
25 changes: 2 additions & 23 deletions backend/src/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ func Init(db *gorm.DB, settings config.Settings) *fiber.App {
apiv1 := app.Group("/api/v1")
apiv1.Use(middlewareService.Authenticate)


eventRoutes(apiv1, &services.EventService{DB: db, Validate: validate})
routes.Utility(app)

routes.Auth(apiv1, services.NewAuthService(db, validate), settings.Auth)
Expand All @@ -60,6 +58,8 @@ func Init(db *gorm.DB, settings config.Settings) *fiber.App {
categoryRouter := routes.Category(apiv1, services.NewCategoryService(db, validate))
routes.CategoryTag(categoryRouter, services.NewCategoryTagService(db, validate))

routes.Event(apiv1, services.NewEventService(db, validate))

return app
}

Expand All @@ -80,24 +80,3 @@ func newFiberApp() *fiber.App {

return app
}


//events := clubs.Group("/:id/events")
//events.Get("/", clubController.GetClubEvents)



func eventRoutes(router fiber.Router, eventService services.EventServiceInterface) {
eventController := controllers.NewEventController(eventService)

events := router.Group("/events")

events.Get("/:id", eventController.GetEvent)
events.Get("/:id/series", eventController.GetSeriesByEventId)
events.Get("/", eventController.GetAllEvents)
events.Post("/", eventController.CreateEvent)
events.Patch("/:id", eventController.UpdateEvent)
events.Delete("/:id", eventController.DeleteEvent)
events.Delete("/:id/series", eventController.DeleteEventSeries)
}

11 changes: 5 additions & 6 deletions backend/src/services/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,17 @@ type EventService struct {
Validate *validator.Validate
}

func NewEventService(db *gorm.DB, validate *validator.Validate) *EventService {
return &EventService{DB: db, Validate: validate}
}

func (c *EventService) GetEvents(limit string, page string) ([]models.Event, *errors.Error) {
limitAsInt, err := utilities.ValidateNonNegative(limit)

if err != nil {
return nil, &errors.FailedToValidateLimit
}

pageAsInt, err := utilities.ValidateNonNegative(page)

if err != nil {
return nil, &errors.FailedToValidatePage
}
Expand All @@ -56,7 +58,6 @@ func (c *EventService) GetClubEvents(id string) ([]models.Event, *errors.Error)
// TODO: add logic for creating the []event here
// TODO Q: should we always return a slice of events? or should we return a slice of events if it's a series and a single event if it's not?
func (c *EventService) CreateEvent(eventBody models.CreateEventRequestBody) ([]models.Event, *errors.Error) {

if err := c.Validate.Struct(eventBody); err != nil {
return nil, &errors.FailedToValidateEvent
}
Expand Down Expand Up @@ -142,17 +143,15 @@ func (c *EventService) DeleteEvent(id string) *errors.Error {
}

func (c *EventService) DeleteEventSeries(id string) *errors.Error {

idAsUUID, err := utilities.ValidateID(id)
if err != nil {
return &errors.FailedToValidateID
}

return transactions.DeleteEventSeries(c.DB, *idAsUUID)

}

//TODO: CreateEventSeries, GetEventSeries, DeleteEventSeries
// TODO: CreateEventSeries, GetEventSeries, DeleteEventSeries

// Helper to create other events in a given series using the given firstEvent
func CreateEventSlice(firstEvent *models.Event, series models.Series) []models.Event {
Expand Down

0 comments on commit 1a5eebf

Please sign in to comment.