This repository has been archived by the owner on Sep 19, 2021. It is now read-only.
/
radio.go
83 lines (66 loc) · 1.8 KB
/
radio.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package api
import "encoding/json"
// Radio is a basic input.
type Radio struct {
ID int `json:"-"`
Value string `json:"value"`
Checked bool `json:"checked,omitempty"`
}
// Unmarshal bytes in to the entity properties.
func (entity *Radio) Unmarshal(raw []byte) error {
return json.Unmarshal(raw, entity)
}
// Marshal to payload structure
func (entity *Radio) Marshal() Payload {
return MarshalPayloadEntity("radio", entity)
}
// Valid checks the value(s) against an battery of tests.
func (entity *Radio) Valid() (bool, error) {
return true, nil
}
// Save the radio to data storage.
func (entity *Radio) Save(context DatabaseService, account int) (int, error) {
if err := context.CheckTable(entity); err != nil {
return entity.ID, err
}
if err := context.Save(entity); err != nil {
return entity.ID, err
}
return entity.ID, nil
}
// Delete the radio from data storage.
func (entity *Radio) Delete(context DatabaseService, account int) (int, error) {
if err := context.CheckTable(entity); err != nil {
return entity.ID, err
}
if entity.ID != 0 {
if err := context.Delete(entity); err != nil {
return entity.ID, err
}
}
return entity.ID, nil
}
// Get the radio from data storage.
func (entity *Radio) Get(context DatabaseService, account int) (int, error) {
if err := context.CheckTable(entity); err != nil {
return entity.ID, err
}
if entity.ID != 0 {
if err := context.Select(entity); err != nil {
return entity.ID, err
}
}
return entity.ID, nil
}
// GetID returns the entity identifier.
func (entity *Radio) GetID() int {
return entity.ID
}
// SetID sets the entity identifier.
func (entity *Radio) SetID(id int) {
entity.ID = id
}
// Find is not used for radios. Please use the `Get` method.
func (entity *Radio) Find(context DatabaseService) error {
return nil
}