office

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: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Monday      = models.WorkingDay{Model: gorm.Model{ID: 1, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Day: "Monday", Value: 1}
	Tuesday     = models.WorkingDay{Model: gorm.Model{ID: 2, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Day: "Tuesday", Value: 2}
	Wednesday   = models.WorkingDay{Model: gorm.Model{ID: 3, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Day: "Wednesday", Value: 3}
	Thursday    = models.WorkingDay{Model: gorm.Model{ID: 4, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Day: "Thursday", Value: 4}
	Friday      = models.WorkingDay{Model: gorm.Model{ID: 5, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Day: "Friday", Value: 5}
	Saturday    = models.WorkingDay{Model: gorm.Model{ID: 6, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Day: "Saturday", Value: 6}
	Sunday      = models.WorkingDay{Model: gorm.Model{ID: 7, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Day: "Sunday", Value: 7}
	WorkingDays = []models.WorkingDay{Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday}
)
View Source
var (
	FakeOffice_1 = models.Office{
		Base:         models.Base{ID: officeID1, CreatedAt: time.Now(), UpdatedAt: time.Now()},
		OpeningHours: openingHours_1.FromString("00:00"),
		ClosingHours: openingHours_1.FromString("23:59"),
		WorkingDays: []models.WorkingDay{
			Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday,
		},
		Vendor:   vendors.FakeVendor_1,
		Location: location.FakeLocation_1,
	}
	FakeOffice_2 = models.Office{
		Base:         models.Base{ID: officeID2, CreatedAt: time.Now(), UpdatedAt: time.Now()},
		OpeningHours: openingHours_2.FromString("00:00"),
		ClosingHours: openingHours_2.FromString("23:59"),
		WorkingDays: []models.WorkingDay{
			Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday,
		},
		Vendor:   vendors.FakeVendor_2,
		Location: location.FakeLocation_2,
	}

	FakeOfficeList = []models.Office{FakeOffice_1, FakeOffice_2}
)
View Source
var (
	OfficeIds = []uuid.UUID{officeID1, officeID2}
)

Functions

func NewOfficeHandler

func NewOfficeHandler(r *gin.RouterGroup, officeService OfficeServiceInterface)

GetOffice is a handler to get a office

Types

type OfficeHandler

type OfficeHandler struct {
	// contains filtered or unexported fields
}

func (*OfficeHandler) CreateOffice

func (h *OfficeHandler) CreateOffice(c *gin.Context)

CreateOffice is a handler to create a office @Summary Create a office @Description Create a office with payload @Tags offices @Accept json @Produce json @Param body body office.OfficeRequest true "Office payload" @Success 200 {object} office.OfficeResponse @Failure 400 {object} _type.APIErrorResponse @Failure 500 {object} _type.APIErrorResponse @Router /offices/ [post]

func (*OfficeHandler) GetOffices

func (h *OfficeHandler) GetOffices(c *gin.Context)

GetAllOffices is a handler to get all office @Summary List all offices @Description List all offices with pagination and search @Tags offices @Accept json @Produce json @Param page query int false "Page number" @Param limit query int false "Page limit" @Success 200 {object} office.OfficeListResponse @Failure 500 {object} _type.APIErrorResponse @Router /offices/ [get]

type OfficeListResponse

type OfficeListResponse struct {
	pgHelper.Pagination
	Data []OfficeResponse `json:"data"`
}

OfficeListResponse is the response for the list of offices

func OfficesToOfficeListResponse

func OfficesToOfficeListResponse(offices *[]models.Office, pg *pgHelper.Pagination) *OfficeListResponse

OfficesToOfficeListResponse converts a list of offices to a response

type OfficeRepository

type OfficeRepository struct {
	// contains filtered or unexported fields
}

func NewOfficeRepository

func NewOfficeRepository(db *gorm.DB) *OfficeRepository

NewOfficeRepository returns a new office repository

func (*OfficeRepository) CreateOffice

func (r *OfficeRepository) CreateOffice(office *models.Office) (*models.Office, error)

CreateOffice creates a new office

func (*OfficeRepository) FindByOfficeAndVendorID

func (r *OfficeRepository) FindByOfficeAndVendorID(officeID, vendorID uuid.UUID) (*models.Office, error)

FindByOfficeAndVendorID returns a office by office id and vendor id

func (*OfficeRepository) GetOfficeIDs

func (r *OfficeRepository) GetOfficeIDs(
	locationId uuid.UUID, pickupWeekDay, dropoffWeekDay int, pickupTime, dropoffTime time.Time,
) ([]uuid.UUID, error)

GetOfficeIDs returns all office based on given params

func (*OfficeRepository) GetOffices

func (r *OfficeRepository) GetOffices(pg *pgHelper.Pagination) (*[]models.Office, error)

GetOffices returns all offices

func (*OfficeRepository) GetWorkingDaysByValues

func (r *OfficeRepository) GetWorkingDaysByValues(workingDays *[]models.WorkingDay) (*[]models.WorkingDay, error)

GetWorkingDaysByValues returns a working day by value

func (*OfficeRepository) LoadWorkingDay

func (r *OfficeRepository) LoadWorkingDay() error

CreateWorkingDay creates a new working day

func (*OfficeRepository) Migration

func (r *OfficeRepository) Migration()

Migration migrates the database also loads the working days

type OfficeRepositoryInterface

type OfficeRepositoryInterface interface {
	GetOffices(pg *pgHelper.Pagination) (*[]models.Office, error)
	CreateOffice(office *models.Office) (*models.Office, error)
	FindByOfficeAndVendorID(officeID, vendorID uuid.UUID) (*models.Office, error)
	GetOfficeIDs(locationId uuid.UUID, pickupWeekDay, dropoffWeekDay int, pickupTime, dropoffTime time.Time) ([]uuid.UUID, error)
	GetWorkingDaysByValues(workingDays *[]models.WorkingDay) (*[]models.WorkingDay, error)
}

type OfficeRequest

type OfficeRequest struct {
	OpeningHours models.JsonTime `json:"opening_hours"`
	ClosingHours models.JsonTime `json:"closing_hours"`
	VendorID     uuid.UUID       `json:"vendor_id"`
	LocationID   uuid.UUID       `json:"location_id"`
	WorkingDays  []uint          `json:"working_days"`
}

func (*OfficeRequest) ToOffice

func (r *OfficeRequest) ToOffice() *models.Office

ToOffice converts the OfficeRequest to Office

func (*OfficeRequest) Validate

func (r *OfficeRequest) Validate() error

Validate validates the OfficeRequest

type OfficeResponse

type OfficeResponse struct {
	ID           uuid.UUID                 `json:"id"`
	OpeningHours models.JsonTime           `json:"opening_hours"`
	ClosingHours models.JsonTime           `json:"closing_hours"`
	Vendor       vendors.VendorResponse    `json:"vendor"`
	Location     location.LocationResponse `json:"location"`
	WorkingDays  []string                  `json:"working_days"`
}

func OfficeToResponse

func OfficeToResponse(office *models.Office) *OfficeResponse

OfficeToResponse converts the Office to OfficeResponse

type OfficeService

type OfficeService struct {
	// contains filtered or unexported fields
}

func NewOfficeService

func NewOfficeService(officeRepo OfficeRepositoryInterface) *OfficeService

NewOfficeService creates a new office service

func (*OfficeService) CreateOffice

func (s *OfficeService) CreateOffice(office *models.Office) (*models.Office, error)

CreateOffice creates a office and returns it

func (*OfficeService) GetOffices

func (s *OfficeService) GetOffices(pg *pgHelper.Pagination) (*[]models.Office, error)

GetOffices returns all offices

type OfficeServiceInterface

type OfficeServiceInterface interface {
	GetOffices(pg *pgHelper.Pagination) (*[]models.Office, error)
	CreateOffice(office *models.Office) (*models.Office, error)
}

type OfficeSimpleResponse

type OfficeSimpleResponse struct {
	ID           uuid.UUID       `json:"id"`
	OpeningHours models.JsonTime `json:"opening_hours"`
	ClosingHours models.JsonTime `json:"closing_hours"`
	Location     uuid.UUID       `json:"location"`
}

func OfficeToSimpleResponse

func OfficeToSimpleResponse(office *models.Office) *OfficeSimpleResponse

Jump to

Keyboard shortcuts

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