Skip to content

Commit db59966

Browse files
committed
It works fine
1 parent fda8f59 commit db59966

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

backend/main.py

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11

22
from datetime import datetime
3-
43
from bson import ObjectId
5-
from database import schemas_collection
6-
from datamodel import SchemaDefinition, UpdateSchema
74
from fastapi import FastAPI, HTTPException
85
from fastapi.middleware.cors import CORSMiddleware
96

7+
from database import schemas_collection
8+
from datamodel import SchemaDefinition, UpdateSchema
9+
1010
# Initialize FastAPI application
1111
app = FastAPI()
1212

@@ -22,22 +22,23 @@
2222
@app.get("/schemas")
2323
async def get_all_schemas():
2424
"""
25-
Retrieve all schemas from the database.
25+
Retrieve all schema documents from the database.
2626
Converts MongoDB ObjectId to string for JSON serialization.
2727
Returns:
2828
list: A list of schema documents with stringified IDs.
2929
"""
30-
# Fetch all schemas from MongoDB
30+
# Fetch all schema documents from MongoDB
3131
schema_documents = list(schemas_collection.find())
3232

33-
# Verbose loop: explain and transform each schema
34-
for schema_doc in schema_documents:
35-
# Convert ObjectId to string for API response
36-
original_id = schema_doc["_id"]
37-
schema_doc["_id"] = str(original_id)
33+
# Verbose loop: clarify what we're iterating over and why
34+
for schema_document in schema_documents:
35+
# Each schema_document is a MongoDB record representing a schema definition
36+
# Convert its ObjectId to string so it can be returned in JSON
37+
original_id = schema_document["_id"]
38+
schema_document["_id"] = str(original_id)
3839

39-
# Optional: Add extra clarity or logging (could use logging module)
40-
# print(f"Processed schema: original_id={original_id}, converted_id={schema_doc['_id']}")
40+
# Optional: Add logging or debugging info
41+
# print(f"Converted ObjectId {original_id} to string for schema: {schema_document}")
4142

4243
return schema_documents
4344

@@ -73,7 +74,7 @@ async def update_schema(id: str, update: UpdateSchema):
7374
dict: Success message.
7475
"""
7576
# Prepare update fields (ignore None values)
76-
update_fields = {k: v for k, v in update.dict().items() if v is not None}
77+
update_fields = {key: value for key, value in update.dict().items() if value is not None}
7778

7879
result = schemas_collection.update_one(
7980
{"_id": ObjectId(id)},
@@ -102,4 +103,8 @@ async def delete_schema(id: str):
102103
if result.deleted_count == 0:
103104
raise HTTPException(status_code=404, detail="Schema not found")
104105

105-
return {"message": "Schema deleted"}
106+
107+
108+
109+
110+

0 commit comments

Comments
 (0)