Documentation ¶
Index ¶
- Variables
- func NewLocationHandler(r *gin.RouterGroup, locationService LocationServiceInterface)
- func Search(search string) func(db *gorm.DB) *gorm.DB
- type LocationHandler
- type LocationListResponse
- type LocationRepository
- func (r *LocationRepository) CreateLocation(location *models.Location) (*models.Location, error)
- func (r *LocationRepository) GetAllActiveLocations(pg *pgHelper.Pagination) (*[]models.Location, error)
- func (r *LocationRepository) GetLocationByID(id uuid.UUID) (*models.Location, error)
- func (r *LocationRepository) Migration()
- type LocationRepositoryInterface
- type LocationRequest
- type LocationResponse
- type LocationService
- type LocationServiceInterface
Constants ¶
This section is empty.
Variables ¶
var (
LocationId1, LocationId2, LocationId3, LocationId4 = uuid.New(), uuid.New(), uuid.New(), uuid.New()
FakeLocation_1 = models.Location{
Base: models.Base{ID: LocationId1, CreatedAt: time.Now(), UpdatedAt: time.Now()},
Name: &locationName1,
IsActive: true,
}
FakeLocation_2 = models.Location{
Base: models.Base{ID: LocationId2, CreatedAt: time.Now(), UpdatedAt: time.Now()},
Name: &locationName2,
IsActive: false,
}
FakeLocation_3 = models.Location{
Base: models.Base{ID: LocationId3, CreatedAt: time.Now(), UpdatedAt: time.Now()},
Name: &locationName3,
IsActive: true,
}
FakeLocation_4 = models.Location{
Base: models.Base{ID: LocationId4, CreatedAt: time.Now(), UpdatedAt: time.Now()},
Name: &locationName4,
IsActive: false,
}
)
var FakeDataWithPagination = pgHelper.Pagination{
Limit: 2,
Page: 1,
Q: "",
}
var FakeLocationsData = []models.Location{FakeLocation_1, FakeLocation_2, FakeLocation_3}
Functions ¶
func NewLocationHandler ¶
func NewLocationHandler(r *gin.RouterGroup, locationService LocationServiceInterface)
Types ¶
type LocationHandler ¶
type LocationHandler struct {
// contains filtered or unexported fields
}
func (*LocationHandler) CreateLocation ¶
func (h *LocationHandler) CreateLocation(c *gin.Context)
CreateLocation is a handler to create a location @Summary Create a location @Description Create a location with payload @Tags location @Accept json @Produce json @Param body body location.LocationRequest true "Location payload" @Success 201 {object} location.LocationResponse @Failure 400 {object} _type.APIErrorResponse @Failure 500 {object} _type.APIErrorResponse @Router /locations/ [post]
func (*LocationHandler) GetAllLocations ¶
func (h *LocationHandler) GetAllLocations(c *gin.Context)
GetAllLocations is a handler to get all locations @Summary List all locations @Description List all locations with pagination and search @Tags location @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} location.LocationListResponse @Failure 500 {object} _type.APIErrorResponse @Router /locations/ [get]
type LocationListResponse ¶
type LocationListResponse struct { pgHelper.Pagination Data []LocationResponse `json:"data"` }
func LocationsToLocationListResponse ¶
func LocationsToLocationListResponse(locations *[]models.Location, pg *pgHelper.Pagination) *LocationListResponse
LocationsToLocationListResponse converts a list of locations to a response
type LocationRepository ¶
type LocationRepository struct {
// contains filtered or unexported fields
}
func NewLocationRepository ¶
func NewLocationRepository(db *gorm.DB) *LocationRepository
NewLocationRepository creates a new location repository
func (*LocationRepository) CreateLocation ¶
CreateLocation creates a location and returns it
func (*LocationRepository) GetAllActiveLocations ¶
func (r *LocationRepository) GetAllActiveLocations(pg *pgHelper.Pagination) (*[]models.Location, error)
GetAllActiveLocations gets all active locations from database
func (*LocationRepository) GetLocationByID ¶
GetLocationByID gets location from database by id
func (*LocationRepository) Migration ¶
func (r *LocationRepository) Migration()
Migration for location table
type LocationRequest ¶
func (*LocationRequest) ToModel ¶
func (req *LocationRequest) ToModel() *models.Location
func (*LocationRequest) Validate ¶
func (req *LocationRequest) Validate() error
type LocationResponse ¶
type LocationResponse struct { ID uuid.UUID `json:"id"` Name string `json:"name"` IsActive bool `json:"is_active"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` }
func LocationToResponse ¶
func LocationToResponse(location *models.Location) *LocationResponse
LocationToResponse converts a location to a response
type LocationService ¶
type LocationService struct {
// contains filtered or unexported fields
}
func NewLocationService ¶
func NewLocationService(locationRepo LocationRepositoryInterface) *LocationService
NewLocationService creates a new location service
func (*LocationService) CreateLocation ¶
CreateLocation creates a location and returns it
func (*LocationService) GetAllActiveLocations ¶
func (s *LocationService) GetAllActiveLocations(pg *pgHelper.Pagination) (*[]models.Location, error)
GetAllActiveLocations returns all active locations