Documentation ¶
Index ¶
- Constants
- func Error(c echo.Context, err error) error
- func MapToFarmRead(farm *domain.Farm) *storage.FarmRead
- func MapToPlantType(plantTypes []domain.PlantType) []string
- func MapToReservoirRead(s *FarmServer, reservoir domain.Reservoir) (storage.ReservoirRead, error)
- func MapToReservoirReadFromRead(s *FarmServer, reservoir storage.ReservoirRead) (storage.ReservoirRead, error)
- func Message(errorCode string) string
- type AreaList
- type AvailableMaterialPlantType
- type DetailArea
- type DetailReservoir
- type FarmServer
- func (s FarmServer) FindAllFarm(c echo.Context) error
- func (s *FarmServer) FindFarmByID(c echo.Context) error
- func (s *FarmServer) GetAreaPhotos(c echo.Context) error
- func (s *FarmServer) GetAreasByID(c echo.Context) error
- func (s *FarmServer) GetAvailableMaterialPlantType(c echo.Context) error
- func (s *FarmServer) GetFarmAreas(c echo.Context) error
- func (s *FarmServer) GetFarmReservoirs(c echo.Context) error
- func (s *FarmServer) GetInventoryPlantTypes(c echo.Context) error
- func (s *FarmServer) GetMaterialByID(c echo.Context) error
- func (s *FarmServer) GetMaterials(c echo.Context) error
- func (s *FarmServer) GetMaterialsSimple(c echo.Context) error
- func (s *FarmServer) GetReservoirsByID(c echo.Context) error
- func (s *FarmServer) GetTotalAreas(c echo.Context) error
- func (s *FarmServer) GetTypes(c echo.Context) error
- func (s *FarmServer) InitSubscriber()
- func (s *FarmServer) Mount(g *echo.Group)
- func (s *FarmServer) RemoveAreaNotes(c echo.Context) error
- func (s *FarmServer) RemoveReservoirNotes(c echo.Context) error
- func (s *FarmServer) SaveArea(c echo.Context) error
- func (s *FarmServer) SaveAreaNotes(c echo.Context) error
- func (s *FarmServer) SaveFarm(c echo.Context) error
- func (s *FarmServer) SaveMaterial(c echo.Context) error
- func (s *FarmServer) SaveReservoir(c echo.Context) error
- func (s *FarmServer) SaveReservoirNotes(c echo.Context) error
- func (s *FarmServer) SaveToAreaReadModel(event interface{}) error
- func (s *FarmServer) SaveToFarmReadModel(event interface{}) error
- func (s *FarmServer) SaveToMaterialReadModel(event interface{}) error
- func (s *FarmServer) SaveToReservoirReadModel(event interface{}) error
- func (s *FarmServer) UpdateArea(c echo.Context) error
- func (s *FarmServer) UpdateFarm(c echo.Context) error
- func (s *FarmServer) UpdateMaterial(c echo.Context) error
- func (s *FarmServer) UpdateReservoir(c echo.Context) error
- type File
- type LocalFile
- type Material
- type MaterialQuantity
- type MaterialSimple
- type MaterialType
- type MaterialTypeAgrochemical
- type MaterialTypePlant
- type MaterialTypeSeed
- type MaterialTypeSeedingContainer
- type PricePerUnit
- type RequestValidation
- func (rv *RequestValidation) ValidateAreaLocation(location string) (string, error)
- func (rv *RequestValidation) ValidateAreaSize(size string, sizeUnit string) (domain.AreaSize, error)
- func (rv *RequestValidation) ValidateCapacity(waterSourceType, capacity string) (float32, error)
- func (rv *RequestValidation) ValidateFarm(s FarmServer, farmUID uuid.UUID) (storage.FarmRead, error)
- func (rv *RequestValidation) ValidateReservoir(s FarmServer, reservoirUID uuid.UUID) (storage.ReservoirRead, error)
- func (rv *RequestValidation) ValidateReservoirName(name string) (string, error)
- func (rv *RequestValidation) ValidateType(t string) (string, error)
- type RequestValidationError
- type ReservoirBucket
- type ReservoirNote
- type ReservoirTap
- type SimpleArea
- type SimpleFarm
- type SortedAreaNotes
- type SortedReservoirNotes
- type WaterSource
Constants ¶
const ( Required = "REQUIRED" Alphanumeric = "ALPHANUMERIC" Alpha = "ALPHA" Numeric = "NUMERIC" Float = "FLOAT" ParseFailed = "PARSE_FAILED" InvalidOption = "INVALID_OPTION" NotFound = "NOT_FOUND" )
Variables ¶
This section is empty.
Functions ¶
func Error ¶
Error wraps errors from application layer and domain layer to some format in JSON for response
func MapToPlantType ¶
func MapToReservoirRead ¶
func MapToReservoirRead(s *FarmServer, reservoir domain.Reservoir) (storage.ReservoirRead, error)
func MapToReservoirReadFromRead ¶
func MapToReservoirReadFromRead(s *FarmServer, reservoir storage.ReservoirRead) (storage.ReservoirRead, error)
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.FarmEvent FarmEventQuery query.FarmEvent FarmReadRepo repository.FarmRead FarmReadQuery query.FarmRead ReservoirEventRepo repository.ReservoirEvent ReservoirEventQuery query.ReservoirEvent ReservoirReadRepo repository.ReservoirRead ReservoirReadQuery query.ReservoirRead ReservoirService domain.ReservoirService AreaEventRepo repository.AreaEvent AreaReadRepo repository.AreaRead AreaEventQuery query.AreaEvent AreaReadQuery query.AreaRead AreaService domain.AreaService MaterialEventRepo repository.MaterialEvent MaterialEventQuery query.MaterialEvent MaterialReadRepo repository.MaterialRead MaterialReadQuery query.MaterialRead CropReadQuery query.CropRead 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 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 MapToMaterialFromRead ¶
func MapToMaterialFromRead(material storage.MaterialRead) Material
type MaterialQuantity ¶
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 MaterialTypeSeed ¶
type MaterialTypeSeedingContainer ¶
type MaterialTypeSeedingContainer struct {
ContainerType domain.ContainerType `json:"container_type"`
}
type PricePerUnit ¶
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 (*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 ¶
func (ReservoirBucket) MarshalJSON ¶
func (rb ReservoirBucket) MarshalJSON() ([]byte, error)
type ReservoirNote ¶
type ReservoirTap ¶
func (ReservoirTap) MarshalJSON ¶
func (rt ReservoirTap) MarshalJSON() ([]byte, error)
type SimpleArea ¶
func MapToSimpleArea ¶
func MapToSimpleArea(areas []domain.Area) []SimpleArea
func (SimpleArea) MarshalJSON ¶
func (sa SimpleArea) MarshalJSON() ([]byte, error)
type SimpleFarm ¶
func MapToSimpleFarm ¶
func MapToSimpleFarm(farms []domain.Farm) []SimpleFarm
func (SimpleFarm) MarshalJSON ¶
func (sf SimpleFarm) MarshalJSON() ([]byte, error)
type SortedAreaNotes ¶
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.