Documentation ¶
Index ¶
- Variables
- func NewCarHandler(r *gin.RouterGroup, carService CarServiceInterface)
- type CarHandler
- type CarListResponse
- type CarRepository
- func (r *CarRepository) CreateCar(car *models.Car) (*models.Car, error)
- func (r *CarRepository) GetCarByID(id uuid.UUID) (*models.Car, error)
- func (r *CarRepository) GetCarsByOfficeIDs(pg *pgHelper.Pagination, officeIDs []uuid.UUID) (*[]models.Car, error)
- func (r *CarRepository) Migration()
- func (r *CarRepository) UpdateCarStatus(car *models.Car) (*models.Car, error)
- type CarRepositoryInterface
- type CarRequest
- type CarResponse
- type CarService
- type CarServiceInterface
- type CarSimpleResponse
Constants ¶
This section is empty.
Variables ¶
var ( FakeCar_1 = models.Car{ Base: models.Base{ID: uuid.New(), CreatedAt: time.Now(), UpdatedAt: time.Now()}, Status: &availableStatus, Name: &carName1, Fuel: models.Diesel, Transmission: models.Automatic, Vendor: vendors.FakeVendor_1, Office: office.FakeOffice_1, } FakeCar_2 = models.Car{ Base: models.Base{ID: uuid.New(), CreatedAt: time.Now(), UpdatedAt: time.Now()}, Status: &availableStatus, Name: &carName2, Fuel: models.Diesel, Transmission: models.Automatic, Vendor: vendors.FakeVendor_2, Office: office.FakeOffice_2, } FakeCar_3 = models.Car{ Base: models.Base{ID: uuid.New(), CreatedAt: time.Now(), UpdatedAt: time.Now()}, Status: &availableStatus, Name: &carName3, Fuel: models.Diesel, Transmission: models.Automatic, Vendor: vendors.FakeVendor_1, Office: office.FakeOffice_1, } FakeCarList = []models.Car{FakeCar_1, FakeCar_2, FakeCar_3} )
var ( FakeCarFilterData = filters.CarFilter{ PickupDate: dateJson.FromString("19-06-2022"), PickupTime: timeJson.FromString("09:00"), DropoffDate: dateJson.FromString("21-06-2022"), DropoffTime: timeJson.FromString("12:00"), Location: location.LocationId1, } )
Functions ¶
func NewCarHandler ¶
func NewCarHandler(r *gin.RouterGroup, carService CarServiceInterface)
Types ¶
type CarHandler ¶
type CarHandler struct {
// contains filtered or unexported fields
}
func (*CarHandler) CreateCar ¶
func (h *CarHandler) CreateCar(c *gin.Context)
CreateCar is a handler to create a car @Summary Create a car @Description Create a car with payload @Tags car @Accept json @Produce json @Param body body car.CarRequest true "Car payload" @Success 200 {object} car.CarResponse @Failure 400 {object} _type.APIErrorResponse @Failure 500 {object} _type.APIErrorResponse @Router /cars/ [post]
func (*CarHandler) GetAllCars ¶
func (h *CarHandler) GetAllCars(c *gin.Context)
GetAllCars is a handler to get all cars @Summary List all cars @Description List all cars with pagination and search @Tags car @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" @Param pickup_date query string true "Pickup date" @Param pickup_time query string true "Pickup time" @Param dropoff_date query string true "Dropoff date" @Param dropoff_time query string true "Dropoff time" @Param location_id query string true "UUID formatted ID" @Success 200 {object} car.CarListResponse @Failure 500 {object} _type.APIErrorResponse @Router /cars/ [get]
type CarListResponse ¶
type CarListResponse struct { pgHelper.Pagination Data []CarResponse `json:"data"` }
func CarsToCarListResponse ¶
func CarsToCarListResponse(cars *[]models.Car, pagination *pgHelper.Pagination) *CarListResponse
CarsToCarListResponse converts a list of cars to a car list response
type CarRepository ¶
type CarRepository struct {
// contains filtered or unexported fields
}
func NewCarRepository ¶
func NewCarRepository(db *gorm.DB) *CarRepository
NewCarRepository creates a new car repository
func (*CarRepository) GetCarByID ¶
GetCarByID returns a car by id
func (*CarRepository) GetCarsByOfficeIDs ¶
func (r *CarRepository) GetCarsByOfficeIDs(pg *pgHelper.Pagination, officeIDs []uuid.UUID) (*[]models.Car, error)
GetCarsByOfficeIDs returns a list of cars by office ids
func (*CarRepository) UpdateCarStatus ¶
UpdateCarStatus updates a car status
type CarRepositoryInterface ¶
type CarRequest ¶
type CarRequest struct { Status models.CarStatusEnums `json:"status" enums:"available,rented"` Name *string `json:"name"` Fuel models.FuelEnums `json:"fuel" enums:"gas,diesel,electric"` Transmission models.TransmissionEnums `json:"transmission" enums:"automatic,manual"` VendorID uuid.UUID `json:"vendor_id"` OfficeID uuid.UUID `json:"office_id"` }
CarRequest is the request for creating a car
func (*CarRequest) ToCar ¶
func (req *CarRequest) ToCar() *models.Car
ToCar converts the request to a car
func (*CarRequest) Validate ¶
func (req *CarRequest) Validate() error
Validate validates the request
type CarResponse ¶
type CarResponse struct { ID uuid.UUID `json:"id"` Status models.CarStatusEnums `json:"status"` Name string `json:"name"` Fuel string `json:"fuel"` Transmission string `json:"transmission"` Vendor vendors.VendorResponse `json:"vendor"` Office office.OfficeSimpleResponse `json:"office"` }
func CarToCarResponse ¶
func CarToCarResponse(car *models.Car) *CarResponse
CarToCarResponse converts a car to a car response
type CarService ¶
type CarService struct {
// contains filtered or unexported fields
}
func NewCarService ¶
func NewCarService( carRepo CarRepositoryInterface, locationRepo location.LocationRepositoryInterface, officeRepo office.OfficeRepositoryInterface, ) *CarService
NewCarService creates a new car service
func (*CarService) GetCars ¶
func (s *CarService) GetCars(pg *pgHelper.Pagination, filter *filters.CarFilter) (*[]models.Car, error)
GetCars returns cars by filter and pagination
type CarServiceInterface ¶
type CarSimpleResponse ¶
type CarSimpleResponse struct { ID uuid.UUID `json:"id"` Status models.CarStatusEnums `json:"status"` Name string `json:"name"` Fuel string `json:"fuel"` Transmission string `json:"transmission"` Vendor string `json:"vendor"` Office string `json:"office"` }
func CarToCarSimpleResponse ¶
func CarToCarSimpleResponse(car *models.Car) *CarSimpleResponse
CarToCarSimpleResponse converts a car to a car list response