Skip to content

Commit

Permalink
Update ProductResponse Schema & Display sale price
Browse files Browse the repository at this point in the history
  • Loading branch information
jll38 committed May 7, 2024
1 parent 614bca4 commit d2f1a9a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
1 change: 1 addition & 0 deletions backend/app/schemas/product_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class ProductBase(BaseModel):
blurb: Optional[str] = Field(None, example="A short description of the product")
description: Optional[str] = Field(None, example="A detailed description of the product")
image_url: Optional[str] = Field(None, example="http://example.com/image.png")
sale_price: Optional[float] = Field(..., gt=0, example=9.99)

class ProductCreate(ProductBase):
# Here we do not include relationships, assuming that only base product data is needed for creation
Expand Down
3 changes: 2 additions & 1 deletion backend/app/services/product_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ def map_product_to_response(db_product: Product) -> ProductResponse:
description=db_product.description,
image_url=db_product.image_url,
categories=categories,
sizes=sizes
sizes=sizes,
sale_price=db_product.sale_price
)
class Product_Service():

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default function ProductCard({ product }: any) {
{product.sale_price && (
<Typography variant="h5" fontSize={16} color="red" component="div">
{" "}
{product.sale_price}
SALE ${product.sale_price}
</Typography>
)}
</CardContent>
Expand Down
20 changes: 18 additions & 2 deletions frontend/src/pages/product/ProductPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,18 @@ export default function ProductPage() {
{productInfo.product_name}
</h2>
<div>⭐️⭐️⭐️⭐️⭐️</div>
<h3 className="text-xl">${productInfo.price}</h3>
<h3 className="text-xl">
{productInfo.sale_price ? (
<s>${productInfo.price}</s>
) : (
`$${productInfo.price}`
)}
</h3>
{productInfo.sale_price && (
<h3 className="text-xl text-red-500">
SALE ${productInfo.sale_price}
</h3>
)}
<p className="text-sm text-black/70">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed
do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Expand Down Expand Up @@ -85,7 +96,12 @@ export default function ProductPage() {
Hear from our community
</Typography>
<div>⭐️⭐️⭐️⭐️⭐️</div>
<TextField multiline={true} rows={4} maxRows={4} sx={{width: "100%"}} />
<TextField
multiline={true}
rows={4}
maxRows={4}
sx={{ width: "100%" }}
/>
<Button variant="contained">Post Review</Button>
</section>
</main>
Expand Down

0 comments on commit d2f1a9a

Please sign in to comment.