Skip to content

Commit

Permalink
Merge branch 'main' into Club-Search-(SAC31+SAC32)
Browse files Browse the repository at this point in the history
  • Loading branch information
garrettladley authored Mar 17, 2024
2 parents faca3cd + d3b373f commit e137152
Show file tree
Hide file tree
Showing 34 changed files with 2,329 additions and 750 deletions.
5 changes: 4 additions & 1 deletion backend/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ require (
github.com/awnumar/memcall v0.2.0 // indirect
github.com/awnumar/memguard v0.22.4 // indirect
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 // indirect
github.com/jackc/puddle/v2 v2.2.1 // indirect
github.com/philhofer/fwd v1.1.2 // indirect
github.com/tinylib/msgp v1.1.8 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/sync v0.6.0 // indirect
)

require (
Expand All @@ -45,7 +48,7 @@ require (
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
github.com/jackc/pgx/v5 v5.4.3 // indirect
github.com/jackc/pgx/v5 v5.5.4 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/joho/godotenv v1.5.1
Expand Down
8 changes: 6 additions & 2 deletions backend/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@ github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsI
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a h1:bbPeKD0xmW/Y25WS6cokEszi5g+S0QxI/d45PkRi7Nk=
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
github.com/jackc/pgx/v5 v5.4.3 h1:cxFyXhxlvAifxnkKKdlxv8XqUf59tDlYjnV5YYfsJJY=
github.com/jackc/pgx/v5 v5.4.3/go.mod h1:Ig06C2Vu0t5qXC60W8sqIthScaEnFvojjj9dSljmHRA=
github.com/jackc/pgx/v5 v5.5.4 h1:Xp2aQS8uXButQdnCMWNmvx6UysWQQC+u1EoizjguY+8=
github.com/jackc/pgx/v5 v5.5.4/go.mod h1:ez9gk+OAat140fv9ErkZDYFWmXLfV+++K0uAOiwgm1A=
github.com/jackc/puddle/v2 v2.2.1 h1:RhxXJtFG022u4ibrCSMSiu5aOq1i77R3OHKNJj77OAk=
github.com/jackc/puddle/v2 v2.2.1/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
Expand Down Expand Up @@ -166,6 +168,8 @@ golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand Down
38 changes: 35 additions & 3 deletions backend/src/controllers/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,14 @@ func (e *EventController) UpdateEvent(c *fiber.Ctx) error {
// UpdateSeriesByID godoc
//
// @Summary Update a series by ID
// @Description Updates a series by ID
// @Description Updates a series by ID. If individual events have been edited prior,
//
// this update will override the previous changes
//
// @ID update-series-by-id
// @Tags event
// @Accept json
// @Produce json
// @Param eventID path string true "Event ID"
// @Param seriesID path string true "Series ID"
// @Param seriesBody body models.UpdateSeriesRequestBody true "Series Body"
// @Success 200 {object} models.Series
Expand All @@ -192,7 +194,37 @@ func (e *EventController) UpdateSeriesByID(c *fiber.Ctx) error {
return errors.FailedToParseRequestBody.FiberError(c)
}

updatedSeries, err := e.eventService.UpdateSeries(c.Params("eventID"), c.Params("seriesID"), seriesBody)
updatedSeries, err := e.eventService.UpdateSeries(c.Params("seriesID"), seriesBody)
if err != nil {
return err.FiberError(c)
}

return c.Status(fiber.StatusOK).JSON(updatedSeries)
}

// UpdateSeriesByEventID godoc
//
// @Summary Update a series by event ID
// @Description Updates a series by event ID
// @ID update-series-by-event-id
// @Tags event
// @Accept json
// @Produce json
// @Param eventID path string true "Event ID"
// @Param seriesBody body models.UpdateSeriesRequestBody true "Series Body"
// @Success 200 {object} models.Series
// @Failure 400 {object} errors.Error
// @Failure 401 {object} errors.Error
// @Failure 404 {object} errors.Error
// @Failure 500 {object} errors.Error
// @Router /events/{eventID}/series/{seriesID}/ [patch]
func (e *EventController) UpdateSeriesByEventID(c *fiber.Ctx) error {
var seriesBody models.UpdateSeriesRequestBody
if err := c.BodyParser(&seriesBody); err != nil {
return errors.FailedToParseRequestBody.FiberError(c)
}

updatedSeries, err := e.eventService.UpdateSeriesByEventID(c.Params("eventID"), seriesBody)
if err != nil {
return err.FiberError(c)
}
Expand Down
24 changes: 24 additions & 0 deletions backend/src/controllers/user_tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,27 @@ func (ut *UserTagController) CreateUserTags(c *fiber.Ctx) error {

return c.Status(fiber.StatusCreated).JSON(&tags)
}

// DeleteUserTag godoc
//
// @Summary Create user tags
// @Description Creates tags for a user
// @ID create-user-tags
// @Tags user-tag
// @Accept json
// @Produce json
// @Param userID path string true "User ID"
// @Success 201 {object} []models.Tag
// @Failure 400 {object} errors.Error
// @Failure 401 {object} errors.Error
// @Failure 404 {object} errors.Error
// @Failure 500 {object} errors.Error
// @Router /users/{userID}/tags/ [post]
func (ut *UserTagController) DeleteUserTag(c *fiber.Ctx) error {
err := ut.userTagService.DeleteUserTag(c.Params("userID"), c.Params("tagID"))
if err != nil {
return err.FiberError(c)
}

return c.SendStatus(fiber.StatusNoContent)
}
5 changes: 2 additions & 3 deletions backend/src/database/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,13 @@ func MigrateDB(settings config.Settings, db *gorm.DB) error {
&models.Category{},
&models.Club{},
&models.Contact{},
&models.Series{},
&models.Event{},
&models.EventSeries{},
&models.Notification{},
&models.PointOfContact{},
&models.Tag{},
&models.User{},
&models.Series{},
&models.EventInstanceException{},
&models.EventSeries{},
&models.Membership{},
)
if err != nil {
Expand Down
64 changes: 37 additions & 27 deletions backend/src/models/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ type Event struct {
StartTime time.Time `gorm:"type:timestamptz" json:"start_time" validate:"required,ltecsfield=EndTime"`
EndTime time.Time `gorm:"type:timestamptz" json:"end_time" validate:"required,gtecsfield=StartTime"`
Location string `gorm:"type:varchar(255)" json:"location" validate:"required,max=255"`
EventType EventType `gorm:"type:varchar(255);default:open" json:"event_type" validate:"required,max=255"`
EventType EventType `gorm:"type:varchar(255);default:open" json:"event_type" validate:"required,max=255,oneof=open membersOnly"`
IsRecurring bool `gorm:"not null;type:bool;default:false" json:"is_recurring" validate:"-"`

ParentEvent *uuid.UUID `gorm:"foreignKey:ParentEvent" json:"-" validate:"uuid4"`
// SeriesID *uuid.UUID `json:"series_id" validate:"uuid4"`
RSVP []User `gorm:"many2many:user_event_rsvps;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;" json:"-" validate:"-"`
Waitlist []User `gorm:"many2many:user_event_waitlists;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;" json:"-" validate:"-"`
Club []Club `gorm:"many2many:club_events;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;" json:"-" validate:"-"`
Expand All @@ -49,17 +49,18 @@ type Series struct {
DayOfWeek int `gorm:"type:int" json:"day_of_week" validate:"min=1,max=7"`
WeekOfMonth int `gorm:"type:int" json:"week_of_month" validate:"min=1,max=5"`
DayOfMonth int `gorm:"type:int" json:"day_of_month" validate:"min=1,max=31"`
Events []Event `gorm:"many2many:event_series" json:"events" validate:"-"`
Events []Event `gorm:"many2many:event_series;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;" json:"events" validate:"-"`
}

// TODO: add not null to required fields on all gorm models
type EventSeries struct {
EventID uuid.UUID `gorm:"not null; type:uuid; primaryKey;" json:"event_id" validate:"uuid4"`
EventID uuid.UUID `gorm:"not null; type:uuid;" json:"event_id" validate:"uuid4"`
Event Event `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;" json:"-" validate:"-"`
SeriesID uuid.UUID `gorm:"not null; type:uuid;" json:"series_id" validate:"uuid4"`
Series Series `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;" json:"-" validate:"-"`
}

// Not needed for now, we will just update the events separately
type EventInstanceException struct {
Model
EventID int `gorm:"not null; type:uuid" json:"event_id" validate:"required"`
Expand All @@ -70,15 +71,6 @@ type EventInstanceException struct {
EndTime time.Time `gorm:"type:timestamptz" json:"end_time" validate:"required,datetime,gtecsfield=StartTime"`
}

type CreateSeriesRequestBody struct {
RecurringType RecurringType `json:"recurring_type" validate:"max=255"`
SeparationCount int `json:"separation_count" validate:"min=0"`
MaxOccurrences int `json:"max_occurrences" validate:"min=2"`
DayOfWeek int `json:"day_of_week" validate:"min=1,max=7"`
WeekOfMonth int `json:"week_of_month" validate:"min=1,max=5"`
DayOfMonth int `json:"day_of_month" validate:"min=1,max=31"`
}

// TODO We will likely need to update the create and update structs to account for recurring series
type CreateEventRequestBody struct {
Name string `json:"name" validate:"required,max=255"`
Expand All @@ -87,7 +79,7 @@ type CreateEventRequestBody struct {
StartTime time.Time `json:"start_time" validate:"required,ltecsfield=EndTime"`
EndTime time.Time `json:"end_time" validate:"required,gtecsfield=StartTime"`
Location string `json:"location" validate:"required,max=255"`
EventType EventType `json:"event_type" validate:"required,max=255"`
EventType EventType `json:"event_type" validate:"required,max=255,oneof=open membersOnly"`
IsRecurring *bool `json:"is_recurring" validate:"required"`

// TODO club/tag/notification logic
Expand All @@ -99,21 +91,39 @@ type CreateEventRequestBody struct {
Series CreateSeriesRequestBody `json:"series" validate:"-"`
}

type CreateSeriesRequestBody struct {
RecurringType RecurringType `json:"recurring_type" validate:"required,max=255,oneof=daily weekly monthly"`
SeparationCount int `json:"separation_count" validate:"required,min=0"`
MaxOccurrences int `json:"max_occurrences" validate:"required,min=2"`
DayOfWeek int `json:"day_of_week" validate:"required,min=1,max=7"`
WeekOfMonth int `json:"week_of_month" validate:"required,min=1,max=5"`
DayOfMonth int `json:"day_of_month" validate:"required,min=1,max=31"`
}

type UpdateEventRequestBody struct {
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"`
Name string `json:"name" validate:"omitempty,max=255"`
Preview string `json:"preview" validate:"omitempty,max=255"`
Content string `json:"content" validate:"omitempty,max=255"`
StartTime time.Time `json:"start_time" validate:"omitempty,ltecsfield=EndTime"`
EndTime time.Time `json:"end_time" validate:"omitempty,gtecsfield=StartTime"`
Location string `json:"location" validate:"omitempty,max=255"`
EventType EventType `gorm:"type:varchar(255);default:open" json:"event_type" validate:"omitempty,max=255,oneof=open membersOnly"`

RSVP []User `json:"-" validate:"omitempty"`
Waitlist []User `json:"-" validate:"omitempty"`
Club []Club `json:"-" validate:"omitempty"`
Tag []Tag `json:"-" validate:"omitempty"`
Notification []Notification `json:"-" validate:"omitempty"`
}

// TODO: probably need to make changes to this to update the events as well
type UpdateSeriesRequestBody struct {
RecurringType RecurringType `json:"recurring_type" validate:"max=255"`
SeparationCount int `json:"separation_count" validate:"min=0"`
MaxOccurrences int `json:"max_occurrences" validate:"min=2"`
DayOfWeek int `json:"day_of_week" validate:"min=1,max=7"`
WeekOfMonth int `json:"week_of_month" validate:"min=1,max=5"`
DayOfMonth int `json:"day_of_month" validate:"min=1,max=31"`
RecurringType RecurringType `json:"recurring_type" validate:"omitempty,max=255,oneof=daily weekly monthly"`
SeparationCount int `json:"separation_count" validate:"omitempty,min=0"`
MaxOccurrences int `json:"max_occurrences" validate:"omitempty,min=2"`
DayOfWeek int `json:"day_of_week" validate:"omitempty,min=1,max=7"`
WeekOfMonth int `json:"week_of_month" validate:"omitempty,min=1,max=5"`
DayOfMonth int `json:"day_of_month" validate:"omitempty,min=1,max=31"`

EventDetails UpdateEventRequestBody `json:"event_details" validate:"omitempty"`
}
14 changes: 7 additions & 7 deletions backend/src/server/routes/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ func Event(router fiber.Router, eventService services.EventServiceInterface, aut
eventID := events.Group("/:eventID")

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

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

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

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

seriesID.Get("/", eventController.GetSeriesByID)
Expand Down
3 changes: 3 additions & 0 deletions backend/src/server/routes/user_tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ func UserTag(usersRouter fiber.Router, userTagService services.UserTagServiceInt

userTags.Post("/", userTagController.CreateUserTags)
userTags.Get("/", userTagController.GetUserTags)

tagID := userTags.Group("/:tagID")
tagID.Delete("/", userTagController.DeleteUserTag)
}
Loading

0 comments on commit e137152

Please sign in to comment.