This commit is contained in:
Stian Fredrik Aune
2021-05-23 14:00:42 +02:00
parent f7f8989d20
commit 21157e4330
25 changed files with 24454 additions and 11560 deletions
+14 -5
View File
@@ -1,11 +1,20 @@
package models
import "context"
type Bridge struct {
ID int `json:"id"`
Name string `json:"name"`
Driver DriverKind `json:"driver"`
Address string `json:"address"`
Token string `json:"token"`
ID int `json:"id" db:"id"`
Name string `json:"name" db:"name"`
Driver DriverKind `json:"driver" db:"driver"`
Address string `json:"address" db:"address"`
Token string `json:"-" db:"token"`
}
type BridgeRepository interface {
Find(ctx context.Context, id int) (Bridge, error)
FetchAll(ctx context.Context) ([]Bridge, error)
Save(ctx context.Context, bridge *Bridge) error
Delete(ctx context.Context, bridge *Bridge) error
}
type DriverKind string
+2
View File
@@ -2,7 +2,9 @@ package models
import "errors"
var ErrNotFound = errors.New("not found")
var ErrInvalidName = errors.New("invalid name")
var ErrBadInput = errors.New("bad input")
var ErrBadColor = errors.New("bad color")
var ErrInternal = errors.New("internal")
var ErrUnknownColorFormat = errors.New("unknown color format")
+9
View File
@@ -1,5 +1,7 @@
package models
import "strconv"
type Event struct {
Name string `json:"name"`
Payload map[string]string `json:"payload,omitempty"`
@@ -16,3 +18,10 @@ func (e *Event) AddPayload(key, value string) {
func (e *Event) HasPayload(key string) bool {
return e.Payload != nil && e.Payload[key] != ""
}
func BridgeConnectedEvent(bridge Bridge) Event {
e := Event{Name: "BridgeConnected"}
e.AddPayload("id", strconv.Itoa(bridge.ID))
return e
}