Skip to content

Commit

Permalink
Merge branch 'main' into 146-create-change-password-auth-route
Browse files Browse the repository at this point in the history
  • Loading branch information
garrettladley authored Feb 11, 2024
2 parents 769b5b9 + ccbbe09 commit 5014cb6
Show file tree
Hide file tree
Showing 52 changed files with 2,048 additions and 61 deletions.
20 changes: 10 additions & 10 deletions backend/src/controllers/category.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ func NewCategoryController(categoryService services.CategoryServiceInterface) *C
// @Failure 400 {string} string "category with that name already exists"
// @Failure 500 {string} string "failed to create category"
// @Router /api/v1/category/ [post]
func (t *CategoryController) CreateCategory(c *fiber.Ctx) error {
func (cat *CategoryController) CreateCategory(c *fiber.Ctx) error {
var categoryBody models.CategoryRequestBody

if err := c.BodyParser(&categoryBody); err != nil {
return errors.FailedToParseRequestBody.FiberError(c)
}

newCategory, err := t.categoryService.CreateCategory(categoryBody)
newCategory, err := cat.categoryService.CreateCategory(categoryBody)
if err != nil {
return err.FiberError(c)
}
Expand All @@ -56,11 +56,11 @@ func (t *CategoryController) CreateCategory(c *fiber.Ctx) error {
// @Success 200 {object} []models.Category
// @Failure 500 {string} string "unable to retrieve categories"
// @Router /api/v1/category/ [get]
func (t *CategoryController) GetCategories(c *fiber.Ctx) error {
func (cat *CategoryController) GetCategories(c *fiber.Ctx) error {
defaultLimit := 10
defaultPage := 1

categories, err := t.categoryService.GetCategories(c.Query("limit", strconv.Itoa(defaultLimit)), c.Query("page", strconv.Itoa(defaultPage)))
categories, err := cat.categoryService.GetCategories(c.Query("limit", strconv.Itoa(defaultLimit)), c.Query("page", strconv.Itoa(defaultPage)))
if err != nil {
return err.FiberError(c)
}
Expand All @@ -80,8 +80,8 @@ func (t *CategoryController) GetCategories(c *fiber.Ctx) error {
// @Failure 404 {string} string "faied to find category"
// @Failure 500 {string} string "failed to retrieve category"
// @Router /api/v1/category/{id} [get]
func (t *CategoryController) GetCategory(c *fiber.Ctx) error {
category, err := t.categoryService.GetCategory(c.Params("categoryID"))
func (cat *CategoryController) GetCategory(c *fiber.Ctx) error {
category, err := cat.categoryService.GetCategory(c.Params("categoryID"))
if err != nil {
return err.FiberError(c)
}
Expand All @@ -101,8 +101,8 @@ func (t *CategoryController) GetCategory(c *fiber.Ctx) error {
// @Failure 404 {string} string "failed to find category"
// @Failure 500 {string} string "failed to delete category"
// @Router /api/v1/category/{id} [delete]
func (t *CategoryController) DeleteCategory(c *fiber.Ctx) error {
if err := t.categoryService.DeleteCategory(c.Params("categoryID")); err != nil {
func (cat *CategoryController) DeleteCategory(c *fiber.Ctx) error {
if err := cat.categoryService.DeleteCategory(c.Params("categoryID")); err != nil {
return err.FiberError(c)
}

Expand All @@ -121,14 +121,14 @@ func (t *CategoryController) DeleteCategory(c *fiber.Ctx) error {
// @Failure 404 {string} string "failed to find category"
// @Failure 500 {string} string "failed to update category"
// @Router /api/v1/category/{id} [patch]
func (t *CategoryController) UpdateCategory(c *fiber.Ctx) error {
func (cat *CategoryController) UpdateCategory(c *fiber.Ctx) error {
var category models.CategoryRequestBody

if err := c.BodyParser(&category); err != nil {
return errors.FailedToValidateCategory.FiberError(c)
}

updatedCategory, err := t.categoryService.UpdateCategory(c.Params("categoryID"), category)
updatedCategory, err := cat.categoryService.UpdateCategory(c.Params("categoryID"), category)
if err != nil {
return err.FiberError(c)
}
Expand Down
8 changes: 4 additions & 4 deletions backend/src/controllers/category_tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@ func NewCategoryTagController(categoryTagService services.CategoryTagServiceInte
return &CategoryTagController{categoryTagService: categoryTagService}
}

func (t *CategoryTagController) GetTagsByCategory(c *fiber.Ctx) error {
func (ct *CategoryTagController) GetTagsByCategory(c *fiber.Ctx) error {
defaultLimit := 10
defaultPage := 1

tags, err := t.categoryTagService.GetTagsByCategory(c.Params("categoryID"), c.Query("limit", strconv.Itoa(defaultLimit)), c.Query("page", strconv.Itoa(defaultPage)))
tags, err := ct.categoryTagService.GetTagsByCategory(c.Params("categoryID"), 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(&tags)
}

func (t *CategoryTagController) GetTagByCategory(c *fiber.Ctx) error {
tag, err := t.categoryTagService.GetTagByCategory(c.Params("categoryID"), c.Params("tagID"))
func (ct *CategoryTagController) GetTagByCategory(c *fiber.Ctx) error {
tag, err := ct.categoryTagService.GetTagByCategory(c.Params("categoryID"), c.Params("tagID"))
if err != nil {
return err.FiberError(c)
}
Expand Down
40 changes: 40 additions & 0 deletions backend/src/controllers/club_contact.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package controllers

import (
"github.com/GenerateNU/sac/backend/src/errors"
"github.com/GenerateNU/sac/backend/src/models"
"github.com/GenerateNU/sac/backend/src/services"
"github.com/gofiber/fiber/v2"
)

type ClubContactController struct {
clubContactService services.ClubContactServiceInterface
}

func NewClubContactController(clubContactService services.ClubContactServiceInterface) *ClubContactController {
return &ClubContactController{clubContactService: clubContactService}
}

func (cc *ClubContactController) GetClubContacts(c *fiber.Ctx) error {
contacts, err := cc.clubContactService.GetClubContacts(c.Params("clubID"))
if err != nil {
return err.FiberError(c)
}

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

func (cc *ClubContactController) PutContact(c *fiber.Ctx) error {
var contactBody models.PutContactRequestBody

if err := c.BodyParser(&contactBody); err != nil {
return errors.FailedToParseRequestBody.FiberError(c)
}

contact, err := cc.clubContactService.PutClubContact(c.Params("clubID"), contactBody)
if err != nil {
return err.FiberError(c)
}

return c.Status(fiber.StatusOK).JSON(contact)
}
28 changes: 28 additions & 0 deletions backend/src/controllers/club_follower.go
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)
}
28 changes: 28 additions & 0 deletions backend/src/controllers/club_member.go
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)
}
46 changes: 46 additions & 0 deletions backend/src/controllers/contact.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package controllers

import (
"strconv"

"github.com/GenerateNU/sac/backend/src/services"
"github.com/gofiber/fiber/v2"
)

type ContactController struct {
contactService services.ContactServiceInterface
}

func NewContactController(contactService services.ContactServiceInterface) *ContactController {
return &ContactController{contactService: contactService}
}

func (co *ContactController) GetContact(c *fiber.Ctx) error {
contact, err := co.contactService.GetContact(c.Params("contactID"))
if err != nil {
return err.FiberError(c)
}

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

func (co *ContactController) GetContacts(c *fiber.Ctx) error {
defaultLimit := 10
defaultPage := 1

contacts, err := co.contactService.GetContacts(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(contacts)
}

func (co *ContactController) DeleteContact(c *fiber.Ctx) error {
err := co.contactService.DeleteContact(c.Params("contactID"))
if err != nil {
return err.FiberError(c)
}

return c.SendStatus(fiber.StatusNoContent)
}
38 changes: 38 additions & 0 deletions backend/src/controllers/user_follower.go
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)
}
41 changes: 41 additions & 0 deletions backend/src/controllers/user_member.go
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)
}
8 changes: 4 additions & 4 deletions backend/src/controllers/user_tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@ func NewUserTagController(userTagService services.UserTagServiceInterface) *User
return &UserTagController{userTagService: userTagService}
}

func (u *UserTagController) GetUserTags(c *fiber.Ctx) error {
tags, err := u.userTagService.GetUserTags(c.Params("userID"))
func (ut *UserTagController) GetUserTags(c *fiber.Ctx) error {
tags, err := ut.userTagService.GetUserTags(c.Params("userID"))
if err != nil {
return err.FiberError(c)
}
return c.Status(fiber.StatusOK).JSON(&tags)
}

func (u *UserTagController) CreateUserTags(c *fiber.Ctx) error {
func (ut *UserTagController) CreateUserTags(c *fiber.Ctx) error {
var requestBody models.CreateUserTagsBody
if err := c.BodyParser(&requestBody); err != nil {
return errors.FailedToParseRequestBody.FiberError(c)
}

tags, err := u.userTagService.CreateUserTags(c.Params("userID"), requestBody)
tags, err := ut.userTagService.CreateUserTags(c.Params("userID"), requestBody)
if err != nil {
return err.FiberError(c)
}
Expand Down
12 changes: 12 additions & 0 deletions backend/src/errors/club.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,20 @@ var (
StatusCode: fiber.StatusNotFound,
Message: "club not found",
}
FailedToGetMembers = Error{
StatusCode: fiber.StatusNotFound,
Message: "failed to get members",
}
FailedtoGetAdminIDs = Error{
StatusCode: fiber.StatusInternalServerError,
Message: "failed to get admin ids",
}
FailedToGetClubFollowers = Error{
StatusCode: fiber.StatusInternalServerError,
Message: "failed to get club followers",
}
FailedToGetClubMembers = Error{
StatusCode: fiber.StatusInternalServerError,
Message: "failed to get club members",
}
)
30 changes: 30 additions & 0 deletions backend/src/errors/contact.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package errors

import "github.com/gofiber/fiber/v2"

var (
FailedToGetContacts = Error{
StatusCode: fiber.StatusInternalServerError,
Message: "failed to get contacts",
}
FailedToGetContact = Error{
StatusCode: fiber.StatusInternalServerError,
Message: "failed to get contact",
}
ContactNotFound = Error{
StatusCode: fiber.StatusNotFound,
Message: "contact not found",
}
FailedToPutContact = Error{
StatusCode: fiber.StatusInternalServerError,
Message: "failed to put contact",
}
FailedToDeleteContact = Error{
StatusCode: fiber.StatusInternalServerError,
Message: "failed to delete contact",
}
FailedToValidateContact = Error{
StatusCode: fiber.StatusBadRequest,
Message: "failed to validate contact",
}
)
Loading

0 comments on commit 5014cb6

Please sign in to comment.