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: 41 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 CropContainerHook

func CropContainerHook() mapstructure.DecodeHookFunc

func Decode

func Decode(f mapstructure.DecodeHookFunc, data *map[string]interface{}, e interface{}) (interface{}, error)

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 MapToCropRead

func MapToCropRead(s *GrowthServer, crop domain.Crop) (storage.CropRead, error)

func Message

func Message(errorCode string) string

Message translates error code to meaningful message

func TimeHook

func TimeHook(layout string) mapstructure.DecodeHookFunc

func UIDHook

func UIDHook() mapstructure.DecodeHookFunc

Types

type CropActivity

type CropActivity storage.CropActivity

func MapToCropActivity

func MapToCropActivity(activity storage.CropActivity) CropActivity

type CropListInArea

type CropListInArea struct {
	UID              uuid.UUID       `json:"uid"`
	BatchID          string          `json:"batch_id"`
	DaysSinceSeeding int             `json:"days_since_seeding"`
	InitialQuantity  int             `json:"initial_quantity"`
	CurrentQuantity  int             `json:"current_quantity"`
	Container        query.Container `json:"container"`
	LastWatered      *time.Time      `json:"last_watered"`
	SeedingDate      time.Time       `json:"seeding_date"`
	MovingDate       time.Time       `json:"moving_date"`
	InitialArea      InitialArea     `json:"initial_area"`
	Inventory        query.Inventory `json:"inventory"`
}

type DumpActivity

type DumpActivity struct{ *storage.DumpActivity }

func (DumpActivity) MarshalJSON

