|
2 | 2 | from sqlalchemy.ext.asyncio import AsyncSession |
3 | 3 | from app.schemas.note import NoteCreate, NoteUpdate, NoteFind |
4 | 4 | from app.utils.get_db import get_db |
5 | | -from app.curd.note import create_note_in_db, delete_note_in_db, update_note_in_db, find_notes_in_db, find_notes_title_in_db |
| 5 | +from app.curd.note import create_note_in_db, delete_note_in_db, update_note_in_db, find_notes_in_db, find_notes_title_in_db, find_self_notes_count_in_db, find_self_recent_notes_in_db |
6 | 6 | from typing import Optional |
7 | | - |
| 7 | +from app.utils.auth import get_current_user |
8 | 8 | router = APIRouter() |
9 | 9 |
|
10 | 10 | @router.post("/create", response_model=dict) |
11 | | -async def create_note(note: NoteCreate, db: AsyncSession = Depends(get_db)): |
12 | | - new_note = await create_note_in_db(note, db) |
| 11 | +async def create_note(note: NoteCreate, db: AsyncSession = Depends(get_db), current_user: dict = Depends(get_current_user)): |
| 12 | + user_id = current_user["id"] |
| 13 | + new_note = await create_note_in_db(note, db, user_id) |
13 | 14 | return {"msg": "Note created successfully", "note_id": new_note.id} |
14 | 15 |
|
15 | 16 | @router.delete("/{note_id}", response_model=dict) |
@@ -52,3 +53,19 @@ async def get_notes_title(note_find: NoteFind = Depends(), db: AsyncSession = De |
52 | 53 | }, |
53 | 54 | "notes": notes |
54 | 55 | } |
| 56 | + |
| 57 | +@router.get("/count", response_model=dict) |
| 58 | +async def get_notes_count(db: AsyncSession = Depends(get_db), current_user: dict = Depends(get_current_user)): |
| 59 | + user_id = current_user["id"] |
| 60 | + count = await find_self_notes_count_in_db(db, user_id) |
| 61 | + return { |
| 62 | + "count": count |
| 63 | + } |
| 64 | + |
| 65 | +@router.get("/count/recent", response_model=dict) |
| 66 | +async def get_recent_notes_count(db: AsyncSession = Depends(get_db), current_user: dict = Depends(get_current_user)): |
| 67 | + user_id = current_user["id"] |
| 68 | + notes = await find_self_recent_notes_in_db(db, user_id) |
| 69 | + return { |
| 70 | + "notes": notes |
| 71 | + } |
0 commit comments