Skip to content

Commit 2a4b4b2

Browse files
authored
Merge pull request #56 from sustech-cs304/backend
fix note query bug
2 parents 8e41d44 + 11a0339 commit 2a4b4b2

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

backend/app/slides/note.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,16 @@
1313
async def get_note(
1414
material_id: str,
1515
db: Session = Depends(get_db),
16-
current_user: User = Depends(get_current_user)
16+
current_user: User = Depends(get_current_user),
1717
):
18-
note = db.query(Note).filter(Note.material_id == material_id).first()
18+
note = (
19+
db.query(Note)
20+
.filter(
21+
Note.material_id == material_id,
22+
Note.user_id == current_user.user_id,
23+
)
24+
.first()
25+
)
1926
return {
2027
"note_id": note.note_id if note else None,
2128
"user_id": note.user_id if note else None,
@@ -32,7 +39,14 @@ async def create_note(
3239
content: str = Form(None),
3340
db: Session = Depends(get_db),
3441
):
35-
note = db.query(Note).filter(Note.note_id == note_id).first()
42+
note = (
43+
db.query(Note)
44+
.filter(
45+
Note.note_id == note_id,
46+
Note.user_id == current_user.user_id,
47+
)
48+
.first()
49+
)
3650
if note is None:
3751
note = Note(
3852
note_id=note_id,
@@ -74,9 +88,13 @@ async def create_note(
7488
async def delete_note(
7589
note_id: str,
7690
db: Session = Depends(get_db),
77-
current_user: User = Depends(get_current_user)
91+
current_user: User = Depends(get_current_user),
7892
):
79-
note = db.query(Note).filter(Note.note_id == note_id).first()
93+
note = (
94+
db.query(Note)
95+
.filter(Note.note_id == note_id, Note.user_id == current_user.user_id)
96+
.first()
97+
)
8098
if note is None:
8199
return {"message": "Note not found"}
82100
else:

0 commit comments

Comments
 (0)