location

package
v0.0.0-...-4cd3371 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 19, 2022 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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,
	}
)
View Source
var FakeDataWithPagination = pgHelper.Pagination{
	Limit: 2,
	Page:  1,
	Q:     "",
}

Functions

func NewLocationHandler

func NewLocationHandler(r *gin.RouterGroup, locationService LocationServiceInterface)
func Search(search string) func(db *gorm.DB) *gorm.DB

Search adds where to search keywords

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

func (r *LocationRepository) CreateLocation(location *models.Location) (*models.Location, error)

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

func (r *LocationRepository) GetLocationByID(id uuid.UUID) (*models.Location, error)

GetLocationByID gets location from database by id

func (*LocationRepository) Migration

func (r *LocationRepository) Migration()

Migration for location table

type LocationRepositoryInterface

type LocationRepositoryInterface interface {
	GetAllActiveLocations(pg *pgHelper.Pagination) (*[]models.Location, error)
	CreateLocation(location *models.Location) (*models.Location, error)
	GetLocationByID(id uuid.UUID) (*models.Location, error)
}

type LocationRequest

type LocationRequest struct {
	Name     string `json:"name"`
	IsActive bool   `json:"is_active"`
}

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

func (s *LocationService) CreateLocation(location *models.Location) (*models.Location, error)

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

type LocationServiceInterface

type LocationServiceInterface interface {
	GetAllActiveLocations(pg *pgHelper.Pagination) (*[]models.Location, error)
	CreateLocation(location *models.Location) (*models.Location, error)
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL