Skip to content

Commit

Permalink
services and transactions progress
Browse files Browse the repository at this point in the history
  • Loading branch information
garrettladley committed May 29, 2024
1 parent a388c91 commit ca8e127
Show file tree
Hide file tree
Showing 7 changed files with 271 additions and 37 deletions.
5 changes: 2 additions & 3 deletions backend/entities/clubs/base/service.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package base

import (
"errors"

"github.com/GenerateNU/sac/backend/entities/clubs"
"github.com/GenerateNU/sac/backend/entities/models"
"github.com/GenerateNU/sac/backend/errs"
"github.com/GenerateNU/sac/backend/types"
"github.com/GenerateNU/sac/backend/utilities"
"github.com/garrettladley/fiberpaginate"
Expand Down Expand Up @@ -59,7 +58,7 @@ func (c *ClubService) UpdateClub(id string, clubBody UpdateClubRequestBody) (*mo
}

if utilities.AtLeastOne(clubBody, UpdateClubRequestBody{}) {
return nil, errors.New("at least one field must be present")
return nil, errs.ErrAtLeastOne
}

if err := utilities.Validate(c.Validate, clubBody); err != nil {
Expand Down
24 changes: 17 additions & 7 deletions backend/entities/clubs/recruitment/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ func (cr *ClubRecruitmentController) CreateClubRecruitment(c *fiber.Ctx) error {
return err
}

club, err := cr.clubRecruitmentService.CreateClubRecruitment(c.UserContext(), c.Params("clubID"), body)
recruitment, err := cr.clubRecruitmentService.CreateClubRecruitment(c.UserContext(), c.Params("clubID"), body)
if err != nil {
return err
}

return c.Status(http.StatusCreated).JSON(club)
return c.Status(http.StatusCreated).JSON(recruitment)
}

func (cr *ClubRecruitmentController) UpdateClubRecruitment(c *fiber.Ctx) error {
Expand All @@ -34,12 +34,12 @@ func (cr *ClubRecruitmentController) UpdateClubRecruitment(c *fiber.Ctx) error {
return err
}

club, err := cr.clubRecruitmentService.UpdateClubRecruitment(c.UserContext(), c.Params("clubID"), body)
recruitment, err := cr.clubRecruitmentService.UpdateClubRecruitment(c.UserContext(), c.Params("clubID"), body)
if err != nil {
return err
}

return c.Status(http.StatusOK).JSON(club)
return c.Status(http.StatusOK).JSON(recruitment)
}

func (cr *ClubRecruitmentController) DeleteClubRecruitment(c *fiber.Ctx) error {
Expand All @@ -50,11 +50,21 @@ func (cr *ClubRecruitmentController) DeleteClubRecruitment(c *fiber.Ctx) error {
return c.SendStatus(http.StatusNoContent)
}

func (cr *ClubRecruitmentController) GetClubRecruitmentApplications(c *fiber.Ctx) error {
return nil
func (cr *ClubRecruitmentController) CreateClubRecruitmentApplication(c *fiber.Ctx) error {
var body CreateApplicationRequestBody
if err := c.BodyParser(&body); err != nil {
return err
}

application, err := cr.clubRecruitmentService.CreateApplicationRequestBody(c.UserContext(), c.Params("clubID"), c.Params("recruitmentID"), body)
if err != nil {
return err
}

return c.Status(http.StatusCreated).JSON(application)
}

func (cr *ClubRecruitmentController) CreateClubRecruitmentApplication(c *fiber.Ctx) error {
func (cr *ClubRecruitmentController) GetClubRecruitmentApplications(c *fiber.Ctx) error {
return nil
}

Expand Down
144 changes: 129 additions & 15 deletions backend/entities/clubs/recruitment/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package recruitment

import (
"context"
"errors"

"github.com/GenerateNU/sac/backend/constants"
"github.com/GenerateNU/sac/backend/entities/models"
Expand All @@ -13,12 +12,13 @@ import (
)

type ClubRecruitmentServicer interface {
CreateClubRecruitment(ctx context.Context, clubID string, body CreateClubRecruitmentRequestBody) (*models.Club, error)
UpdateClubRecruitment(ctx context.Context, clubID string, body UpdateClubRecruitmentRequestBody) (*models.Club, error)
CreateClubRecruitment(ctx context.Context, clubID string, body CreateClubRecruitmentRequestBody) (*models.Recruitment, error)
GetClubRecruitment(ctx context.Context, clubID string) (*models.Recruitment, error)
UpdateClubRecruitment(ctx context.Context, clubID string, body UpdateClubRecruitmentRequestBody) (*models.Recruitment, error)
DeleteClubRecruitment(ctx context.Context, clubID string) error

GetClubRecruitmentApplications(ctx context.Context, clubID string, recruitmentID string, pageInfo fiberpaginate.PageInfo) ([]models.Application, error)
CreateApplicationRequestBody(ctx context.Context, clubID string, recruitmentID string, body CreateApplicationRequestBody) (*models.Application, error)
GetClubRecruitmentApplications(ctx context.Context, clubID string, recruitmentID string, pageInfo fiberpaginate.PageInfo) ([]models.Application, error)

GetClubRecruitmentApplication(ctx context.Context, clubID string, recruitmentID string, applicationID string) (*models.Application, error)
UpdateClubRecruitmentApplication(ctx context.Context, clubID string, recruitmentID string, applicationID string, body UpdateApplicationRequestBody) (*models.Application, error)
Expand All @@ -33,7 +33,7 @@ func NewClubRecruitmentService(params types.ServiceParams) ClubRecruitmentServic
return &ClubRecruitmentService{params}
}

func (s *ClubRecruitmentService) CreateClubRecruitment(ctx context.Context, clubID string, body CreateClubRecruitmentRequestBody) (*models.Club, error) {
func (s *ClubRecruitmentService) CreateClubRecruitment(ctx context.Context, clubID string, body CreateClubRecruitmentRequestBody) (*models.Recruitment, error) {
idAsUUID, err := utilities.ValidateID(clubID)
if err != nil {
return nil, err
Expand All @@ -54,14 +54,26 @@ func (s *ClubRecruitmentService) CreateClubRecruitment(ctx context.Context, club
return CreateClubRecruitment(createClubRecruitmentCtx, s.DB, idAsUUID, recruitment)
}

func (s *ClubRecruitmentService) UpdateClubRecruitment(ctx context.Context, clubID string, body UpdateClubRecruitmentRequestBody) (*models.Club, error) {
func (s *ClubRecruitmentService) GetClubRecruitment(ctx context.Context, clubID string) (*models.Recruitment, error) {
idAsUUID, err := utilities.ValidateID(clubID)
if err != nil {
return nil, err
}

getClubRecruitmentCtx, getClubRecruitmentCancel := context.WithTimeoutCause(ctx, constants.DB_TIMEOUT, errs.ErrDatabaseTimeout)
defer getClubRecruitmentCancel()

return GetClubRecruitment(getClubRecruitmentCtx, s.DB, idAsUUID)
}

func (s *ClubRecruitmentService) UpdateClubRecruitment(ctx context.Context, clubID string, body UpdateClubRecruitmentRequestBody) (*models.Recruitment, error) {
clubIDAsUUID, err := utilities.ValidateID(clubID)
if err != nil {
return nil, err
}

if utilities.AtLeastOne(body, UpdateClubRecruitmentRequestBody{}) {
return nil, errors.New("at least one field must be present")
return nil, errs.ErrAtLeastOne
}

if err := utilities.Validate(s.Validate, body); err != nil {
Expand All @@ -76,7 +88,7 @@ func (s *ClubRecruitmentService) UpdateClubRecruitment(ctx context.Context, club
updateClubRecruitmentCtx, updateClubRecruitmentCancel := context.WithTimeoutCause(ctx, constants.DB_TIMEOUT, errs.ErrDatabaseTimeout)
defer updateClubRecruitmentCancel()

return UpdateClubRecruitment(updateClubRecruitmentCtx, s.DB, idAsUUID, recruitment)
return UpdateClubRecruitment(updateClubRecruitmentCtx, s.DB, clubIDAsUUID, recruitment)
}

func (s *ClubRecruitmentService) DeleteClubRecruitment(ctx context.Context, clubID string) error {
Expand All @@ -91,22 +103,124 @@ func (s *ClubRecruitmentService) DeleteClubRecruitment(ctx context.Context, club
return DeleteClubRecruitment(deleteClubRecruitmentCtx, s.DB, idAsUUID)
}

func (s *ClubRecruitmentService) GetClubRecruitmentApplications(ctx context.Context, clubID string, recruitmentID string, pageInfo fiberpaginate.PageInfo) ([]models.Application, error) {
return nil, nil
func (s *ClubRecruitmentService) CreateApplicationRequestBody(ctx context.Context, clubID string, recruitmentID string, body CreateApplicationRequestBody) (*models.Application, error) {
clubIDAsUUID, err := utilities.ValidateID(clubID)
if err != nil {
return nil, err
}

recruitmentIDAsUUID, err := utilities.ValidateID(recruitmentID)
if err != nil {
return nil, err
}

if err := utilities.Validate(s.Validate, body); err != nil {
return nil, err
}

application, err := utilities.MapJsonTags(body, &models.Application{})
if err != nil {
return nil, err
}

createApplicationCtx, createApplicationCancel := context.WithTimeoutCause(ctx, constants.DB_TIMEOUT, errs.ErrDatabaseTimeout)
defer createApplicationCancel()

return CreateApplication(createApplicationCtx, s.DB, clubIDAsUUID, recruitmentIDAsUUID, application)
}

func (s *ClubRecruitmentService) CreateApplicationRequestBody(ctx context.Context, clubID string, recruitmentID string, body CreateApplicationRequestBody) (*models.Application, error) {
return nil, nil
func (s *ClubRecruitmentService) GetClubRecruitmentApplications(ctx context.Context, clubID string, recruitmentID string, pageInfo fiberpaginate.PageInfo) ([]models.Application, error) {
clubIDAsUUID, err := utilities.ValidateID(clubID)
if err != nil {
return nil, err
}

recruitmentIDAsUUID, err := utilities.ValidateID(recruitmentID)
if err != nil {
return nil, err
}

getClubRecruitmentApplicationsCtx, getClubRecruitmentApplicationsCancel := context.WithTimeoutCause(ctx, constants.DB_TIMEOUT, errs.ErrDatabaseTimeout)
defer getClubRecruitmentApplicationsCancel()

return GetClubRecruitmentApplications(getClubRecruitmentApplicationsCtx, s.DB, clubIDAsUUID, recruitmentIDAsUUID, pageInfo)
}

func (s *ClubRecruitmentService) GetClubRecruitmentApplication(ctx context.Context, clubID string, recruitmentID string, applicationID string) (*models.Application, error) {
return nil, nil
clubIDAsUUID, err := utilities.ValidateID(clubID)
if err != nil {
return nil, err
}

recruitmentIDAsUUID, err := utilities.ValidateID(recruitmentID)
if err != nil {
return nil, err
}

applicationIDAsUUID, err := utilities.ValidateID(applicationID)
if err != nil {
return nil, err
}

getClubRecruitmentApplicationCtx, getClubRecruitmentApplicationCancel := context.WithTimeoutCause(ctx, constants.DB_TIMEOUT, errs.ErrDatabaseTimeout)
defer getClubRecruitmentApplicationCancel()

return GetClubRecruitmentApplication(getClubRecruitmentApplicationCtx, s.DB, clubIDAsUUID, recruitmentIDAsUUID, applicationIDAsUUID)
}

func (s *ClubRecruitmentService) UpdateClubRecruitmentApplication(ctx context.Context, clubID string, recruitmentID string, applicationID string, body UpdateApplicationRequestBody) (*models.Application, error) {
return nil, nil
clubIDAsUUID, err := utilities.ValidateID(clubID)
if err != nil {
return nil, err
}

recruitmentIDAsUUID, err := utilities.ValidateID(recruitmentID)
if err != nil {
return nil, err
}

applicationIDAsUUID, err := utilities.ValidateID(applicationID)
if err != nil {
return nil, err
}

if utilities.AtLeastOne(body, UpdateApplicationRequestBody{}) {
return nil, errs.ErrAtLeastOne
}

if err := utilities.Validate(s.Validate, body); err != nil {
return nil, err
}

application, err := utilities.MapJsonTags(body, &models.Application{})
if err != nil {
return nil, err
}

updateClubRecruitmentApplicationCtx, updateClubRecruitmentApplicationCancel := context.WithTimeoutCause(ctx, constants.DB_TIMEOUT, errs.ErrDatabaseTimeout)
defer updateClubRecruitmentApplicationCancel()

return UpdateClubRecruitmentApplication(updateClubRecruitmentApplicationCtx, s.DB, clubIDAsUUID, recruitmentIDAsUUID, applicationIDAsUUID, application)
}

func (s *ClubRecruitmentService) DeleteClubRecruitmentApplication(ctx context.Context, clubID string, recruitmentID string, applicationID string) error {
return nil
clubIDAsUUID, err := utilities.ValidateID(clubID)
if err != nil {
return err
}

recruitmentIDAsUUID, err := utilities.ValidateID(recruitmentID)
if err != nil {
return err
}

applicationIDAsUUID, err := utilities.ValidateID(applicationID)
if err != nil {
return err
}

deleteClubRecruitmentApplicationCtx, deleteClubRecruitmentApplicationCancel := context.WithTimeoutCause(ctx, constants.DB_TIMEOUT, errs.ErrDatabaseTimeout)
defer deleteClubRecruitmentApplicationCancel()

return DeleteClubRecruitmentApplication(deleteClubRecruitmentApplicationCtx, s.DB, clubIDAsUUID, recruitmentIDAsUUID, applicationIDAsUUID)
}
Loading

0 comments on commit ca8e127

Please sign in to comment.