-
Notifications
You must be signed in to change notification settings - Fork 0
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
Issue/87/liked reviews #88
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,12 @@ import { Controller, Get, HttpException, Param, Query } from '@nestjs/common'; | |
import { session_userprofile } from '@prisma/client'; | ||
import { GetUser } from 'src/common/decorators/get-user.decorator'; | ||
import { CourseResponseDtoNested } from 'src/common/interfaces/dto/course/course.response.dto'; | ||
import { UserTakenCoursesQueryDto } from 'src/common/interfaces/dto/user/user.request.dto'; | ||
import { | ||
ReviewLikedQueryDto, | ||
UserTakenCoursesQueryDto, | ||
} from 'src/common/interfaces/dto/user/user.request.dto'; | ||
import { UserService } from './user.service'; | ||
import { ReviewResponseDto } from '../../common/interfaces/dto/reviews/review.response.dto'; | ||
|
||
@Controller('api/users') | ||
export class UserController { | ||
|
@@ -21,4 +25,17 @@ export class UserController { | |
throw new HttpException("Can't find user", 401); | ||
} | ||
} | ||
|
||
@Get(':user_id/liked-reviews') | ||
async getUserLikedReviews( | ||
@Query() query: ReviewLikedQueryDto, | ||
@Param('user_id') userId: number, | ||
@GetUser() user: session_userprofile, | ||
): Promise<(ReviewResponseDto & { userspecific_is_liked: boolean })[]> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. userspecific_is_liked도 포함된 타입을 정의해주면 좋을 것 같습니다. 다른 부분에서도 이런 경우 많았던 것 같아요. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이건 다같이 한번 논의해보는게 좋을 것 같습니다! |
||
if (userId === user.id) { | ||
return await this.userService.getUserLikedReviews(user, userId, query); | ||
} else { | ||
throw new HttpException("Can't find user", 401); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
import { Injectable, NotFoundException } from '@nestjs/common'; | ||
import { session_userprofile } from '@prisma/client'; | ||
import { CourseResponseDtoNested } from 'src/common/interfaces/dto/course/course.response.dto'; | ||
import { UserTakenCoursesQueryDto } from 'src/common/interfaces/dto/user/user.request.dto'; | ||
import { | ||
ReviewLikedQueryDto, | ||
UserTakenCoursesQueryDto, | ||
} from 'src/common/interfaces/dto/user/user.request.dto'; | ||
import { ProfileDto } from 'src/common/interfaces/dto/user/user.response.dto'; | ||
import { toJsonCourse } from 'src/common/interfaces/serializer/course.serializer'; | ||
import { ResearchLecture } from '../../common/interfaces/constants/lecture'; | ||
|
@@ -14,6 +17,7 @@ import { LectureRepository } from '../../prisma/repositories/lecture.repository' | |
import { ReviewsRepository } from '../../prisma/repositories/review.repository'; | ||
import { UserRepository } from '../../prisma/repositories/user.repository'; | ||
import { CourseRepository } from './../../prisma/repositories/course.repository'; | ||
import { ReviewResponseDto } from '../../common/interfaces/dto/reviews/review.response.dto'; | ||
|
||
@Injectable() | ||
export class UserService { | ||
|
@@ -120,4 +124,35 @@ export class UserService { | |
}), | ||
); | ||
} | ||
|
||
async getUserLikedReviews( | ||
user: session_userprofile, | ||
userId: number, | ||
query: ReviewLikedQueryDto, | ||
): Promise<(ReviewResponseDto & { userspecific_is_liked: boolean })[]> { | ||
const MAX_LIMIT = 300; | ||
const DEFAULT_ORDER = ['-written_datetime', '-id']; | ||
|
||
const reviews = await this.reviewRepository.getLikedReviews( | ||
userId, | ||
query.order ?? DEFAULT_ORDER, | ||
query.offset ?? 0, | ||
query.limit ?? MAX_LIMIT, | ||
); | ||
|
||
const result = await Promise.all( | ||
reviews.map(async (review) => { | ||
const result = toJsonReview(review); | ||
const isLiked: boolean = await this.reviewRepository.isLiked( | ||
review.id, | ||
user.id, | ||
); | ||
return Object.assign(result, { | ||
userspecific_is_liked: isLiked, | ||
}); | ||
Comment on lines
+146
to
+152
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 혹시 모든 review의 userspecific_is_liked가 true가 되지 않을까 생각이 들었는데, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이번주 task부분에 적어놓은것과 동일한 문제같아요! 그 부분 해결되면 해결책 여기에 적용시키겠습니다! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @doxylee 저도 일단 1) 모두 true가 될 거 같다는 생각을 하구 2) 근데 언제 false가 되는지 파악이 안 되긴 합니다. 기능 확인해보고 메서드 이름 수정해보도록 하시져 |
||
}), | ||
); | ||
|
||
return result; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
으로 해주는 것은 어떨까 싶은데 어떻게 생각하시나요? 대부분의 코드가 작성하신 것처럼 되어있긴 한데 나중에라도 이런 식으로 바꿔주면 좋을 것 같아요.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IsInt()를 사용하는게 맞는것 같습니다! 일단 이 부분은 수정해서 다시 커밋할게요 다른 부분에 isnumber사용된 것들이 많은데 그것들은 pr들 merge끝난 후에 한번에 고치는게 좋을 것 같습니다!
min max도 저렇게 추가할게요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@doxylee 이거 근데 지금 paginationDTO로 분리해낼까 싶어서요. PaginationDTO로 분리해내고, extends 하는 클래스에서 MinMax 설정하는 식으로 해야할 거 같습니다. extends 하는 클래스에서 무조건 Max를 설정하게끔 강제하는 방법이 있을까요..?