|
| 1 | +from typing import Union |
| 2 | + |
1 | 3 | from auth_lib.fastapi import UnionAuth |
2 | 4 | from fastapi import APIRouter, Depends, Query |
3 | 5 | from fastapi_sqlalchemy import db |
|
30 | 32 | async def get_notes(type_id: int = Query(None), user=Depends(UnionAuth())) -> list[NoteGet]: |
31 | 33 | """ |
32 | 34 | Получить список модалок по type_id. |
| 35 | +
|
33 | 36 | В случае несуществующего type_id ошибка ObjectNotFound |
34 | 37 | """ |
35 | 38 | notes = await NoteService.get_note_by_type_id(db, type_id) |
36 | 39 | return [NoteGet.model_validate(note) for note in notes] |
37 | 40 |
|
38 | 41 |
|
| 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 | + |
39 | 63 | @note.post("/info", response_model=NoteInfoGet) |
40 | 64 | async def create_note_info( |
41 | 65 | note: NoteInfoPost, user=Depends(UnionAuth(scopes=["modal.note.create"])) |
|
0 commit comments