Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions backend/router/stories.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
):
Expand All @@ -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,
)
6 changes: 4 additions & 2 deletions backend/stories/crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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]):
Expand Down