-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c9e2ec0
commit 8323abc
Showing
12 changed files
with
116 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from app.config import jwt_settings | ||
from app.database import get_session | ||
from app.models.orders import Order as m_Order | ||
from app.models.orders import OrderItem as m_OrderItem | ||
from app.schemas.orders import ShowOrderItem | ||
from app.utils.exceptions import get_user_or_404 | ||
from fastapi import APIRouter, Depends, Security, status | ||
from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer | ||
from fastapi_jwt_auth import AuthJWT | ||
from sqlalchemy.ext.asyncio import AsyncSession | ||
|
||
router = APIRouter(prefix="/orders", tags=["orders"], responses={404: {"description": "Not found"}}) | ||
security = HTTPBearer() | ||
|
||
|
||
@AuthJWT.load_config | ||
def get_jwt_settings(): | ||
return jwt_settings | ||
|
||
|
||
@router.get( | ||
"/get/", | ||
status_code=status.HTTP_200_OK, | ||
summary="Получение заказов пользователя", | ||
) | ||
async def get_orders( | ||
session: AsyncSession = Depends(get_session), | ||
authorize: AuthJWT = Depends(), | ||
credentials: HTTPAuthorizationCredentials = Security(security), | ||
): | ||
authorize.jwt_required() | ||
email = authorize.get_jwt_subject() | ||
user = await get_user_or_404(email=email, session=session) | ||
orders = await m_Order.filter(session=session, user_id=user.guid) | ||
order_guids = [order.guid for order in orders] | ||
orders = [] | ||
for guid in order_guids: | ||
items = await m_OrderItem.get_items(session, order_id=guid) | ||
[ShowOrderItem.from_orm(order_item).dict() for order_item in items] if items else None | ||
# return [Product.from_orm(product).dict() for product in products] if products else None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import uuid | ||
|
||
from pydantic import BaseModel | ||
|
||
|
||
class Order(BaseModel): | ||
guid: uuid.UUID | ||
user_id: uuid.UUID | ||
|
||
|
||
class ShowOrderItem(BaseModel): | ||
quantity: int | ||
product: uuid.UUID | ||
|
||
class Config: | ||
orm_mode = True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters