-
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
[FEAT] 수정된 주제, 선택지 조회 API 반영 #53
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
5ddabf7
refactor: 예외 처리 회의 결과에 따라 exception 패키지 분리 및 이름 변경
leegwichan f876f78
feat: 변경된 ERD (v1.1) 적용
leegwichan e2963a6
feat: 변경된 '주제, 선택지 조회' API 반영
leegwichan 2b575f3
style: 바뀐 Exception 이름에 따라, GlobalExceptionHandler 메서드 명 변경
leegwichan 4b6ac2a
style: total_round가 current_round 보다 앞에 있도록 수정 #52
leegwichan a580383
feat: 변경된 정책에 따라, 밸런스 게임의 현재 내용 조회 구현 수정 #52
leegwichan 8900a29
style: 중복을 줄이기 위해, exception 이름 변경 #52
leegwichan 8853706
feat: currentRound의 기본 값 설정 #52
leegwichan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
14 changes: 9 additions & 5 deletions
14
backend/src/main/java/ddangkong/controller/balance/content/dto/BalanceContentResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
backend/src/main/java/ddangkong/domain/balance/content/RoomRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package ddangkong.domain.balance.content; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface RoomRepository extends JpaRepository<Room, Long> { | ||
} |
8 changes: 8 additions & 0 deletions
8
backend/src/main/java/ddangkong/exception/BadRequestException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package ddangkong.exception; | ||
|
||
public class BadRequestException extends RuntimeException { | ||
|
||
public BadRequestException(String message) { | ||
super(message); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
backend/src/main/java/ddangkong/exception/InternalServerException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package ddangkong.exception; | ||
|
||
public class InternalServerException extends RuntimeException { | ||
|
||
public InternalServerException(String message) { | ||
super(message); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,11 +2,14 @@ | |
|
||
import ddangkong.controller.balance.content.dto.BalanceContentResponse; | ||
import ddangkong.domain.balance.content.BalanceContent; | ||
import ddangkong.domain.balance.content.Room; | ||
import ddangkong.domain.balance.content.RoomContent; | ||
import ddangkong.domain.balance.content.RoomContentRepository; | ||
import ddangkong.domain.balance.content.RoomRepository; | ||
import ddangkong.domain.balance.option.BalanceOption; | ||
import ddangkong.domain.balance.option.BalanceOptionRepository; | ||
import ddangkong.service.excpetion.BusinessLogicException; | ||
import ddangkong.service.excpetion.ViolateDataException; | ||
import ddangkong.exception.BadRequestException; | ||
import ddangkong.exception.InternalServerException; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
@@ -18,26 +21,29 @@ public class BalanceContentService { | |
|
||
private static final int BALANCE_OPTION_SIZE = 2; | ||
|
||
private final RoomRepository roomRepository; | ||
|
||
private final RoomContentRepository roomContentRepository; | ||
|
||
private final BalanceOptionRepository balanceOptionRepository; | ||
|
||
@Transactional(readOnly = true) | ||
public BalanceContentResponse findRecentBalanceContent(Long roomId) { | ||
BalanceContent balanceContent = findRecentContent(roomId); | ||
List<BalanceOption> balanceOptions = findBalanceOptions(balanceContent); | ||
RoomContent roomContent = findCurrentRoomContent(roomId); | ||
List<BalanceOption> balanceOptions = findBalanceOptions(roomContent.getBalanceContent()); | ||
|
||
return BalanceContentResponse.builder() | ||
.balanceContent(balanceContent) | ||
.roomContent(roomContent) | ||
.firstOption(balanceOptions.get(0)) | ||
.secondOption(balanceOptions.get(1)) | ||
.build(); | ||
} | ||
|
||
private BalanceContent findRecentContent(Long roomId) { | ||
return roomContentRepository.findTopByRoomIdOrderByCreatedAtDesc(roomId) | ||
.orElseThrow(() -> new BusinessLogicException("해당 방의 질문이 존재하지 않습니다.")) | ||
.getBalanceContent(); | ||
private RoomContent findCurrentRoomContent(Long roomId) { | ||
Room room = roomRepository.findById(roomId) | ||
.orElseThrow(() -> new BadRequestException("해당 방이 존재하지 않습니다.")); | ||
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. 사소한 의견) 이후에 중복 로직이 될 것 같아서 Repository에서 getById로 만들어두는 것은 어떨까 싶습니다:) |
||
return roomContentRepository.findByRoomAndRound(room, room.getCurrentRound()) | ||
.orElseThrow(() -> new BadRequestException("해당 방의 현재 진행중인 질문이 존재하지 않습니다.")); | ||
} | ||
|
||
private List<BalanceOption> findBalanceOptions(BalanceContent balanceContent) { | ||
|
@@ -48,7 +54,7 @@ private List<BalanceOption> findBalanceOptions(BalanceContent balanceContent) { | |
|
||
private void validateBalanceOptions(List<BalanceOption> balanceOptions) { | ||
if (balanceOptions.size() != BALANCE_OPTION_SIZE) { | ||
throw new ViolateDataException("밸런스 게임의 선택지가 %d개입니다".formatted(balanceOptions.size())); | ||
throw new InternalServerException("밸런스 게임의 선택지가 %d개입니다".formatted(balanceOptions.size())); | ||
} | ||
} | ||
} |
8 changes: 0 additions & 8 deletions
8
backend/src/main/java/ddangkong/service/excpetion/BusinessLogicException.java
This file was deleted.
Oops, something went wrong.
8 changes: 0 additions & 8 deletions
8
backend/src/main/java/ddangkong/service/excpetion/ViolateDataException.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
사소한 의견) default 값이지만 필드 주입보다는 생성자에서 넣는 것은 어떠신지요..!
곧 바뀔 거긴 한데 불..편합니다.. 못참겠어요ㅋㅋㅋㅋㅋ
사실 바꿀거면 지금이 눈에 잘띄어서 괜찮을 것 같기도 해서 사소한 의견으로 남겨봅니당ㅎㅎ
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.
나중에 Room 생성 기능 구현 때에 추가하는 것이 좋을 것 같습니다! 이번에는 넘기도록 하겠습니다~