mirror of
https://github.com/notherealmarco/WASAPhoto.git
synced 2025-05-06 04:42:36 +02:00
Add GET bans
This commit is contained in:
parent
77e9f405c6
commit
4f391f0b65
7 changed files with 117 additions and 10 deletions
|
@ -44,3 +44,40 @@ func (rt *_router) GetUserProfile(w http.ResponseWriter, r *http.Request, ps htt
|
|||
return
|
||||
}
|
||||
}
|
||||
|
||||
func (rt *_router) GetUserPhotos(w http.ResponseWriter, r *http.Request, ps httprouter.Params, ctx reqcontext.RequestContext) {
|
||||
|
||||
// Get user id
|
||||
uid := ps.ByName("user_id")
|
||||
|
||||
if !authorization.SendErrorIfNotLoggedIn(ctx.Auth.Authorized, rt.db, w, rt.baseLogger) ||
|
||||
!helpers.SendNotFoundIfBanned(rt.db, ctx.Auth.GetUserID(), uid, w, rt.baseLogger) {
|
||||
return
|
||||
}
|
||||
|
||||
// Get limits, or use default values
|
||||
start_index, limit, err := helpers.GetLimits(r.URL.Query())
|
||||
|
||||
if err != nil {
|
||||
helpers.SendBadRequest(w, "Invalid start_index or limit value", rt.baseLogger)
|
||||
return
|
||||
}
|
||||
|
||||
// Get user photos
|
||||
photos, err := rt.db.GetUserPhotos(uid, start_index, limit)
|
||||
|
||||
if err != nil {
|
||||
helpers.SendInternalError(err, "Database error: GetUserPhotos", w, rt.baseLogger)
|
||||
return
|
||||
}
|
||||
|
||||
// Return user photos
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
err = json.NewEncoder(w).Encode(photos)
|
||||
|
||||
if err != nil {
|
||||
helpers.SendInternalError(err, "Error encoding json", w, rt.baseLogger)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue