-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.go
189 lines (159 loc) · 4.89 KB
/
api.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
package cocka2notesapi
import (
"sync"
"time"
)
/*
Six910 is a shopping cart and E-commerce system.
Copyright (C) 2020 Ulbora Labs LLC. (www.ulboralabs.com)
All rights reserved.
Copyright (C) 2020 Ken Williamson
All rights reserved.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// go mod init github.com/Ulbora/cocka2notesApi
const (
post = "POST"
put = "PUT"
get = "GET"
delete = "DELETE"
)
//ResponseID ResponseID
type ResponseID struct {
ID int64 `json:"id"`
Success bool `json:"success"`
Code int64 `json:"code"`
Message string `json:"message"`
}
//Response Response
type Response struct {
Success bool `json:"success"`
Code int64 `json:"code"`
Message string `json:"message"`
}
//LoginResponse LoginResponse
type LoginResponse struct {
Success bool `json:"success"`
Email string `json:"email"`
}
//Headers Headers
type Headers struct {
headers map[string]string
mu sync.Mutex
}
//Set Set
func (h *Headers) Set(key string, value string) {
h.mu.Lock()
defer h.mu.Unlock()
if h.headers == nil {
h.headers = make(map[string]string)
}
h.headers[key] = value
}
//User User
type User struct {
Email string `json:"email"`
Password string `json:"password"`
WebEnabled bool `json:"webEnabled"`
}
//NoteUsers NoteUsers
type NoteUsers struct {
OwnerEmail string `json:"ownerEmail"`
NoteID int64 `json:"noteId"`
UserEmail string `json:"userEmail"`
}
//TextNote TextNote
type TextNote struct {
ID int64 `json:"id"`
Title string `json:"title"`
Type string `json:"type"`
OwnerEmail string `json:"ownerEmail"`
NoteItems []NoteItem `json:"noteTextItems"`
LastUsed time.Time `json:"lastUsed"`
}
//Note Note
type Note struct {
ID int64 `json:"id"`
Title string `json:"title"`
Type string `json:"type"`
OwnerEmail string `json:"ownerEmail"`
NoteTextItems []NoteItem `json:"noteTextItems"`
NoteCheckboxItems []CheckboxNoteItem `json:"noteCheckboxItems"`
LastUsed time.Time `json:"lastUsed"`
}
//NoteItem NoteItem
type NoteItem struct {
ID int64 `json:"id"`
Text string `json:"text"`
NoteID int64 `json:"noteId"`
}
//CheckboxNote CheckboxNote
type CheckboxNote struct {
ID int64 `json:"id"`
Title string `json:"title"`
Type string `json:"type"`
OwnerEmail string `json:"ownerEmail"`
NoteItems []CheckboxNoteItem `json:"noteCheckboxItems"`
LastUsed time.Time `json:"lastUsed"`
}
//CheckboxNoteItem CheckboxNoteItem
type CheckboxNoteItem struct {
ID int64 `json:"id"`
Text string `json:"text"`
Checked bool `json:"checked"`
NoteID int64 `json:"noteId"`
}
//MailServer MailServer
type MailServer struct {
ID int64 `json:"id"`
Host string `json:"host"`
Username string `json:"username"`
Password string `json:"password"`
Port string `json:"port"`
SenderEmail string `json:"senderEmail"`
}
//API API
type API interface {
AddUser(u *User) *Response
UpdateUser(u *User) *Response
GetUser(email string) *User
Login(u *User) *LoginResponse
ResetPassword(u *User) *Response
AddUserToNote(n *NoteUsers) *Response
GetNoteUserList(noteID int64, ownerEmail string) *[]string
AddNote(n *Note) *ResponseID
UpdateNote(n *Note) *Response
GetCheckboxNote(id int64) *CheckboxNote
GetNote(id int64) *TextNote
GetUsersNotes(email string) (*[]Note, bool)
DeleteNote(id int64, ownerEmail string) *Response
setSavedCheckboxNote(cb *CheckboxNote)
getSavedCheckboxNote(id int64) *CheckboxNote
setSavedTextNote(tx *TextNote)
getSavedTextNote(id int64) *TextNote
setSavedCheckboxItem(cb *CheckboxNoteItem)
setSavedTextItem(cb *NoteItem)
AddCheckboxItem(ni *CheckboxNoteItem) *ResponseID
UpdateCheckboxItem(ni *CheckboxNoteItem) *Response
DeleteCheckboxItem(id int64) *Response
AddNoteItem(ni *NoteItem) *ResponseID
UpdateNoteItem(ni *NoteItem) *Response
DeleteNoteItem(id int64) *Response
//Offline functionality below
GetFailAddCheckboxNoteItemList() []CheckboxNoteItem
GetFailUpdateCheckboxNoteItemList() []CheckboxNoteItem
GetFailAddNoteItemList() []NoteItem
GetFailUpdateNoteItemList() []NoteItem
FlushFailedCache()
SetNoteList(noteList []Note)
GetNoteList() []Note
}