server

package
v0.0.0-...-87346ed Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2020 License: Apache-2.0 Imports: 38 Imported by: 0

Documentation

Index

Constants

View Source
const (
	REQUIRED       = "REQUIRED"
	ALPHANUMERIC   = "ALPHANUMERIC"
	ALPHA          = "ALPHA"
	NUMERIC        = "NUMERIC"
	FLOAT          = "FLOAT"
	PARSE_FAILED   = "PARSE_FAILED"
	INVALID_OPTION = "INVALID_OPTION"
	NOT_FOUND      = "NOT_FOUND"
)

Variables

This section is empty.

Functions

func Error

func Error(c echo.Context, err error) error

Error wraps errors from application layer and domain layer to some format in JSON for response

func MapToFarmRead

func MapToFarmRead(farm *domain.Farm) *storage.FarmRead

func MapToPlantType

func MapToPlantType(plantTypes []domain.PlantType) []string

func MapToReservoirRead

func MapToReservoirRead(s *FarmServer, reservoir domain.Reservoir) (storage.ReservoirRead, error)

func MapToReservoirReadFromRead

func MapToReservoirReadFromRead(s *FarmServer, reservoir storage.ReservoirRead) (storage.ReservoirRead, error)

func Message

func Message(errorCode string) string

Message translates error code to meaningful message

Types

type AreaList

type AreaList struct {
	UID            uuid.UUID        `json:"uid"`
	Name           string           `json:"name"`
	Type           string           `json:"type"`
	Size           storage.AreaSize `json:"size"`
	TotalCropBatch int              `json:"total_crop_batch"`
	PlantQuantity  int              `json:"plant_quantity"`
}

func MapToAreaList

func MapToAreaList(s *FarmServer, areas []storage.AreaRead) ([]AreaList, error)

type AvailableMaterialPlantType

type AvailableMaterialPlantType struct {
	PlantType string   `json:"plant_type"`
	Names     []string `json:"names"`
}

func MapToAvailableMaterialPlantType

func MapToAvailableMaterialPlantType(materials []storage.MaterialRead) []AvailableMaterialPlantType

type DetailArea

type DetailArea struct {
	storage.AreaRead
	TotalCropBatch int `json:"total_crop_batch"`
	TotalVariety   int `json:"total_variety"`
	PlantQuantity  int `json:"plant_quantity"`
}

func MapToDetailArea

func MapToDetailArea(s *FarmServer, area domain.Area) (DetailArea, error)

func MapToDetailAreaFromStorage

func MapToDetailAreaFromStorage(s *FarmServer, areaRead storage.AreaRead) (DetailArea, error)

type DetailReservoir

type DetailReservoir struct {
	UID              uuid.UUID            `json:"uid"`
	Name             string               `json:"name"`
	WaterSource      WaterSource          `json:"water_source"`
	Farm             SimpleFarm           `json:"farm"`
	CreatedDate      time.Time            `json:"created_date"`
	Notes            SortedReservoirNotes `json:"notes"`
	InstalledToAreas []SimpleArea         `json:"installed_to_areas"`
}

type FarmServer

type FarmServer struct {
	FarmEventRepo       repository.FarmEventRepository
	FarmEventQuery      query.FarmEventQuery
	FarmReadRepo        repository.FarmReadRepository
	FarmReadQuery       query.FarmReadQuery
	ReservoirEventRepo  repository.ReservoirEventRepository
	ReservoirEventQuery query.ReservoirEventQuery
	ReservoirReadRepo   repository.ReservoirReadRepository
	ReservoirReadQuery  query.ReservoirReadQuery
	ReservoirService    domain.ReservoirService
	AreaEventRepo       repository.AreaEventRepository
	AreaReadRepo        repository.AreaReadRepository
	AreaEventQuery      query.AreaEventQuery
	AreaReadQuery       query.AreaReadQuery
	AreaService         domain.AreaService
	MaterialEventRepo   repository.MaterialEventRepository
	MaterialEventQuery  query.MaterialEventQuery
	MaterialReadRepo    repository.MaterialReadRepository
	MaterialReadQuery   query.MaterialReadQuery
	CropReadQuery       query.CropReadQuery
	File                File
	EventBus            eventbus.TaniaEventBus
}

