Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BE] 7.04 매도 API 구현 #50 #71

Merged
merged 3 commits into from
Nov 12, 2024
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
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);
}
}
Loading