Skip to content

Commit

Permalink
✨ feat: 주식 즐겨찾기 취소 API 구현 #178
Browse files Browse the repository at this point in the history
  • Loading branch information
sieunie committed Nov 25, 2024
1 parent ae44015 commit b24753f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
27 changes: 26 additions & 1 deletion BE/src/stock/bookmark/stock-bookmark.controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { Controller, Param, Post, Req, UseGuards } from '@nestjs/common';
import {
Controller,
Delete,
Param,
Post,
Req,
UseGuards,
} from '@nestjs/common';
import {
ApiBearerAuth,
ApiOperation,
Expand Down Expand Up @@ -31,4 +38,22 @@ export class StockBookmarkController {
stockCode,
);
}

@Delete('/:stockCode')
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@ApiOperation({ summary: '종목 즐겨찾기 취소 API' })
@ApiResponse({
status: 200,
description: '종목 즐겨찾기 취소 성공',
})
async deleteBookmark(
@Req() request: Request,
@Param('stockCode') stockCode: string,
) {
await this.stockBookmarkService.unregisterBookmark(
parseInt(request.user.userId, 10),
stockCode,
);
}
}
17 changes: 16 additions & 1 deletion BE/src/stock/bookmark/stock-bookmark.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { BadRequestException, Injectable } from '@nestjs/common';
import {
BadRequestException,
Injectable,
NotFoundException,
} from '@nestjs/common';
import { StockBookmarkRepository } from './stock-bookmark.repository';

@Injectable()
Expand All @@ -22,4 +26,15 @@ export class StockBookmarkService {
});
await this.stockBookmarkRepository.insert(bookmark);
}

async unregisterBookmark(userId, stockCode) {
const bookmark = await this.stockBookmarkRepository.findOneBy({
user_id: userId,
stock_code: stockCode,
});

if (!bookmark) throw new NotFoundException('존재하지 않는 북마크입니다.');

await this.stockBookmarkRepository.remove(bookmark);
}
}

0 comments on commit b24753f

Please sign in to comment.