FarmServer ties the routes and handlers with injected dependencies

func NewFarmServer

func NewFarmServer(
	db *sql.DB,
	farmEventStorage *storage.FarmEventStorage,
	farmReadStorage *storage.FarmReadStorage,
	areaEventStorage *storage.AreaEventStorage,
	areaReadStorage *storage.AreaReadStorage,
	reservoirEventStorage *storage.ReservoirEventStorage,
	reservoirReadStorage *storage.ReservoirReadStorage,
	materialEventStorage *storage.MaterialEventStorage,
	materialReadStorage *storage.MaterialReadStorage,
	cropReadStorage *growthstorage.CropReadStorage,
	eventBus eventbus.TaniaEventBus,
) (*FarmServer, error)

NewFarmServer initializes FarmServer's dependencies and create new FarmServer struct

func (FarmServer) FindAllFarm

func (s FarmServer) FindAllFarm(c echo.Context) error

func (*FarmServer) FindFarmByID

func (s *FarmServer) FindFarmByID(c echo.Context) error

func (*FarmServer) GetAreaPhotos

func (s *FarmServer) GetAreaPhotos(c echo.Context) error

func (*FarmServer) GetAreasByID

func (s *FarmServer) GetAreasByID(c echo.Context) error

func (*FarmServer) GetAvailableMaterialPlantType

func (s *FarmServer) GetAvailableMaterialPlantType(c echo.Context) error

func (*FarmServer) GetFarmAreas

func (s *FarmServer) GetFarmAreas(c echo.Context) error

func (*FarmServer) GetFarmReservoirs

func (s *FarmServer) GetFarmReservoirs(c echo.Context) error

func (*FarmServer) GetInventoryPlantTypes

func (s *FarmServer) GetInventoryPlantTypes(c echo.Context) error

func (*FarmServer) GetMaterialByID

func (s *FarmServer) GetMaterialByID(c echo.Context) error

func (*FarmServer) GetMaterials

func (s *FarmServer) GetMaterials(c echo.Context) error

func (*FarmServer) GetMaterialsSimple

func (s *FarmServer) GetMaterialsSimple(c echo.Context) error

func (*FarmServer) GetReservoirsByID

func (s *FarmServer) GetReservoirsByID(c echo.Context) error

func (*FarmServer) GetTotalAreas

func (s *FarmServer) GetTotalAreas(c echo.Context) error

func (*FarmServer) GetTypes

func (s *FarmServer) GetTypes(c echo.Context) error

GetTypes is a FarmServer's handle to get farm types

func (*FarmServer) InitSubscriber

func (s *FarmServer) InitSubscriber()

InitSubscriber defines the mapping of which event this domain listen with their handler

func (*FarmServer) Mount

func (s *FarmServer) Mount(g *echo.Group)

Mount defines the FarmServer's endpoints with its handlers

func (*FarmServer) RemoveAreaNotes

func (s *FarmServer) RemoveAreaNotes(c echo.Context) error

func (*FarmServer) RemoveReservoirNotes

func (s *FarmServer) RemoveReservoirNotes(c echo.Context) error

func (*FarmServer) SaveArea

func (s *FarmServer) SaveArea(c echo.Context) error

func (*FarmServer) SaveAreaNotes

func (s *FarmServer) SaveAreaNotes(c echo.Context) error

func (*FarmServer) SaveFarm

func (s *FarmServer) SaveFarm(c echo.Context) error

SaveFarm is a FarmServer's handler to save new Farm

func (*FarmServer) SaveMaterial

func (s *FarmServer) SaveMaterial(c echo.Context) error

func (*FarmServer) SaveReservoir

