-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: edwinliiiii <[email protected]> Co-authored-by: Garrett Ladley <[email protected]> Co-authored-by: garrettladley <[email protected]>
- Loading branch information
1 parent
6ca4f11
commit ccbbe09
Showing
22 changed files
with
876 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package controllers | ||
|
||
import ( | ||
"strconv" | ||
|
||
"github.com/GenerateNU/sac/backend/src/services" | ||
"github.com/gofiber/fiber/v2" | ||
) | ||
|
||
type ClubMemberController struct { | ||
clubMemberService services.ClubMemberServiceInterface | ||
} | ||
|
||
func NewClubMemberController(clubMemberService services.ClubMemberServiceInterface) *ClubMemberController { | ||
return &ClubMemberController{clubMemberService: clubMemberService} | ||
} | ||
|
||
func (cm *ClubMemberController) GetClubMembers(c *fiber.Ctx) error { | ||
defaultLimit := 10 | ||
defaultPage := 1 | ||
|
||
followers, err := cm.clubMemberService.GetClubMembers(c.Params("clubID"), c.Query("limit", strconv.Itoa(defaultLimit)), c.Query("page", strconv.Itoa(defaultPage))) | ||
if err != nil { | ||
return err.FiberError(c) | ||
} | ||
|
||
return c.Status(fiber.StatusOK).JSON(followers) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package controllers | ||
|
||
import ( | ||
"github.com/GenerateNU/sac/backend/src/services" | ||
"github.com/gofiber/fiber/v2" | ||
) | ||
|
||
type UserMemberController struct { | ||
clubMemberService services.UserMemberServiceInterface | ||
} | ||
|
||
func NewUserMemberController(clubMemberService services.UserMemberServiceInterface) *UserMemberController { | ||
return &UserMemberController{clubMemberService: clubMemberService} | ||
} | ||
|
||
func (um *UserMemberController) CreateMembership(c *fiber.Ctx) error { | ||
err := um.clubMemberService.CreateMembership(c.Params("userID"), c.Params("clubID")) | ||
if err != nil { | ||
return err.FiberError(c) | ||
} | ||
|
||
return c.SendStatus(fiber.StatusCreated) | ||
} | ||
|
||
func (um *UserMemberController) DeleteMembership(c *fiber.Ctx) error { | ||
err := um.clubMemberService.DeleteMembership(c.Params("userID"), c.Params("clubID")) | ||
if err != nil { | ||
return err.FiberError(c) | ||
} | ||
|
||
return c.SendStatus(fiber.StatusNoContent) | ||
} | ||
|
||
func (um *UserMemberController) GetMembership(c *fiber.Ctx) error { | ||
followers, err := um.clubMemberService.GetMembership(c.Params("clubID")) | ||
if err != nil { | ||
return err.FiberError(c) | ||
} | ||
|
||
return c.Status(fiber.StatusOK).JSON(followers) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package routes | ||
|
||
import ( | ||
"github.com/GenerateNU/sac/backend/src/controllers" | ||
"github.com/GenerateNU/sac/backend/src/services" | ||
"github.com/gofiber/fiber/v2" | ||
) | ||
|
||
func ClubMember(clubsIDRouter fiber.Router, clubMemberService services.ClubMemberServiceInterface) { | ||
clubMemberController := controllers.NewClubMemberController(clubMemberService) | ||
|
||
clubMember := clubsIDRouter.Group("/member") | ||
|
||
// api/v1/clubs/:clubID/member/* | ||
clubMember.Get("/", clubMemberController.GetClubMembers) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package routes | ||
|
||
import ( | ||
"github.com/GenerateNU/sac/backend/src/controllers" | ||
"github.com/GenerateNU/sac/backend/src/services" | ||
"github.com/gofiber/fiber/v2" | ||
) | ||
|
||
func UserMember(usersRouter fiber.Router, userMembershipService services.UserMemberServiceInterface) { | ||
userMemberController := controllers.NewUserMemberController(userMembershipService) | ||
|
||
userMember := usersRouter.Group("/:userID/member") | ||
|
||
// api/v1/users/:userID/member/* | ||
userMember.Post("/", userMemberController.CreateMembership) | ||
userMember.Delete("/", userMemberController.DeleteMembership) | ||
userMember.Get("/", userMemberController.GetMembership) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package services | ||
|
||
import ( | ||
"github.com/GenerateNU/sac/backend/src/errors" | ||
"github.com/GenerateNU/sac/backend/src/models" | ||
"github.com/GenerateNU/sac/backend/src/transactions" | ||
"github.com/GenerateNU/sac/backend/src/utilities" | ||
"github.com/go-playground/validator/v10" | ||
"gorm.io/gorm" | ||
) | ||
|
||
type ClubMemberServiceInterface interface { | ||
GetClubMembers(clubID string, limit string, page string) ([]models.User, *errors.Error) | ||
} | ||
|
||
type ClubMemberService struct { | ||
DB *gorm.DB | ||
} | ||
|
||
func NewClubMemberService(db *gorm.DB, validate *validator.Validate) *ClubMemberService { | ||
return &ClubMemberService{DB: db} | ||
} | ||
|
||
func (cms *ClubMemberService) GetClubMembers(clubID string, limit string, page string) ([]models.User, *errors.Error) { | ||
idAsUUID, err := utilities.ValidateID(clubID) | ||
if err != nil { | ||
return nil, &errors.FailedToValidateID | ||
} | ||
|
||
limitAsInt, err := utilities.ValidateNonNegative(limit) | ||
if err != nil { | ||
return nil, &errors.FailedToValidateLimit | ||
} | ||
|
||
pageAsInt, err := utilities.ValidateNonNegative(page) | ||
if err != nil { | ||
return nil, &errors.FailedToValidatePage | ||
} | ||
|
||
return transactions.GetClubMembers(cms.DB, *idAsUUID, *limitAsInt, *pageAsInt) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package services | ||
|
||
import ( | ||
"github.com/GenerateNU/sac/backend/src/errors" | ||
"github.com/GenerateNU/sac/backend/src/models" | ||
"github.com/GenerateNU/sac/backend/src/transactions" | ||
"github.com/GenerateNU/sac/backend/src/utilities" | ||
"gorm.io/gorm" | ||
) | ||
|
||
type UserMemberServiceInterface interface { | ||
CreateMembership(userID string, clubID string) *errors.Error | ||
DeleteMembership(userID string, clubID string) *errors.Error | ||
GetMembership(userID string) ([]models.Club, *errors.Error) | ||
} | ||
|
||
type UserMemberService struct { | ||
DB *gorm.DB | ||
} | ||
|
||
func NewUserMemberService(db *gorm.DB) *UserMemberService { | ||
return &UserMemberService{DB: db} | ||
} | ||
|
||
func (u *UserMemberService) CreateMembership(userID string, clubID string) *errors.Error { | ||
userIdAsUUID, err := utilities.ValidateID(userID) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
clubIdAsUUID, err := utilities.ValidateID(clubID) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return transactions.CreateMember(u.DB, *userIdAsUUID, *clubIdAsUUID) | ||
} | ||
|
||
func (u *UserMemberService) DeleteMembership(userID string, clubID string) *errors.Error { | ||
userIdAsUUID, err := utilities.ValidateID(userID) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
clubIdAsUUID, err := utilities.ValidateID(clubID) | ||
if err != nil { | ||
return err | ||
} | ||
return transactions.DeleteMember(u.DB, *userIdAsUUID, *clubIdAsUUID) | ||
} | ||
|
||
func (u *UserMemberService) GetMembership(userID string) ([]models.Club, *errors.Error) { | ||
userIdAsUUID, err := utilities.ValidateID(userID) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return transactions.GetClubMembership(u.DB, *userIdAsUUID) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.