1
0
Fork 0

feat: add endpoints to update payment and attendance status of training date attendee

This commit is contained in:
Vojtěch Mareš 2024-05-13 12:55:13 +02:00
parent 140ec493bf
commit f5e632a46f
Signed by: vojtech.mares
GPG key ID: C6827B976F17240D
3 changed files with 555 additions and 37 deletions

View file

@ -797,3 +797,171 @@ func (h *APIHandlers) UpdateTrainingDateAttendee(ctx context.Context, req Update
},
}, nil
}
func (h *APIHandlers) UpdateTrainingDateAttendeePayment(ctx context.Context, req UpdateTrainingDateAttendeePaymentRequestObject) (UpdateTrainingDateAttendeePaymentResponseObject, error) {
_, err := h.trainingRepository.FindByID(req.TrainingID)
if err != nil {
if errors.Is(err, training.ErrTrainingNotFound) {
return UpdateTrainingDateAttendeePayment404ApplicationProblemPlusJSONResponse{
NotFoundErrorApplicationProblemPlusJSONResponse: NotFoundErrorApplicationProblemPlusJSONResponse{
Status: fiber.StatusNotFound,
Title: "Not Found: Training not found",
}}, nil
} else {
return UpdateTrainingDateAttendeePayment500ApplicationProblemPlusJSONResponse{
InternalErrorApplicationProblemPlusJSONResponse: InternalErrorApplicationProblemPlusJSONResponse{
Status: fiber.StatusInternalServerError,
Title: "Internal Server Error: Failed to get training",
Detail: err.Error(),
}}, nil
}
}
_, err = h.trainingDateRepository.FindByID(req.TrainingDateID)
if err != nil {
if errors.Is(err, training.ErrTrainingDateNotFound) {
return UpdateTrainingDateAttendeePayment404ApplicationProblemPlusJSONResponse{
NotFoundErrorApplicationProblemPlusJSONResponse: NotFoundErrorApplicationProblemPlusJSONResponse{
Status: fiber.StatusNotFound,
Title: "Not Found: Training date not found",
}}, nil
} else {
return UpdateTrainingDateAttendeePayment500ApplicationProblemPlusJSONResponse{
InternalErrorApplicationProblemPlusJSONResponse: InternalErrorApplicationProblemPlusJSONResponse{
Status: fiber.StatusInternalServerError,
Title: "Internal Server Error: Failed to get training date",
Detail: err.Error(),
}}, nil
}
}
ta, err := h.trainingDateAttendeeRepository.FindByID(req.TrainingDateAttendeeID)
if err != nil {
if errors.Is(err, training.ErrTrainingDateAttendeeNotFound) {
return UpdateTrainingDateAttendeePayment404ApplicationProblemPlusJSONResponse{
NotFoundErrorApplicationProblemPlusJSONResponse: NotFoundErrorApplicationProblemPlusJSONResponse{
Status: fiber.StatusNotFound,
Title: "Not Found: Training date attendee not found",
}}, nil
} else {
return UpdateTrainingDateAttendeePayment500ApplicationProblemPlusJSONResponse{
InternalErrorApplicationProblemPlusJSONResponse: InternalErrorApplicationProblemPlusJSONResponse{
Status: fiber.StatusInternalServerError,
Title: "Internal Server Error: Failed to get training date attendee",
Detail: err.Error(),
}}, nil
}
}
ta.HasPaid = req.Body.Paid
err = h.trainingDateAttendeeRepository.Update(ta)
if err != nil {
return UpdateTrainingDateAttendeePayment500ApplicationProblemPlusJSONResponse{
InternalErrorApplicationProblemPlusJSONResponse: InternalErrorApplicationProblemPlusJSONResponse{
Status: fiber.StatusInternalServerError,
Title: "Internal Server Error: Failed to update training date attendee",
Detail: err.Error(),
}}, nil
}
return UpdateTrainingDateAttendeePayment200JSONResponse{
Id: ta.ID,
Name: ta.Name,
Email: types.Email(ta.Email),
Phone: ta.Phone,
Company: ta.Company,
Position: ta.Position,
IsStudent: &ta.IsStudent,
HasAttended: ta.HasAttended,
HasPaid: ta.HasPaid,
Bill: Price{
Amount: ta.Bill.Amount.String(),
Currency: ta.Bill.Currency,
},
}, nil
}
func (h *APIHandlers) UpdateTrainingDateAttendeeAttendance(ctx context.Context, req UpdateTrainingDateAttendeeAttendanceRequestObject) (UpdateTrainingDateAttendeeAttendanceResponseObject, error) {
_, err := h.trainingRepository.FindByID(req.TrainingID)
if err != nil {
if errors.Is(err, training.ErrTrainingNotFound) {
return UpdateTrainingDateAttendeeAttendance404ApplicationProblemPlusJSONResponse{
NotFoundErrorApplicationProblemPlusJSONResponse: NotFoundErrorApplicationProblemPlusJSONResponse{
Status: fiber.StatusNotFound,
Title: "Not Found: Training not found",
}}, nil
} else {
return UpdateTrainingDateAttendeeAttendance500ApplicationProblemPlusJSONResponse{
InternalErrorApplicationProblemPlusJSONResponse: InternalErrorApplicationProblemPlusJSONResponse{
Status: fiber.StatusInternalServerError,
Title: "Internal Server Error: Failed to get training",
Detail: err.Error(),
}}, nil
}
}
_, err = h.trainingDateRepository.FindByID(req.TrainingDateID)
if err != nil {
if errors.Is(err, training.ErrTrainingDateNotFound) {
return UpdateTrainingDateAttendeeAttendance404ApplicationProblemPlusJSONResponse{
NotFoundErrorApplicationProblemPlusJSONResponse: NotFoundErrorApplicationProblemPlusJSONResponse{
Status: fiber.StatusNotFound,
Title: "Not Found: Training date not found",
}}, nil
} else {
return UpdateTrainingDateAttendeeAttendance500ApplicationProblemPlusJSONResponse{
InternalErrorApplicationProblemPlusJSONResponse: InternalErrorApplicationProblemPlusJSONResponse{
Status: fiber.StatusInternalServerError,
Title: "Internal Server Error: Failed to get training date",
Detail: err.Error(),
}}, nil
}
}
ta, err := h.trainingDateAttendeeRepository.FindByID(req.TrainingDateAttendeeID)
if err != nil {
if errors.Is(err, training.ErrTrainingDateAttendeeNotFound) {
return UpdateTrainingDateAttendeeAttendance404ApplicationProblemPlusJSONResponse{
NotFoundErrorApplicationProblemPlusJSONResponse: NotFoundErrorApplicationProblemPlusJSONResponse{
Status: fiber.StatusNotFound,
Title: "Not Found: Training date attendee not found",
}}, nil
} else {
return UpdateTrainingDateAttendeeAttendance500ApplicationProblemPlusJSONResponse{
InternalErrorApplicationProblemPlusJSONResponse: InternalErrorApplicationProblemPlusJSONResponse{
Status: fiber.StatusInternalServerError,
Title: "Internal Server Error: Failed to get training date attendee",
Detail: err.Error(),
}}, nil
}
}
ta.HasAttended = req.Body.Attended
err = h.trainingDateAttendeeRepository.Update(ta)
if err != nil {
return UpdateTrainingDateAttendeeAttendance500ApplicationProblemPlusJSONResponse{
InternalErrorApplicationProblemPlusJSONResponse: InternalErrorApplicationProblemPlusJSONResponse{
Status: fiber.StatusInternalServerError,
Title: "Internal Server Error: Failed to update training date attendee",
Detail: err.Error(),
}}, nil
}
return UpdateTrainingDateAttendeeAttendance200JSONResponse{
Id: ta.ID,
Name: ta.Name,
Email: types.Email(ta.Email),
Phone: ta.Phone,
Company: ta.Company,
Position: ta.Position,
IsStudent: &ta.IsStudent,
HasAttended: ta.HasAttended,
HasPaid: ta.HasPaid,
Bill: Price{
Amount: ta.Bill.Amount.String(),
Currency: ta.Bill.Currency,
},
}, nil
}