Fix inconsistency of the latest commit

This commit is contained in:
Marco Realacci 2022-11-22 15:21:33 +01:00
parent 963e392cea
commit c134becb61
3 changed files with 20 additions and 4 deletions

View file

@ -33,8 +33,16 @@ func (rt *_router) GetComments(w http.ResponseWriter, r *http.Request, ps httpro
return return
} }
// get limits, or use defaults
start_index, limit, err := helpers.GetLimits(r.URL.Query())
if err != nil {
helpers.SendBadRequest(w, "Invalid start_index or limit", rt.baseLogger)
return
}
// get the user's comments // get the user's comments
success, comments, err := rt.db.GetComments(uid, photo_id, ctx.Auth.GetUserID()) success, comments, err := rt.db.GetComments(uid, photo_id, ctx.Auth.GetUserID(), start_index, limit)
if err != nil { if err != nil {
helpers.SendInternalError(err, "Database error: GetComments", w, rt.baseLogger) helpers.SendInternalError(err, "Database error: GetComments", w, rt.baseLogger)

View file

@ -23,13 +23,21 @@ func (rt *_router) GetLikes(w http.ResponseWriter, r *http.Request, ps httproute
return return
} }
// get limits, or use defaults
start_index, limit, err := helpers.GetLimits(r.URL.Query())
if err != nil {
helpers.SendBadRequest(w, "Invalid start_index or limit", rt.baseLogger)
return
}
// send 404 if the user does not exist // send 404 if the user does not exist
if !helpers.VerifyUserOrNotFound(rt.db, uid, w, rt.baseLogger) { if !helpers.VerifyUserOrNotFound(rt.db, uid, w, rt.baseLogger) {
return return
} }
// get the user's likes // get the user's likes
success, likes, err := rt.db.GetPhotoLikes(uid, photo_id, ctx.Auth.GetUserID()) success, likes, err := rt.db.GetPhotoLikes(uid, photo_id, ctx.Auth.GetUserID(), start_index, limit)
if err != nil { if err != nil {
helpers.SendInternalError(err, "Database error: GetLikes", w, rt.baseLogger) helpers.SendInternalError(err, "Database error: GetLikes", w, rt.baseLogger)

View file

@ -60,14 +60,14 @@ type AppDatabase interface {
PostPhoto(uid string) (DBTransaction, int64, error) PostPhoto(uid string) (DBTransaction, int64, error)
DeletePhoto(uid string, photo int64) (bool, error) DeletePhoto(uid string, photo int64) (bool, error)
GetPhotoLikes(uid string, photo int64, requesting_uid string) (QueryResult, *[]structures.UIDName, error) GetPhotoLikes(uid string, photo int64, requesting_uid string, start_index int, offset int) (QueryResult, *[]structures.UIDName, error)
LikePhoto(uid string, photo int64, liker_uid string) (QueryResult, error) LikePhoto(uid string, photo int64, liker_uid string) (QueryResult, error)
UnlikePhoto(uid string, photo int64, liker_uid string) (QueryResult, error) UnlikePhoto(uid string, photo int64, liker_uid string) (QueryResult, error)
GetUserProfile(uid string) (QueryResult, *structures.UserProfile, error) GetUserProfile(uid string) (QueryResult, *structures.UserProfile, error)
GetUserStream(uid string, start_index int, limit int) (*[]structures.Photo, error) GetUserStream(uid string, start_index int, limit int) (*[]structures.Photo, error)
GetComments(uid string, photo_id int64, requesting_uid string) (QueryResult, *[]structures.Comment, error) GetComments(uid string, photo_id int64, requesting_uid string, start_index int, offset int) (QueryResult, *[]structures.Comment, error)
PostComment(uid string, photo_id int64, comment_user string, comment string) (QueryResult, error) PostComment(uid string, photo_id int64, comment_user string, comment string) (QueryResult, error)
DeleteComment(uid string, photo_id int64, comment_id int64) (QueryResult, error) DeleteComment(uid string, photo_id int64, comment_id int64) (QueryResult, error)
GetCommentOwner(uid string, photo_id int64, comment_id int64) (QueryResult, string, error) GetCommentOwner(uid string, photo_id int64, comment_id int64) (QueryResult, string, error)