diff --git a/service/api/comments.go b/service/api/comments.go index 0a1aa00..9db468b 100644 --- a/service/api/comments.go +++ b/service/api/comments.go @@ -33,8 +33,16 @@ func (rt *_router) GetComments(w http.ResponseWriter, r *http.Request, ps httpro 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 - 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 { helpers.SendInternalError(err, "Database error: GetComments", w, rt.baseLogger) diff --git a/service/api/likes.go b/service/api/likes.go index 38bed29..f107dad 100644 --- a/service/api/likes.go +++ b/service/api/likes.go @@ -23,13 +23,21 @@ func (rt *_router) GetLikes(w http.ResponseWriter, r *http.Request, ps httproute 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 if !helpers.VerifyUserOrNotFound(rt.db, uid, w, rt.baseLogger) { return } // 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 { helpers.SendInternalError(err, "Database error: GetLikes", w, rt.baseLogger) diff --git a/service/database/database.go b/service/database/database.go index c9f1607..e2e07b3 100644 --- a/service/database/database.go +++ b/service/database/database.go @@ -60,14 +60,14 @@ type AppDatabase interface { PostPhoto(uid string) (DBTransaction, int64, 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) UnlikePhoto(uid string, photo int64, liker_uid string) (QueryResult, error) GetUserProfile(uid string) (QueryResult, *structures.UserProfile, 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) DeleteComment(uid string, photo_id int64, comment_id int64) (QueryResult, error) GetCommentOwner(uid string, photo_id int64, comment_id int64) (QueryResult, string, error)