WIP: EOL
This commit is contained in:
parent
7ed1e05284
commit
49e05cac10
23 changed files with 613 additions and 253 deletions
126
internal/api/server.go
Normal file
126
internal/api/server.go
Normal file
|
|
@ -0,0 +1,126 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"gitlab.mareshq.com/hq/backoffice/backoffice-api/internal/postgres"
|
||||
"gitlab.mareshq.com/hq/backoffice/backoffice-api/pkg/training"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type APIServer struct {
|
||||
logger *zap.SugaredLogger
|
||||
|
||||
trainingRepo *postgres.TrainingRepository
|
||||
dateRepo *postgres.DateRepository
|
||||
attendeeRepo *postgres.AttendeeRepository
|
||||
}
|
||||
|
||||
func NewAPIServer(db *sql.DB, logger *zap.SugaredLogger) *APIServer {
|
||||
return &APIServer{
|
||||
logger: logger,
|
||||
|
||||
trainingRepo: postgres.NewTrainingRepository(db),
|
||||
dateRepo: postgres.NewDateRepository(db),
|
||||
attendeeRepo: postgres.NewAttendeeRepository(db),
|
||||
}
|
||||
}
|
||||
|
||||
func (s *APIServer) ListTrainings(c *fiber.Ctx) error {
|
||||
all, err := s.trainingRepo.FindAll()
|
||||
if err != nil {
|
||||
s.logger.Error("ListTrainings", zap.Error(err))
|
||||
c.JSON(ListTrainings500ApplicationProblemPlusJSONResponse{
|
||||
Status: fiber.StatusInternalServerError,
|
||||
Title: fmt.Sprintf("Internal server error: %s", "failed to list trainings"),
|
||||
})
|
||||
}
|
||||
|
||||
c.JSON(ListTrainings200JSONResponse{})
|
||||
}
|
||||
|
||||
func (s *APIServer) CreateTraining(c *fiber.Ctx) error {
|
||||
tr := &training.Training{}
|
||||
if err := c.BodyParser(tr); err != nil {
|
||||
s.logger.Error("CreateTraining", zap.Error(err))
|
||||
c.JSON(CreateTraining400ApplicationProblemPlusJSONResponse{
|
||||
Status: fiber.StatusBadRequest,
|
||||
Title: fmt.Sprintf("Internal server error: %s", "failed to parse request body"),
|
||||
})
|
||||
}
|
||||
|
||||
if err := s.trainingRepo.Create(tr); err != nil {
|
||||
s.logger.Error("CreateTraining", zap.Error(err))
|
||||
c.JSON(CreateTraining500ApplicationProblemPlusJSONResponse{
|
||||
Status: fiber.StatusInternalServerError,
|
||||
Title: fmt.Sprintf("Internal server error: %s", "failed to save training"),
|
||||
})
|
||||
}
|
||||
|
||||
c.JSON(CreateTraining201JSONResponse{
|
||||
Id: tr.ID,
|
||||
Name: tr.Name,
|
||||
Days: int32(tr.Days),
|
||||
Price: tr.Price,
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
func (s *APIServer) UpdateTraining(c *fiber.Ctx) error {
|
||||
s.logger.Info("UpdateTraining")
|
||||
}
|
||||
|
||||
func (s *APIServer) DeleteTraining(c *fiber.Ctx, trainingID training.ID) error {
|
||||
s.logger.Info("DeleteTraining")
|
||||
}
|
||||
|
||||
func (s *APIServer) GetTraining(c *fiber.Ctx, trainingID training.ID) error {
|
||||
s.logger.Info("GetTraining")
|
||||
}
|
||||
|
||||
func (s *APIServer) ListTrainingDates(c *fiber.Ctx, trainingID training.ID) error {
|
||||
s.logger.Info("ListTrainingDates")
|
||||
}
|
||||
|
||||
func (s *APIServer) CreateTrainingDate(c *fiber.Ctx, trainingID training.ID) error {
|
||||
s.logger.Info("CreateTrainingDate")
|
||||
}
|
||||
|
||||
func (s *APIServer) UpdateTrainingDate(c *fiber.Ctx, trainingID training.ID, dateID training.DateID) error {
|
||||
s.logger.Info("UpdateTrainingDate")
|
||||
}
|
||||
|
||||
func (s *APIServer) DeleteTrainingDate(c *fiber.Ctx, trainingID training.ID, dateID training.DateID) error {
|
||||
s.logger.Info("DeleteTrainingDate")
|
||||
}
|
||||
|
||||
func (s *APIServer) ListUpcomingTrainingDates(c *fiber.Ctx, params ListUpcomingTrainingDatesParams) error {
|
||||
s.logger.Info("ListUpcomingTrainingDates")
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *APIServer) ListTrainingDateAttendees(c *fiber.Ctx, trainingID training.ID, dateID training.DateID) error {
|
||||
s.logger.Info("ListTrainingDateAttendees")
|
||||
}
|
||||
|
||||
func (s *APIServer) CreateTrainingDateAttendee(c *fiber.Ctx, trainingID training.ID, dateID training.DateID) error {
|
||||
s.logger.Info("CreateTrainingDateAttendee")
|
||||
}
|
||||
|
||||
func (s *APIServer) DeleteTrainingDateAttendee(c *fiber.Ctx, trainingID training.ID, dateID training.DateID, attendeeID training.AttendeeID) error {
|
||||
s.logger.Info("DeleteTrainingDateAttendee")
|
||||
}
|
||||
|
||||
func (s *APIServer) CreateTrainingDateAttendeeFeedback(c *fiber.Ctx, trainingID training.ID, dateID training.DateID, attendeeID training.AttendeeID) error {
|
||||
s.logger.Info("CreateTrainingDateAttendeeFeedback")
|
||||
}
|
||||
|
||||
func (s *APIServer) ListTrainingDateFeedback(c *fiber.Ctx, trainingID training.ID, dateID training.DateID) error {
|
||||
s.logger.Info("ListTrainingDateFeedback")
|
||||
}
|
||||
|
||||
func (s *APIServer) ListTrainingFeedback(c *fiber.Ctx, trainingID training.ID) error {
|
||||
s.logger.Info("ListTrainingFeedback")
|
||||
}
|
||||
Reference in a new issue