Skip to content

Commit

Permalink
fix: non-registerable event
Browse files Browse the repository at this point in the history
  • Loading branch information
ImSoZRious committed Jan 10, 2024
1 parent b260633 commit a419067
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions apperror/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ var (
ScheduleNotFound = &AppError{"schedule-not-found", http.StatusNotFound}
DuplicatePeriod = &AppError{"duplicate-period", http.StatusConflict}
ScheduleFull = &AppError{"schedule-full", http.StatusBadRequest}
NonRegisterableEvent = &AppError{"non-registerable-event", http.StatusBadRequest}
)
2 changes: 1 addition & 1 deletion internal/evtreg/evtreg.repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (r *repositoryImpl) GetUserWithEventRegistrationByEmail(user *model.User, e
}

func (r *repositoryImpl) GetScheduleById(schedule *model.Schedule, scheduleId int) error {
return r.db.Model(schedule).Where("id = ?", scheduleId).First(schedule).Error
return r.db.Model(schedule).Preload("Event").Where("id = ?", scheduleId).First(schedule).Error
}

func (r *repositoryImpl) RegisterEvent(evtreg *model.EventRegistration) error {
Expand Down
4 changes: 4 additions & 0 deletions internal/evtreg/evtreg.service.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ func (h *serviceImpl) RegisterEvent(ctx context.Context, userEmail string, sched
return apperror.InternalError
}

if !schedule.Event.RequireRegistration {
return apperror.NonRegisterableEvent
}

for _, regEvt := range user.RegisteredEvents {
if regEvt.Schedule.Period == schedule.Period {
return apperror.DuplicatePeriod
Expand Down

0 comments on commit a419067

Please sign in to comment.