domain

package
v0.0.0-...-ae75a06 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2022 License: Apache-2.0 Imports: 5 Imported by: 23

Documentation

Overview

Package domain provides the operation that farm holder can do to their farm

Index

Constants

View Source
const (
	AreaTypeSeeding = "SEEDING"
	AreaTypeGrowing = "GROWING"
)
View Source
const (
	AreaLocationOutdoor = "OUTDOOR"
	AreaLocationIndoor  = "INDOOR"
)
View Source
const (
	SquareMeter = "m2"
	Hectare     = "Ha"
)
View Source
const (
	AreaErrorNameEmptyCode = iota
	AreaErrorNameNotEnoughCharacterCode
	AreaErrorNameExceedMaximunCharacterCode
	AreaErrorNameAlphanumericOnlyCode
	AreaErrorFarmNotFound
	AreaErrorReservoirNotFound

	AreaErrorSizeEmptyCode
	AreaErrorInvalidSizeUnitCode

	AreaErrorTypeEmptyCode
	AreaErrorInvalidAreaTypeCode
	AreaErrorCropAlreadyCreated

	AreaErrorLocationEmptyCode
	AreaErrorInvalidAreaLocationCode

	AreaNoteErrorInvalidContent
	AreaNoteErrorInvalidID
	AreaNoteErrorNotFound
)
View Source
const (
	FarmErrorInvalidFarmTypeCode = iota

	FarmErrorReservoirAlreadyAdded
	FarmErrorReservoirNotFound

	FarmErrorAreaAlreadyAdded
	FarmErrorAreaNotFound

	FarmErrorNameEmptyCode
	FarmErrorNameNotEnoughCharacterCode
	FarmErrorNameExceedMaximunCharacterCode
	FarmErrorNameAlphanumericOnlyCode

	FarmErrorInvalidLatitudeValueCode
	FarmErrorInvalidLongitudeValueCode
	FarmErrorInvalidCountry
	FarmErrorInvalidCity
)
View Source
const (
	FarmTypeOrganic      = "organic"
	FarmTypeHydroponic   = "hydroponic"
	FarmTypeAquaponic    = "aquaponic"
	FarmTypeMushroom     = "mushroom"
	FarmTypeLiveStock    = "livestock"
	FarmTypeFisheries    = "fisheries"
	FarmTypePermaculture = "permaculture"
)
View Source
const (
	InventoryMaterialInvalidPlantType = iota
	InventoryMaterialInvalidVariety
	InventoryMaterialErrorWrongType
)
View Source
const (
	MoneyEUR = "EUR"
	MoneyIDR = "IDR"
)
View Source
const (
	MaterialUnitSeeds      = "SEEDS"
	MaterialUnitPackets    = "PACKETS"
	MaterialUnitGram       = "GRAM"
	MaterialUnitKilogram   = "KILOGRAM"
	MaterialUnitBags       = "BAGS"
	MaterialUnitBottles    = "BOTTLES"
	MaterialUnitCubicMetre = "CUBIC_METRE"
	MaterialUnitPieces     = "PIECES"
	MaterialUnitUnits      = "UNITS"
)
View Source
const (
	MaterialTypeSeedCode                = "SEED"
	MaterialTypePlantCode               = "PLANT"
	MaterialTypeGrowingMediumCode       = "GROWING_MEDIUM"
	MaterialTypeAgrochemicalCode        = "AGROCHEMICAL"
	MaterialTypeLabelAndCropSupportCode = "LABEL_AND_CROP_SUPPORT"
	MaterialTypeSeedingContainerCode    = "SEEDING_CONTAINER"
	MaterialTypePostHarvestSupplyCode   = "POST_HARVEST_SUPPLY"
	MaterialTypeOtherCode               = "OTHER"
)
View Source
const (
	PlantTypeVegetable = "VEGETABLE"
	PlantTypeFruit     = "FRUIT"
	PlantTypeHerb      = "HERB"
	PlantTypeFlower    = "FLOWER"
	PlantTypeTree      = "TREE"
)
View Source
const (
	ChemicalTypeDisinfectant = "DISINFECTANT"
	ChemicalTypeFertilizer   = "FERTILIZER"
	ChemicalTypeHormone      = "HORMONE"
	ChemicalTypeManure       = "MANURE"
	ChemicalTypePesticide    = "PESTICIDE"
)
View Source
const (
	ContainerTypeTray = "TRAY"
	ContainerTypePot  = "POT"
)
View Source
const (
	BucketType = "BUCKET"
	TapType    = "TAP"
)
View Source
const (
	ReservoirErrorNameEmptyCode = iota
	ReservoirErrorNameNotEnoughCharacterCode
	ReservoirErrorNameExceedMaximunCharacterCode
	ReservoirErrorNameAlphanumericOnlyCode
	ReservoirErrorFarmNotFound

	ReservoirErrorPHInvalidCode

	ReservoirErrorECInvalidCode

	ReservoirErrorBucketCapacityInvalidCode
	ReservoirErrorBucketVolumeInvalidCode

	ReservoirErrorWaterSourceAlreadyAttachedCode

	ReservoirNoteErrorInvalidContent
	ReservoirNoteErrorNotFound
)
View Source
const (
	MaterialErrorInvalidMaterialType = iota
)

