Skip to content

Commit 5209739

Browse files
Merge pull request #16 from wafflestudio/feature/auction
add top_bidder_id on ProductResponse
2 parents 7b63ec5 + 9f655c2 commit 5209739

File tree

4 files changed

+40
-1
lines changed

4 files changed

+40
-1
lines changed

carrot/app/auction/models.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ class Auction(Base):
2323

2424
id: Mapped[str] = mapped_column(String(36), primary_key=True, index=True, default=lambda: str(uuid.uuid4()))
2525
product_id: Mapped[str] = mapped_column(String(36), ForeignKey("product.id", ondelete="CASCADE"), nullable=False, unique=True, index=True)
26-
26+
top_bidder_id: Mapped[Optional[str]] = mapped_column(String(36), ForeignKey("user.id", ondelete="SET NULL"), nullable=True, index=True)
27+
2728
# starting_price: Mapped[int] = mapped_column(Integer, nullable=False) # 시작가
2829
current_price: Mapped[int] = mapped_column(Integer, nullable=False) # 현재가
2930
# is_sold: Mapped[bool] = mapped_column(Boolean, default=False) # Product의 is_sold와 중복

carrot/app/auction/schemas.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class Config:
6161
class AuctionResponse(BaseModel):
6262
id: str
6363
product_id: str
64+
top_bidder_id: Optional[str]
6465
current_price: int
6566
end_at: datetime
6667
bid_count: int

carrot/app/auction/services.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ async def place_bid(self, auction_id: str, bidder_id: str, bid_price: int) -> Bi
4545
await self.repository.add_bid_without_commit(new_bid)
4646

4747
auction.current_price = bid_price
48+
auction.top_bidder_id = bidder_id
4849
auction.bid_count += 1
4950
await self.repository.update_auction_without_commit(auction)
5051

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
"""empty message
2+
3+
Revision ID: 4033bf20b748
4+
Revises: 7fa611714908
5+
Create Date: 2026-02-04 03:33:33.744532
6+
7+
"""
8+
from typing import Sequence, Union
9+
10+
from alembic import op
11+
import sqlalchemy as sa
12+
13+
14+
# revision identifiers, used by Alembic.
15+
revision: str = '4033bf20b748'
16+
down_revision: Union[str, Sequence[str], None] = '7fa611714908'
17+
branch_labels: Union[str, Sequence[str], None] = None
18+
depends_on: Union[str, Sequence[str], None] = None
19+
20+
21+
def upgrade() -> None:
22+
"""Upgrade schema."""
23+
# ### commands auto generated by Alembic - please adjust! ###
24+
op.add_column('auction', sa.Column('top_bidder_id', sa.String(length=36), nullable=True))
25+
op.create_index(op.f('ix_auction_top_bidder_id'), 'auction', ['top_bidder_id'], unique=False)
26+
op.create_foreign_key(None, 'auction', 'user', ['top_bidder_id'], ['id'], ondelete='SET NULL')
27+
# ### end Alembic commands ###
28+
29+
30+
def downgrade() -> None:
31+
"""Downgrade schema."""
32+
# ### commands auto generated by Alembic - please adjust! ###
33+
op.drop_constraint(None, 'auction', type_='foreignkey')
34+
op.drop_index(op.f('ix_auction_top_bidder_id'), table_name='auction')
35+
op.drop_column('auction', 'top_bidder_id')
36+
# ### end Alembic commands ###

0 commit comments

Comments
 (0)