Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lost and found refactor #13

Closed
wants to merge 1 commit into from
Closed
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
16 changes: 8 additions & 8 deletions backend/backend/Routes/Lost_and_Found/found.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from typing import Dict, Any, List, Tuple
from Routes.Auth.cookie import get_user_id
from utils import *
from queries.lost_and_found import *
from models import LfItem, LfResponse
from queries.found import *
from utils import S3Client
from .funcs import get_image_dict, authorize_edit_delete

Expand All @@ -24,7 +24,7 @@ async def add_item( request: Request,
form_data_dict = json.loads(form_data)
user_id = get_user_id(request)
with conn.cursor() as cur:
cur.execute( insert_in_found_table( form_data_dict, user_id ) )
cur.execute( insert_in_table(1, form_data_dict, user_id ) )
item = LfItem.from_row(cur.fetchone())

# update in elasticsearch
Expand All @@ -33,7 +33,7 @@ async def add_item( request: Request,
image_paths = S3Client.uploadToCloud(images, item.id, "found")

with conn.cursor() as cur:
cur.execute(insert_found_images(image_paths, item.id))
cur.execute(insert_images(1, image_paths, item.id))
conn.commit()

return {"message": "Data inserted successfully"}
Expand Down Expand Up @@ -71,13 +71,13 @@ def show_found_items(id: int) -> LfResponse:
try:
with conn.cursor() as cur:
print('hello')
cur.execute(get_particular_found_item(id))
cur.execute(get_particular_item(1, id))
found_item = cur.fetchall()

if found_item == []:
raise HTTPException(status_code=404, detail="Item not found")
found_item = found_item[0]
cur.execute(get_all_image_uris(id))
cur.execute(get_all_image_uris(1, id))
found_images = cur.fetchall()
image_urls = list(map(lambda x: x[0], found_images))
res = LfResponse.from_row(found_item, image_urls)
Expand Down Expand Up @@ -125,7 +125,7 @@ def edit_selected_item( request: Request, item_id: int = Form(...), form_data:s
form_data_dict = json.loads(form_data)

with conn.cursor() as cur:
cur.execute( update_in_found_table( item_id, form_data_dict ) )
cur.execute( update_in_table(1, item_id, form_data_dict ) )
row = cur.fetchone()
item = LfItem.from_row(row)
conn.commit()
Expand All @@ -139,11 +139,11 @@ def edit_selected_item( request: Request, item_id: int = Form(...), form_data:s
def search(query : str, max_results: int = 100) -> List[Dict[str, Any]]:
try:
with conn.cursor() as cur:
cur.execute( search_found_items( query, max_results ) )
cur.execute( search_items(1, query, max_results ) )
res = cur.fetchall()
if len(res) == 0:
return []
cur.execute(get_some_image_uris([x[0] for x in res]))
cur.execute(get_some_image_uris(1, [x[0] for x in res]))
images = cur.fetchall()

image_dict = get_image_dict(images)
Expand Down
16 changes: 8 additions & 8 deletions backend/backend/Routes/Lost_and_Found/lost.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from typing import Dict, Any, List
from Routes.Auth.cookie import get_user_id
from utils import *
from queries.lost import *
from queries.lost_and_found import *
from models import LfItem, LfResponse
from utils import S3Client
from .funcs import *
Expand All @@ -22,7 +22,7 @@ async def add_item( request: Request,
form_data_dict = json.loads(form_data)
user_id = get_user_id(request)
with conn.cursor() as cur:
cur.execute( insert_in_lost_table( form_data_dict, user_id ) )
cur.execute( insert_in_table(0, form_data_dict, user_id ) )
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You were supposed to pass a TableType.LOST or TableType.FOUND, but you have passed integers, and it gives errors. Fix this error in all the files.

item = LfItem.from_row(cur.fetchone())

# update in elasticsearch
Expand All @@ -31,7 +31,7 @@ async def add_item( request: Request,
image_paths = S3Client.uploadToCloud(images, item.id, "lost")

with conn.cursor() as cur:
cur.execute(insert_lost_images(image_paths, item.id))
cur.execute(insert_images(0, image_paths, item.id))
conn.commit()
return {"message": "Data inserted successfully"}

Expand Down Expand Up @@ -67,13 +67,13 @@ async def get_all_lost_item_names() -> List[Dict[str, Any]]:
def show_lost_items(id: int) -> LfResponse:
try:
with conn.cursor() as cur:
cur.execute(get_particular_lost_item(id))
cur.execute(get_particular_item(0, id))

lost_item = cur.fetchall()
if lost_item == []:
raise HTTPException(status_code=404, detail="Item not found")
lost_item = lost_item[0]
cur.execute(get_all_image_uris(id))
cur.execute(get_all_image_uris(0, id))
lost_images = cur.fetchall()
image_urls = list(map(lambda x: x[0], lost_images))
res = LfResponse.from_row(lost_item, image_urls)
Expand Down Expand Up @@ -126,7 +126,7 @@ def edit_selected_item(request: Request, item_id: int = Form(...), form_data:st
form_data_dict = json.loads(form_data)

with conn.cursor() as cur:
cur.execute( update_in_lost_table( item_id, form_data_dict ) )
cur.execute( update_in_table(0, item_id, form_data_dict ) )
row = cur.fetchone()
item = LfItem.from_row(row)

Expand All @@ -144,12 +144,12 @@ def edit_selected_item(request: Request, item_id: int = Form(...), form_data:st
def search(query : str, max_results: int = 100) -> List[Dict[str, Any]] :
try:
with conn.cursor() as cur:
cur.execute( search_lost_items( query, max_results ) )
cur.execute( search_items(0, query, max_results ) )
res = cur.fetchall()

if len(res) == 0:
return []
cur.execute(get_some_image_uris([x[0] for x in res]))
cur.execute(get_some_image_uris(0, [x[0] for x in res]))
images = cur.fetchall()

image_dict = get_image_dict(images)
Expand Down
89 changes: 0 additions & 89 deletions backend/backend/queries/found.py

This file was deleted.

87 changes: 0 additions & 87 deletions backend/backend/queries/lost.py

This file was deleted.

Loading