Variables

This section is empty.

Functions

func GetCurrencyCode

func GetCurrencyCode(currencyCode string) (string, error)

Types

type Area

type Area struct {
	UID          uuid.UUID              `json:"uid"`
	Name         string                 `json:"name"`
	Size         AreaSize               `json:"size"`
	Type         AreaType               `json:"type"`
	Location     AreaLocation           `json:"location"`
	Photo        AreaPhoto              `json:"photo"`
	CreatedDate  time.Time              `json:"created_date"`
	Notes        map[uuid.UUID]AreaNote `json:"-"`
	ReservoirUID uuid.UUID              `json:"-"`
	FarmUID      uuid.UUID              `json:"-"`

	// Events
	Version            int
	UncommittedChanges []interface{}
}

func CreateArea

func CreateArea(
	areaService AreaService,
	farmUID uuid.UUID,
	reservoirUID uuid.UUID,
	name string,
	areaType string,
	size AreaSize,
	locationCode string) (*Area, error,
)

CreateArea registers a new area to a farm.

func (*Area) AddNewNote

func (a *Area) AddNewNote(content string) error

func (*Area) ChangeLocation

func (a *Area) ChangeLocation(locationCode string) error

ChangeLocation changes an area location.

func (*Area) ChangeName

func (a *Area) ChangeName(name string) error

func (*Area) ChangePhoto

func (a *Area) ChangePhoto(photo AreaPhoto) error

TODO: Do file type validation here.

func (*Area) ChangeReservoir

func (a *Area) ChangeReservoir(reservoirUID uuid.UUID) error

func (*Area) ChangeSize

func (a *Area) ChangeSize(size AreaSize) error

ChangeSize changes an area size.

func (*Area) ChangeType

func (a *Area) ChangeType(areaService AreaService, areaType string) error

func (*Area) RemoveNote

func (a *Area) RemoveNote(uid uuid.UUID) error

func (*Area) TrackChange

func (a *Area) TrackChange(event interface{})

func (*Area) Transition

func (a *Area) Transition(event interface{})

type AreaCreated

type AreaCreated struct {
	UID          uuid.UUID
	Name         string
	Type         AreaType
	Location     AreaLocation
	Size         AreaSize
	FarmUID      uuid.UUID
	ReservoirUID uuid.UUID
	CreatedDate  time.Time
}

type AreaError

type AreaError struct {
	Code int
}

AreaError is a custom error from Go built-in error

func (AreaError) Error

func (e AreaError) Error() string

type AreaFarmServiceResult

type AreaFarmServiceResult struct {
	UID  uuid.UUID
	Name string
}

type AreaLocation

type AreaLocation struct {
	Code string `json:"code"`
	Name string `json:"name"`
}

func AreaLocations

func AreaLocations() []AreaLocation

func GetAreaLocation

func GetAreaLocation(code string) AreaLocation

type AreaLocationChanged

type AreaLocationChanged struct {
	AreaUID  uuid.UUID
	Location AreaLocation
}

type AreaNameChanged

type AreaNameChanged struct {
	AreaUID uuid.UUID
	Name    string
}

type AreaNote

type AreaNote struct {
	UID         uuid.UUID `json:"uid"`
	Content     string    `json:"content"`
	CreatedDate time.Time `json:"created_date"`
}

type AreaNoteAdded

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

type AreaNoteRemoved

type AreaNoteRemoved struct {
	AreaUID uuid.UUID
	UID     uuid.UUID
}

type AreaPhoto

type AreaPhoto struct {
	Filename string `json:"filename"`
	MimeType string `json:"mime_type"`
	Size     int    `json:"size"`
	Width    int    `json:"width"`
	Height   int    `json:"height"`
}

type AreaPhotoAdded

type AreaPhotoAdded struct {
	AreaUID  uuid.UUID
	Filename string
	MimeType string
	Size     int
	Width    int
	Height   int
}

type AreaReservoirChanged

