/
api.go
175 lines (149 loc) · 6.52 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
package todos
import "time"
//===========================================================================
// Top Level Requests and Responses
//===========================================================================
// Response contains standard fields that are embedded in most API responses
type Response struct {
Success bool `json:"success"`
Error string `json:"error,omitempty" yaml:"error,omitempty"`
}
// StatusResponse is returned on status requests. Note that no request is needed.
type StatusResponse struct {
Status string `json:"status"`
Timestamp time.Time `json:"timestamp,omitempty"`
Version string `json:"version,omitempty"`
Error string `json:"error,omitempty" yaml:"error,omitempty"`
}
// OverviewResponse is returned on an overview request.
type OverviewResponse struct {
Success bool `json:"success"`
Error string `json:"error,omitempty" yaml:"error,omitempty"`
User string `json:"user"`
Tasks int `json:"tasks"`
Checklists int `json:"checklists"`
}
//===========================================================================
// Authentication
//===========================================================================
// RegisterRequest allows a administrative users to create new users.
type RegisterRequest struct {
Username string `json:"username" binding:"required"`
Email string `json:"email" binding:"required"`
Password string `json:"password" binding:"required"`
IsAdmin bool `json:"is_admin"`
}
// RegisterResponse returns the status of a a Register request.
type RegisterResponse struct {
Success bool `json:"success"`
Error string `json:"error,omitempty" yaml:"error,omitempty"`
Username string `json:"username"`
}
// LoginRequest to authenticate a user with the service and return tokens
type LoginRequest struct {
Username string `json:"username" binding:"required"`
Password string `json:"password" binding:"required"`
NoCookie bool `json:"no_cookie"`
}
// LoginResponse is returned on a successful login
type LoginResponse struct {
Success bool `json:"success"`
Error string `json:"error,omitempty" yaml:"error,omitempty"`
AccessToken string `json:"access_token,omitempty"`
RefreshToken string `json:"refresh_token,omitempty"`
}
// LogoutRequest to logout the current user and optionally revoke all logins. Must be
// authenticated to log out a user.
type LogoutRequest struct {
RevokeAll bool `json:"revoke_all"`
}
// RefreshRequest is a reauthorization with a request token rather than username/password
type RefreshRequest struct {
RefreshToken string `json:"refresh_token" binding:"required"`
NoCookie bool `json:"no_cookie"`
}
//===========================================================================
// Tasks RESTful API
//===========================================================================
// ListTasksRequest fetches tasks with specific filters.
type ListTasksRequest struct {
Checklist uint `json:"checklist,omitempty"`
Page int `json:"page,omitempty"`
PerPage int `json:"per_page,omitempty"`
}
// ListTasksResponse returns the tasks, and response info such as pagination.
type ListTasksResponse struct {
Success bool `json:"success"`
Error string `json:"error,omitempty" yaml:"error,omitempty"`
Tasks []Task `json:"tasks,omitempty"`
Page int `json:"page,omitempty"`
NumPages int `json:"num_pages,omitempty"`
}
// CreateTaskResponse returns the information about the created task. Currently the
// CreateTaskRequest is simply the task object itself.
type CreateTaskResponse struct {
Success bool `json:"success"`
Error string `json:"error,omitempty" yaml:"error,omitempty"`
TaskID uint `json:"task,omitempty"`
}
// DetailTaskResponse returns the detailed information about the task. Currently there
// is no DetailTaskRequest, the request is in the URL.
type DetailTaskResponse struct {
Success bool `json:"success"`
Error string `json:"error,omitempty" yaml:"error,omitempty"`
Task Task `json:"task"`
}
// UpdateTaskResponse returns information about the update call. Currently there is no
// UpdateTaskRequest, because it is simply the task object itself.
type UpdateTaskResponse struct {
Success bool `json:"success"`
Error string `json:"error,omitempty" yaml:"error,omitempty"`
}
// DeleteTaskResponse returns information about the delete call. Currently there is no
// DeleteTaskRequest, because the request is in the URL.
type DeleteTaskResponse struct {
Success bool `json:"success"`
Error string `json:"error,omitempty" yaml:"error,omitempty"`
}
//===========================================================================
// Checklist RESTful API
//===========================================================================
// ListChecklistsRequest fetches checklists with specific filters.
type ListChecklistsRequest struct {
Page int `json:"page,omitempty"`
PerPage int `json:"per_page,omitempty"`
}
// ListChecklistsResponse returns the checklists, and response info such as pagination.
type ListChecklistsResponse struct {
Success bool `json:"success"`
Error string `json:"error,omitempty" yaml:"error,omitempty"`
Checklists []Checklist `json:"checklists,omitempty"`
Page int `json:"page,omitempty"`
NumPages int `json:"num_pages,omitempty"`
}
// CreateChecklistResponse returns the information about the created checklist.
// Currently the CreateChecklistRequest is simply the checklist object itself.
type CreateChecklistResponse struct {
Success bool `json:"success"`
Error string `json:"error,omitempty" yaml:"error,omitempty"`
ChecklistID uint `json:"checklist,omitempty"`
}
// DetailChecklistResponse returns the detailed information about the checklist.
// Currently there is no DetailChecklistRequest, the request is in the URL.
type DetailChecklistResponse struct {
Success bool `json:"success"`
Error string `json:"error,omitempty" yaml:"error,omitempty"`
Checklist Checklist `json:"checklist"`
}
// UpdateChecklistResponse returns information about the update call. Currently there is
// no UpdateChecklistRequest, because it is simply the checklist object itself.
type UpdateChecklistResponse struct {
Success bool `json:"success"`
Error string `json:"error,omitempty" yaml:"error,omitempty"`
}
// DeleteChecklistResponse returns information about the delete call. Currently there is
// no DeleteChecklistRequest, because the request is in the URL.
type DeleteChecklistResponse struct {
Success bool `json:"success"`
Error string `json:"error,omitempty" yaml:"error,omitempty"`
}