Documentation ¶
Index ¶
- func GetDevice(db *pg.DB, deviceID int64) (*Device, *JSONError)
- func GetUser(db *pg.DB, uid int64) (*User, *JSONError)
- func SwitchDevicePower(db *pg.DB, device *Device) (*Device, *JSONError)
- func UpdateUser(db *pg.DB, uid int64, uu *User) (*User, *JSONError)
- type Claims
- type Device
- type JSONError
- func AcquireDevice(db *pg.DB, device *Device, uid int64) *JSONError
- func AddDevice(db *pg.DB, d *Device) *JSONError
- func AddDeviceMulti(db *pg.DB, devices *[]Device) *JSONError
- func AddUser(db *pg.DB, user *User) *JSONError
- func DeleteDevice(db *pg.DB, uid int64) *JSONError
- func DeleteUser(db *pg.DB, uid int64) *JSONError
- func GetAllDevices(db *pg.DB) (*[]Device, *JSONError)
- func GetAllUsers(db *pg.DB) (*[]User, *JSONError)
- func NewBadRequestError() *JSONError
- func NewForbiddenError() *JSONError
- func NewInternalServerError() *JSONError
- func NewUnauthorizedError() *JSONError
- func ReleaseDevice(db *pg.DB, device *Device) *JSONError
- type JWT
- type NewUser
- type PutUser
- type Role
- type User
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SwitchDevicePower ¶
SwitchDevicePower inverse the `isTurnedOn` field of the `Device` with the given `deviceID`
Types ¶
type Device ¶
type Device struct { ID int64 `json:"id" pg:",pk"` Hostname string `json:"hostname"` IsTurnedOn bool `json:"isTurnedOn"` 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 GetAllDevices ¶
GetAllDevices returns all the `Device` from the database
func GetAllUsers ¶
GetAllUsers returns all the `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 JWT ¶
type JWT struct {
// contains filtered or unexported fields
}
JWT is used for swagger doc only
type NewUser ¶
type NewUser struct { Username string `json:"username" example:"rubus"` Email string `json:"email" example:"rubus@mail.com"` Password string `json:"password" example:"rubus_secret"` Role Role `json:"role" example:"administrator"` Expiration string `json:"expiration" example:"2020-05-18"` }
NewUser is the model sent to create a new `User`
type PutUser ¶
type PutUser struct { Username string `json:"username" example:"rubus"` Email string `json:"email" example:"rubus@mail.com"` Password string `json:"password" example:"rubus_secret"` }
PutUser is only use to document the PUT `User` endpoint
type User ¶
type User struct { ID int64 `json:"id" pg:",pk" example:"1"` Username string `json:"username" pg:",unique, notnull" example:"rubus"` Email string `json:"email" pg:",unique, notnull" example:"rubus@mail.com"` Role Role `json:"role" example:"administrator"` Expiration time.Time `json:"expiration" example:"2020-05-18"` PasswordHash string `json:"-" pg:",notnull"` }
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)