service

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: May 1, 2025 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrIPNotFound            = errors.New("local ip not found")
	ErrIFacesNotFound        = errors.New("cant get interfaces")
	ErrIFacesAddressNotFound = errors.New("cant get interfaces address")
	ErrHostnameNotFound      = errors.New("cant get hostname")
	ErrValidation            = errors.New("validation error")

	ErrPluginRegistered       = NewError(BadRequest, "plugin already registered")
	ErrPluginNotRegistered    = NewError(BadRequest, "plugin not registered")
	ErrVehiclePlateTaken      = NewError(BadRequest, "number plate is already taken")
	ErrVehicleUnsupportedType = NewError(BadRequest, "vehicle type is not supported")
	ErrUserNotCorrectRole     = NewError(BadRequest, "user has an incorrect role")
)

Functions

func MapError

func MapError(ctx context.Context, err error, errorMask ErrorLogMask) error

Types

type AuthService

type AuthService interface {
	Service
	LoginRequest(ctx context.Context, loginRequest *domain.LoginRequest) *domain.LoginResp
	LogoutRequest(ctx context.Context, logoutRequest *domain.Logout) error
	ClientTokenCallback(ctx context.Context, loginCallback *domain.LoginCallback) (*domain.ClientToken, error)
	Register(ctx context.Context, user *domain.RegisterUser) (*domain.User, error)
	RetrospectToken(ctx context.Context, token string) (*domain.IntroSpectTokenResult, error)
	RefreshToken(ctx context.Context, refreshToken string) (*domain.ClientToken, error)
	GetAll(ctx context.Context) ([]*domain.User, error)
	GetByIDs(ctx context.Context, ids []string) ([]*domain.User, error)
	GetAllByRole(ctx context.Context, role domain.UserRole) ([]*domain.User, error)
}

type BasicCrudService

type BasicCrudService[T any, CreateType any, UpdateType any] interface {
	GetAll(ctx context.Context, query domain.Query) ([]*T, int64, error)
	GetByID(ctx context.Context, id int32) (*T, error)
	Create(ctx context.Context, createData *CreateType) (*T, error)
	Update(ctx context.Context, id int32, updateData *UpdateType) (*T, error)
	Delete(ctx context.Context, id int32) error
}

type CrudService

type CrudService[T any, CreateType any, UpdateType any] interface {
	Service
	BasicCrudService[T, CreateType, UpdateType]
}

type Error

type Error struct {
	Message string
	Code    ErrorCode
}

func NewError

func NewError(code ErrorCode, msg string) Error

func (Error) Error

func (e Error) Error() string

type ErrorCode

type ErrorCode int
const (
	BadRequest    ErrorCode = 400
	Unauthorized  ErrorCode = 401
	Forbidden     ErrorCode = 403
	NotFound      ErrorCode = 404
	Conflict      ErrorCode = 409
	Gone          ErrorCode = 410
	InternalError ErrorCode = 500
)

type ErrorLogMask

type ErrorLogMask int
const (
	ErrorLogNothing        ErrorLogMask = -1
	ErrorLogAll            ErrorLogMask = 0
	ErrorLogEntityNotFound ErrorLogMask = (1 << iota)
	ErrorLogValidation
)

Bitmask

type EvaluationService

type EvaluationService interface {
	Service
	GetEvaluation(ctx context.Context) (*domain.Evaluation, error)
}

type InfoService

type InfoService interface {
	Service
	GetAppInfo(context.Context) (*domain.App, error)
	GetAppInfoResponse(context.Context) (*domain.App, error)
}

type PluginService

type PluginService interface {
	Service
	Register(ctx context.Context, plugin *domain.Plugin) (*domain.ClientToken, error)
	RefreshToken(ctx context.Context, auth *domain.AuthPlugin, slug string) (*domain.ClientToken, error)
	Get(ctx context.Context, slug string) (domain.Plugin, error)
	GetAll(ctx context.Context) ([]domain.Plugin, []time.Time)
	HeartBeat(ctx context.Context, slug string) error
	Unregister(ctx context.Context, slug string)
	StartCleanup(ctx context.Context)
}

type RegionService

type RegionService interface {
	Service
	GetAll(ctx context.Context) ([]*domain.Region, int64, error)
	GetByID(ctx context.Context, id int32) (*domain.Region, error)
}

type SensorService

