Documentation
¶
Index ¶
- Variables
- func AdjustStation(ctx context.Context, db *sqlx.DB, account auth.Claims, id string, ...) error
- func Delete(ctx context.Context, db *sqlx.DB, id string) error
- func DeleteStation(ctx context.Context, db *sqlx.DB, id string) error
- func Update(ctx context.Context, db *sqlx.DB, id string, update UpdateStationType, ...) error
- type NewStation
- type NewStationType
- type Station
- type StationType
- type UpdateStation
- type UpdateStationType
Constants ¶
This section is empty.
Variables ¶
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.
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 DeleteStation ¶
DeleteStation removes the station identified by a given ID.
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 ¶
GetStation gets a specific Station from the database.
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.
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.