Skip to content

Commit dd53ee8

Browse files
authored
Merge pull request #17 from sdglitched/fix-lint-typo
Correct typos and apply linting correctly
2 parents 146581b + db38b17 commit dd53ee8

10 files changed

Lines changed: 73 additions & 35 deletions

File tree

README.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -104,16 +104,16 @@ This project serves as a strong foundation for developers to build upon.
104104
(venv) $ mv fastapi_ecom/config/config.py.example config.py
105105
(venv) $ nano fastapi_ecom/config/config.py
106106
```
107-
Change the variables as per your requirement
108-
`database` = `<DATABASE-NAME>` as mentioned while setting up the database container.
109-
`username` = `<DATABASE-USER>` as mentioned while setting up the database container.
110-
`password` = `<DATABASE-PASSWORD>` as mentioned while setting up the database container.
111-
`dtbsbhost` = `<HOST>` as mentioned while setting up the database container.
112-
`dtbsbport` = `<PORT>` as mentioned while setting up the database container.
113-
`dtbsdriver` = `postgresql+asyncpg` if async database driver to be used or `postgresql+psycopg2` is sync database driver to be used.
114-
`servhost` = `127.0.0.1` if the service is intended to be accessible only on the same device.
115-
`servport` = `8080` if the service is intended to be accessible on the port number `8080` or `[1-65535]` depending on your choice.
116-
`cgreload` = `True` for use in development environments to which automatically reload the unvicorn service.
107+
Change the variables as per your requirement
108+
`database` = `<DATABASE-NAME>` as mentioned while setting up the database container.
109+
`username` = `<DATABASE-USER>` as mentioned while setting up the database container.
110+
`password` = `<DATABASE-PASSWORD>` as mentioned while setting up the database container.
111+
`dtbsbhost` = `<HOST>` as mentioned while setting up the database container.
112+
`dtbsbport` = `<PORT>` as mentioned while setting up the database container.
113+
`dtbsdriver` = `postgresql+asyncpg` if async database driver to be used or `postgresql+psycopg2` is sync database driver to be used.
114+
`servhost` = `127.0.0.1` if the service is intended to be accessible only on the same device.
115+
`servport` = `8080` if the service is intended to be accessible on the port number `8080` or `[1-65535]` depending on your choice.
116+
`cgreload` = `True` for use in development environments to which automatically reload the uvicorn service.
117117
Command
118118
```shell
119119
(venv) $ mv fastapi_ecom/migrations/alembic.ini.example fastapi_ecom/migrations/alembic.ini
@@ -446,10 +446,10 @@ This project serves as a strong foundation for developers to build upon.
446446
2. Business Route
447447
This route contains endpoints for performing CRUD operations on business entity.
448448
`create`: Endpoint to create a new business account. No authentication is needed for connecting to this endpoint.
449-
`me`: It is a endpoint to fetch the email of the currently authenticated business.
449+
`me`: It is an endpoint to fetch the email of the currently authenticated business.
450450
`search`: Endpoint to fetch a paginated list of businesses from the database. No authentication is needed for connecting to this endpoint.
451451
`delete`: Endpoint for an authenticated business to delete its own record.
452-
_Note:_ This endpoint will be depricated in future update with the implementation of archiving.
452+
_Note:_ This endpoint will be deprecated in future update with the implementation of archiving.
453453
`update`: Endpoint for an authenticated business to update its own record.
454454
![](https://raw.githubusercontent.com/sdglitched/FastAPI-eCom/main/docs/imgs/business_enpt.png)
455455
3. Product Route
@@ -460,13 +460,13 @@ This project serves as a strong foundation for developers to build upon.
460460
`search/internal`: Endpoint fetches a paginated list of products associated with the authenticated business.
461461
`search/uuid`: Endpoint fetches a specific product by its UUID (Product ID) associated with the authenticated business.
462462
`delete/uuid`: Endpoint to delete a product by its UUID associated for an authenticated business.
463-
_Note:_ This endpoint will be depricated in future update with the implementation of archiving.
463+
_Note:_ This endpoint will be deprecated in future update with the implementation of archiving.
464464
`update/uuid`: Endpoint to update a product by its UUID associated for an authenticated business.
465465
![](https://raw.githubusercontent.com/sdglitched/FastAPI-eCom/main/docs/imgs/product_enpt.png)
466466
4. Customer Route
467467
This route contains endpoints for performing CRUD operations on customer entity.
468468
`create`: Endpoint to create a new customer account. No authentication is needed for connecting to this endpoint.
469-
`me`: It is a endpoint to fetch the email of the currently authenticated customer.
469+
`me`: It is an endpoint to fetch the email of the currently authenticated customer.
470470
`search`: Endpoint to fetch a paginated list of customers from the database. No authentication is needed for connecting to this endpoint.
471471
`delete`: Endpoint for an authenticated customer to delete its own record.
472472
`update`: Endpoint for an authenticated customer to update its own record.
@@ -476,10 +476,10 @@ This project serves as a strong foundation for developers to build upon.
476476
`create`: Endpoint to place an order by the authenticated customer.
477477
`search`: Endpoint fetches a paginated list of orders and its details associated with the authenticated customer.
478478
`search/internal`: Endpoint fetches a paginated list of orders and its details.
479-
_Note:_ This endpoint is ment to be used by an admin account which will created in future update. Currently no authentication is needed for connecting to this endpoint.
479+
_Note:_ This endpoint is ment to be used by an admin account which will created in future update. Currently, no authentication is needed for connecting to this endpoint.
480480
`search/uuid`: Endpoint fetches a specific order and its details by its UUID associated with the authenticated customer.
481-
`delete/uuid`: Endpoint to delete a order by its UUID associated for an authenticated customer.
482-
_Note:_ This endpoint will be depricated in future update with the implementation of archiving.
481+
`delete/uuid`: Endpoint to delete an order by its UUID associated for an authenticated customer.
482+
_Note:_ This endpoint will be deprecated in future update with the implementation of archiving.
483483
![](https://raw.githubusercontent.com/sdglitched/FastAPI-eCom/main/docs/imgs/order_enpt.png)
484484
485485
## Future Roadmap

fastapi_ecom/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
tags_metadata = [
1111
{"name": "business", "description": "Operations on businesses"},
1212
{"name": "product", "description": "Operations on products"},
13-
{"name": "customer", "description": "Operations on customeres"},
13+
{"name": "customer", "description": "Operations on customers"},
1414
{"name": "order", "description": "Operations on orders"}
1515
]
1616

fastapi_ecom/database/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
# Base class for ORM models, to be used with SQLAlchemy's declarative system.
1111
baseobjc = declarative_base()
1212

13+
# Path of alembic configuration file
14+
alempath = str(Path(str(Path(str(Path(__file__).parent.resolve().parent.resolve()),"migrations").resolve()),"alembic.ini").resolve())
15+
1316
# Migration path for alembic configuration
1417
migrpath = str(Path(str(Path(__file__).parent.resolve().parent.resolve()),"migrations").resolve())
1518

fastapi_ecom/database/db_setup.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
from pathlib import Path
21
from typing import AsyncGenerator
32

43
from alembic import command, config
54
from sqlalchemy.ext.asyncio import AsyncSession
65

7-
from fastapi_ecom.database import ( #noqa: F401
6+
from fastapi_ecom.database import ( # noqa: F401
7+
alempath,
88
baseobjc,
99
get_async_session,
1010
get_database_url,
@@ -28,7 +28,7 @@ def make_database() -> None:
2828
baseobjc.metadata.create_all(bind=sync_engine)
2929

3030
# Set up Alembic configuration for migration management.
31-
alembic_config = config.Config(str(Path(str(Path(str(Path(__file__).parent.resolve().parent.resolve()),"migrations").resolve()),"alembic.ini").resolve()))
31+
alembic_config = config.Config(alempath)
3232
alembic_config.set_main_option("script_location", migrpath)
3333
alembic_config.set_main_option("sqlalchemy.url", get_database_url().render_as_string(hide_password=False))
3434

fastapi_ecom/router/business.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,11 @@ async def delete_business(db: AsyncSession = Depends(get_db), business_auth = De
153153
}
154154

155155
@router.put("/update/me", status_code=status.HTTP_202_ACCEPTED, response_model=BusinessResult, tags=["business"])
156-
async def update_business(business: BusinessUpdate, db: AsyncSession = Depends(get_db), business_auth = Depends(verify_business_cred)) -> BusinessResult:
156+
async def update_business(
157+
business: BusinessUpdate,
158+
db: AsyncSession = Depends(get_db),
159+
business_auth = Depends(verify_business_cred)
160+
) -> BusinessResult:
157161
"""
158162
Endpoint for an authenticated business to update its own record.
159163

fastapi_ecom/router/product.py

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@
2424
router = APIRouter(prefix="/product")
2525

2626
@router.post("/create", status_code=status.HTTP_201_CREATED, response_model=ProductResultInternal, tags=["product"])
27-
async def add_product(product: ProductCreate, db: AsyncSession = Depends(get_db), business_auth = Depends(verify_business_cred)) -> ProductResultInternal:
27+
async def add_product(
28+
product: ProductCreate,
29+
db: AsyncSession = Depends(get_db),
30+
business_auth = Depends(verify_business_cred)
31+
) -> ProductResultInternal:
2832
"""
2933
Endpoint to add a new product by currently authenticated business.
3034
@@ -121,7 +125,9 @@ async def get_product_by_text(
121125
:raises HTTPException:
122126
If no matching products exists in the database, it raises 404 Not Found.
123127
"""
124-
query = select(Product).where(or_(Product.name.ilike(f"%{text}%"), Product.description.ilike(f"%{text}%"))).options(selectinload("*")).offset(skip).limit(limit)
128+
query = select(Product).where(
129+
or_(Product.name.ilike(f"%{text}%"), Product.description.ilike(f"%{text}%"))
130+
).options(selectinload("*")).offset(skip).limit(limit)
125131
result = await db.execute(query)
126132
products = result.scalars().all()
127133
if not products:
@@ -169,7 +175,11 @@ async def get_products_internal(
169175
}
170176

171177
@router.get("/search/uuid/{product_id}", status_code=status.HTTP_200_OK, response_model=ProductResultInternal, tags=["product"])
172-
async def get_product_by_uuid(product_id: str, db: AsyncSession = Depends(get_db), business_auth = Depends(verify_business_cred)) -> ProductResultInternal:
178+
async def get_product_by_uuid(
179+
product_id: str,
180+
db: AsyncSession = Depends(get_db),
181+
business_auth = Depends(verify_business_cred)
182+
) -> ProductResultInternal:
173183
"""
174184
Endpoint fetches a specific product by its UUID associated with the authenticated business.
175185
@@ -198,7 +208,11 @@ async def get_product_by_uuid(product_id: str, db: AsyncSession = Depends(get_db
198208
}
199209

200210
@router.delete("/delete/uuid/{product_id}", status_code=status.HTTP_202_ACCEPTED, response_model=ProductResultInternal, tags=["product"])
201-
async def delete_product(product_id: str, db: AsyncSession = Depends(get_db), business_auth = Depends(verify_business_cred)) -> ProductResultInternal:
211+
async def delete_product(
212+
product_id: str,
213+
db: AsyncSession = Depends(get_db),
214+
business_auth = Depends(verify_business_cred)
215+
) -> ProductResultInternal:
202216
"""
203217
Endpoint to delete a product by its UUID associated for an authenticated business.
204218
@@ -242,7 +256,12 @@ async def delete_product(product_id: str, db: AsyncSession = Depends(get_db), bu
242256
}
243257

244258
@router.put("/update/uuid/{product_id}", status_code=status.HTTP_202_ACCEPTED, response_model=ProductResultInternal, tags=["product"])
245-
async def update_product(product_id: str, product: ProductUpdate, db: AsyncSession = Depends(get_db), business_auth = Depends(verify_business_cred)) -> ProductResultInternal:
259+
async def update_product(
260+
product_id: str,
261+
product: ProductUpdate,
262+
db: AsyncSession = Depends(get_db),
263+
business_auth = Depends(verify_business_cred)
264+
) -> ProductResultInternal:
246265
"""
247266
Endpoint to update a product by its UUID associated for an authenticated business.
248267

pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ aiosqlite = "^0.20.0"
2727
pytest-mock = "^3.14.0"
2828

2929
[tool.ruff]
30-
line-length = 100
30+
line-length = 150
3131
fix = true
3232

3333
[tool.ruff.lint]
3434
select = ["E", "F", "W", "I", "S", "B", "UP"]
3535

3636
[tool.ruff.lint.per-file-ignores]
37-
"fastapi_ecom/*" = ["E501", "B008"]
38-
"tests/*" = ["S101", "S106", "E501"]
37+
"fastapi_ecom/*" = ["B008"]
38+
"tests/*" = ["S101", "S106",]
3939

4040
[tool.pytest.ini_options]
4141
asyncio_mode = "auto"

tests/product/test_product_delete.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,14 @@
88
@pytest.mark.parametrize(
99
"business_id, product_id, present",
1010
[
11-
pytest.param("5c1c48fb", "d5cf6983", True, id="PRODUCT DELETE Endpoint - Deletes the specific product of currently authenticated business"),
12-
pytest.param("5c1c48fb", "d76a11f2", False, id="PRODUCT DELETE Endpoint - Fails to find the specific product of currently authenticated business"),
11+
pytest.param(
12+
"5c1c48fb", "d5cf6983", True,
13+
id="PRODUCT DELETE Endpoint - Deletes the specific product of currently authenticated business"
14+
),
15+
pytest.param(
16+
"5c1c48fb", "d76a11f2", False,
17+
id="PRODUCT DELETE Endpoint - Fails to find the specific product of currently authenticated business"
18+
),
1319
]
1420
)
1521
async def test_delete_product(

tests/product/test_product_get.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,14 @@ async def test_get_products_internal(
229229
@pytest.mark.parametrize(
230230
"business_id, product_id, present",
231231
[
232-
pytest.param("d76a11f2", "3250fcbe", True, id="PRODUCT GET Endpoint - Fetch specific product by its UUID which is associated with the authenticated business"),
233-
pytest.param("d76a11f2", "xxxxyyyy", False, id="PRODUCT GET Endpoint - Fail to fetch specific product by its UUID which is associated with the authenticated business")
232+
pytest.param(
233+
"d76a11f2", "3250fcbe", True,
234+
id="PRODUCT GET Endpoint - Fetch specific product by its UUID which is associated with the authenticated business"
235+
),
236+
pytest.param(
237+
"d76a11f2", "xxxxyyyy", False,
238+
id="PRODUCT GET Endpoint - Fail to fetch specific product by its UUID which is associated with the authenticated business"
239+
)
234240
]
235241
)
236242
async def test_get_product_by_uuid(

tests/product/test_product_put.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"name": "Updated Test Product",
1616
"description": "Updated Fifth Test Product",
1717
"category": "updated test",
18-
"mfg_date": datetime.now(timezone.utc).replace(hour=0, minute=0, second=0, microsecond=0, tzinfo=None).isoformat(),#"1900-01-01 00:00:00+00:00",
18+
"mfg_date": datetime.now(timezone.utc).replace(hour=0, minute=0, second=0, microsecond=0, tzinfo=None).isoformat(),
1919
"exp_date": datetime.now(timezone.utc).replace(hour=0, minute=0, second=0, microsecond=0, tzinfo=None).isoformat(),
2020
"price": 1950.05
2121
},

0 commit comments

Comments
 (0)