This repository has been archived by the owner on Sep 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
/
checkbox.go
83 lines (66 loc) · 1.85 KB
/
checkbox.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"
// Checkbox is a basic input.
type Checkbox struct {
ID int `json:"-"`
Value string `json:"value"`
Checked bool `json:"checked,omitempty"`
}
// Unmarshal bytes in to the entity properties.
func (entity *Checkbox) Unmarshal(raw []byte) error {
return json.Unmarshal(raw, entity)
}
// Marshal to payload structure
func (entity *Checkbox) Marshal() Payload {
return MarshalPayloadEntity("checkbox", entity)
}
// Valid checks the value(s) against an battery of tests.
func (entity *Checkbox) Valid() (bool, error) {
return true, nil
}
// Save the checkbox to data storage.
func (entity *Checkbox) 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 checkbox from data storage.
func (entity *Checkbox) 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 checkbox from data storage.
func (entity *Checkbox) 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 *Checkbox) GetID() int {
return entity.ID
}
// SetID sets the entity identifier.
func (entity *Checkbox) SetID(id int) {
entity.ID = id
}
// Find is not used for checkboxes. Please use the `Get` method.
func (entity *Checkbox) Find(context DatabaseService) error {
return nil
}