lavkach3

Форк
0
53 строки · 1.9 Кб
1
import typing
2
import uuid
3

4
from fastapi import APIRouter, Query, Request, Depends
5
from fastapi_filter import FilterDepends
6

7
from app.inventory.order.schemas.suggest_schemas import (
8
    SuggestScheme,
9
    SuggestCreateScheme,
10
    SuggestUpdateScheme,
11
    SuggestListSchema,
12
    SuggestFilter,
13
    SuggestConfirmScheme
14
)
15
from app.inventory.order.services.suggest_service import SuggestService
16

17
suggest_router = APIRouter(
18
)
19

20

21
@suggest_router.get("", response_model=SuggestListSchema)
22
async def suggest_list(
23
        model_filter: SuggestFilter = FilterDepends(SuggestFilter),
24
        size: int = Query(ge=1, le=100, default=20),
25
        service: SuggestService = Depends()
26
):
27
    data = await service.list(model_filter, size)
28
    cursor = model_filter.lsn__gt
29
    return {'size': len(data), 'cursor': cursor, 'data': data}
30

31

32
@suggest_router.post("", response_model=SuggestScheme)
33
async def suggest_create(schema: SuggestCreateScheme, service: SuggestService = Depends()):
34
    return await service.create(obj=schema)
35

36

37
@suggest_router.get("/{suggest_id}", response_model=SuggestScheme)
38
async def suggest_get(suggest_id: uuid.UUID, service: SuggestService = Depends()) -> typing.Union[None, SuggestScheme]:
39
    return await service.get(id=suggest_id)
40

41

42
@suggest_router.put("/{suggest_id}", response_model=SuggestScheme)
43
async def suggest_update(suggest_id: uuid.UUID, schema: SuggestUpdateScheme, service: SuggestService = Depends()):
44
    return await service.update(id=suggest_id, obj=schema)
45

46

47
@suggest_router.delete("/{suggest_id}")
48
async def suggest_delete(suggest_id: uuid.UUID, service: SuggestService = Depends()):
49
    await service.delete(id=suggest_id)
50

51
@suggest_router.post("/confirm", responses={200: {'model': list[SuggestScheme]}})
52
async def action_suggest_confirm(schema: SuggestConfirmScheme, service: SuggestService = Depends()):
53
    return await service.suggest_confirm(suggest_ids=schema.ids, value=schema.value)
54

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.