func (a DumpActivity) MarshalJSON() ([]byte, 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 GrowthServer

type GrowthServer struct {
	CropEventRepo     repository.CropEventRepository
	CropEventQuery    query.CropEventQuery
	CropReadRepo      repository.CropReadRepository
	CropReadQuery     query.CropReadQuery
	CropActivityRepo  repository.CropActivityRepository
	CropActivityQuery query.CropActivityQuery
	CropService       domain.CropService
	AreaReadQuery     query.AreaReadQuery
	MaterialReadQuery query.MaterialReadQuery
	FarmReadQuery     query.FarmReadQuery
	TaskReadQuery     query.TaskReadQuery
	EventBus          eventbus.TaniaEventBus
	File              File
}

GrowthServer ties the routes and handlers with injected dependencies

func NewGrowthServer

func NewGrowthServer(
	db *sql.DB,
	bus eventbus.TaniaEventBus,
	cropEventStorage *storage.CropEventStorage,
	cropReadStorage *storage.CropReadStorage,
	cropActivityStorage *storage.CropActivityStorage,
	areaReadStorage *assetsstorage.AreaReadStorage,
	materialReadStorage *assetsstorage.MaterialReadStorage,
	farmReadStorage *assetsstorage.FarmReadStorage,
	taskReadStorage *taskstorage.TaskReadStorage,
) (*GrowthServer, error)

NewGrowthServer initializes GrowthServer's dependencies and create new GrowthServer struct

func (*GrowthServer) DumpCrop

func (s *GrowthServer) DumpCrop(c echo.Context) error

func (*GrowthServer) FindAllCropArchives

func (s *GrowthServer) FindAllCropArchives(c echo.Context) error

func (*GrowthServer) FindAllCrops

func (s *GrowthServer) FindAllCrops(c echo.Context) error

func (*GrowthServer) FindAllCropsByArea

func (s *GrowthServer) FindAllCropsByArea(c echo.Context) error

func (*GrowthServer) FindCropByID

func (s *GrowthServer) FindCropByID(c echo.Context) error

func (*GrowthServer) GetBatchQuantity

func (s *GrowthServer) GetBatchQuantity(c echo.Context) error

func (*GrowthServer) GetCropActivities

func (s *GrowthServer) GetCropActivities(c echo.Context) error

func (*GrowthServer) GetCropPhotos

func (s *GrowthServer) GetCropPhotos(c echo.Context) error

func (*GrowthServer) GetCropsInformation

func (s *GrowthServer) GetCropsInformation(c echo.Context) error

func (*GrowthServer) HarvestCrop

func (s *GrowthServer) HarvestCrop(c echo.Context) error

func (*GrowthServer) InitSubscriber

func (s *GrowthServer) InitSubscriber()

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

func (*GrowthServer) Mount

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

Mount defines the GrowthServer's endpoints with its handlers

func (*GrowthServer) MoveCrop

func (s *GrowthServer) MoveCrop(c echo.Context) error

func (*GrowthServer) RemoveCropNotes

func (s *GrowthServer) RemoveCropNotes(c echo.Context) error

func (*GrowthServer) SaveAreaCropBatch

func (s *GrowthServer) SaveAreaCropBatch(c echo.Context) error

func (*GrowthServer) SaveCropNotes

func (s *GrowthServer) SaveCropNotes(c echo.Context) error

func (*GrowthServer) SaveToCropActivityReadModel

func (s *GrowthServer) SaveToCropActivityReadModel(event interface{}) error

func (*GrowthServer) SaveToCropReadModel

func (s *GrowthServer) SaveToCropReadModel(event interface{}) error

func (*GrowthServer) UpdateCropBatch

func (s *GrowthServer) UpdateCropBatch(c echo.Context) error

func (*GrowthServer) UploadCropPhotos

func (s *GrowthServer) UploadCropPhotos(c echo.Context) error

func (*GrowthServer) WaterCrop

func (s *GrowthServer) WaterCrop(c echo.Context) error

type HarvestActivity

type HarvestActivity struct{ *storage.HarvestActivity }

func (HarvestActivity) MarshalJSON

func (a HarvestActivity) MarshalJSON() ([]byte, error)

type InitialArea

type InitialArea struct {
	AreaUID uuid.UUID `json:"area_id"`
	Name    string    `json:"name"`
}

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 MoveActivity

type MoveActivity struct{ *storage.MoveActivity }

func (MoveActivity) MarshalJSON

func (a MoveActivity) MarshalJSON() ([]byte, error)

type PhotoActivity

type PhotoActivity struct{ *storage.PhotoActivity }

func (PhotoActivity) MarshalJSON

func (a PhotoActivity) MarshalJSON() ([]byte, error)

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.

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 SeedActivity

type SeedActivity struct{ *storage.SeedActivity }

func (SeedActivity) MarshalJSON

func (a SeedActivity) MarshalJSON() ([]byte, error)

type SortedCropNotes

type SortedCropNotes []domain.CropNote

func (SortedCropNotes) Len

func (sn SortedCropNotes) Len() int

Len is part of sort.Interface.

func (SortedCropNotes) Less

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

Less is part of sort.Interface.

func (SortedCropNotes) Swap

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

Swap is part of sort.Interface.

type TaskCropActivity

type TaskCropActivity struct{ *storage.TaskCropActivity }

func (TaskCropActivity) MarshalJSON

func (a TaskCropActivity) MarshalJSON() ([]byte, error)

type TaskNutrientActivity

type TaskNutrientActivity struct{ *storage.TaskNutrientActivity }

func (TaskNutrientActivity) MarshalJSON

func (a TaskNutrientActivity) MarshalJSON() ([]byte, error)

type TaskPestControlActivity

type TaskPestControlActivity struct {
	*storage.TaskPestControlActivity
}

func (TaskPestControlActivity) MarshalJSON

func (a TaskPestControlActivity) MarshalJSON() ([]byte, error)

type TaskSafetyActivity

type TaskSafetyActivity struct{ *storage.TaskSafetyActivity }

func (TaskSafetyActivity) MarshalJSON

func (a TaskSafetyActivity) MarshalJSON() ([]byte, error)

type TaskSanitationActivity

type TaskSanitationActivity struct {
	*storage.TaskSanitationActivity
}

func (TaskSanitationActivity) MarshalJSON

func (a TaskSanitationActivity) MarshalJSON() ([]byte, error)

type WaterActivity

type WaterActivity struct{ *storage.WaterActivity }

func (WaterActivity) MarshalJSON

func (a WaterActivity) MarshalJSON() ([]byte, error)

Jump to

Keyboard shortcuts

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