station_type

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrStationNotFound is used when a specific Station is requested but does not exist.
	ErrStationNotFound = errors.New("station not found")

	// ErrForbidden occurs when an account tries to do something that is forbidden to
	// it according to our access control policies.
	ErrForbidden = errors.New("Attempted action is not allowed")
)

Predefined errors identify expected failure conditions.

View Source
var (
	// ErrNotFound is used when a specific StationType is requested but does not exist.
	ErrNotFound = errors.New("station type not found")

	// ErrInvalidID is used when an invalid UUID is provided.
	ErrInvalidID = errors.New("ID is not in its proper UUID format")
)

Predefined errors identify expected failure conditions.

Functions

func AdjustStation

func AdjustStation(ctx context.Context, db *sqlx.DB, account auth.Claims, id string, update UpdateStation, now time.Time) error

AdjustStation modifies data about a Station. It will error if the specified ID is invalid or does not reference an existing Station.

func Delete

func Delete(ctx context.Context, db *sqlx.DB, id string) error

Delete removes the station type identified by a given ID.

func DeleteStation

func DeleteStation(ctx context.Context, db *sqlx.DB, id string) error

DeleteStation removes the station identified by a given ID.

func Update

func Update(ctx context.Context, db *sqlx.DB, id string, update UpdateStationType, now time.Time) error

Update modifies data about a StationType. It will error if the specified ID is invalid or does not reference an existing StationType.

Types

type NewStation

type NewStation struct {
	Name        string `db:"name"            json:"name" validate:"required"`
	Description string `db:"description"     json:"description"`
	LocationX   int    `db:"location_x"      json:"location_x" validate:"required,gte=0"`
	LocationY   int    `db:"location_y"      json:"location_y" validate:"required,gte=0"`
}

NewStation is a what we require from clients when adding a Station.

type NewStationType

type NewStationType struct {
	Name        string `json:"name" validate:"required"`
	Description string `json:"description"`
}

NewStationType is what we require from clients when adding a StationType.

type Station

type Station struct {
	Id            string    `db:"id"              json:"id"`
	StationTypeId string    `db:"station_type_id" json:"station_type_id"`
	AccountId     string    `db:"account_id"      json:"account_id"`
	Name          string    `db:"name"            json:"name"`
	Description   string    `db:"description"     json:"description"`
	LocationX     int       `db:"location_x"      json:"location_x"`
	LocationY     int       `db:"location_y"      json:"location_y"`
	DateCreated   time.Time `db:"date_created"    json:"date_created"`
	DateUpdated   time.Time `db:"date_updated"    json:"date_updated"`
}

Station is a station that is defined as one of the station types in StationType.

func AddStation

func AddStation(ctx context.Context, db *sqlx.DB, account auth.Claims, ns NewStation, stationTypeID string, now time.Time) (*Station, error)

AddStation adds a station of a specific StationType.

func GetStation

func GetStation(ctx context.Context, db *sqlx.DB, id string) (*Station, error)

GetStation gets a specific Station from the database.

func ListStations

func ListStations(ctx context.Context, db *sqlx.DB, stationTypeID string) ([]Station, error)

ListStations gives all Stations for a StationType.

type StationType

type StationType struct {
	Id          string    `db:"id"           json:"id"`
	Name        string    `db:"name"         json:"name"`
	Description string    `db:"description"  json:"description"`
	Stations    int       `db:"stations"     json:"stations"`
	DateCreated time.Time `db:"date_created" json:"date_created"`
	DateUpdated time.Time `db:"date_updated" json:"date_updated"`
}

*

  • StationType is a type of station in the automated garden system. *
  • Note: use of "struct tags" (ex: `json:"id"`) to manage the names of properties to be lowercase and snake_case. Due to
  • the use of case for visibility in Go "id" rather and "Id" would result in the value being excluded in the JSON
  • response as the encoding/json package is external to this package. *
  • Note: the use of db:"id" allows renaming to map to the column used in the database

func Create

func Create(ctx context.Context, db *sqlx.DB, nst NewStationType, now time.Time) (*StationType, error)

Create adds a StationType to the database. It returns the created StationType with fields like ID and DateCreated populated.

func Get

func Get(ctx context.Context, db *sqlx.DB, id string) (*StationType, error)

Get finds the product identified by a given ID.

func List

func List(ctx context.Context, db *sqlx.DB) ([]StationType, error)

List gets all StationType from the database.

type UpdateStation

type UpdateStation struct {
	Name        *string `json:"name"`
	Description *string `json:"description"`
	LocationX   *int    `json:"location_x" validate:"omitempty,gte=0"`
	LocationY   *int    `json:"location_y" validate:"omitempty,gte=0"`
}

UpdateStation defines what information may be provided to modify an existing Station. All fields are optional so clients can send just the fields they want changed. It uses pointer fields so we can differentiate between a field that were not provided and a field that was provided as explicitly blank. Normally we do not want to use pointers to basic types but we make exceptions around marshalling/unmarshalling.

type UpdateStationType

type UpdateStationType struct {
	Name        *string `json:"name"`
	Description *string `json:"description"`
}

UpdateStationType defines what information may be provided to modify an existing StationType. All fields are optional so clients can send just the fields they want changed. It uses pointer fields so we can differentiate between a field that were not provided and a field that was provided as explicitly blank. Normally we do not want to use pointers to basic types but we make exceptions around marshalling/unmarshalling.

Jump to

Keyboard shortcuts

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