type AreaReservoirChanged struct {
	AreaUID      uuid.UUID
	ReservoirUID uuid.UUID
}

type AreaReservoirServiceResult

type AreaReservoirServiceResult struct {
	UID  uuid.UUID
	Name string
}

type AreaService

type AreaService interface {
	FindFarmByID(farmUID uuid.UUID) (AreaFarmServiceResult, error)
	FindReservoirByID(reservoirUID uuid.UUID) (AreaReservoirServiceResult, error)
	CountCropsByAreaID(areaUID uuid.UUID) (int, error)
}

type AreaSize

type AreaSize struct {
	Unit  AreaUnit `json:"unit"`
	Value float32  `json:"value"`
}

type AreaSizeChanged

type AreaSizeChanged struct {
	AreaUID uuid.UUID
	Size    AreaSize
}

type AreaType

type AreaType struct {
	Code  string `json:"code"`
	Label string `json:"label"`
}

func AreaTypes

func AreaTypes() []AreaType

func GetAreaType

func GetAreaType(code string) AreaType

type AreaTypeChanged

type AreaTypeChanged struct {
	AreaUID uuid.UUID
	Type    AreaType
}

type AreaUnit

type AreaUnit struct {
	Label  string `json:"label"`
	Symbol string `json:"symbol"`
}

func AreaUnits

func AreaUnits() []AreaUnit

func GetAreaUnit

func GetAreaUnit(symbol string) AreaUnit

type Bucket

type Bucket struct {
	Capacity float32
}

Bucket is value object attached to the Reservoir.waterSource.

func CreateBucket

func CreateBucket(capacity float32) (Bucket, error)

CreateBucket registers a new Bucket.

func (Bucket) Type

func (b Bucket) Type() string

type ChemicalType

type ChemicalType struct {
	Code  string `json:"code"`
	Label string `json:"label"`
}

func ChemicalTypes

func ChemicalTypes() []ChemicalType

func GetChemicalType

func GetChemicalType(code string) ChemicalType

type ContainerType

type ContainerType struct {
	Code  string `json:"code"`
	Label string `json:"label"`
}

func ContainerTypes

func ContainerTypes() []ContainerType

func GetContainerType

func GetContainerType(code string) ContainerType

type Farm

type Farm struct {
	UID         uuid.UUID `json:"uid"`
	Name        string    `json:"name"`
	Latitude    string    `json:"latitude"`
	Longitude   string    `json:"longitude"`
	Type        string    `json:"type"`
	Country     string    `json:"country"`
	City        string    `json:"city"`
	IsActive    bool      `json:"is_active"`
	CreatedDate time.Time `json:"created_date"`

	// Events
	Version            int
	UncommittedChanges []interface{}
}

func CreateFarm

func CreateFarm(name, farmType, latitude, longitude, country, city string) (*Farm, error)

CreateFarm registers a new farm to Tania

func (*Farm) ChangeGeoLocation

func (f *Farm) ChangeGeoLocation(latitude, longitude string) error

ChangeGeoLocation changes the geolocation of a farm

func (*Farm) ChangeName

func (f *Farm) ChangeName(name string) error

func (*Farm) ChangeRegion

func (f *Farm) ChangeRegion(country, city string) error

ChangeRegion changes country and city of a farm

func (*Farm) ChangeType

func (f *Farm) ChangeType(farmType string) error

func (*Farm) TrackChange

func (f *Farm) TrackChange(event interface{})

func (*Farm) Transition

func (f *Farm) Transition(event interface{})

type FarmCountry

type FarmCountry struct {
	Code string `json:"country_code"`
	Name string `json:"country_name"`
}

type FarmCreated

type FarmCreated struct {
	UID         uuid.UUID
	Name        string
	Type        string
	Latitude    string
	Longitude   string
	Country     string
	City        string
	IsActive    bool
	CreatedDate time.Time
}

type FarmError

type FarmError struct {
	Code int
}

FarmError is a custom error from Go built-in error

func (FarmError) Error

func (e FarmError) Error() string

type FarmGeolocationChanged

type FarmGeolocationChanged struct {
	FarmUID   uuid.UUID
	Latitude  string
	Longitude string
}

type FarmNameChanged

type FarmNameChanged struct {
	FarmUID uuid.UUID
	Name    string
}

type FarmRegionChanged

type FarmRegionChanged struct {
	FarmUID uuid.UUID
	Country string
	City    string
}

type FarmService

type FarmService interface {
	GetCountryNameByCode() string
}

type FarmType

type FarmType struct {
	Code string `json:"code"`
	Name string `json:"name"`
}

func FindAllFarmTypes

func FindAllFarmTypes() []FarmType

