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.05/7.06 매수/매도 예약 취소 API 구현 #51,#52 #73

Merged
merged 3 commits into from
Nov 12, 2024
Merged
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: 20 additions & 0 deletions BE/src/stock/order/stock-order.controller.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import {
Body,
Controller,
Delete,
Param,
Post,
Req,
UseGuards,
@@ -57,4 +59,22 @@ export class StockOrderController {
) {
await this.stockTradeService.sell(request.user.id, stockOrderRequest);
}

@Delete('/:order_id')
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@ApiOperation({
summary: '주식 매도/매수 취소 API',
description: '주문 id로 미체결된 주문을 취소한다.',
})
@ApiResponse({
status: 200,
description: '주식 매도/매수 취소 성공',
})
async cancel(
@Req() request: RequestInterface,
@Param('order_id') orderId: number,
) {
await this.stockTradeService.cancel(request.user.id, orderId);
}
}
20 changes: 20 additions & 0 deletions BE/src/stock/order/stock-order.service.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
import {
ConflictException,
ForbiddenException,
Injectable,
} from '@nestjs/common';
import { NotFoundError } from 'rxjs';
import { Injectable } from '@nestjs/common';
import { StockOrderRequestDto } from './dto/stock-order-request.dto';
import { StockOrderRepository } from './stock-order.repository';
@@ -33,4 +39,18 @@ export class StockOrderService {

await this.stockOrderRepository.save(order);
}

async cancel(userId: number, orderId: number) {
const order = await this.stockOrderRepository.findOneBy({ id: orderId });

if (!order) throw new NotFoundError('주문을 찾을 수 없습니다.');

if (order.user_id !== userId)
throw new ForbiddenException('다른 사용자의 주문은 취소할 수 없습니다.');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 이게 가능한 시나리오에서의 에러인가요? 지난 번 학습 스프린트 때 멘토님이 불가능한 상황에 대한 예외처리는 굳이 할 필요가 없다고 하셨던게 생각나서 여쭤봅니다.
로그인한 사용자만 사용할 수 있는 api인 만큼, 토큰으로 해당 사용자의 정보를 구분해서 취소를 할 수 있는데 이게 가능한 시나리오일까..? 하는 생각이 드네요!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

음... 프론트엔드랑 연결된 실제 서비스에서는 일어날지 잘 모르겠는데, swagger 여러 명이 같이 사용할 때 혼동이 있을까봐 추가해두긴 했습니다.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

하긴 swagger 같은 환경에서는 충분히 혼동이 올 수도 있겠네요.. 제가 너무 실제 환경으로만 생각한 거 같아요! 좋은 의견 감사합니다


if (order.status === StatusType.COMPLETE)
throw new ConflictException('이미 체결된 주문은 취소할 수 없습니다.');

await this.stockOrderRepository.remove(order);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 이거 그냥 hard delete 하는 건가요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵 지금은 hard delete이긴 한뎅 내일 다른 백엔드 분들 이야기 들어보고 결정해보려고 합니당

+ 뭔가 제 생각으로는 주문 취소는 soft delete로 굳이 남겨둘 필요가 있나 시프네용

}
}

Unchanged files with check annotations Beta

indicator.style.left = `${currentButton.offsetLeft}px`;
indicator.style.width = `${currentButton.offsetWidth}px`;
}
}, [currentMarket]);

Check warning on line 31 in FE/src/components/TopFive/Nav.tsx

GitHub Actions / FE-test-and-build

React Hook useEffect has a missing dependency: 'markets'. Either include it or remove the dependency array
return (
<div className='relative flex gap-1 text-xl font-bold'>