forked from anselm94/googlekeepclone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
models_gen.go
141 lines (116 loc) · 2.92 KB
/
models_gen.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// Code generated by github.com/99designs/gqlgen, DO NOT EDIT.
package server
import (
"fmt"
"io"
"strconv"
"github.com/volatiletech/authboss/v3"
)
type Label struct {
ID string `json:"id"`
Name string `json:"name"`
Todos []*Todo `gorm:"many2many:todos_labels"` // many-to-many
UserID string `sql:"type:TEXT REFERENCES users(id) ON DELETE CASCADE"`
}
type LabelAction struct {
Action Action `json:"action"`
Label *Label `json:"label"`
}
type Note struct {
ID string `gorm:"primary_key"`
TodoID string `sql:"type:TEXT REFERENCES todos(id) ON DELETE CASCADE"`
Text string `json:"text"`
IsCompleted bool `json:"isCompleted"`
}
type NotesInput struct {
Text string `json:"text"`
IsCompleted bool `json:"isCompleted"`
}
type Todo struct {
ID string `json:"id"`
Title string `json:"title"`
Notes []*Note `json:"notes" gorm:"foreignkey:TodoID"` // has-many
Labels []*Label `json:"labels" gorm:"many2many:todos_labels"` // many-to-many
Color string `json:"color"`
IsCheckboxMode bool `json:"isCheckboxMode"`
UserID string `sql:"type:TEXT REFERENCES users(id) ON DELETE CASCADE"`
}
type TodoAction struct {
Action Action `json:"action"`
Todo *Todo `json:"todo"`
}
type User struct {
authboss.ArbitraryUser
ID string `json:"id"`
Name string `json:"name"`
Email string `json:"email"`
Password string `json:"password"`
ListMode bool `json:"listMode"`
DarkMode bool `json:"darkMode"`
Todos []*Todo `gorm:"foreignkey:UserID"` // has-many
Labels []*Label `gorm:"foreignkey:UserID"` // has-many
}
func (u *User) GetPID() string {
return u.ID
}
func (u *User) PutPID(pid string) {
u.ID = pid
}
func (u *User) GetPassword() string {
return u.Password
}
func (u *User) PutPassword(password string) {
u.Password = password
}
func (u *User) GetArbitrary() map[string]string {
return map[string]string{
"name": u.Name,
"email": u.Email,
}
}
func (u *User) PutArbitrary(values map[string]string) {
if name, ok := values["name"]; ok {
u.Name = name
}
if email, ok := values["email"]; ok {
u.Email = email
}
}
func (u *User) Validate() []error {
return nil
}
type Action string
const (
ActionCreated Action = "CREATED"
ActionDeleted Action = "DELETED"
ActionUpdated Action = "UPDATED"
)
var AllAction = []Action{
ActionCreated,
ActionDeleted,
ActionUpdated,
}
func (e Action) IsValid() bool {
switch e {
case ActionCreated, ActionDeleted, ActionUpdated:
return true
}
return false
}
func (e Action) String() string {
return string(e)
}
func (e *Action) UnmarshalGQL(v interface{}) error {
str, ok := v.(string)
if !ok {
return fmt.Errorf("enums must be strings")
}
*e = Action(str)
if !e.IsValid() {
return fmt.Errorf("%s is not a valid Action", str)
}
return nil
}
func (e Action) MarshalGQL(w io.Writer) {
fmt.Fprint(w, strconv.Quote(e.String()))
}