func FindFarmTypeByCode

func FindFarmTypeByCode(code string) (FarmType, error)

type FarmTypeChanged

type FarmTypeChanged struct {
	FarmUID uuid.UUID
	Type    string
}

type InventoryMaterialError

type InventoryMaterialError struct {
	Code int
}

InventoryMaterialError is a custom error from Go built-in error

func (InventoryMaterialError) Error

func (e InventoryMaterialError) Error() string

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"`
	Notes          *string          `json:"notes"`
	ProducedBy     *string          `json:"produced_by"`
	CreatedDate    time.Time        `json:"created_date"`

	// Events
	Version            int
	UncommittedChanges []interface{}
}

func CreateMaterial

func CreateMaterial(
	name string,
	price string,
	priceUnit string,
	materialType MaterialType,
	quantity float32,
	quantityUnit string,
	expirationDate *time.Time,
	notes *string,
	producedBy *string) (*Material, error,
)

func (*Material) ChangeExpirationDate

func (m *Material) ChangeExpirationDate(expDate time.Time) error

func (*Material) ChangeName

func (m *Material) ChangeName(name string) error

func (*Material) ChangeNotes

func (m *Material) ChangeNotes(notes string) error

func (*Material) ChangePricePerUnit

func (m *Material) ChangePricePerUnit(price, priceUnit string) error

func (*Material) ChangeProducedBy

func (m *Material) ChangeProducedBy(producedBy string) error

func (*Material) ChangeQuantityUnit

func (m *Material) ChangeQuantityUnit(quantity float32, quantityUnit string, materialType MaterialType) error

func (*Material) ChangeType

func (m *Material) ChangeType(materialType MaterialType) error

func (*Material) TrackChange

func (m *Material) TrackChange(event interface{})

func (*Material) Transition

func (m *Material) Transition(event interface{})

type MaterialCreated

type MaterialCreated struct {
	UID            uuid.UUID
	Name           string
	PricePerUnit   PricePerUnit
	Type           MaterialType
	Quantity       MaterialQuantity
	ExpirationDate *time.Time
	Notes          *string
	ProducedBy     *string
	CreatedDate    time.Time
}

type MaterialError

type MaterialError struct {
	Code int
}

MaterialError is a custom error from Go built-in error

func (MaterialError) Error

func (e MaterialError) Error() string

type MaterialExpirationDateChanged

type MaterialExpirationDateChanged struct {
	MaterialUID    uuid.UUID
	ExpirationDate time.Time
}

type MaterialNameChanged

type MaterialNameChanged struct {
	MaterialUID uuid.UUID
	Name        string
}

type MaterialNotesChanged

type MaterialNotesChanged struct {
	MaterialUID uuid.UUID
	Notes       string
}

type MaterialPriceChanged

type MaterialPriceChanged struct {
	MaterialUID uuid.UUID
	Price       PricePerUnit
}

type MaterialProducedByChanged

type MaterialProducedByChanged struct {
	MaterialUID uuid.UUID
	ProducedBy  string
}

type MaterialQuantity

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

type MaterialQuantityChanged

type MaterialQuantityChanged struct {
	MaterialUID      uuid.UUID
	MaterialTypeCode string
	Quantity         MaterialQuantity
}

type MaterialQuantityUnit

type MaterialQuantityUnit struct {
	Code  string `json:"code"`
	Label string `json:"label"`
}

func GetMaterialQuantityUnit

func GetMaterialQuantityUnit(materialTypeCode string, code string) MaterialQuantityUnit

func MaterialQuantityUnits

func MaterialQuantityUnits(materialTypeCode string) []MaterialQuantityUnit

type MaterialType

type MaterialType interface {
	Code() string
}

type MaterialTypeAgrochemical

type MaterialTypeAgrochemical struct {
	ChemicalType ChemicalType
}

func CreateMaterialTypeAgrochemical

func CreateMaterialTypeAgrochemical(chemicalType string) (MaterialTypeAgrochemical, error)

func (MaterialTypeAgrochemical) Code

func (mt MaterialTypeAgrochemical) Code() string

type MaterialTypeChanged

type MaterialTypeChanged struct {
	MaterialUID  uuid.UUID
	MaterialType MaterialType
}

type MaterialTypeGrowingMedium

type MaterialTypeGrowingMedium struct{}

func (MaterialTypeGrowingMedium) Code

type MaterialTypeLabelAndCropSupport

type MaterialTypeLabelAndCropSupport struct{}

func (MaterialTypeLabelAndCropSupport) Code

type MaterialTypeOther

type MaterialTypeOther struct{}

func (MaterialTypeOther) Code

