lavkach3

Форк
0
98 строк · 3.3 Кб
1
import uuid
2

3
from fastapi import APIRouter, Query, Depends
4
from fastapi_filter import FilterDepends
5
from starlette.requests import Request
6

7
from app.basic.uom.schemas import (
8
    UomCategoryScheme,
9
    UomCategoryCreateScheme,
10
    UomCategoryUpdateScheme,
11
    UomCategoryListSchema,
12
    UomCategoryFilter, ConvertSchema
13
)
14
from app.basic.uom.schemas import (
15
    UomScheme,
16
    UomCreateScheme,
17
    UomUpdateScheme,
18
    ExceptionResponseSchema,
19
    UomListSchema,
20
    UomFilter
21
)
22
from app.basic.uom.services.uom_category_service import UomCategoryService
23
from app.basic.uom.services.uom_service import UomService
24

25
uom_category_router = APIRouter(
26
    responses={"400": {"model": ExceptionResponseSchema}},
27
)
28
uom_router = APIRouter(
29
    responses={"400": {"model": ExceptionResponseSchema}},
30
)
31

32

33
@uom_category_router.get("", response_model=UomCategoryListSchema)
34
async def uom_category_list(
35
        model_filter: UomCategoryFilter = FilterDepends(UomCategoryFilter),
36
        size: int = Query(ge=1, le=100, default=100),
37
        service: UomCategoryService = Depends()
38
):
39
    data = await service.list(model_filter, size)
40
    cursor = model_filter.lsn__gt
41
    return {'size': len(data), 'cursor': cursor, 'data': data}
42

43

44
@uom_category_router.post("", response_model=UomCategoryScheme)
45
async def uom_category_create(schema: UomCategoryCreateScheme, service: UomCategoryService = Depends()):
46
    return await service.create(obj=schema)
47

48

49
@uom_category_router.get("/{category_id}")
50
async def uom_category_get(category_id: uuid.UUID, service: UomCategoryService = Depends()):
51
    return await service.get(id=category_id)
52

53

54
@uom_category_router.put("/{category_id}", response_model=UomCategoryScheme)
55
async def uom_category_update(category_id: uuid.UUID, schema: UomCategoryUpdateScheme, service: UomCategoryService = Depends()):
56
    return await service.update(id=category_id, obj=schema)
57

58

59
@uom_category_router.delete("/{category_id}")
60
async def uom_category_delete(category_id: uuid.UUID, service: UomCategoryService = Depends()):
61
    await service.delete(id=category_id)
62

63

64
#####################################UOM########################################
65
@uom_router.get("", response_model=UomListSchema)
66
async def uom_list(
67
        model_filter: UomFilter = FilterDepends(UomFilter),
68
        size: int = Query(ge=1, le=100, default=100),
69
        service: UomService = Depends()
70
):
71
    data = await service.list(model_filter, size)
72
    cursor = model_filter.lsn__gt
73
    return {'size': len(data), 'cursor': cursor, 'data': data}
74

75

76
@uom_router.post("", response_model=UomScheme)
77
async def uom_create(schema: UomCreateScheme, service: UomService = Depends()):
78
    return await service.create(obj=schema)
79

80

81
@uom_router.get("/{uom_id}")
82
async def uom_get(uom_id: uuid.UUID, service: UomService = Depends()):
83
    return await service.get(id=uom_id)
84

85

86
@uom_router.put("/{uom_id}", response_model=UomScheme)
87
async def uom_update(uom_id: uuid.UUID, schema: UomUpdateScheme, service: UomService = Depends()):
88
    return await service.update(id=uom_id, obj=schema)
89

90

91
@uom_router.delete("/{uom_id}")
92
async def uom_delete(uom_id: uuid.UUID, service: UomService = Depends()):
93
    await service.delete(id=uom_id)
94

95

96
@uom_router.post("/convert", response_model=list[ConvertSchema])
97
async def uom_convert(schema: list[ConvertSchema], service: UomService = Depends()):
98
    await service.convert(schema)
99

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

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

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

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