Skip to content

Commit

Permalink
Minor Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Alder Whiteford authored and Alder Whiteford committed Mar 5, 2024
1 parent 6714fab commit 93ba58f
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 131 deletions.
4 changes: 2 additions & 2 deletions backend/src/controllers/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func (e *EventController) CreateEvent(c *fiber.Ctx) error {
return c.Status(fiber.StatusCreated).JSON(event)
}

// CreateSeries godoc
// UpdateEvent godoc
//
// @Summary Create a series
// @Description Creates a series
Expand All @@ -148,7 +148,7 @@ func (e *EventController) CreateEvent(c *fiber.Ctx) error {
// @Accept json
// @Produce json
// @Param eventID path string true "Event ID"
// @Param seriesBody body models.CreateSeriesRequestBody true "Series Body"
// @Param seriesBody body models.UpdateEventRequestBody true "Series Body"
// @Success 201 {object} models.Series
// @Failure 400 {object} errors.Error
// @Failure 401 {object} errors.Error
Expand Down
4 changes: 4 additions & 0 deletions backend/src/errors/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@ var (
StatusCode: fiber.StatusInternalServerError,
Message: "failed to cast to custom claims",
}
FailedToValidateUpdatePasswordBody = Error {

Check failure on line 14 in backend/src/errors/auth.go

View workflow job for this annotation

GitHub Actions / Lint

File is not `goimports`-ed (goimports)

Check failure on line 14 in backend/src/errors/auth.go

View workflow job for this annotation

GitHub Actions / Lint

File is not `goimports`-ed (goimports)
StatusCode: fiber.StatusBadRequest,
Message: "failed to validate update password body",
}
)
20 changes: 7 additions & 13 deletions backend/src/models/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,19 +100,13 @@ type CreateEventRequestBody struct {
}

type UpdateEventRequestBody struct {
Name string `json:"name" validate:"required,max=255"`
Preview string `json:"preview" validate:"required,max=255"`
Content string `json:"content" validate:"required,max=255"`
StartTime time.Time `json:"start_time" validate:"required,datetime,ltecsfield=EndTime"`
EndTime time.Time `json:"end_time" validate:"required,datetime,gtecsfield=StartTime"`
Location string `json:"location" validate:"required,max=255"`
EventType EventType `gorm:"type:varchar(255);default:open" json:"event_type" validate:"required,max=255"`

RSVP []User `json:"-" validate:"-"`
Waitlist []User `json:"-" validate:"-"`
Club []Club `json:"-" validate:"-"`
Tag []Tag `json:"-" validate:"-"`
Notification []Notification `json:"-" validate:"-"`
Name string `json:"name" validate:"max=255"`
Preview string `json:"preview" validate:"max=255"`
Content string `json:"content" validate:"max=255"`
StartTime time.Time `json:"start_time" validate:"ltecsfield=EndTime"`
EndTime time.Time `json:"end_time" validate:"gtecsfield=StartTime"`
Location string `json:"location" validate:"max=255"`
EventType EventType `gorm:"type:varchar(255);default:open" json:"event_type" validate:"max=255"`
}

type UpdateSeriesRequestBody struct {
Expand Down
9 changes: 2 additions & 7 deletions backend/src/server/routes/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,14 @@ func Event(router fiber.Router, eventService services.EventServiceInterface, aut
eventID := events.Group("/:eventID")

eventID.Get("/", eventController.GetEvent)
eventID.Get("/series", eventController.GetSeriesByEventID)
events.Patch("/", authMiddleware.ClubAuthorizeById, eventController.UpdateEvent)
eventID.Patch("/", authMiddleware.ClubAuthorizeById, eventController.UpdateEvent)
eventID.Delete("/", authMiddleware.ClubAuthorizeById, eventController.DeleteEvent)
eventID.Delete("/series", authMiddleware.ClubAuthorizeById, eventController.DeleteSeriesByEventID)

// api/v1/events/:eventID/series/*
series := events.Group("/series")

series.Get("/", eventController.GetSeriesByEventID)
series.Delete("/", eventController.DeleteSeriesByEventID)

series.Get("/", eventController.GetSeriesByEventID)
series.Delete("/", eventController.DeleteSeriesByEventID)
series.Delete("/", authMiddleware.ClubAuthorizeById, eventController.DeleteSeriesByEventID)

// api/v1/events/:eventID/series/:seriesID/*
seriesID := series.Group("/:seriesID")
Expand Down
9 changes: 6 additions & 3 deletions backend/src/server/routes/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ func Tag(router fiber.Router, tagService services.TagServiceInterface, authMiddl
tags := router.Group("/tags")

tags.Get("/", tagController.GetTags)
tags.Get("/:tagID", tagController.GetTag)
tags.Post("/", authMiddleware.Authorize(p.CreateAll), tagController.CreateTag)
tags.Patch("/:tagID", authMiddleware.Authorize(p.WriteAll), tagController.UpdateTag)
tags.Delete("/:tagID", authMiddleware.Authorize(p.DeleteAll), tagController.DeleteTag)

tagID := tags.Group("/:tagID");

Check failure on line 19 in backend/src/server/routes/tag.go

View workflow job for this annotation

GitHub Actions / Lint

File is not `goimports`-ed (goimports)

Check failure on line 19 in backend/src/server/routes/tag.go

View workflow job for this annotation

GitHub Actions / Lint

File is not `goimports`-ed (goimports)

tagID.Get("/", tagController.GetTag)
tagID.Patch("/", authMiddleware.Authorize(p.WriteAll), tagController.UpdateTag)
tagID.Delete("/", authMiddleware.Authorize(p.DeleteAll), tagController.DeleteTag)
}
2 changes: 1 addition & 1 deletion backend/src/services/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (a *AuthService) UpdatePassword(id string, passwordBody models.UpdatePasswo

// TODO: Validate password
if err := a.Validate.Struct(passwordBody); err != nil {
return &errors.FailedToValidateUser
return &errors.FailedToValidateUpdatePasswordBody
}

passwordHash, err := transactions.GetUserPasswordHash(a.DB, *idAsUint)
Expand Down
9 changes: 7 additions & 2 deletions backend/src/transactions/club_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@ import (
)

func GetClubEvents(db *gorm.DB, clubID uuid.UUID, limit int, offset int) ([]models.Event, *errors.Error) {
club, err := GetClub(db, clubID)
if err != nil {
return nil, err
}

var events []models.Event

if err := db.Where("club_id = ?", clubID).Limit(limit).Offset(offset).Find(&events).Error; err != nil {
return nil, &errors.FailedToGetEvents
if err := db.Model(&club).Association("Event").Find(&events); err != nil {
return nil, &errors.FailedToGetClubMembers
}

return events, nil
Expand Down
Loading

0 comments on commit 93ba58f

Please sign in to comment.