Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,6 @@ installed.txt
filter-repo/
.git/

# Requirements obsoletos
requirements.txt
dependencies_*.txt
# Logs
logs
*.log
Expand Down Expand Up @@ -227,6 +224,3 @@ installed.txt
filter-repo/
.git/

# Requirements obsoletos
requirements.txt
dependencies_*.txt
9 changes: 0 additions & 9 deletions backend/zato-csm-backend/.env.example
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
# Database Configuration
DATABASE_TYPE=postgres

# PostgreSQL Configuration
POSTGRES_HOST=localhost
POSTGRES_USER=your_postgres_user
POSTGRES_PASSWORD=your_postgres_password
POSTGRES_DATABASE=your_database_name
POSTGRES_PORT=5432

# MySQL Configuration
MYSQL_HOST=localhost
MYSQL_USER=your_mysql_user
MYSQL_PASSWORD=your_mysql_password
MYSQL_DATABASE=your_database_name

# JWT Configuration
SECRET_KEY=your_very_long_and_secure_secret_key_here
ALGORITHM=HS256
Expand Down
27 changes: 27 additions & 0 deletions backend/zato-csm-backend/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
annotated-types==0.7.0
anyio==4.9.0
argon2-cffi==25.1.0
argon2-cffi-bindings==25.1.0
cffi==1.17.1
click==8.2.1
colorama==0.4.6
cryptography==45.0.5
fastapi==0.116.1
h11==0.16.0
idna==3.10
passlib==1.7.4
psycopg2==2.9.10
psycopg2-binary==2.9.10
pycparser==2.22
pydantic==2.11.7
pydantic_core==2.33.2
PyJWT==2.10.1
PyMySQL==1.1.1
python-dotenv==1.1.1
python-multipart==0.0.20
pytz==2025.2
sniffio==1.3.1
starlette==0.47.2
typing-inspection==0.4.1
typing_extensions==4.14.1
uvicorn==0.35.0
35 changes: 33 additions & 2 deletions backend/zato-csm-backend/routes/products.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,43 @@ def get_product(

@router.put("/{product_id}")
def update_product(
request: Request,
product_id: int,
updates: dict = Body(...),
name: Optional[str] = Form(None),
description: Optional[str] = Form(None),
price: Optional[float] = Form(None),
stock: Optional[int] = Form(None),
category: Optional[str] = Form(None),
images: List[UploadFile] = File(None),
body: Optional[dict] = Body(None),
current_user=Depends(get_current_user),
product_service=Depends(_get_product_service),
):
product_updated = product_service.update_product(product_id, updates)
user_timezone = get_user_timezone_from_request(request)

updates = {}

if body:
updates.update(body)

if name is not None:
updates["name"] = name
if description is not None:
updates["description"] = description
if price is not None:
updates["price"] = price
if stock is not None:
updates["stock"] = stock
if category is not None:
updates["category"] = category

if images:
updates["images"] = images

if not updates:
raise HTTPException(status_code=400, detail="No update fields provided")

product_updated = product_service.update_product(product_id, updates, user_timezone)
return {
"success": True,
"message": "Product updated successfully",
Expand Down
10 changes: 7 additions & 3 deletions backend/zato-csm-backend/services/product_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ def get_product(self, product_id):
raise HTTPException(status_code=404, detail="Product not found")
return product

def update_product(self, product_id: int, updates: dict):
def update_product(self, product_id: int, updates: dict, user_timezone: str = "UTC"):
# Validation allowed fields
allowed_fields = ["name", "description", "price", "stock", "category", "images"]

for field in updates.keys():
for field in list(updates.keys()):
if field not in allowed_fields:
raise HTTPException(status_code=400, detail=f"Invalid field: {field}")

Expand All @@ -82,7 +82,11 @@ def update_product(self, product_id: int, updates: dict):
if "stock" in updates and updates["stock"] < 0:
raise HTTPException(status_code=400, detail="Stock cannot be negative")

return self.product_repo.update_product(product_id, updates)
images = updates.get("images")
if images and isinstance(images, list):
updates["images"] = self._process_images(images)

return self.product_repo.update_product(product_id, updates, user_timezone)

def delete_product(self, product_id):
return self.product_repo.delete_product(product_id)