77 "time"
88
99 "github.com/go-chi/chi/v5"
10- "github.com/go-chi/render"
1110 "github.com/go-pkgz/auth/v2"
1211 cache "github.com/go-pkgz/lcw/v2"
1312 log "github.com/go-pkgz/lgr"
@@ -54,8 +53,7 @@ func (a *admin) deleteCommentCtrl(w http.ResponseWriter, r *http.Request) {
5453 return
5554 }
5655 a .cache .Flush (cache .Flusher (locator .SiteID ).Scopes (locator .SiteID , locator .URL , lastCommentsScope ))
57- render .Status (r , http .StatusOK )
58- render .JSON (w , r , R.JSON {"id" : id , "locator" : locator })
56+ R .RenderJSON (w , R.JSON {"id" : id , "locator" : locator })
5957}
6058
6159// DELETE /user/{userid}?site=side-id - delete all user comments for requested userid
@@ -69,8 +67,7 @@ func (a *admin) deleteUserCtrl(w http.ResponseWriter, r *http.Request) {
6967 return
7068 }
7169 a .cache .Flush (cache .Flusher (siteID ).Scopes (userID , siteID , lastCommentsScope ))
72- render .Status (r , http .StatusOK )
73- render .JSON (w , r , R.JSON {"user_id" : userID , "site_id" : siteID })
70+ R .RenderJSON (w , R.JSON {"user_id" : userID , "site_id" : siteID })
7471}
7572
7673// GET /user/{userid}?site=side-id - get user info for requested userid
@@ -84,8 +81,7 @@ func (a *admin) getUserInfoCtrl(w http.ResponseWriter, r *http.Request) {
8481 rest .SendErrorJSON (w , r , http .StatusBadRequest , err , "can't get user info" , rest .ErrInternal )
8582 return
8683 }
87- render .Status (r , http .StatusOK )
88- render .JSON (w , r , ucomments [0 ].User )
84+ R .RenderJSON (w , ucomments [0 ].User )
8985}
9086
9187// GET /deleteme?token=jwt - delete all user comments and details by user's request. Gets info about deleted used from provided token
@@ -135,8 +131,7 @@ func (a *admin) deleteMeRequestCtrl(w http.ResponseWriter, r *http.Request) {
135131 }
136132
137133 a .cache .Flush (cache .Flusher (audience ).Scopes (audience , claims .User .ID , lastCommentsScope ))
138- render .Status (r , http .StatusOK )
139- render .JSON (w , r , R.JSON {"user_id" : claims .User .ID , "site_id" : claims .Audience })
134+ R .RenderJSON (w , R.JSON {"user_id" : claims .User .ID , "site_id" : claims .Audience })
140135}
141136
142137// PUT /user/{userid}?site=side-id&block=1&ttl=7d - block or unblock user
@@ -164,7 +159,7 @@ func (a *admin) setBlockCtrl(w http.ResponseWriter, r *http.Request) {
164159 }
165160 }
166161 a .cache .Flush (cache .Flusher (siteID ).Scopes (userID , siteID , lastCommentsScope ))
167- render . JSON ( w , r , R.JSON {"user_id" : userID , "site_id" : siteID , "block" : blockStatus })
162+ R . RenderJSON ( w , R.JSON {"user_id" : userID , "site_id" : siteID , "block" : blockStatus })
168163}
169164
170165// GET /blocked?site=siteID - list blocked users
@@ -175,7 +170,7 @@ func (a *admin) blockedUsersCtrl(w http.ResponseWriter, r *http.Request) {
175170 rest .SendErrorJSON (w , r , http .StatusBadRequest , err , "can't get blocked users" , rest .ErrSiteNotFound )
176171 return
177172 }
178- render . JSON ( w , r , users )
173+ R . RenderJSON ( w , users )
179174}
180175
181176// PUT /readonly?site=siteID&url=post-url&ro=1 - set or reset read-only status for the post
@@ -202,7 +197,7 @@ func (a *admin) setReadOnlyCtrl(w http.ResponseWriter, r *http.Request) {
202197 return
203198 }
204199 a .cache .Flush (cache .Flusher (locator .SiteID ).Scopes (locator .URL , locator .SiteID ))
205- render . JSON ( w , r , R.JSON {"locator" : locator , "read-only" : roStatus })
200+ R . RenderJSON ( w , R.JSON {"locator" : locator , "read-only" : roStatus })
206201}
207202
208203// PUT /title/{id}?site=siteID&url=post-url - set comment PostTitle to page's title
@@ -218,8 +213,7 @@ func (a *admin) setTitleCtrl(w http.ResponseWriter, r *http.Request) {
218213 log .Printf ("[INFO] set comment's title %s to %q" , id , c .PostTitle )
219214
220215 a .cache .Flush (cache .Flusher (locator .SiteID ).Scopes (locator .URL , lastCommentsScope ))
221- render .Status (r , http .StatusOK )
222- render .JSON (w , r , R.JSON {"id" : id , "locator" : locator })
216+ R .RenderJSON (w , R.JSON {"id" : id , "locator" : locator })
223217}
224218
225219// PUT /verify?site=siteID&url=post-url&ro=1 - set or reset read-only status for the post
@@ -233,7 +227,7 @@ func (a *admin) setVerifyCtrl(w http.ResponseWriter, r *http.Request) {
233227 return
234228 }
235229 a .cache .Flush (cache .Flusher (siteID ).Scopes (siteID , userID ))
236- render . JSON ( w , r , R.JSON {"user" : userID , "verified" : verifyStatus })
230+ R . RenderJSON ( w , R.JSON {"user" : userID , "verified" : verifyStatus })
237231}
238232
239233// PUT /pin/{id}?site=siteID&url=post-url&pin=1
@@ -248,5 +242,5 @@ func (a *admin) setPinCtrl(w http.ResponseWriter, r *http.Request) {
248242 return
249243 }
250244 a .cache .Flush (cache .Flusher (locator .SiteID ).Scopes (locator .URL ))
251- render . JSON ( w , r , R.JSON {"id" : commentID , "locator" : locator , "pin" : pinStatus })
245+ R . RenderJSON ( w , R.JSON {"id" : commentID , "locator" : locator , "pin" : pinStatus })
252246}
0 commit comments