models

package module
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2023 License: BSD-3-Clause Imports: 16 Imported by: 8

README

Models

Build codecov

This repository contains the main functionalities used in all the microservices present in the project.

Designed in a way to maintain centralized the database models and controllers.

Development

Make sure you have the environment setup.

docker compose up -d

Then unit tests could be executed with:

go test -v ./...

Always ensure coverage is over 80%. If 100% is possible go ahead.

Documentation

You will find the entire documentation for this project at docs/.

File Description
docs/README.md Detailed description of the documentation files.
CONTRIBUTING.md Rules for contributing to this repository. Including commit nomenclature, code quality and more.
CHANGELOG.md This file is autogenerated by the Build Action's pipeline, should never be modified manually.

Coverage

Coverage Coverage

Documentation

Index

Constants

View Source
const (
	SMSCooldown = time.Hour
	SMSFrom     = "Hidromatoligia Service"
)

Variables

View Source
var ErrUnauthorized = fmt.Errorf("unauthorized")

Functions

This section is empty.

Types

type Controller

type Controller struct {
	DB          *gorm.DB
	Cache       cache.Cache
	JWT         *session.JWT
	SMSClient   *vonage.SMSClient
	MailHost    string
	MailFrom    string
	MailOptions []mail.Option
}

func NewController

func NewController(options *Options) *Controller

func (*Controller) AddSensors

func (c *Controller) AddSensors(session *tables.User, station *tables.Station, sensors []tables.Sensor) error

func (*Controller) Authenticate

func (c *Controller) Authenticate(u *tables.User) (*tables.User, error)

func (*Controller) Authorize

func (c *Controller) Authorize(jwtS string) (*tables.User, error)

func (*Controller) AuthorizeAPIKey

func (c *Controller) AuthorizeAPIKey(apiKey string) (*tables.Station, error)

func (*Controller) CheckAlert added in v0.0.6

func (c *Controller) CheckAlert(registry *tables.SensorRegistry) ([]tables.Alert, error)

func (*Controller) Close

func (c *Controller) Close() error

func (*Controller) ConfirmAccount added in v0.0.6

func (c *Controller) ConfirmAccount(emailCode, smsCode string) error

func (*Controller) CreateAlert

func (c *Controller) CreateAlert(session *tables.User, alert *tables.Alert) error

func (*Controller) CreateStation

func (c *Controller) CreateStation(session *tables.User, station *tables.Station) (*tables.Station, error)

func (*Controller) DeleteAlert

func (c *Controller) DeleteAlert(session *tables.User, alert *tables.Alert) error

func (*Controller) DeleteSensors

func (c *Controller) DeleteSensors(session *tables.User, station *tables.Station, sensors []tables.Sensor) error

func (*Controller) DeleteStation

func (c *Controller) DeleteStation(session *tables.User, station *tables.Station) error

func (*Controller) Historical

func (c *Controller) Historical(filter *HistoricalFilter) ([]tables.SensorRegistry, error)

func (*Controller) PushRegistry added in v0.0.6

func (c *Controller) PushRegistry(session *tables.Station, registries []tables.SensorRegistry) error

func (*Controller) QueryAccount

func (c *Controller) QueryAccount(session *tables.User) (*tables.User, error)

func (*Controller) QueryManyAlert

func (c *Controller) QueryManyAlert(session *tables.User, filter *Filter[tables.Alert]) (*Results[tables.Alert], error)

func (*Controller) QueryManyStation

func (c *Controller) QueryManyStation(filter *Filter[tables.Station]) (*Results[tables.Station], error)

func (*Controller) QueryOneAlert

func (c *Controller) QueryOneAlert(session *tables.User, alert *tables.Alert) (*tables.Alert, error)

func (*Controller) QueryStation

func (c *Controller) QueryStation(station *tables.Station) (*tables.Station, error)

func (*Controller) Register

func (c *Controller) Register(u *tables.User) error

func (*Controller) RequestConfirmation added in v0.0.6

func (c *Controller) RequestConfirmation(session *tables.User) (string, string, error)

func (*Controller) SendMessage added in v0.0.6

func (c *Controller) SendMessage(message *tables.Message) error

func (*Controller) UpdateAccount

func (c *Controller) UpdateAccount(session, details *tables.User, password string) error

Update account user should have the Password set, the details to update

func (*Controller) UpdateAlert

func (c *Controller) UpdateAlert(session *tables.User, alert *tables.Alert) error

func (*Controller) UpdateStation

func (c *Controller) UpdateStation(session *tables.User, station *tables.Station) error

type Filter

type Filter[T any] struct {
	Page     int `json:"page"`
	PageSize int `json:"pageSize"`
	Target   T   `json:"target"`
}

type HistoricalFilter

type HistoricalFilter struct {
	SensorUUID uuid.UUID  `json:"sensorUUID"`
	From       *time.Time `json:"from"`
	To         *time.Time `json:"to"`
}

type MailOptions added in v0.0.6

type MailOptions struct {
	Host    string
	From    string
	Options []mail.Option
}

type Options added in v0.0.6

type Options struct {
	Database  *gorm.DB
	Cache     cache.Cache
	JWTSecret []byte
	Vonage    *VonageOptions
	Mail      *MailOptions
}

type Results

type Results[T any] struct {
	Page     int `json:"page"`
	PageSize int `json:"pageSize"`
	Count    int `json:"count"`
	Entries  []T `json:"entries"`
}

type VonageOptions added in v0.0.6

type VonageOptions struct {
	Secret string
	APIKey string
}

Directories

Path Synopsis
common
sqlite
sqlite will be only used for unit tests and when no postgres DSN is provided
sqlite will be only used for unit tests and when no postgres DSN is provided

Jump to

Keyboard shortcuts

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