-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Finished follower endpoints #142
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
aff5bb7
Finished follower endpoints
zacklassetter 347310d
refactor associations into seperate verticals | gen clean up
garrettladley 5b76f07
DELETE and GET test cases for club and user
in-mai-space 78bd4ea
Merge branch 'main' into SAC-26-Follower-CRUD
garrettladley 47d824e
GML init clean up / refactor
garrettladley 4f355a8
register routes
garrettladley d8ee450
linter
garrettladley ea174d8
format
garrettladley c3cdebf
i ripped my hair out but the test is passing now
garrettladley File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,28 @@ | ||
package controllers | ||
|
||
import ( | ||
"strconv" | ||
|
||
"github.com/GenerateNU/sac/backend/src/services" | ||
"github.com/gofiber/fiber/v2" | ||
) | ||
|
||
type ClubFollowerController struct { | ||
clubFollowerService services.ClubFollowerServiceInterface | ||
} | ||
|
||
func NewClubFollowerController(clubFollowerService services.ClubFollowerServiceInterface) *ClubFollowerController { | ||
return &ClubFollowerController{clubFollowerService: clubFollowerService} | ||
} | ||
|
||
func (cf *ClubFollowerController) GetClubFollowers(c *fiber.Ctx) error { | ||
defaultLimit := 10 | ||
defaultPage := 1 | ||
|
||
followers, err := cf.clubFollowerService.GetClubFollowers(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,38 @@ | ||
package controllers | ||
|
||
import ( | ||
"github.com/GenerateNU/sac/backend/src/services" | ||
"github.com/gofiber/fiber/v2" | ||
) | ||
|
||
type UserFollowerController struct { | ||
userFollowerService services.UserFollowerServiceInterface | ||
} | ||
|
||
func NewUserFollowerController(userFollowerService services.UserFollowerServiceInterface) *UserFollowerController { | ||
return &UserFollowerController{userFollowerService: userFollowerService} | ||
} | ||
|
||
func (uf *UserFollowerController) CreateFollowing(c *fiber.Ctx) error { | ||
err := uf.userFollowerService.CreateFollowing(c.Params("userID"), c.Params("clubID")) | ||
if err != nil { | ||
return err.FiberError(c) | ||
} | ||
return c.SendStatus(fiber.StatusCreated) | ||
} | ||
|
||
func (uf *UserFollowerController) DeleteFollowing(c *fiber.Ctx) error { | ||
err := uf.userFollowerService.DeleteFollowing(c.Params("userID"), c.Params("clubID")) | ||
if err != nil { | ||
return err.FiberError(c) | ||
} | ||
return c.SendStatus(fiber.StatusNoContent) | ||
} | ||
|
||
func (uf *UserFollowerController) GetAllFollowing(c *fiber.Ctx) error { | ||
clubs, err := uf.userFollowerService.GetFollowing(c.Params("userID")) | ||
if err != nil { | ||
return err.FiberError(c) | ||
} | ||
return c.Status(fiber.StatusOK).JSON(clubs) | ||
} |
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
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 |
---|---|---|
|
@@ -49,7 +49,7 @@ type User struct { | |
Tag []Tag `gorm:"many2many:user_tags;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;" json:"-" validate:"-"` | ||
Admin []Club `gorm:"many2many:user_club_admins;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;" json:"-" validate:"-"` | ||
Member []Club `gorm:"many2many:user_club_members;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;" json:"-" validate:"-"` | ||
Follower []Club `gorm:"many2many:user_club_followers;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;" json:"-" validate:"-"` | ||
Follower []Club `gorm:"many2many:user_club_followers;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;" json:"clubs_followed,omitempty" validate:"-"` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we want to send a list of followers? or should it only be passed when requested? might be unnecessary information |
||
IntendedApplicant []Club `gorm:"many2many:user_club_intended_applicants;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;" json:"-" validate:"-"` | ||
Asked []Comment `gorm:"foreignKey:AskedByID;constraint:OnUpdate:CASCADE,OnDelete:SET NULL;" json:"-" validate:"-"` | ||
Answered []Comment `gorm:"foreignKey:AnsweredByID;constraint:OnUpdate:CASCADE,OnDelete:SET NULL;" json:"-" validate:"-"` | ||
|
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 ClubFollower(clubsIDRouter fiber.Router, clubFollowerService services.ClubFollowerServiceInterface) { | ||
clubFollowerController := controllers.NewClubFollowerController(clubFollowerService) | ||
|
||
clubFollower := clubsIDRouter.Group("/followers") | ||
|
||
// api/clubs/:clubID/followers/* | ||
clubFollower.Get("/", clubFollowerController.GetClubFollowers) | ||
} |
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 UserFollower(usersIDRouter fiber.Router, userFollowerService services.UserFollowerServiceInterface) { | ||
userFollowerController := controllers.NewUserFollowerController(userFollowerService) | ||
|
||
userFollower := usersIDRouter.Group("/:userID/follower") | ||
|
||
// api/v1/users/:userID/follower/* | ||
userFollower.Post("/:clubID", userFollowerController.CreateFollowing) | ||
userFollower.Delete("/:clubID", userFollowerController.DeleteFollowing) | ||
userFollower.Get("/", userFollowerController.GetAllFollowing) | ||
} |
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,42 @@ | ||
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 ClubFollowerServiceInterface interface { | ||
GetClubFollowers(clubID string, limit string, page string) ([]models.User, *errors.Error) | ||
} | ||
|
||
type ClubFollowerService struct { | ||
DB *gorm.DB | ||
Validate *validator.Validate | ||
} | ||
|
||
func NewClubFollowerService(db *gorm.DB, validate *validator.Validate) *ClubFollowerService { | ||
return &ClubFollowerService{DB: db, Validate: validate} | ||
} | ||
|
||
func (cf *ClubFollowerService) GetClubFollowers(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.GetClubFollowers(cf.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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above