type SensorService interface {
	Service
	GetAll(ctx context.Context, query domain.Query) ([]*domain.Sensor, int64, error)
	GetByID(ctx context.Context, id string) (*domain.Sensor, error)
	Create(ctx context.Context, createData *domain.SensorCreate) (*domain.Sensor, error)
	Update(ctx context.Context, id string, updateData *domain.SensorUpdate) (*domain.Sensor, error)
	Delete(ctx context.Context, id string) error
	GetAllDataByID(ctx context.Context, id string) ([]*domain.SensorData, error)
	HandleMessage(ctx context.Context, payload *domain.MqttPayload) (*domain.SensorData, error)
	MapSensorToTree(ctx context.Context, sen *domain.Sensor) error
	UpdateStatuses(ctx context.Context) error
}

type Service

type Service interface {
	Ready() bool
}

type Services

type Services struct {
	InfoService         InfoService
	TreeService         TreeService
	AuthService         AuthService
	RegionService       RegionService
	TreeClusterService  TreeClusterService
	SensorService       SensorService
	VehicleService      VehicleService
	PluginService       PluginService
	WateringPlanService WateringPlanService
	EvaluationService   EvaluationService
}

func (*Services) AllServicesReady

func (s *Services) AllServicesReady() bool

type ServicesInterface

type ServicesInterface interface {
	AllServicesReady() bool
}

type TreeClusterService

type TreeClusterService interface {
	Service
	// TODO: use CrudService as soon as every service has pagination
	// CrudService[domain.TreeCluster, domain.TreeClusterCreate, domain.TreeClusterUpdate]
	GetAll(ctx context.Context, query domain.TreeClusterQuery) ([]*domain.TreeCluster, int64, error)
	GetByID(ctx context.Context, id int32) (*domain.TreeCluster, error)
	Create(ctx context.Context, createData *domain.TreeClusterCreate) (*domain.TreeCluster, error)
	Update(ctx context.Context, id int32, updateData *domain.TreeClusterUpdate) (*domain.TreeCluster, error)
	Delete(ctx context.Context, id int32) error

	HandleUpdateTree(context.Context, *domain.EventUpdateTree) error
	HandleCreateTree(context.Context, *domain.EventCreateTree) error
	HandleDeleteTree(context.Context, *domain.EventDeleteTree) error
	HandleNewSensorData(context.Context, *domain.EventNewSensorData) error
	HandleUpdateWateringPlan(context.Context, *domain.EventUpdateWateringPlan) error
	UpdateWateringStatuses(ctx context.Context) error
}

type TreeService

type TreeService interface {
	Service
	GetAll(ctx context.Context, query domain.TreeQuery) ([]*domain.Tree, int64, error)
	GetByID(ctx context.Context, id int32) (*domain.Tree, error)
	Create(ctx context.Context, createData *domain.TreeCreate) (*domain.Tree, error)
	Update(ctx context.Context, id int32, updateData *domain.TreeUpdate) (*domain.Tree, error)
	Delete(ctx context.Context, id int32) error

	GetBySensorID(ctx context.Context, id string) (*domain.Tree, error)
	HandleNewSensorData(context.Context, *domain.EventNewSensorData) error
	UpdateWateringStatuses(ctx context.Context) error
}

type VehicleService

type VehicleService interface {
	Service
	GetAll(ctx context.Context, query domain.VehicleQuery) ([]*domain.Vehicle, int64, error)
	GetAllArchived(ctx context.Context) ([]*domain.Vehicle, error)
	GetByID(ctx context.Context, id int32) (*domain.Vehicle, error)
	Create(ctx context.Context, createData *domain.VehicleCreate) (*domain.Vehicle, error)
	Update(ctx context.Context, id int32, updateData *domain.VehicleUpdate) (*domain.Vehicle, error)
	Delete(ctx context.Context, id int32) error
	Archive(ctx context.Context, id int32) error
	GetByPlate(ctx context.Context, plate string) (*domain.Vehicle, error)
}

type WateringPlanService

type WateringPlanService interface {
	Service
	GetAll(ctx context.Context, query domain.Query) ([]*domain.WateringPlan, int64, error)
	GetByID(ctx context.Context, id int32) (*domain.WateringPlan, error)
	Create(ctx context.Context, createData *domain.WateringPlanCreate) (*domain.WateringPlan, error)
	Update(ctx context.Context, id int32, updateData *domain.WateringPlanUpdate) (*domain.WateringPlan, error)
	Delete(ctx context.Context, id int32) error

	PreviewRoute(ctx context.Context, transporterID int32, trailerID *int32, clusterIDs []int32) (*domain.GeoJSON, error)
	GetGPXFileStream(ctx context.Context, objName string) (io.ReadSeekCloser, error)

	UpdateStatuses(ctx context.Context) error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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