Skip to content

Commit

Permalink
좋아요 기능 - JWT 인증 및 도메인 객체 간소화
Browse files Browse the repository at this point in the history
- 좋아요 기능 호출 시 사용자 인증을 위해 accessToken 을 사용합니다.
  - users/jwt/jwt.provider.ts 의 validateToken 함수를 이용하여 토큰을 검증하고 사용자 ID 를 추출합니다.
좋아요 추가 로직을 간소화했습니다.

- 좋아요 도메인 객체 Like 를 직접 생성하지 않고 필요한 데이터 (userId, likedBookId)만 save 함수에 전달합니다.
  • Loading branch information
jihwooon committed Mar 14, 2024
1 parent dd7650b commit 8faee7d
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions server/src/likes/application/add-like.service.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import { StatusCodes } from 'http-status-codes';
import { validateToken } from 'src/users/jwt/jwt.provider';

import HttpException from 'src/utils/httpException';

import { validateToken } from 'src/users/jwt/jwt.provider';
import { StatusCodes } from 'http-status-codes';

import Like from '../domain/like';
import { save } from '../domain/likes.repository';

export const addLike = async (accessToken: any, likedBookId: number): Promise<boolean> => {
const { userId } = validateToken(accessToken);
const like = new Like({ userId, likedBookId });
const likeData = like.getDataOfLike();

const savedLike = await save(likeData);
const savedLike = await save({ userId, likedBookId });
if (!savedLike) {
throw new HttpException('좋아요 추가에 실패했습니다.', StatusCodes.BAD_REQUEST);
}
Expand Down

0 comments on commit 8faee7d

Please sign in to comment.