Skip to content

Commit 7169a0a

Browse files
committed
added get note id
1 parent 5f91518 commit 7169a0a

2 files changed

Lines changed: 25 additions & 2 deletions

File tree

modal_backend/routes/notes.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import Union
2+
13
from auth_lib.fastapi import UnionAuth
24
from fastapi import APIRouter, Depends, Query
35
from fastapi_sqlalchemy import db
@@ -30,12 +32,34 @@
3032
async def get_notes(type_id: int = Query(None), user=Depends(UnionAuth())) -> list[NoteGet]:
3133
"""
3234
Получить список модалок по type_id.
35+
3336
В случае несуществующего type_id ошибка ObjectNotFound
3437
"""
3538
notes = await NoteService.get_note_by_type_id(db, type_id)
3639
return [NoteGet.model_validate(note) for note in notes]
3740

3841

42+
@note.get("/{id}", response_model=Union[NoteInfoGet, NoteRatingGet, NoteTextGet, NoteChoiceGet, NoteImageGet])
43+
async def get_note(
44+
id: int, user=Depends(UnionAuth())
45+
) -> Union[NoteInfoGet, NoteRatingGet, NoteTextGet, NoteChoiceGet, NoteImageGet]:
46+
"""
47+
Получить полную информацию о модалке по id.
48+
49+
В случае несуществующего id ошибка ObjectNotFound
50+
"""
51+
note = Note.get(session=db.session, id=id)
52+
schema_type = {
53+
1: NoteInfoGet,
54+
2: NoteRatingGet,
55+
3: NoteTextGet,
56+
4: NoteChoiceGet,
57+
5: NoteImageGet,
58+
}
59+
schema_class = schema_type.get(note.type_id)
60+
return schema_class.model_validate(note)
61+
62+
3963
@note.post("/info", response_model=NoteInfoGet)
4064
async def create_note_info(
4165
note: NoteInfoPost, user=Depends(UnionAuth(scopes=["modal.note.create"]))

modal_backend/routes/services.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ async def get_services(
1616
user=Depends(UnionAuth()),
1717
) -> list[ServiceGet]:
1818
"""
19-
Получить все сервисы.
20-
В случае несуществующего id ошибка ObjectNotFound
19+
Получить список всех сервисов.
2120
"""
2221
services = await ServiceManager.get_services(db)
2322
return [ServiceGet.model_validate(service) for service in services]

0 commit comments

Comments
 (0)