diff --git a/backend/router/stories.py b/backend/router/stories.py index 7010fadd..485f6871 100644 --- a/backend/router/stories.py +++ b/backend/router/stories.py @@ -201,8 +201,11 @@ def search_my_story(query: schemas.Search, db: Session = Depends(get_db)): return crud.search_my_story(db, query.text) -@router.get("/explore", response_model=List[schemas.MyStoryWithStory]) +@router.get( + "/explore/{page_num}", response_model=List[schemas.MyStoryWithStory] +) def explore( + page_num: int, current_story: schemas.Story = Depends(main.get_current_story), db: Session = Depends(get_db), ): @@ -213,6 +216,11 @@ def explore( detail=msg, headers={"WWW-Authenticate": "Bearer"}, ) + return crud.get_story_feed( - db, current_story.id, current_story.latitude, current_story.longitude + db, + current_story.id, + current_story.latitude, + current_story.longitude, + page_num, ) diff --git a/backend/stories/crud.py b/backend/stories/crud.py index 78727cb4..19d53ff8 100644 --- a/backend/stories/crud.py +++ b/backend/stories/crud.py @@ -167,7 +167,7 @@ def search_my_story(db: Session, query: str): ) -def get_story_feed(db: Session, cur_id, lat, lng): +def get_story_feed(db: Session, cur_id, lat, lng, page_num): dist = func.sqrt( func.pow(models.Story.latitude - lat, 2) + func.pow(models.Story.longitude - lng, 2) @@ -179,10 +179,12 @@ def get_story_feed(db: Session, cur_id, lat, lng): .filter(models.Story.id != cur_id) .order_by(dist) .order_by(models.MyStory.updated_at.desc()) + .limit(10) + .offset(10 * page_num) .all() ) - return rand_per_story(db_my_stories) + return db_my_stories def rand_per_story(arr: [models.MyStory]):