-
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.
## Description - update market price only when a higher price is offered than the current on - make bid price Pydantic model <!-- Add a more detailed description of the changes if needed. --> ## Related Issue close #36 <!-- If your PR refers to a related issue, link it here. -->
- Loading branch information
Showing
4 changed files
with
54 additions
and
0 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
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,32 @@ | ||
from typing import Any, List | ||
from fastapi import APIRouter, Depends, HTTPException | ||
from sqlalchemy.orm import Session | ||
from app.api.dependencies import database | ||
from app.crud.crud_bid_prices import bid | ||
from app.models.domain.bid_prices import BidPrice | ||
from app.services.user_manager import current_active_user | ||
from app.crud.crud_users import get_user_by_email | ||
from app.db.fastapi_user import User | ||
|
||
router = APIRouter() | ||
|
||
|
||
@router.put("/{post_id}", description="경매 게시글의 경매 가격을 제시합니다.") | ||
def bid_for_item( | ||
*, | ||
db: Session = Depends(database.get_db), | ||
current_user: User = Depends(current_active_user), | ||
post_id: int, | ||
bid_price: BidPrice, | ||
) -> Any: | ||
current_user_name = get_user_by_email(db=db, email=current_user.email).username | ||
|
||
# market price update | ||
market = bid(db=db, post_id=post_id, bid_price=bid_price.bid_price) | ||
if market: | ||
return {"message": f"{current_user_name} successfully placed a bid"} | ||
else: | ||
raise HTTPException( | ||
status_code=400, | ||
detail="Bid price must be higher than current price", | ||
) |
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,15 @@ | ||
from sqlalchemy.orm import Session | ||
from app.models.schemas.markets import Market | ||
|
||
|
||
def bid(db: Session, *, post_id: int, bid_price: int) -> Market: | ||
market = db.query(Market).filter(Market.post_id == post_id).one() | ||
|
||
if bid_price > market.price: | ||
market.price = bid_price | ||
db.add(market) | ||
db.commit() | ||
db.refresh(market) | ||
return market | ||
|
||
return None |
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,5 @@ | ||
from pydantic import BaseModel | ||
|
||
|
||
class BidPrice(BaseModel): | ||
bid_price: int |