-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpython.json
99 lines (97 loc) · 3.31 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
98
99
{
"api": {
"prefix": "freenitapi",
"body": [
"import ormar.exceptions",
"from fastapi import Header, HTTPException",
"from freenit.api.router import route",
"from freenit.models.pagination import Page, paginate",
"",
"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(",
" page: int = Header(default=1),",
" perpage: int = Header(default=10),",
" ) -> Page[${1/(.*)/${1:/capitalize}/}]:",
" return await paginate(${1/(.*)/${1:/capitalize}/}.objects, page, perpage)",
"",
" @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": "freenitsql",
"body": [
"import ormar",
"from freenit.models.sql.base import OrmarBaseModel, make_optional, ormar_config",
"",
"",
"class ${1}(OrmarBaseModel):",
" ormar_config = ormar_config.copy()",
"",
" id = ormar.Integer(primary_key=True)",
" ${0}",
"",
"",
"class ${1}Optional(${1}):",
" pass",
"",
"",
"make_optional(${1}Optional)"
],
"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"
}
}