Skip to content

Commit

Permalink
Merge branch 'main' into club-search
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-brennan2005 committed May 20, 2024
2 parents 9c6ed85 + 21ae854 commit 15ee987
Show file tree
Hide file tree
Showing 37 changed files with 303 additions and 141 deletions.
10 changes: 5 additions & 5 deletions backend/entities/auth/base/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ func (a *AuthController) Register(c *fiber.Ctx) error {

// Refresh godoc
//
// @Summary Refreshes a user's access token
// @Description Refreshes a user's access token
// @Summary Refreshes a user's access token and returns a new pair of tokens
// @Description Refreshes a user's access token and returns a new pair of tokens
// @ID refresh-user
// @Tags auth
// @Accept json
Expand All @@ -100,10 +100,10 @@ func (a *AuthController) Register(c *fiber.Ctx) error {
// @Failure 500 {object} error
// @Router /auth/refresh [post]
func (a *AuthController) Refresh(c *fiber.Ctx) error {
var refreshBody authEntities.RefreshTokenRequestBody
var refreshBody RefreshTokenCookieBody

if err := c.BodyParser(&refreshBody); err != nil {
return utilities.InvalidJSON()
if err := c.CookieParser(&refreshBody); err != nil {
return utilities.InvalidCookies()
}

tokens, err := a.authService.Refresh(refreshBody.RefreshToken)
Expand Down
4 changes: 4 additions & 0 deletions backend/entities/auth/base/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ type VerifyPasswordResetTokenRequestBody struct {
type EmailRequestBody struct {
Email string `json:"email" validate:"required,email"`
}

type RefreshTokenCookieBody struct {
RefreshToken string `cookie:"refresh_token" validate:"required"`
}
3 changes: 1 addition & 2 deletions backend/entities/categories/base/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"github.com/GenerateNU/sac/backend/auth"
"github.com/GenerateNU/sac/backend/entities/categories/tags"
"github.com/GenerateNU/sac/backend/types"
"github.com/garrettladley/fiberpaginate"
"github.com/gofiber/fiber/v2"
)

Expand All @@ -24,7 +23,7 @@ func Category(categoryParams types.RouteParams) fiber.Router {
categories := categoryParams.Router.Group("/categories")

categories.Post("/", categoryParams.AuthMiddleware.Authorize(auth.CreateAll), categoryController.CreateCategory)
categories.Get("/", fiberpaginate.New(), categoryController.GetCategories)
categories.Get("/", categoryParams.UtilityMiddleware.Paginator, categoryController.GetCategories)

// api/v1/categories/:categoryID/*
categoryID := categories.Group("/:categoryID")
Expand Down
3 changes: 1 addition & 2 deletions backend/entities/categories/tags/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package tags

import (
"github.com/GenerateNU/sac/backend/types"
"github.com/garrettladley/fiberpaginate"
)

func CategoryTag(categoryParams types.RouteParams) {
Expand All @@ -11,6 +10,6 @@ func CategoryTag(categoryParams types.RouteParams) {
// api/v1/categories/:categoryID/tags/*
categoryTags := categoryParams.Router.Group("/tags")

categoryTags.Get("/", fiberpaginate.New(), categoryTagController.GetTagsByCategory)
categoryTags.Get("/", categoryParams.UtilityMiddleware.Paginator, categoryTagController.GetTagsByCategory)
categoryTags.Get("/:tagID", categoryTagController.GetTagByCategory)
}
7 changes: 3 additions & 4 deletions backend/entities/clubs/base/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import (
"github.com/GenerateNU/sac/backend/entities/clubs/members"
"github.com/GenerateNU/sac/backend/entities/clubs/pocs"
"github.com/GenerateNU/sac/backend/entities/clubs/tags"
"github.com/GenerateNU/sac/backend/middleware"
"github.com/garrettladley/fiberpaginate"
authMiddleware "github.com/GenerateNU/sac/backend/middleware/auth"

"github.com/GenerateNU/sac/backend/types"
"github.com/gofiber/fiber/v2"
Expand All @@ -32,7 +31,7 @@ func ClubRouter(clubParams types.RouteParams) fiber.Router {
// api/v1/clubs/*
clubs := clubParams.Router.Group("/clubs")

clubs.Get("/", fiberpaginate.New(), clubController.GetClubs)
clubs.Get("/", clubParams.UtilityMiddleware.Paginator, clubController.GetClubs)
clubs.Post("/", clubParams.AuthMiddleware.Authorize(p.CreateAll), clubController.CreateClub)

// api/v1/clubs/:clubID/*
Expand All @@ -41,7 +40,7 @@ func ClubRouter(clubParams types.RouteParams) fiber.Router {
clubID.Get("/", clubController.GetClub)
clubID.Patch(
"/",
middleware.AttachExtractor(clubParams.AuthMiddleware.ClubAuthorizeById, middleware.ExtractFromParams("clubID")),
authMiddleware.AttachExtractor(clubParams.AuthMiddleware.ClubAuthorizeById, authMiddleware.ExtractFromParams("clubID")),
clubController.UpdateClub,
)
clubID.Delete("/", clubParams.AuthMiddleware.Authorize(p.DeleteAll), clubController.DeleteClub)
Expand Down
4 changes: 2 additions & 2 deletions backend/entities/clubs/contacts/routes.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package contacts

import (
"github.com/GenerateNU/sac/backend/middleware"
authMiddleware "github.com/GenerateNU/sac/backend/middleware/auth"
"github.com/GenerateNU/sac/backend/types"
)

Expand All @@ -14,7 +14,7 @@ func ClubContact(clubParams types.RouteParams) {
clubContacts.Get("/", clubContactController.GetClubContacts)
clubContacts.Put(
"/",
middleware.AttachExtractor(clubParams.AuthMiddleware.ClubAuthorizeById, middleware.ExtractFromParams("clubID")),
authMiddleware.AttachExtractor(clubParams.AuthMiddleware.ClubAuthorizeById, authMiddleware.ExtractFromParams("clubID")),
clubContactController.PutContact,
)
}
3 changes: 1 addition & 2 deletions backend/entities/clubs/events/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package events

import (
"github.com/GenerateNU/sac/backend/types"
"github.com/garrettladley/fiberpaginate"
)

func ClubEvent(clubParams types.RouteParams) {
Expand All @@ -11,5 +10,5 @@ func ClubEvent(clubParams types.RouteParams) {
// api/v1/clubs/:clubID/events/*
events := clubParams.Router.Group("/events")

events.Get("/", fiberpaginate.New(), clubEventController.GetClubEvents)
events.Get("/", clubParams.UtilityMiddleware.Paginator, clubEventController.GetClubEvents)
}
3 changes: 1 addition & 2 deletions backend/entities/clubs/followers/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package followers

import (
"github.com/GenerateNU/sac/backend/types"
"github.com/garrettladley/fiberpaginate"
)

func ClubFollower(clubParams types.RouteParams) {
Expand All @@ -11,5 +10,5 @@ func ClubFollower(clubParams types.RouteParams) {
clubFollowers := clubParams.Router.Group("/followers")

// api/clubs/:clubID/followers/*
clubFollowers.Get("/", fiberpaginate.New(), clubFollowerController.GetClubFollowers)
clubFollowers.Get("/", clubParams.UtilityMiddleware.Paginator, clubFollowerController.GetClubFollowers)
}
9 changes: 4 additions & 5 deletions backend/entities/clubs/members/routes.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package members

import (
"github.com/GenerateNU/sac/backend/middleware"
authMiddleware "github.com/GenerateNU/sac/backend/middleware/auth"
"github.com/GenerateNU/sac/backend/types"
"github.com/garrettladley/fiberpaginate"
)

func ClubMember(clubParams types.RouteParams) {
Expand All @@ -12,15 +11,15 @@ func ClubMember(clubParams types.RouteParams) {
clubMembers := clubParams.Router.Group("/members")

// api/v1/clubs/:clubID/members/*
clubMembers.Get("/", fiberpaginate.New(), clubMemberController.GetClubMembers)
clubMembers.Get("/", clubParams.UtilityMiddleware.Paginator, clubMemberController.GetClubMembers)
clubMembers.Post(
"/:userID",
middleware.AttachExtractor(clubParams.AuthMiddleware.ClubAuthorizeById, middleware.ExtractFromParams("clubID")),
authMiddleware.AttachExtractor(clubParams.AuthMiddleware.ClubAuthorizeById, authMiddleware.ExtractFromParams("clubID")),
clubMemberController.CreateClubMember,
)
clubMembers.Delete(
"/:userID",
middleware.AttachExtractor(clubParams.AuthMiddleware.ClubAuthorizeById, middleware.ExtractFromParams("clubID")),
authMiddleware.AttachExtractor(clubParams.AuthMiddleware.ClubAuthorizeById, authMiddleware.ExtractFromParams("clubID")),
clubMemberController.DeleteClubMember,
)
}
10 changes: 5 additions & 5 deletions backend/entities/clubs/pocs/routes.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package pocs

import (
"github.com/GenerateNU/sac/backend/middleware"
authMiddleware "github.com/GenerateNU/sac/backend/middleware/auth"
"github.com/GenerateNU/sac/backend/types"
)

Expand All @@ -15,22 +15,22 @@ func ClubPointOfContact(clubParams types.RouteParams) {
clubPointOfContacts.Get("/:pocID", clubPointOfContactController.GetClubPointOfContact)
clubPointOfContacts.Post(
"/",
middleware.AttachExtractor(clubParams.AuthMiddleware.ClubAuthorizeById, middleware.ExtractFromParams("clubID")),
authMiddleware.AttachExtractor(clubParams.AuthMiddleware.ClubAuthorizeById, authMiddleware.ExtractFromParams("clubID")),
clubPointOfContactController.CreateClubPointOfContact,
)
clubPointOfContacts.Patch(
"/:pocID",
middleware.AttachExtractor(clubParams.AuthMiddleware.ClubAuthorizeById, middleware.ExtractFromParams("clubID")),
authMiddleware.AttachExtractor(clubParams.AuthMiddleware.ClubAuthorizeById, authMiddleware.ExtractFromParams("clubID")),
clubPointOfContactController.UpdateClubPointOfContact,
)
clubPointOfContacts.Patch(
"/:pocID/photo",
middleware.AttachExtractor(clubParams.AuthMiddleware.ClubAuthorizeById, middleware.ExtractFromParams("clubID")),
authMiddleware.AttachExtractor(clubParams.AuthMiddleware.ClubAuthorizeById, authMiddleware.ExtractFromParams("clubID")),
clubPointOfContactController.UpdateClubPointOfContactPhoto,
)
clubPointOfContacts.Delete(
"/:pocID",
middleware.AttachExtractor(clubParams.AuthMiddleware.ClubAuthorizeById, middleware.ExtractFromParams("clubID")),
authMiddleware.AttachExtractor(clubParams.AuthMiddleware.ClubAuthorizeById, authMiddleware.ExtractFromParams("clubID")),
clubPointOfContactController.DeleteClubPointOfContact,
)
}
6 changes: 3 additions & 3 deletions backend/entities/clubs/tags/routes.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package tags

import (
"github.com/GenerateNU/sac/backend/middleware"
authMiddleware "github.com/GenerateNU/sac/backend/middleware/auth"
"github.com/GenerateNU/sac/backend/types"
)

Expand All @@ -14,12 +14,12 @@ func ClubTag(clubParams types.RouteParams) {
clubTags.Get("/", clubTagController.GetClubTags)
clubTags.Post(
"/",
middleware.AttachExtractor(clubParams.AuthMiddleware.ClubAuthorizeById, middleware.ExtractFromParams("clubID")),
authMiddleware.AttachExtractor(clubParams.AuthMiddleware.ClubAuthorizeById, authMiddleware.ExtractFromParams("clubID")),
clubTagController.CreateClubTags,
)
clubTags.Delete(
"/:tagID",
middleware.AttachExtractor(clubParams.AuthMiddleware.ClubAuthorizeById, middleware.ExtractFromParams("clubID")),
authMiddleware.AttachExtractor(clubParams.AuthMiddleware.ClubAuthorizeById, authMiddleware.ExtractFromParams("clubID")),
clubTagController.DeleteClubTag,
)
}
3 changes: 1 addition & 2 deletions backend/entities/contacts/base/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package base
import (
"github.com/GenerateNU/sac/backend/auth"
"github.com/GenerateNU/sac/backend/types"
"github.com/garrettladley/fiberpaginate"
)

func Contact(contactParams types.RouteParams) {
Expand All @@ -12,7 +11,7 @@ func Contact(contactParams types.RouteParams) {
// api/v1/contacts/*
contacts := contactParams.Router.Group("/contacts")

contacts.Get("/", fiberpaginate.New(), contactController.GetContacts)
contacts.Get("/", contactParams.UtilityMiddleware.Paginator, contactController.GetContacts)
contacts.Get("/:contactID", contactController.GetContact)
contacts.Delete("/:contactID", contactParams.AuthMiddleware.Authorize(auth.DeleteAll), contactController.DeleteContact)
}
7 changes: 3 additions & 4 deletions backend/entities/events/base/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ import (
"github.com/GenerateNU/sac/backend/entities/events/tags"
"github.com/gofiber/fiber/v2"

"github.com/GenerateNU/sac/backend/middleware"
authMiddleware "github.com/GenerateNU/sac/backend/middleware/auth"
"github.com/GenerateNU/sac/backend/types"
"github.com/garrettladley/fiberpaginate"
)

func EventRoutes(eventParams types.RouteParams) {
Expand All @@ -23,10 +22,10 @@ func EventRouter(eventParams types.RouteParams) fiber.Router {
// api/v1/events/*
events := eventParams.Router.Group("/events")

events.Get("/", fiberpaginate.New(), eventController.GetAllEvents)
events.Get("/", eventParams.UtilityMiddleware.Paginator, eventController.GetAllEvents)
events.Post(
"/",
middleware.AttachExtractor(eventParams.AuthMiddleware.ClubAuthorizeById, middleware.ExtractFromParams("clubID")),
authMiddleware.AttachExtractor(eventParams.AuthMiddleware.ClubAuthorizeById, authMiddleware.ExtractFromParams("clubID")),
eventController.CreateEvent,
)

Expand Down
8 changes: 4 additions & 4 deletions backend/entities/events/series/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package series

import (
"github.com/GenerateNU/sac/backend/extractors"
"github.com/GenerateNU/sac/backend/middleware"
authMiddleware "github.com/GenerateNU/sac/backend/middleware/auth"
"github.com/GenerateNU/sac/backend/types"
)

Expand All @@ -14,7 +14,7 @@ func EventSeries(eventParams types.RouteParams) {

eventSeries.Post(
"/",
middleware.AttachExtractor(eventParams.AuthMiddleware.ClubAuthorizeById, middleware.ExtractFromBody("host")),
authMiddleware.AttachExtractor(eventParams.AuthMiddleware.ClubAuthorizeById, authMiddleware.ExtractFromBody("host")),
eventSeriesController.CreateEventSeries,
)

Expand All @@ -23,9 +23,9 @@ func EventSeries(eventParams types.RouteParams) {
eventSeriedID.Get("/", eventSeriesController.GetEventSeries)
eventSeriedID.Delete(
"/",
middleware.AttachExtractor(
authMiddleware.AttachExtractor(
eventParams.AuthMiddleware.ClubAuthorizeById,
middleware.FromExtractFromParamIntoQuery("seriesID", eventParams.ServiceParams.DB, extractors.GetSeriesHost),
authMiddleware.FromExtractFromParamIntoQuery("seriesID", eventParams.ServiceParams.DB, extractors.GetSeriesHost),
),
eventSeriesController.DeleteEventSeries,
)
Expand Down
6 changes: 3 additions & 3 deletions backend/entities/events/tags/routes.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package tags

import (
"github.com/GenerateNU/sac/backend/middleware"
authMiddleware "github.com/GenerateNU/sac/backend/middleware/auth"
"github.com/GenerateNU/sac/backend/types"
)

Expand All @@ -13,12 +13,12 @@ func EventTags(eventParams types.RouteParams) {
eventTags.Get("/", eventTagController.GetEventTags)
eventTags.Post(
"/",
middleware.AttachExtractor(eventParams.AuthMiddleware.EventAuthorizeById, middleware.ExtractFromParams("eventID")),
authMiddleware.AttachExtractor(eventParams.AuthMiddleware.EventAuthorizeById, authMiddleware.ExtractFromParams("eventID")),
eventTagController.CreateEventTags,
)
eventTags.Delete(
"/:tagID",
middleware.AttachExtractor(eventParams.AuthMiddleware.EventAuthorizeById, middleware.ExtractFromParams("eventID")),
authMiddleware.AttachExtractor(eventParams.AuthMiddleware.EventAuthorizeById, authMiddleware.ExtractFromParams("eventID")),
eventTagController.DeleteEventTag,
)
}
3 changes: 1 addition & 2 deletions backend/entities/files/base/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ package base

import (
"github.com/GenerateNU/sac/backend/types"
"github.com/garrettladley/fiberpaginate"
)

func File(fileParams types.RouteParams) {
fileController := NewFileController(NewFileService(fileParams.ServiceParams))

file := fileParams.Router.Group("/files")

file.Get("/", fiberpaginate.New(), fileController.GetFiles)
file.Get("/", fileParams.UtilityMiddleware.Paginator, fileController.GetFiles)
file.Get("/:fileID", fileController.GetFile)
file.Post("/", fileController.CreateFile)
file.Delete("/:fileID", fileController.DeleteFile)
Expand Down
3 changes: 1 addition & 2 deletions backend/entities/pocs/base/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package base

import (
"github.com/GenerateNU/sac/backend/types"
"github.com/garrettladley/fiberpaginate"
)

func PointOfContact(pointOfContactParams types.RouteParams) {
Expand All @@ -11,7 +10,7 @@ func PointOfContact(pointOfContactParams types.RouteParams) {
// api/v1/pocs/*
pointofContact := pointOfContactParams.Router.Group("/pocs")

pointofContact.Get("/", fiberpaginate.New(), pointOfContactController.GetPointOfContacts)
pointofContact.Get("/", pointOfContactParams.UtilityMiddleware.Paginator, pointOfContactController.GetPointOfContacts)
pointofContact.Get("/:pocID", pointOfContactController.GetPointOfContact)
// pointOfContact.Get("/:pocID/file", pointOfContactController.GetPointOfContacFileInfo))
}
3 changes: 1 addition & 2 deletions backend/entities/users/base/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"github.com/GenerateNU/sac/backend/entities/users/members"
"github.com/GenerateNU/sac/backend/entities/users/tags"
"github.com/GenerateNU/sac/backend/types"
"github.com/garrettladley/fiberpaginate"

"github.com/gofiber/fiber/v2"
)
Expand All @@ -27,7 +26,7 @@ func UsersRouter(userParams types.RouteParams) fiber.Router {
// api/v1/users/*
users := userParams.Router.Group("/users")

users.Get("/", userParams.AuthMiddleware.Authorize(p.ReadAll), fiberpaginate.New(), userController.GetUsers)
users.Get("/", userParams.AuthMiddleware.Authorize(p.ReadAll), userParams.UtilityMiddleware.Paginator, userController.GetUsers)
users.Get("/me", userParams.AuthMiddleware.Authorize(p.UserRead), userController.GetMe)

// api/v1/users/:userID/*
Expand Down
Loading

0 comments on commit 15ee987

Please sign in to comment.