domain

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

Documentation

Index

Constants

View Source
const (
	CropActive   = "ACTIVE"
	CropArchived = "ARCHIVED"
)

We just recorded two crop status because other activities are recurring and parallel. So we can't have crop batch with a status, for example `HARVESTED`, because not all the crop has harvested

View Source
const (
	CropTypeSeeding = "SEEDING"
	CropTypeGrowing = "GROWING"
)
View Source
const (
	HarvestTypeAll     = "ALL"
	HarvestTypePartial = "PARTIAL"
)
View Source
const (
	Kg = "Kg"
	Gr = "Gr"
)
View Source
const (
	CropErrorInvalidArea = iota
	CropErrorInvalidCropType
	CropErrorInvalidCropStatus

	// Crop move to area errors
	CropMoveToAreaErrorInvalidSourceArea
	CropMoveToAreaErrorSourceAreaNotFound
	CropMoveToAreaErrorInvalidDestinationArea
	CropMoveToAreaErrorDestinationAreaNotFound
	CropMoveToAreaErrorInvalidQuantity
	CropMoveToAreaErrorInvalidAreaRules
	CropMoveToAreaErrorInvalidExistingSourceArea
	CropMoveToAreaErrorCannotBeSame
	CropMoveToAreaErrorInvalidExistingArea

	// Crop harvest errors
	CropHarvestErrorInvalidSourceArea
	CropHarvestErrorSourceAreaNotFound
	CropHarvestErrorInvalidQuantity
	CropHarvestErrorNotEnoughQuantity
	CropHarvestErrorInvalidHarvestType

	// Crop dump errors
	CropDumpErrorInvalidSourceArea
	CropDumpErrorSourceAreaNotFound
	CropDumpErrorInvalidQuantity
	CropDumpErrorNotEnoughQuantity

	// Crop water errors
	CropWaterErrorInvalidWateringDate
	CropWaterErrorInvalidSourceArea
	CropWaterErrorSourceAreaNotFound

	// Crop Batch ID errors
	CropErrorInvalidBatchID
	CropErrorBatchIDAlreadyCreated

	// Crop Photo errros
	CropErrorPhotoInvalidFilename
	CropErrorPhotoInvalidMimeType
	CropErrorPhotoInvalidSize
	CropErrorPhotoInvalidDescription

	CropContainerErrorInvalidType
	CropContainerErrorInvalidQuantity
	CropContainerErrorInvalidTrayCell
	CropContainerErrorCropHasBeenMoved

	CropMaterialErrorInvalidMaterial
	CropMaterialErrorNotFound

	CropNoteErrorInvalidContent
	CropNoteErrorNotFound
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Crop

type Crop struct {
	UID          uuid.UUID
	BatchID      string
	Status       CropStatus
	Type         CropType
	Container    CropContainer
	InventoryUID uuid.UUID
	FarmUID      uuid.UUID
	Photos       []CropPhoto

	// Fields to track crop's movement
	InitialArea      InitialArea
	MovedArea        []MovedArea
	HarvestedStorage []HarvestedStorage
	Trash            []Trash

	// Fields to track care crop
	LastFertilized time.Time
	LastPruned     time.Time
	LastPesticided time.Time

	// Notes
	Notes map[uuid.UUID]CropNote

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

func CreateCropBatch

func CreateCropBatch(
	cropService CropService,
	areaUID uuid.UUID,
	cropType string,
	inventoryUID uuid.UUID,
	quantity int, containerType CropContainerType) (*Crop, error)

func (*Crop) AddNewNote

func (c *Crop) AddNewNote(content string) error

func (*Crop) AddPhoto

func (c *Crop) AddPhoto(filename, mimeType string, size, width, height int, description string) error

func (Crop) CalculateDaysSinceSeeding

func (c Crop) CalculateDaysSinceSeeding() int

CalculateDaysSinceSeeding will find how long since its been seeded It basically tell use the days since this crop is created.

func (*Crop) ChangeContainer

func (c *Crop) ChangeContainer(quantity int, containerType CropContainerType) error

func (*Crop) ChangeCropStatus

func (c *Crop) ChangeCropStatus(cropStatus string) error

func (*Crop) ChangeCropType

func (c *Crop) ChangeCropType(cropType string) error

func (*Crop) ChangeInventory

func (c *Crop) ChangeInventory(cropService CropService, inventoryUID uuid.UUID) error

func (*Crop) Dump

func (c *Crop) Dump(cropService CropService, sourceAreaUID uuid.UUID, quantity int, notes string) error

func (*Crop) Fertilize

func (c *Crop) Fertilize() error

func (*Crop) Harvest

func (c *Crop) Harvest(
	cropService CropService,
	sourceAreaUID uuid.UUID,
	harvestType string,
	producedQuantity float32,
	producedUnit ProducedUnit,
	notes string) error

func (*Crop) MoveToArea

func (c *Crop) MoveToArea(cropService CropService, sourceAreaUID uuid.UUID, destinationAreaUID uuid.UUID, quantity int) error

func (*Crop) Pesticide

func (c *Crop) Pesticide() error

func (*Crop) Prune

func (c *Crop) Prune() error

func (*Crop) RemoveNote

func (c *Crop) RemoveNote(uid uuid.UUID) error

func (*Crop) TrackChange

func (state *Crop) TrackChange(event interface{})

func (*Crop) Transition

func (state *Crop) Transition(event interface{})

func (*Crop) Water

func (c *Crop) Water(cropService CropService, sourceAreaUID uuid.UUID, wateringDate time.Time) error

type CropBatchContainerChanged

type CropBatchContainerChanged struct {
	UID       uuid.UUID
	Container CropContainer
}

type CropBatchCreated

type CropBatchCreated struct {
	UID            uuid.UUID
	BatchID        string
	Status         CropStatus
	Type           CropType
	Container      CropContainer
	InventoryUID   uuid.UUID
	FarmUID        uuid.UUID
	CreatedDate    time.Time
	InitialAreaUID uuid.UUID
	Quantity       int
}

type CropBatchDumped

type CropBatchDumped struct {
	UID            uuid.UUID
	CropStatus     string // Values: ACTIVE / ARCHIVED
	Quantity       int
	UpdatedTrash   Trash
	DumpedArea     interface{}
	DumpedAreaCode string // Values: INITIAL_AREA / MOVED_AREA
	DumpDate       time.Time
	Notes          string
}

type CropBatchHarvested

type CropBatchHarvested struct {
	UID                     uuid.UUID
	CropStatus              string // Values: ACTIVE / ARCHIVED
	HarvestType             string
	HarvestedQuantity       int
	ProducedGramQuantity    float32
	UpdatedHarvestedStorage HarvestedStorage
	HarvestedArea           interface{}
	HarvestedAreaCode       string // Values: INITIAL_AREA / MOVED_AREA
	HarvestDate             time.Time
	Notes                   string
}

type CropBatchInventoryChanged

type CropBatchInventoryChanged struct {
	UID          uuid.UUID
	InventoryUID uuid.UUID
	BatchID      string
}

type CropBatchMoved

type CropBatchMoved struct {
	UID                uuid.UUID
	Quantity           int
	SrcAreaUID         uuid.UUID
	DstAreaUID         uuid.UUID
	MovedDate          time.Time
	UpdatedSrcAreaCode string // Values: INITIAL_AREA / MOVED_AREA
	UpdatedSrcArea     interface{}
	UpdatedDstAreaCode string // Values: INITIAL_AREA / MOVED_AREA
	UpdatedDstArea     interface{}
}

type CropBatchNoteCreated

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

type CropBatchNoteRemoved

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

type CropBatchPhotoCreated

type CropBatchPhotoCreated struct {
	UID         uuid.UUID
	CropUID     uuid.UUID
	Filename    string
	MimeType    string
	Size        int
	Width       int
	Height      int
	Description string
}

type CropBatchTypeChanged

type CropBatchTypeChanged struct {
	UID  uuid.UUID
	Type CropType
}

type CropBatchWatered

type CropBatchWatered struct {
	UID           uuid.UUID
	BatchID       string
	ContainerType string
	AreaUID       uuid.UUID
	AreaName      string
	WateringDate  time.Time
}

type CropContainer

type CropContainer struct {
	Quantity int
	Type     CropContainerType
}

type CropContainerType

type CropContainerType interface {
	Code() string
}

CropContainerType defines the type of a container

type CropError

type CropError struct {
	Code int
}

CropError is a custom error from Go built-in error

func (CropError) Error

func (e CropError) Error() string

type CropNote

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

type CropPhoto

type CropPhoto struct {
	UID         uuid.UUID `json:"uid"`
	Filename    string    `json:"filename"`
	MimeType    string    `json:"mime_type"`
	Size        int       `json:"size"`
	Width       int       `json:"width"`
	Height      int       `json:"height"`
	Description string    `json:"description"`
}

type CropService

type CropService interface {
	FindMaterialByID(uid uuid.UUID) ServiceResult
	FindByBatchID(batchID string) ServiceResult
	FindAreaByID(uid uuid.UUID) ServiceResult
}

CropService handles crop behaviours that needs external interaction to be worked

type CropStatus

type CropStatus struct {
	Code  string `json:"code"`
	Label string `json:"-"`
}

func CropStatuses

func CropStatuses() []CropStatus

func GetCropStatus

func GetCropStatus(code string) CropStatus

type CropType

type CropType struct {
	Code  string
	Label string
}

func CropTypes

func CropTypes() []CropType

func GetCropType

func GetCropType(code string) CropType

type HarvestType

type HarvestType struct {
	Code  string
	Label string
}

func GetHarvestType

func GetHarvestType(code string) HarvestType

func HarvestTypes

func HarvestTypes() []HarvestType

type HarvestedStorage

type HarvestedStorage struct {
	Quantity             int       `json:"quantity"`
	ProducedGramQuantity float32   `json:"produced_gram_quantity"`
	SourceAreaUID        uuid.UUID `json:"source_area_id"`
	CreatedDate          time.Time `json:"created_date"`
	LastUpdated          time.Time `json:"last_updated"`
}

type InitialArea

type InitialArea struct {
	AreaUID         uuid.UUID `json:"area_id"`
	InitialQuantity int       `json:"initial_quantity"`
	CurrentQuantity int       `json:"current_quantity"`
	CreatedDate     time.Time `json:"created_date"`
	LastUpdated     time.Time `json:"last_updated"`

	LastWatered    time.Time `json:"last_watered"`
	LastFertilized time.Time `json:"last_fertilized"`
	LastPruned     time.Time `json:"last_pruned"`
	LastPesticided time.Time `json:"last_pesticided"`
}

type MovedArea

type MovedArea struct {
	AreaUID         uuid.UUID `json:"area_id"`
	SourceAreaUID   uuid.UUID `json:"source_area_id"`
	InitialQuantity int       `json:"initial_quantity"`
	CurrentQuantity int       `json:"current_quantity"`
	CreatedDate     time.Time `json:"created_date"`
	LastUpdated     time.Time `json:"last_updated"`

	LastWatered    time.Time `json:"last_watered"`
	LastFertilized time.Time `json:"last_fertilized"`
	LastPruned     time.Time `json:"last_pruned"`
	LastPesticided time.Time `json:"last_pesticided"`
}

type Pot

type Pot struct{}

Pot implements CropContainerType

func (Pot) Code

func (p Pot) Code() string

type ProducedUnit

type ProducedUnit struct {
	Code  string
	Label string
}

func GetProducedUnit

func GetProducedUnit(code string) ProducedUnit

func ProducedUnits

func ProducedUnits() []ProducedUnit

type ServiceResult

type ServiceResult struct {
	Result interface{}
	Error  error
}

ServiceResult is the container for service result

type Trash

type Trash struct {
	Quantity      int       `json:"quantity"`
	SourceAreaUID uuid.UUID `json:"source_area_id"`
	CreatedDate   time.Time `json:"created_date"`
	LastUpdated   time.Time `json:"last_updated"`
}

type Tray

type Tray struct {
	Cell int
}

Tray implements CropContainerType

func (Tray) Code

func (t Tray) Code() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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