Skip to content

Commit

Permalink
Merge pull request #71 from boostcampwm-2024/feature/api/stocksell-#50
Browse files Browse the repository at this point in the history
[BE] 7.04 매도 API 구현 #50
  • Loading branch information
sieunie authored Nov 12, 2024
2 parents 41495ef + 55e0ef9 commit 6915b77
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
20 changes: 19 additions & 1 deletion BE/src/stock/order/stock-order.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,30 @@ export class StockOrderController {
})
@ApiResponse({
status: 201,
description: '주식 매수 성공',
description: '주식 매수 예약 등록 성공',
})
async buy(
@Req() request: RequestInterface,
@Body(ValidationPipe) stockOrderRequest: StockOrderRequestDto,
) {
await this.stockTradeService.buy(request.user.id, stockOrderRequest);
}

@Post('/sell')
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@ApiOperation({
summary: '주식 매도 API',
description: '주식 id, 매도 가격, 수량으로 주식을 매도한다.',
})
@ApiResponse({
status: 201,
description: '주식 매도 예약 등록 성공',
})
async sell(
@Req() request: RequestInterface,
@Body(ValidationPipe) stockOrderRequest: StockOrderRequestDto,
) {
await this.stockTradeService.sell(request.user.id, stockOrderRequest);
}
}
13 changes: 13 additions & 0 deletions BE/src/stock/order/stock-order.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,17 @@ export class StockOrderService {

await this.stockOrderRepository.save(order);
}

async sell(userId: number, stockOrderRequest: StockOrderRequestDto) {
const order = this.stockOrderRepository.create({
user_id: userId,
stock_id: stockOrderRequest.stock_id,
trade_type: TradeType.SELL,
amount: stockOrderRequest.amount,
price: stockOrderRequest.price,
status: StatusType.PENDING,
});

await this.stockOrderRepository.save(order);
}
}

0 comments on commit 6915b77

Please sign in to comment.