-
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.
- Loading branch information
1 parent
fd8634a
commit 158fd91
Showing
30 changed files
with
655 additions
and
763 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
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,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) | ||
} |
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,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) | ||
} |
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,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", | ||
} | ||
) |
Oops, something went wrong.