func (s *FarmServer) SaveReservoir(c echo.Context) error

SaveReservoir is a FarmServer's handler to save new Reservoir and place it to a Farm

func (*FarmServer) SaveReservoirNotes

func (s *FarmServer) SaveReservoirNotes(c echo.Context) error

func (*FarmServer) SaveToAreaReadModel

func (s *FarmServer) SaveToAreaReadModel(event interface{}) error

func (*FarmServer) SaveToFarmReadModel

func (s *FarmServer) SaveToFarmReadModel(event interface{}) error

func (*FarmServer) SaveToMaterialReadModel

func (s *FarmServer) SaveToMaterialReadModel(event interface{}) error

func (*FarmServer) SaveToReservoirReadModel

func (s *FarmServer) SaveToReservoirReadModel(event interface{}) error

func (*FarmServer) UpdateArea

func (s *FarmServer) UpdateArea(c echo.Context) error

func (*FarmServer) UpdateFarm

func (s *FarmServer) UpdateFarm(c echo.Context) error

func (*FarmServer) UpdateMaterial

func (s *FarmServer) UpdateMaterial(c echo.Context) error

func (*FarmServer) UpdateReservoir

func (s *FarmServer) UpdateReservoir(c echo.Context) error

type File

type File interface {
	GetFile(src string) ([]byte, error)
	Upload(file *multipart.FileHeader, destPath string) error
}

File used to handle file path and file operation. We use interface so we can swap it to other file storage easily

type LocalFile

type LocalFile struct {
}

func (LocalFile) GetFile

func (f LocalFile) GetFile(srcPath string) ([]byte, error)

func (LocalFile) Upload

func (f LocalFile) Upload(file *multipart.FileHeader, destPath string) error

Upload saves uploaded file to the destined path

type Material

type Material struct {
	UID            uuid.UUID        `json:"uid"`
	Name           string           `json:"name"`
	PricePerUnit   PricePerUnit     `json:"price_per_unit"`
	Type           MaterialType     `json:"type"`
	Quantity       MaterialQuantity `json:"quantity"`
	ExpirationDate *time.Time       `json:"expiration_date,omitempty"`
	Notes          *string          `json:"notes"`
	ProducedBy     *string          `json:"produced_by"`
	CreatedDate    time.Time        `json:"created_date"`
}

func MapToMaterial

func MapToMaterial(material domain.Material) Material

func MapToMaterialFromRead

func MapToMaterialFromRead(material storage.MaterialRead) Material

type MaterialQuantity

type MaterialQuantity struct {
	Value float32 `json:"value"`
	Unit  string  `json:"unit"`
}

type MaterialSimple

type MaterialSimple struct {
	UID  uuid.UUID    `json:"uid"`
	Name string       `json:"name"`
	Type MaterialType `json:"type"`
}

func MapToMaterialSimpleFromRead

func MapToMaterialSimpleFromRead(materials []storage.MaterialRead) []MaterialSimple

type MaterialType

type MaterialType struct {
	Code               string      `json:"code"`
	MaterialTypeDetail interface{} `json:"type_detail"`
}

type MaterialTypeAgrochemical

type MaterialTypeAgrochemical struct {
	ChemicalType domain.ChemicalType `json:"chemical_type"`
}

type MaterialTypePlant

type MaterialTypePlant struct {
	PlantType domain.PlantType `json:"plant_type"`
}

type MaterialTypeSeed

type MaterialTypeSeed struct {
	PlantType domain.PlantType `json:"plant_type"`
}

type MaterialTypeSeedingContainer

type MaterialTypeSeedingContainer struct {
	ContainerType domain.ContainerType `json:"container_type"`
}

type PricePerUnit

type PricePerUnit struct {
	Code   string `json:"code"`
	Symbol string `json:"symbol"`
	Amount string `json:"amount"`
}

type RequestValidation

type RequestValidation struct {
}

