Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
F
fast-food
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Мырзабеков Бекайдар
fast-food
Commits
0fe70edd
Commit
0fe70edd
authored
Nov 28, 2023
by
Мырзабеков Бекайдар
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added get orders
parent
22ac274b
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
52 additions
and
6 deletions
+52
-6
ctrl.py
src/app/api/order/ctrl.py
+3
-0
routes.py
src/app/api/order/routes.py
+6
-1
schemas.py
src/app/api/order/schemas.py
+8
-4
services.py
src/app/api/order/services.py
+18
-1
order.py
src/app/db/repositories/order.py
+17
-0
No files found.
src/app/api/order/ctrl.py
View file @
0fe70edd
...
...
@@ -33,3 +33,6 @@ class OrderController(BaseController):
except
common_exc
.
NotFoundException
as
e
:
raise
http_exc
.
HTTPNotFoundException
(
detail
=
str
(
e
))
async
def
get_list
(
self
,
**
kwargs
):
return
await
self
.
order_service
.
get_order_list
(
**
kwargs
)
src/app/api/order/routes.py
View file @
0fe70edd
...
...
@@ -3,7 +3,7 @@ from uuid import UUID
import
fastapi
as
fa
from
.ctrl
import
OrderController
from
.schemas
import
OrderPostSchema
,
OrderIdSchema
,
OrderStatusSchema
from
.schemas
import
OrderPostSchema
,
OrderIdSchema
,
OrderStatusSchema
,
OrderListSchema
router
=
fa
.
APIRouter
(
prefix
=
'/orders'
,
tags
=
[
'Order'
])
...
...
@@ -25,3 +25,8 @@ async def accepted_order(body: OrderIdSchema):
async
def
get_order_status
(
id
:
UUID
):
order
=
await
ctrl
.
get_order_status
(
id
)
return
OrderStatusSchema
.
model_validate
(
order
)
@
router
.
get
(
''
)
async
def
get_orders
(
page
:
int
=
1
,
size
:
int
=
10
):
return
await
ctrl
.
get_list
(
page
=
page
,
size
=
size
)
src/app/api/order/schemas.py
View file @
0fe70edd
import
datetime
from
typing
import
List
from
uuid
import
UUID
...
...
@@ -6,10 +7,6 @@ from pydantic import BaseModel, ConfigDict
from
api.product.schemas
import
ProductPostSchema
,
ProductOrderGetSchema
class
OrderBaseSchema
(
BaseModel
):
name
:
str
|
None
=
None
class
OrderIdSchema
(
BaseModel
):
id
:
UUID
...
...
@@ -29,3 +26,10 @@ class OrderGetSchema(OrderIdSchema):
class
OrderStatusSchema
(
BaseModel
):
id
:
UUID
status
:
str
class
OrderListSchema
(
BaseModel
):
id
:
UUID
status
:
str
created_at
:
datetime
.
datetime
updated_at
:
datetime
.
datetime
src/app/api/order/services.py
View file @
0fe70edd
...
...
@@ -2,7 +2,7 @@ from uuid import UUID
from
db.repositories.order
import
OrderRepository
from
db.repositories.product
import
ProductRepository
from
.schemas
import
OrderGetSchema
from
.schemas
import
OrderGetSchema
,
OrderListSchema
,
OrderStatusSchema
from
exceptions
import
common
as
common_exc
,
http
as
http_exc
from
db.models
import
ProductOrder
,
Order
...
...
@@ -57,3 +57,20 @@ class OrderService:
async
def
get_order_status
(
self
,
id
:
UUID
):
order
=
await
self
.
order_repository
.
get
(
id
)
return
{
'id'
:
order
.
id
,
'status'
:
order
.
status
}
async
def
get_order_list
(
self
,
**
kwargs
):
orders
=
await
self
.
order_repository
.
get_list
(
**
kwargs
)
return
{
"page"
:
orders
[
'page'
],
"size"
:
orders
[
'size'
],
"total"
:
orders
[
'total'
],
"result"
:
[
OrderListSchema
.
model_validate
(
{
'id'
:
order
.
id
,
'status'
:
order
.
status
,
'created_at'
:
order
.
created_at
,
'updated_at'
:
order
.
updated_at
}
)
for
order
in
orders
[
'result'
]
]
}
src/app/db/repositories/order.py
View file @
0fe70edd
import
math
from
.base
import
BaseRepository
from
..models
import
Order
class
OrderRepository
(
BaseRepository
):
model
=
Order
async
def
get_list
(
self
,
page
,
size
,
**
kwargs
):
query
=
self
.
model
.
all
()
offset_min
=
(
page
-
1
)
*
size
offset_max
=
page
*
size
data
=
await
query
result
=
{
"page"
:
page
,
"size"
:
size
,
"total"
:
math
.
ceil
(
len
(
data
)
/
size
)
-
1
,
"result"
:
data
[
offset_min
:
offset_max
]
}
return
result
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment