@@ -119,21 +119,20 @@ func serveAPI(e *echo.Echo) {
119
119
// e.POST("/login/", login(userCollection))
120
120
121
121
// Routes for posts
122
- e .GET ("/post/:id/" , getPost (postsCollection ))
123
- e .GET ("/posts/" , getAllPosts (postsCollection ))
124
- e .POST ("/post/" , newPost (postsCollection ))
125
- e .PUT ("/post/:id/" , updatePost (postsCollection ))
126
- e .DELETE ("/post/:id/" , deletePost (postsCollection ))
122
+ e .GET ("/posts/:id/" , getPosts (postsCollection ))
123
+ e .POST ("/post/" , newPosts (postsCollection ))
124
+ e .PUT ("/post/:id/" , updatePosts (postsCollection ))
125
+ e .DELETE ("/post/:id/" , deletePosts (postsCollection ))
127
126
128
127
// Routes for categories
129
- e .GET ("/category/:id/" , getCat (catCollection ))
130
- e .POST ("/category/" , newCat (catCollection ))
131
- e .PATCH ("/category/" , patchCat (catCollection ))
132
- e .DELETE ("/category/" , deleteCat (catCollection ))
128
+ e .GET ("/category/:id/" , getCats (catCollection ))
129
+ e .POST ("/category/" , newCats (catCollection ))
130
+ e .PATCH ("/category/" , patchCats (catCollection ))
131
+ e .DELETE ("/category/" , deleteCats (catCollection ))
133
132
134
133
// Routes for sponsors
135
- e .POST ("/sponsor/" , newSponsor (sponsorCollection ))
136
- e .DELETE ("/sponsor/" , deleteSponsor (sponsorCollection ))
134
+ e .POST ("/sponsor/" , newSponsors (sponsorCollection ))
135
+ e .DELETE ("/sponsor/" , deleteSponsors (sponsorCollection ))
137
136
}
138
137
139
138
// func login(collection *mongo.Collection) echo.HandlerFunc {
@@ -148,29 +147,27 @@ func serveAPI(e *echo.Echo) {
148
147
// }
149
148
// }
150
149
151
- func getPost (collection * mongo.Collection ) echo.HandlerFunc {
150
+ func getPosts (collection * mongo.Collection ) echo.HandlerFunc {
152
151
return func (c echo.Context ) error {
153
- id , _ := strconv .Atoi (c .QueryParam ("id" ))
152
+ id := c .QueryParam ("id" )
153
+ count , _ := strconv .Atoi (c .QueryParam ("nPosts" ))
154
154
category := c .QueryParam ("category" )
155
- result := GetPost (collection , id , category )
155
+ if id == "" {
156
+ posts := GetAllPosts (collection , count , category )
157
+ return c .JSON (http .StatusOK , H {
158
+ "post" : posts ,
159
+ })
160
+ }
161
+
162
+ idInt , _ := strconv .Atoi (id )
163
+ result := GetPosts (collection , idInt , category )
156
164
return c .JSON (http .StatusOK , H {
157
165
"post" : result ,
158
166
})
159
167
}
160
168
}
161
169
162
- func getAllPosts (collection * mongo.Collection ) echo.HandlerFunc {
163
- return func (c echo.Context ) error {
164
- count , _ := strconv .Atoi (c .QueryParam ("id" ))
165
- cat := c .QueryParam ("category" )
166
- posts := GetAllPosts (collection , count , cat )
167
- return c .JSON (http .StatusOK , H {
168
- "posts" : posts ,
169
- })
170
- }
171
- }
172
-
173
- func newPost (collection * mongo.Collection ) echo.HandlerFunc {
170
+ func newPosts (collection * mongo.Collection ) echo.HandlerFunc {
174
171
return func (c echo.Context ) error {
175
172
id , _ := strconv .Atoi (c .FormValue ("id" ))
176
173
category , _ := strconv .Atoi (c .FormValue ("category" ))
@@ -181,12 +178,12 @@ func newPost(collection *mongo.Collection) echo.HandlerFunc {
181
178
content := c .FormValue ("content" )
182
179
github := c .FormValue ("linkGithub" )
183
180
fb := c .FormValue ("linkFacebook" )
184
- NewPost (collection , id , category , showInMenu , title , subtitle , postType , content , github , fb )
181
+ NewPosts (collection , id , category , showInMenu , title , subtitle , postType , content , github , fb )
185
182
return c .JSON (http .StatusOK , H {})
186
183
}
187
184
}
188
185
189
- func updatePost (collection * mongo.Collection ) echo.HandlerFunc {
186
+ func updatePosts (collection * mongo.Collection ) echo.HandlerFunc {
190
187
return func (c echo.Context ) error {
191
188
id , _ := strconv .Atoi (c .FormValue ("id" ))
192
189
category , _ := strconv .Atoi (c .FormValue ("category" ))
@@ -197,78 +194,78 @@ func updatePost(collection *mongo.Collection) echo.HandlerFunc {
197
194
content := c .FormValue ("content" )
198
195
github := c .FormValue ("linkGithub" )
199
196
fb := c .FormValue ("linkFacebook" )
200
- UpdatePost (collection , id , category , showInMenu , title , subtitle , postType , content , github , fb )
197
+ UpdatePosts (collection , id , category , showInMenu , title , subtitle , postType , content , github , fb )
201
198
return c .JSON (http .StatusOK , H {})
202
199
}
203
200
}
204
201
205
- func deletePost (collection * mongo.Collection ) echo.HandlerFunc {
202
+ func deletePosts (collection * mongo.Collection ) echo.HandlerFunc {
206
203
return func (c echo.Context ) error {
207
204
id , _ := strconv .Atoi (c .FormValue ("id" ))
208
- DeletePost (collection , id )
205
+ DeletePosts (collection , id )
209
206
return c .JSON (http .StatusOK , H {})
210
207
}
211
208
}
212
209
213
- func getCat (collection * mongo.Collection ) echo.HandlerFunc {
210
+ func getCats (collection * mongo.Collection ) echo.HandlerFunc {
214
211
return func (c echo.Context ) error {
215
212
token := c .FormValue ("token" )
216
213
id , _ := strconv .Atoi (c .QueryParam ("id" ))
217
- result := GetCat (collection , id , token )
214
+ result := GetCats (collection , id , token )
218
215
return c .JSON (http .StatusOK , H {
219
216
"category" : result ,
220
217
})
221
218
}
222
219
}
223
220
224
- func newCat (collection * mongo.Collection ) echo.HandlerFunc {
221
+ func newCats (collection * mongo.Collection ) echo.HandlerFunc {
225
222
return func (c echo.Context ) error {
226
223
token := c .FormValue ("token" )
227
224
catID , _ := strconv .Atoi (c .FormValue ("id" ))
228
225
index , _ := strconv .Atoi (c .FormValue ("index" ))
229
226
name := c .FormValue ("name" )
230
- NewCat (collection , catID , index , name , token )
227
+ NewCats (collection , catID , index , name , token )
231
228
return c .JSON (http .StatusOK , H {})
232
229
}
233
230
}
234
231
235
- func patchCat (collection * mongo.Collection ) echo.HandlerFunc {
232
+ func patchCats (collection * mongo.Collection ) echo.HandlerFunc {
236
233
return func (c echo.Context ) error {
237
234
token := c .FormValue ("token" )
238
235
catID , _ := strconv .Atoi (c .FormValue ("id" ))
239
236
name := c .FormValue ("name" )
240
237
index , _ := strconv .Atoi (c .FormValue ("index" ))
241
- PatchCat (collection , catID , name , index , token )
238
+ PatchCats (collection , catID , name , index , token )
242
239
return c .JSON (http .StatusOK , H {})
243
240
}
244
241
}
245
242
246
- func deleteCat (collection * mongo.Collection ) echo.HandlerFunc {
243
+ func deleteCats (collection * mongo.Collection ) echo.HandlerFunc {
247
244
return func (c echo.Context ) error {
248
245
token := c .FormValue ("token" )
249
246
id , _ := strconv .Atoi (c .FormValue ("id" ))
250
- DeleteCat (collection , id , token )
247
+ DeleteCats (collection , id , token )
251
248
return c .JSON (http .StatusOK , H {})
252
249
}
253
250
}
254
251
255
- func newSponsor (collection * mongo.Collection ) echo.HandlerFunc {
252
+ func newSponsors (collection * mongo.Collection ) echo.HandlerFunc {
256
253
return func (c echo.Context ) error {
257
254
token := c .FormValue ("token" )
258
255
expiryStr := c .FormValue ("expiry" )
259
256
name := c .FormValue ("name" )
260
257
logo := c .FormValue ("logo" )
261
258
tier := c .FormValue ("tier" )
262
- NewSponsor (collection , expiryStr , name , logo , tier , token )
259
+ NewSponsors (collection , expiryStr , name , logo , tier , token )
263
260
return c .JSON (http .StatusOK , H {})
264
261
}
265
262
}
266
263
267
- func deleteSponsor (collection * mongo.Collection ) echo.HandlerFunc {
264
+ func deleteSponsors (collection * mongo.Collection ) echo.HandlerFunc {
268
265
return func (c echo.Context ) error {
269
266
token := c .FormValue ("token" )
270
267
id := c .FormValue ("id" )
271
- DeleteSponsor (collection , id , token )
268
+ DeleteSponsors (collection , id , token )
272
269
return c .JSON (http .StatusOK , H {})
273
270
}
274
271
}
0 commit comments