Skip to content

Commit

Permalink
Merge pull request #50 from tigran-saatchyan/fix/last_fixes
Browse files Browse the repository at this point in the history
[FIX] README.md update and file structure minor fix
  • Loading branch information
tigran-saatchyan authored Nov 19, 2023
2 parents 7767499 + 17ccb33 commit e4e3f34
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 37 deletions.
47 changes: 37 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ You will need the following installed on your computer.

* [Git](https://git-scm.com/)
* [Python Poetry](https://python-poetry.org/)
* [PostgreSQL](https://www.postgresql.org/)

### Installation

Expand All @@ -104,6 +105,10 @@ Let's go through the steps to run the project "UniMart_by_EvoQ".

3. **Install Poetry:**
- If you haven't installed Poetry yet, please follow the instructions on the official website: https://python-poetry.org/docs/#installation
- If you have Poetry installed, you can use the following command to activate Python 3.12 for the project:
```bash
poetry env use python3.12
```

4. **Install Project Dependencies:**
```bash
Expand All @@ -115,14 +120,35 @@ Let's go through the steps to run the project "UniMart_by_EvoQ".
poetry shell
```

6. **Run the Project:**
- Unfortunately, without specific information about how the project should be run, I can't provide an exact command. Look for a `main.py`, `app.py`, or similar file, and run it using:
6. **Create Database:**
- If you haven't installed PostgreSQL yet, please follow the instructions on the official website: https://www.postgresql.org/download/
```bash
createdb --host=POSTGRES_HOST --port=POSTGRES_PORT --username=POSTGRES_USER POSTGRES_DB
```
- **Note:** Don't forget to rename .env.sample and replace the values with your own.
- **Note:** If you are using the default PostgreSQL settings, you can use the following command:
```bash
createdb --host=localhost --port=5432 --username=postgres unimart_db
```

7. **Run Migrations:**
```bash
alembic upgrade head
```

8. **Run the Project:**
```bash
uvicorn app.main:app --reload --host 127.0.0.1 --port 8000
```

9. **Testing:**
- Create a test database:
```bash
uvicorn main:app --reload --host 127.0.0.1 --port 8000
createdb --host=TEST_POSTGRES_HOST --port=TEST_POSTGRES_PORT --username=TEST_POSTGRES_USER TEST_POSTGRES_DB
```
- **Note:** Don't forget to replace the values with your own and put them in the .env.test file.
7. **Testing:**
- If there are tests available, you can run them with:
- You can run tests by using the following command:
```bash
poetry run pytest
```
Expand All @@ -146,9 +172,9 @@ Please note that the success of these steps depends on the project's structure a
=================== Created: 5 days ago
========== Language:
========================== ======= ● Python (100.0 %)
============================ ======== Authors: 100% Tigran Saatchyan 20
============================ ======== Authors: 100% Tigran Saatchyan
============================= ========= URL: [email protected]:tigran-saatchyan/UniMart_by_EvoQ.git
============================ ========== Commits: 20
============================ ==========
========== ============================
========= ============================= Lines of code: 1369
======== ============================ Size: 244.97 KiB (60 files)
Expand Down Expand Up @@ -197,6 +223,7 @@ app
│ ├── __init__.py
│ ├── cart.py
│ ├── products.py
│ ├── repository.py
│ └── users.py
├── schemas
│ ├── __init__.py
Expand All @@ -216,10 +243,10 @@ app
└── utils
├── __init__.py
├── factories.py
├── repository.py
├── unitofwork.py
└── utils.py
```
</details>
Expand Down Expand Up @@ -262,8 +289,8 @@ Detailed changes for each release will be documented in the
[release notes](https://github.com/users/tigran-saatchyan/projects/11).
## Issues
<a href="https://github.com/tigran-saatchyan/UniMart_by_EvoQ/issues?q=is%3Aopen+is%3Aissue"><img src="https://img.shields.io/github/issues/tigran-saatchyan/UniMart_by_Evoq" alt="Support me on Paypal"></a>
<a href="https://github.com/tigran-saatchyan/UniMart_by_EvoQ/issues?q=is%3Aissue+is%3Aclosed"><img src="https://img.shields.io/github/issues-closed/tigran-saatchyan/UniMart_by_Evoq" alt="Support me on Paypal"></a>
<a href="https://github.com/tigran-saatchyan/UniMart_by_EvoQ/issues?q=is%3Aopen+is%3Aissue"><img src="https://img.shields.io/github/issues/tigran-saatchyan/UniMart_by_Evoq" alt="open"></a>
<a href="https://github.com/tigran-saatchyan/UniMart_by_EvoQ/issues?q=is%3Aissue+is%3Aclosed"><img src="https://img.shields.io/github/issues-closed/tigran-saatchyan/UniMart_by_Evoq" alt="close"></a>
Please make sure to read the [Issue Reporting Checklist](https://github.com/tigran-saatchyan/UniMart_by_Evoq/issues?q=is%3Aopen) before opening an issue. Issues not conforming to the guidelines may be closed immediately.
Expand Down
15 changes: 8 additions & 7 deletions app/api/v1/cart.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from typing import Annotated, List, Union

from fastapi import APIRouter, Depends
from starlette import status

from app.api.v1.dependencies import UOWDependency, current_user
from app.models import User
Expand All @@ -15,7 +16,7 @@
)


@router.post("/")
@router.post("/", status_code=status.HTTP_201_CREATED)
async def add_product_to_cart(
user: Annotated[User, Depends(current_user)],
product: Union[CartCreate, List[CartCreate]],
Expand All @@ -35,7 +36,7 @@ async def add_product_to_cart(
return await CartService().add(uow, product, user)


@router.get("/get_all/")
@router.get("/get_all/", status_code=status.HTTP_200_OK)
async def get_all_products_from_cart(
uow: UOWDependency,
user: Annotated[User, Depends(current_user)],
Expand All @@ -52,7 +53,7 @@ async def get_all_products_from_cart(
return await CartService().get_all(uow, user)


@router.get("/{product_id}")
@router.get("/{product_id}", status_code=status.HTTP_200_OK)
async def get_one_product_from_cart(
uow: UOWDependency,
product_id: int,
Expand All @@ -71,7 +72,7 @@ async def get_one_product_from_cart(
return await CartService().get(uow, product_id, user)


@router.patch("/{product_id}")
@router.patch("/{product_id}", status_code=status.HTTP_200_OK)
async def update_product_quantity(
uow: UOWDependency,
product_id: int,
Expand All @@ -92,7 +93,7 @@ async def update_product_quantity(
return await CartService().update(uow, product_id, product, user)


@router.delete("/{product_id}")
@router.delete("/{product_id}", status_code=status.HTTP_204_NO_CONTENT)
async def remove_product_from_cart(
uow: UOWDependency,
product_id: int,
Expand All @@ -111,7 +112,7 @@ async def remove_product_from_cart(
return await CartService().delete(uow, product_id, user)


@router.delete("/clear_cart/")
@router.delete("/clear_cart/", status_code=status.HTTP_204_NO_CONTENT)
async def clear_cart(
uow: UOWDependency,
user: Annotated[User, Depends(current_user)],
Expand All @@ -128,7 +129,7 @@ async def clear_cart(
return await CartService().delete_all(uow, user)


@router.get("/total_price/")
@router.get("/total_price/", status_code=status.HTTP_200_OK)
async def get_total_cart_price(
user: Annotated[User, Depends(current_user)],
uow: UOWDependency,
Expand Down
11 changes: 6 additions & 5 deletions app/api/v1/products.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from typing import Annotated

from fastapi import APIRouter, Depends
from starlette import status

from app.api.v1.dependencies import UOWDependency, current_user
from app.models import User
Expand All @@ -15,7 +16,7 @@
)


@router.post("/")
@router.post("/", status_code=status.HTTP_201_CREATED)
async def add_product(
user: Annotated[User, Depends(current_user)],
product: ProductsCreate,
Expand All @@ -34,7 +35,7 @@ async def add_product(
return await ProductsService().add(uow, product, user)


@router.get("/")
@router.get("/", status_code=status.HTTP_200_OK)
async def get_products(
uow: UOWDependency,
user: Annotated[User, Depends(current_user)],
Expand All @@ -51,7 +52,7 @@ async def get_products(
return await ProductsService().get_all(uow, user)


@router.get("/{product_id}")
@router.get("/{product_id}", status_code=status.HTTP_200_OK)
async def get_product(
product_id: int,
uow: UOWDependency,
Expand All @@ -70,7 +71,7 @@ async def get_product(
return await ProductsService().get(uow, product_id, user)


@router.patch("/{product_id}")
@router.patch("/{product_id}", status_code=status.HTTP_200_OK)
async def update_product(
product_id: int,
product: ProductsUpdate,
Expand All @@ -92,7 +93,7 @@ async def update_product(
return {"message": "Product updated successfully"}


@router.delete("/{product_id}")
@router.delete("/{product_id}", status_code=status.HTTP_204_NO_CONTENT)
async def delete_product(
product_id: int,
uow: UOWDependency,
Expand Down
4 changes: 2 additions & 2 deletions app/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
__all__ = ["BaseModel", "Product", "User", "Cart"]

from app.models.base_model import BaseModel
from app.models.cart import Cart
from app.models.products import Product
from app.models.users import User

__all__ = ["BaseModel", "Product", "User", "Cart"]
2 changes: 1 addition & 1 deletion app/repositories/cart.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from app.models import User
from app.models.cart import Cart
from app.utils.repository import BaseRepository
from app.repositories.repository import BaseRepository


class CartRepository(BaseRepository):
Expand Down
2 changes: 1 addition & 1 deletion app/repositories/products.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Repository for interacting with the Product model in the database."""

from app.models import Product
from app.utils.repository import BaseRepository
from app.repositories.repository import BaseRepository


class ProductsRepository(BaseRepository):
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion app/repositories/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from sqlalchemy import select

from app.models import User
from app.utils.repository import BaseRepository
from app.repositories.repository import BaseRepository


class UsersRepository(BaseRepository):
Expand Down
8 changes: 4 additions & 4 deletions app/services/cart.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ class CartService:
"""

@overload
def add(self, uow: UOWDependency, product: CartCreate, user: User) -> int:
pass
def add(
self, uow: UOWDependency, product: CartCreate, user: User
) -> int: ...

@overload
def add(
self, uow: UOWDependency, products: List[CartCreate], user: User
) -> List[int]:
pass
) -> List[int]: ...

async def add(
self,
Expand Down
4 changes: 0 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@
USER_DATA = {
"email": USER_EMAIL,
"password": USER_PASSWORD,
"is_active": True,
"is_superuser": False,
"is_verified": False,
"confirm_password": USER_PASSWORD,
"first_name": "string",
"last_name": "string",
Expand Down Expand Up @@ -82,7 +79,6 @@ async def prepare_database():
await conn.run_sync(Base.metadata.drop_all)


# SETUP
@pytest.fixture(scope="session")
def event_loop(request):
"""Create an instance of the default event loop for each test case."""
Expand Down
2 changes: 1 addition & 1 deletion tests/test_cart.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ async def test_add_to_cart(ac: AsyncClient):
},
)

assert response.status_code == status.HTTP_200_OK
assert response.status_code == status.HTTP_201_CREATED

@staticmethod
async def test_get_all_from_cart(ac: AsyncClient):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ async def test_add_product(ac: AsyncClient):
},
)

assert response.status_code == status.HTTP_200_OK
assert response.status_code == status.HTTP_201_CREATED

0 comments on commit e4e3f34

Please sign in to comment.