-
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.
Merge pull request #45 from tigran-saatchyan/features/22-cart-impleme…
…ntation [FEATURE] Cart implementation + refactoring - #22
- Loading branch information
Showing
33 changed files
with
592 additions
and
600 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
from typing import Annotated, List, Union | ||
|
||
from fastapi import APIRouter, Depends | ||
|
||
from app.api.v1.dependencies import UOWDependency, current_user | ||
from app.models import User | ||
from app.schemas.cart import CartCreate, CartUpdate | ||
from app.services.cart import CartService | ||
|
||
router = APIRouter( | ||
prefix="/cart", | ||
tags=["Cart"], | ||
) | ||
|
||
|
||
@router.post("/") | ||
async def add_product_to_cart( | ||
user: Annotated[User, Depends(current_user)], | ||
product: Union[CartCreate, List[CartCreate]], | ||
uow: UOWDependency, | ||
) -> Union[int, List[int]]: | ||
return await CartService().add(uow, product, user) | ||
|
||
|
||
@router.get("/get_all/") | ||
async def get_all_products_from_cart( | ||
uow: UOWDependency, | ||
user: Annotated[User, Depends(current_user)], | ||
): | ||
return await CartService().get_all(uow, user) | ||
|
||
|
||
@router.get("/{product_id}") | ||
async def get_one_product_from_cart( | ||
uow: UOWDependency, | ||
product_id: int, | ||
user: Annotated[User, Depends(current_user)], | ||
): | ||
return await CartService().get(uow, product_id, user) | ||
|
||
|
||
@router.patch("/{product_id}") | ||
async def update_product_quantity( | ||
uow: UOWDependency, | ||
product_id: int, | ||
product: CartUpdate, | ||
user: Annotated[User, Depends(current_user)], | ||
): | ||
return await CartService().update(uow, product_id, product, user) | ||
|
||
|
||
@router.delete("/{product_id}") | ||
async def remove_product_from_cart( | ||
uow: UOWDependency, | ||
product_id: int, | ||
user: Annotated[User, Depends(current_user)], | ||
): | ||
return await CartService().delete(uow, product_id, user) | ||
|
||
|
||
@router.delete("/clear_cart/") | ||
async def clear_cart( | ||
uow: UOWDependency, | ||
user: Annotated[User, Depends(current_user)], | ||
): | ||
return await CartService().delete_all(uow, user) | ||
|
||
|
||
@router.get("/total_price/") | ||
async def get_total_cart_price( | ||
user: Annotated[User, Depends(current_user)], | ||
uow: UOWDependency, | ||
) -> float: | ||
return await CartService().get_total_price(uow, user) |
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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
from app.api.v1.cart import router as cart_router | ||
from app.api.v1.products import router as product_router | ||
|
||
all_routers = [ | ||
product_router, | ||
cart_router, | ||
] |
40 changes: 0 additions & 40 deletions
40
app/migrations/versions/1aeee680cc4d_removed_password_salt_field.py
This file was deleted.
Oops, something went wrong.
46 changes: 0 additions & 46 deletions
46
app/migrations/versions/49af15ac2ace_updated_last_login.py
This file was deleted.
Oops, something went wrong.
40 changes: 0 additions & 40 deletions
40
app/migrations/versions/541102dacd00_updated_users_table.py
This file was deleted.
Oops, something went wrong.
46 changes: 0 additions & 46 deletions
46
app/migrations/versions/64ad69e55ba4_updated_password_hash_field_type.py
This file was deleted.
Oops, something went wrong.
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,47 @@ | ||
"""initial | ||
Revision ID: 6a1f68c6ba5c | ||
Revises: | ||
Create Date: 2023-11-16 20:49:30.626229+04:00 | ||
""" | ||
from typing import Sequence, Union | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision: str = '6a1f68c6ba5c' | ||
down_revision: Union[str, None] = None | ||
branch_labels: Union[str, Sequence[str], None] = None | ||
depends_on: Union[str, Sequence[str], None] = None | ||
|
||
|
||
def upgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.create_table('user', | ||
sa.Column('telephone', sa.String(length=50), nullable=False), | ||
sa.Column('first_name', sa.String(length=150), nullable=True), | ||
sa.Column('last_name', sa.String(length=150), nullable=True), | ||
sa.Column('last_login', sa.TIMESTAMP(timezone=True), server_default=sa.text('now()'), nullable=True), | ||
sa.Column('email', sa.String(length=320), nullable=False), | ||
sa.Column('hashed_password', sa.String(length=1024), nullable=False), | ||
sa.Column('is_active', sa.Boolean(), nullable=False), | ||
sa.Column('is_superuser', sa.Boolean(), nullable=False), | ||
sa.Column('is_verified', sa.Boolean(), nullable=False), | ||
sa.Column('id', sa.Integer(), nullable=False), | ||
sa.Column('created_at', sa.TIMESTAMP(timezone=True), server_default=sa.text('now()'), nullable=False), | ||
sa.Column('updated_at', sa.TIMESTAMP(timezone=True), server_default=sa.text('now()'), nullable=False), | ||
sa.PrimaryKeyConstraint('id'), | ||
sa.UniqueConstraint('telephone') | ||
) | ||
op.create_index(op.f('ix_user_email'), 'user', ['email'], unique=True) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_index(op.f('ix_user_email'), table_name='user') | ||
op.drop_table('user') | ||
# ### end Alembic commands ### |
Oops, something went wrong.