RequestValidation sanitizes request inputs and convert the input to its correct data type. This is mostly used to prevent issues like invalid data type or potential SQL Injection. So we can focus on processing data without converting data type after this sanitizing. This validation doesn't aim to validate business process. The business process validation will be handled in each entity's behaviour.

func (*RequestValidation) ValidateAreaLocation

func (rv *RequestValidation) ValidateAreaLocation(location string) (string, error)

func (*RequestValidation) ValidateAreaSize

func (rv *RequestValidation) ValidateAreaSize(size string, sizeUnit string) (domain.AreaSize, error)

func (*RequestValidation) ValidateCapacity

func (rv *RequestValidation) ValidateCapacity(waterSourceType, capacity string) (float32, error)

func (*RequestValidation) ValidateFarm

func (rv *RequestValidation) ValidateFarm(s FarmServer, farmUID uuid.UUID) (storage.FarmRead, error)

func (*RequestValidation) ValidateReservoir

func (rv *RequestValidation) ValidateReservoir(s FarmServer, reservoirUID uuid.UUID) (storage.ReservoirRead, error)

func (*RequestValidation) ValidateReservoirName

func (rv *RequestValidation) ValidateReservoirName(name string) (string, error)

func (*RequestValidation) ValidateType

func (rv *RequestValidation) ValidateType(t string) (string, error)

type RequestValidationError

type RequestValidationError struct {
	FieldName    string `json:"field_name"`
	ErrorCode    string `json:"error_code"`
	ErrorMessage string `json:"error_message"`
}

RequestValidationError contains fields used for JSON error response

func NewRequestValidationError

func NewRequestValidationError(errorCode, fieldName string) RequestValidationError

NewRequestValidationError initializes new RequestValidation struct

func (RequestValidationError) Error

func (rve RequestValidationError) Error() string

type ReservoirBucket

type ReservoirBucket struct{ domain.Bucket }

func (ReservoirBucket) MarshalJSON

func (rb ReservoirBucket) MarshalJSON() ([]byte, error)

type ReservoirNote

type ReservoirNote struct {
	UID         uuid.UUID
	Content     string
	CreatedDate time.Time
}

type ReservoirTap

type ReservoirTap struct{ domain.Tap }

func (ReservoirTap) MarshalJSON

func (rt ReservoirTap) MarshalJSON() ([]byte, error)

type SimpleArea

type SimpleArea struct {
	UID  uuid.UUID
	Name string
	Type string
}

func MapToSimpleArea

func MapToSimpleArea(areas []domain.Area) []SimpleArea

func (SimpleArea) MarshalJSON

func (sa SimpleArea) MarshalJSON() ([]byte, error)

type SimpleFarm

type SimpleFarm domain.Farm

func MapToSimpleFarm

func MapToSimpleFarm(farms []domain.Farm) []SimpleFarm

func (SimpleFarm) MarshalJSON

func (sf SimpleFarm) MarshalJSON() ([]byte, error)

type SortedAreaNotes

type SortedAreaNotes []domain.AreaNote

func (SortedAreaNotes) Len

func (sn SortedAreaNotes) Len() int

Len is part of sort.Interface.

func (SortedAreaNotes) Less

func (sn SortedAreaNotes) Less(i, j int) bool

Less is part of sort.Interface.

func (SortedAreaNotes) Swap

func (sn SortedAreaNotes) Swap(i, j int)

Swap is part of sort.Interface.

type SortedReservoirNotes

type SortedReservoirNotes []domain.ReservoirNote

func (SortedReservoirNotes) Len

func (sn SortedReservoirNotes) Len() int

Len is part of sort.Interface.

func (SortedReservoirNotes) Less

func (sn SortedReservoirNotes) Less(i, j int) bool

Less is part of sort.Interface.

func (SortedReservoirNotes) Swap

func (sn SortedReservoirNotes) Swap(i, j int)

Swap is part of sort.Interface.

type WaterSource

type WaterSource struct {
	Type     string
	Capacity float32
}

Jump to

Keyboard shortcuts

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