Documentation ¶
Index ¶
- Variables
- func NewReservationHandler(r *gin.RouterGroup, reservationService ReservationServiceInterface)
- type ReservationHandler
- type ReservationListResponse
- type ReservationRepository
- type ReservationRepositoryInterface
- type ReservationRequest
- type ReservationResponse
- type ReservationService
- type ReservationServiceInterface
Constants ¶
This section is empty.
Variables ¶
var ( FakeReservation1 = &models.Reservation{ Base: models.Base{ID: uuid.New(), CreatedAt: time.Now(), UpdatedAt: time.Now()}, PickupLocation: location.FakeLocation_1, PickupDate: dateJson.FromString("01-01-2020"), PickupTime: timeJson.FromString("12:00"), DropoffLocation: location.FakeLocation_1, DropoffDate: dateJson.FromString("01-01-2020"), DropoffTime: timeJson.FromString("13:00"), Car: car.FakeCar_1, Driver: FakeDriver, } FakeReservation2 = models.Reservation{ Base: models.Base{ID: uuid.New(), CreatedAt: time.Now(), UpdatedAt: time.Now()}, PickupLocation: location.FakeLocation_1, PickupDate: dateJson.FromString("01-01-2020"), PickupTime: timeJson.FromString("12:00"), DropoffLocation: location.FakeLocation_1, DropoffDate: dateJson.FromString("01-01-2020"), DropoffTime: timeJson.FromString("13:00"), Car: car.FakeCar_1, Driver: FakeDriver, } FakeReservation3 = models.Reservation{ Base: models.Base{ID: uuid.New(), CreatedAt: time.Now(), UpdatedAt: time.Now()}, PickupLocation: location.FakeLocation_1, PickupDate: dateJson.FromString("01-01-2020"), PickupTime: timeJson.FromString("12:00"), DropoffLocation: location.FakeLocation_1, DropoffDate: dateJson.FromString("01-01-2020"), DropoffTime: timeJson.FromString("13:00"), Car: car.FakeCar_1, Driver: FakeDriver, } FakeReservationList = []models.Reservation{*FakeReservation1, FakeReservation2, FakeReservation3} FakeReservation4 = models.Reservation{ PickupLocationID: location.FakeLocation_1.ID, PickupDate: dateJson.FromString("01-01-2020"), PickupTime: timeJson.FromString("12:00"), DropoffLocationID: location.FakeLocation_1.ID, DropoffDate: dateJson.FromString("01-01-2020"), DropoffTime: timeJson.FromString("13:00"), CarID: car.FakeCar_1.ID, Driver: FakeDriver, } FakeReservationRequest, _ = json.Marshal(FakeReservation4) )
Functions ¶
func NewReservationHandler ¶
func NewReservationHandler(r *gin.RouterGroup, reservationService ReservationServiceInterface)
NewReservationHandler creates a new reservation handler
Types ¶
type ReservationHandler ¶
type ReservationHandler struct {
// contains filtered or unexported fields
}
func (*ReservationHandler) CreateReservation ¶
func (h *ReservationHandler) CreateReservation(c *gin.Context)
CreateReservation is a handler to create a reservation @Summary Create a reservation @Description Create a reservation with payload @Tags reservation @Accept json @Produce json @Param body body reservation.ReservationRequest true "Reservation payload" @Success 201 {object} reservation.ReservationResponse @Failure 400 {object} _type.APIErrorResponse @Failure 500 {object} _type.APIErrorResponse @Router /reservations/ [post]
func (*ReservationHandler) GetAllReservations ¶
func (h *ReservationHandler) GetAllReservations(c *gin.Context)
GetAllReservations is a handler to get all reservations @Summary List all reservations @Description List all reservations with pagination and search @Tags reservation @Accept json @Produce json @Param q query string false "Search query" @Param page query int false "Page number" @Param limit query int false "Page limit" @Success 200 {object} reservation.ReservationListResponse @Failure 500 {object} _type.APIErrorResponse @Router /reservations/ [get]
type ReservationListResponse ¶
type ReservationListResponse struct { pgHelper.Pagination Data []ReservationResponse `json:"data"` }
func ReservationsToReservationListResponse ¶
func ReservationsToReservationListResponse(reservations *[]models.Reservation, pagination *pgHelper.Pagination) *ReservationListResponse
ReservationsToReservationListResponse converts a list of reservations to a reservation list response
type ReservationRepository ¶
type ReservationRepository struct {
// contains filtered or unexported fields
}
func NewReservationRepository ¶
func NewReservationRepository(db *gorm.DB) *ReservationRepository
NewReservationRepository creates a new reservation repository
func (*ReservationRepository) CreateReservation ¶
func (r *ReservationRepository) CreateReservation(reservation *models.Reservation) (*models.Reservation, error)
CreateReservation creates a new reservation in database
func (*ReservationRepository) GetReservations ¶
func (r *ReservationRepository) GetReservations(pg *pgHelper.Pagination) (*[]models.Reservation, error)
GetReservations gets reservations from database with pagination
func (*ReservationRepository) Migration ¶
func (r *ReservationRepository) Migration()
Migration migrates database
type ReservationRepositoryInterface ¶
type ReservationRepositoryInterface interface { GetReservations(pg *pgHelper.Pagination) (*[]models.Reservation, error) CreateReservation(reservation *models.Reservation) (*models.Reservation, error) }
type ReservationRequest ¶
type ReservationRequest struct { PickupLocationID uuid.UUID `json:"pickup_location_id" validate:"required" binding:"required" format:"UUID"` PickUpDate models.JsonDate `json:"pick_up_date" validate:"required" binding:"required" format:"02-01-2006"` PickUpTime models.JsonTime `json:"pick_up_time" validate:"required" binding:"required" format:"15:04"` DropoffLocationID uuid.UUID `json:"dropoff_location_id" validate:"required" binding:"required" format:"UUID"` DropOffDate models.JsonDate `json:"drop_off_date" validate:"required" binding:"required" format:"02-01-2006"` DropOffTime models.JsonTime `json:"drop_off_time" validate:"required" binding:"required" format:"15:04"` CarID uuid.UUID `json:"car_id" validate:"required" binding:"required" format:"UUID"` Driver *driver.DriverRequest `json:"driver" validate:"required" binding:"required"` }
ReservationRequest represents the reservation request.
func (*ReservationRequest) ToReservation ¶
func (r *ReservationRequest) ToReservation() *models.Reservation
ToReservation converts the reservation request to reservation model.
func (*ReservationRequest) Validate ¶
func (r *ReservationRequest) Validate() error
Validate validates the reservation request.
type ReservationResponse ¶
type ReservationResponse struct { ID uuid.UUID `json:"id"` PickupLocation location.LocationResponse `json:"pickup_location"` PickupDate models.JsonDate `json:"pick_up_date"` PickupTime models.JsonTime `json:"pick_up_time"` DropoffLocation location.LocationResponse `json:"dropoff_location"` DropoffDate models.JsonDate `json:"drop_off_date"` DropoffTime models.JsonTime `json:"drop_off_time"` Car car.CarSimpleResponse `json:"car"` Driver driver.DriverResponse `json:"driver_response"` }
ReservationResponse represents the reservation response.
func ReservationToResponse ¶
func ReservationToResponse(reservation *models.Reservation) *ReservationResponse
ReservationToResponse converts a reservation to a response.
type ReservationService ¶
type ReservationService struct {
// contains filtered or unexported fields
}
func NewReservationService ¶
func NewReservationService( reservationRepo ReservationRepositoryInterface, carRepo car.CarRepositoryInterface, officeRepo office.OfficeRepositoryInterface, locationRepo location.LocationRepositoryInterface, ) *ReservationService
NewReservationService creates a new reservation service
func (*ReservationService) CreateReservation ¶
func (s *ReservationService) CreateReservation(reservation *models.Reservation) error
CreateReservation creates a reservation and returns it
func (*ReservationService) GetReservations ¶
func (s *ReservationService) GetReservations(pg *pgHelper.Pagination) (*[]models.Reservation, error)
GetReservations returns all reservations
type ReservationServiceInterface ¶
type ReservationServiceInterface interface { GetReservations(pg *pgHelper.Pagination) (*[]models.Reservation, error) CreateReservation(reservation *models.Reservation) error }