func (mt MaterialTypeOther) Code() string

type MaterialTypePlant

type MaterialTypePlant struct {
	PlantType PlantType
}

func CreateMaterialTypePlant

func CreateMaterialTypePlant(plantType string) (MaterialTypePlant, error)

func (MaterialTypePlant) Code

func (mt MaterialTypePlant) Code() string

type MaterialTypePostHarvestSupply

type MaterialTypePostHarvestSupply struct{}

func (MaterialTypePostHarvestSupply) Code

type MaterialTypeSeed

type MaterialTypeSeed struct {
	PlantType PlantType
}

func CreateMaterialTypeSeed

func CreateMaterialTypeSeed(plantType string) (MaterialTypeSeed, error)

func (MaterialTypeSeed) Code

func (mt MaterialTypeSeed) Code() string

type MaterialTypeSeedingContainer

type MaterialTypeSeedingContainer struct {
	ContainerType ContainerType
}

func CreateMaterialTypeSeedingContainer

func CreateMaterialTypeSeedingContainer(containerType string) (MaterialTypeSeedingContainer, error)

func (MaterialTypeSeedingContainer) Code

type PlantType

type PlantType struct {
	Code  string `json:"code"`
	Label string `json:"label"`
}

func GetPlantType

func GetPlantType(code string) PlantType

func PlantTypes

func PlantTypes() []PlantType

type PricePerUnit

type PricePerUnit struct {
	Amount       string `json:"amount"`
	CurrencyCode string `json:"code"`
}

func CreatePricePerUnit

func CreatePricePerUnit(amount, currencyCode string) (PricePerUnit, error)

func (PricePerUnit) Symbol

func (p PricePerUnit) Symbol() string

type Reservoir

type Reservoir struct {
	UID         uuid.UUID
	Name        string
	WaterSource WaterSource
	FarmUID     uuid.UUID
	Notes       map[uuid.UUID]ReservoirNote
	CreatedDate time.Time

	// Events
	Version            int
	UncommittedChanges []interface{}
}

Reservoir is entity that provides the operation that farm owner or his/her staff can do with the reservoir in a farm.

func CreateReservoir

func CreateReservoir(rs ReservoirService, farmUID uuid.UUID, name, waterSourceType string, capacity float32) (*Reservoir, error)

CreateReservoir registers a new Reservoir.

func (*Reservoir) AddNewNote

func (r *Reservoir) AddNewNote(content string) error

func (*Reservoir) ChangeName

func (r *Reservoir) ChangeName(name string) error

ChangeName is used to change Reservoir Name.

func (*Reservoir) ChangeWaterSource

func (r *Reservoir) ChangeWaterSource(waterSourceType string, capacity float32) error

func (*Reservoir) RemoveNote

func (r *Reservoir) RemoveNote(uid uuid.UUID) error

func (*Reservoir) TrackChange

func (r *Reservoir) TrackChange(event interface{})

func (*Reservoir) Transition

func (r *Reservoir) Transition(event interface{})

type ReservoirCreated

type ReservoirCreated struct {
	UID         uuid.UUID
	Name        string
	WaterSource WaterSource
	FarmUID     uuid.UUID
	CreatedDate time.Time
}

type ReservoirError

type ReservoirError struct {
	Code int
}

ReservoirError is a custom error from Go built-in error

func (ReservoirError) Error

func (e ReservoirError) Error() string

type ReservoirFarmServiceResult

type ReservoirFarmServiceResult struct {
	UID  uuid.UUID
	Name string
}

type ReservoirNameChanged

type ReservoirNameChanged struct {
	ReservoirUID uuid.UUID
	Name         string
}

type ReservoirNote

type ReservoirNote struct {
	UID         uuid.UUID `json:"uid"`
	Content     string    `json:"content"`
	CreatedDate time.Time `json:"created_date"`
}

type ReservoirNoteAdded

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

type ReservoirNoteRemoved

type ReservoirNoteRemoved struct {
	ReservoirUID uuid.UUID
	UID          uuid.UUID
}

type ReservoirService

type ReservoirService interface {
	FindFarmByID(farmUID uuid.UUID) (ReservoirFarmServiceResult, error)
}

type ReservoirWaterSourceChanged

type ReservoirWaterSourceChanged struct {
	ReservoirUID uuid.UUID
	WaterSource  WaterSource
}

type Tap

type Tap struct{}

Tap is value object attached to the Reservoir.waterSource domain.

func CreateTap

func CreateTap() (Tap, error)

CreateTap registers a new Tab.

func (Tap) Type

func (t Tap) Type() string

type WaterSource

type WaterSource interface {
	Type() string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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