Skip to content

Commit

Permalink
fix: backend cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
samderanova committed Dec 12, 2023
1 parent b31f583 commit 0462e5a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
12 changes: 7 additions & 5 deletions apps/api/src/routers/demo.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Annotated, Union, Optional, Any
from typing import Annotated, Union, Any

from fastapi import APIRouter, Cookie, Form

Expand All @@ -20,10 +20,12 @@ async def square(value: Annotated[int, Form()]) -> int:


@router.post("/user")
async def get_user(name: Annotated[str, Form()]) -> list[dict[str, Any]]:
results = await retrieve(Collection.USERS, {"name": name}, ["name", "ucinetid"])
for i in range(len(results)):
results[i]["_id"] = str(results[i]["_id"])
async def get_user(search_name: Annotated[str, Form()]) -> list[dict[str, object]]:
results = await retrieve(
Collection.USERS, {"name": search_name}, ["name", "ucinetid"]
)
for result in results:
result["_id"] = str(result["_id"])
return results


Expand Down
5 changes: 0 additions & 5 deletions apps/api/src/services/mongodb_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import os
from enum import Enum
from logging import getLogger

from typing import Any, Mapping, Optional, Union

from bson import CodecOptions
Expand Down Expand Up @@ -40,7 +39,6 @@ class Config:
class Collection(str, Enum):
USERS = "users"
TESTING = "testing"

SETTINGS = "settings"


Expand Down Expand Up @@ -73,12 +71,10 @@ async def retrieve(
) -> list[dict[str, object]]:
"""Search for and retrieve the specified fields of a document (if any exist)
that satisfy the provided query."""

COLLECTION = DB[collection.value]

result = COLLECTION.find(query, fields)
output: list[dict[str, object]] = await result.to_list(length=None)

return output


Expand All @@ -105,7 +101,6 @@ async def raw_update_one(
result: UpdateResult = await COLLECTION.update_one(query, update, upsert=upsert)
if not result.acknowledged:
log.error("MongoDB document update was not acknowledged")

raise RuntimeError("Could not update documents in MongoDB collection")

return result.modified_count > 0
Expand Down

0 comments on commit 0462e5a

Please sign in to comment.