-
Notifications
You must be signed in to change notification settings - Fork 0
/
python.json
97 lines (95 loc) · 3.16 KB
/
python.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
{
"api": {
"prefix": "freenitapi",
"body": [
"from typing import List",
"",
"import ormar",
"import ormar.exceptions",
"from fastapi import HTTPException",
"from freenit.api.router import route",
"",
"from ..models.${1} import ${1/(.*)/${1:/capitalize}/}, ${1/(.*)/${1:/capitalize}/}Optional",
"",
"tags=['${1}']",
"",
"",
"@route('/${1}s', tags=tags)",
"class ${1/(.*)/${1:/capitalize}/}ListAPI():",
" @staticmethod",
" async def get() -> List[${1/(.*)/${1:/capitalize}/}]:",
" return await ${1/(.*)/${1:/capitalize}/}.objects.all()",
"",
" @staticmethod",
" async def post(${1}: ${1/(.*)/${1:/capitalize}/}) -> ${1/(.*)/${1:/capitalize}/}:",
" await ${1}.save()",
" return ${1}",
"",
"",
"@route('/${1}s/{id}', tags=tags)",
"class ${1/(.*)/${1:/capitalize}/}DetailAPI():",
" @staticmethod",
" async def get(id: int) -> ${1/(.*)/${1:/capitalize}/}:",
" try:",
" ${1} = await ${1/(.*)/${1:/capitalize}/}.objects.get(pk=id)",
" except ormar.exceptions.NoMatch:",
" raise HTTPException(status_code=404, detail=\"No such ${1}\")",
" return ${1}",
"",
" @staticmethod",
" async def patch(id: int, ${1}_data: ${1/(.*)/${1:/capitalize}/}Optional) -> ${1/(.*)/${1:/capitalize}/}:",
" try:",
" ${1} = await ${1/(.*)/${1:/capitalize}/}.objects.get(pk=id)",
" await ${1}.patch(${1}_data)",
" except ormar.exceptions.NoMatch:",
" raise HTTPException(status_code=404, detail=\"No such ${1}\")",
" return ${1}",
"",
" @staticmethod",
" async def delete(id: int) -> ${1/(.*)/${1:/capitalize}/}:",
" try:",
" ${1} = await ${1/(.*)/${1:/capitalize}/}.objects.get(pk=id)",
" except ormar.exceptions.NoMatch:",
" raise HTTPException(status_code=404, detail=\"No such ${1}\")",
" await ${1}.delete()",
" return ${1}"
],
"description": "Freenit API"
},
"ormar": {
"prefix": "freenitormar",
"body": [
"import ormar",
"from freenit.models.ormar.base import (",
" OrmarBaseModel,",
" generate_optional,",
" ormar_config,",
")",
"",
"",
"class ${1}(OrmarBaseModel):",
" ormar_config = ormar_config.copy()",
"",
" id: int = ormar.Integer(primary_key=True)",
" ${0}",
"",
"${1}Optional = generate_optional(${1})"
],
"description": "Freenit model using Ormar"
},
"pydantic": {
"prefix": "freenitpydantic",
"body": [
"from pydantic import BaseModel, Field",
"from freenit.models.ormar.base import generate_optional",
"",
"",
"class ${1}(BaseModel):",
" ${2:field_name}: str = Field(\"\", description=(\"${3:Field description}\"))",
"",
"",
"${1}Optional = generate_optional(${1})"
],
"description": "Freenit model using Pydantic"
}
}