Documentation
¶
Index ¶
- func GetAllDevices() ([]*Device, *JSONError)
- func GetAllUsers() (users []*User, jsonErr *JSONError)
- func GetDevice(deviceID int64) (*Device, *JSONError)
- func GetUser(uid int64) (*User, *JSONError)
- func SwitchDevicePower(device *Device) (*Device, *JSONError)
- func UpdateUser(uid int64, uu *User) (u *User, jsonErr *JSONError)
- type Claims
- type Device
- type JSONError
- func AcquireDevice(device *Device, uid int64) *JSONError
- func AddDevice(d *Device) *JSONError
- func AddDeviceMulti(devices *[]Device) *JSONError
- func AddUser(u *User) *JSONError
- func DeleteDevice(uid int64) *JSONError
- func DeleteUser(uid int64) *JSONError
- func NewBadRequestError() *JSONError
- func NewForbiddenError() *JSONError
- func NewInternalServerError() *JSONError
- func NewUnauthorizedError() *JSONError
- func ReleaseDevice(device *Device) *JSONError
- type NewUser
- type PutUser
- type Role
- type User
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetAllDevices ¶
GetAllDevices returns all the `Device` from the database
func GetAllUsers ¶
GetAllUsers returns all the `User` from the database
func SwitchDevicePower ¶
SwitchDevicePower inverse the `isTurnOn` field of the `Device` with the given `deviceID`
Types ¶
type Device ¶
type Device struct { ID int64 `json:"id" orm:"pk"` Hostname string `json:"hostname"` IsTurnOn bool `json:"isTurnOn"` Owner *int64 `json:"owner" orm:"null"` }
Device contains the information about a device
type JSONError ¶
JSONError is the struct representing a JSON formatted error
func AcquireDevice ¶
AcquireDevice sets the `User` parameter as the owner of the `Device`
func AddDeviceMulti ¶
AddDeviceMulti insters multiple `Device` into the database
func DeleteDevice ¶
DeleteDevice removes the given Rubus `Device` from the database
func DeleteUser ¶
DeleteUser removes the given Rubus `User` from the database
func NewBadRequestError ¶
func NewBadRequestError() *JSONError
NewBadRequestError return an error 400 JSON formatted
func NewForbiddenError ¶
func NewForbiddenError() *JSONError
NewForbiddenError return an error 403 JSON formatted
func NewInternalServerError ¶
func NewInternalServerError() *JSONError
NewInternalServerError returns an error 500 JSON formatted
func NewUnauthorizedError ¶
func NewUnauthorizedError() *JSONError
NewUnauthorizedError return an error 401 JSON formatted
func ReleaseDevice ¶
ReleaseDevice sets the `owner` of the `Device` as nil, if it is the current `owner` which is modifying it.
type NewUser ¶
type NewUser struct { Username string `json:"username"` Email string `json:"email"` Password string `json:"password"` Role Role `json:"role"` }
NewUser is the model sent to create a new `User`
type PutUser ¶
type PutUser struct { Username string `json:"username"` Email string `json:"email"` Password string `json:"password"` }
PutUser is only use to document the PUT `User` endpoint
type User ¶
type User struct { ID int64 `json:"id" orm:"pk;auto"` Username string `json:"username" orm:"unique"` Email string `json:"email" orm:"unique"` Role Role `json:"role"` PasswordHash string `json:"-"` }
User is the `User` model in the database
func (*User) BindWithEmptyFields ¶
BindWithEmptyFields transforms the given payload into a `User`, with some validations, but does not require any field (they should be either nil or valid)