models

package module
v0.0.16 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2023 License: BSD-3-Clause Imports: 15 Imported by: 8

README

Models

Build codecov Go Report Card GitHub go.mod Go version

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.

Usage

Installing
go get -u github.com/hidromatologia-v2/models

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

This section is empty.

Variables

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

Functions

This section is empty.

Types

type Controller

type Controller struct {
	DB            *gorm.DB
	EmailCache    cache.Cache
	PasswordCache cache.Cache
	JWT           *session.JWT
	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 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) (err 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) QueryStationAPIKey added in v0.0.14

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

func (*Controller) QueryStationNoAPIKey added in v0.0.14

func (c *Controller) QueryStationNoAPIKey(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, error)

func (*Controller) RequestResetPassword added in v0.0.14

func (c *Controller) RequestResetPassword(account *tables.User) (string, error)

func (*Controller) ResetPassword added in v0.0.14

func (c *Controller) ResetPassword(resetCode string, newPassword 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) UpdatePassword added in v0.0.14

func (c *Controller) UpdatePassword(session *tables.User, currentPassword, newPassword string) 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
	EmailCache    cache.Cache
	PasswordCache cache.Cache
	JWTSecret     []byte
	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"`
}

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