Skip to content

Commit

Permalink
Merge pull request #81 from dnd-side-project/fix/#80-evaluation
Browse files Browse the repository at this point in the history
책 평가 리스트 조회 응답 구조를 수정한다.
  • Loading branch information
f1v3-dev authored Feb 10, 2025
2 parents b2d0227 + 9c94c84 commit 02bbbd3
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public List<GetEvaluationResponse> get(Long memberId, Long memberBookId) {
throw new BookReadStatusException(ErrorType.BOOK_READ_STATUS_NOT_COMPLETED);
}

return evaluationRepository.findAll().stream()
.map(evaluation -> GetEvaluationResponse.of(evaluation.getKeyword()))
return evaluationRepository.findAllWithSelectedByMemberBookId(memberBookId).stream()
.map(GetEvaluationResponse::of)
.toList();
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
package com.dnd.sbooky.api.evaluation.response;

import com.dnd.sbooky.core.evaluation.EvaluationKeyword;
import com.dnd.sbooky.core.evaluation.dto.GetEvaluationDTO;
import io.swagger.v3.oas.annotations.media.Schema;

@Schema(description = "평가 리스트 조회 응답")
public record GetEvaluationResponse(
@Schema(description = "평가 ID") Long evaluationId,
@Schema(description = "평가 타입") String type,
@Schema(description = "평가 키워드") String keyword) {
@Schema(description = "평가 키워드") String keyword,
@Schema(description = "선택 여부") boolean isSelected) {

public static GetEvaluationResponse of(EvaluationKeyword keyword) {
public static GetEvaluationResponse of(GetEvaluationDTO dto) {
return new GetEvaluationResponse(
keyword.getId(), keyword.getType().getDescription(), keyword.getDescription());
dto.evaluationId(),
dto.type().getDescription(),
dto.keyword().getDescription(),
dto.isSelected());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

import org.springframework.data.jpa.repository.JpaRepository;

public interface EvaluationRepository extends JpaRepository<EvaluationEntity, Long> {}
public interface EvaluationRepository
extends JpaRepository<EvaluationEntity, Long>, EvaluationRepositoryCustom {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.dnd.sbooky.core.evaluation;

import com.dnd.sbooky.core.evaluation.dto.GetEvaluationDTO;
import java.util.List;
import org.springframework.data.repository.NoRepositoryBean;

@NoRepositoryBean
public interface EvaluationRepositoryCustom {

List<GetEvaluationDTO> findAllWithSelectedByMemberBookId(Long memberBookId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.dnd.sbooky.core.evaluation;

import com.dnd.sbooky.core.evaluation.dto.GetEvaluationDTO;
import com.querydsl.core.types.Projections;
import com.querydsl.jpa.impl.JPAQueryFactory;
import java.util.List;
import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
public class EvaluationRepositoryImpl implements EvaluationRepositoryCustom {

private final JPAQueryFactory queryFactory;
private final QEvaluationEntity evaluation = QEvaluationEntity.evaluationEntity;
private final QBookEvaluationEntity bookEvaluation = QBookEvaluationEntity.bookEvaluationEntity;

@Override
public List<GetEvaluationDTO> findAllWithSelectedByMemberBookId(Long memberBookId) {

return queryFactory
.select(
Projections.constructor(
GetEvaluationDTO.class,
evaluation.id,
evaluation.type,
evaluation.keyword,
bookEvaluation.isNotNull().as("isSelected")))
.from(evaluation)
.leftJoin(bookEvaluation)
.on(
bookEvaluation
.evaluation
.id
.eq(evaluation.id)
.and(bookEvaluation.memberBook.id.eq(memberBookId)))
.fetch();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.dnd.sbooky.core.evaluation.dto;

import com.dnd.sbooky.core.evaluation.EvaluationKeyword;
import com.dnd.sbooky.core.evaluation.EvaluationType;

public record GetEvaluationDTO(
Long evaluationId, EvaluationType type, EvaluationKeyword keyword, boolean isSelected) {}

0 comments on commit 02bbbd3

Please sign in to comment.