Skip to content

Commit

Permalink
[BBB-127] ✨Feat: 스터디 설정 API 응답 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
msjang4 committed Sep 30, 2024
1 parent f883136 commit e01d216
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import com.bombombom.devs.external.study.service.dto.result.BookStudyResult;
import com.bombombom.devs.external.study.service.dto.result.StudyDetailsResult;
import com.bombombom.devs.external.study.service.dto.result.StudyProgressResult;
import com.bombombom.devs.external.study.service.dto.result.StudyResult;
import com.bombombom.devs.security.AppUserDetails;
import jakarta.validation.Valid;
import jakarta.validation.constraints.Min;
Expand Down Expand Up @@ -186,17 +185,17 @@ public ResponseEntity<List<AssignmentResult>> editAssignments(
}

@PatchMapping("/{id}/config")
public ResponseEntity<StudyResponse> configureStudy(
public ResponseEntity<Void> configureStudy(
@LoginUser AppUserDetails userDetails,
@PathVariable("id") Long studyId,
@Valid @RequestBody ConfigureStudyRequest configureStudyRequest) {

StudyResult studyResult = studyService.configure(
studyService.configure(
userDetails.getId(),
studyId,
configureStudyRequest.toServiceDto());

return ResponseEntity.ok().body(StudyResponse.fromResult(studyResult));
return ResponseEntity.noContent().build();
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,15 +446,15 @@ public List<AssignmentResult> getAssignments(Long studyId,
public AssignmentVoteResult voteAssignment(Long userId, Long studyId,
VoteAssignmentCommand voteAssignmentCommand) {

// lock
// mysql - repeatable read (phantom read) 격리레벨 강제로 상위로 올리기?
// unit test에서 쓰레드 여러개 쏴보기
Study study = studyRepository.findById(studyId)
.orElseThrow(() -> new NotFoundException(ErrorCode.STUDY_NOT_FOUND));

study.canVote();

if (!userStudyRepository.existsByUserIdAndStudyId(userId, studyId)) {
User user = userRepository.findById(userId)
.orElseThrow(() -> new NotFoundException(ErrorCode.USER_NOT_FOUND));

if (!userStudyRepository.existsByUserIdAndStudyId(user.getId(), studyId)) {
throw new ForbiddenException(ErrorCode.ONLY_MEMBER_ALLOWED);
}

Expand Down Expand Up @@ -485,17 +485,13 @@ public AssignmentVoteResult voteAssignment(Long userId, Long studyId,
AssignmentVote vote = assignmentVoteRepository.findByUserIdAndRound(userId,
nextRound)
.orElseGet(
() -> {
User user = userRepository.findById(userId)
.orElseThrow(() -> new NotFoundException(ErrorCode.USER_NOT_FOUND));

return AssignmentVote.builder()
.user(user)
.first(first)
.second(second)
.round(nextRound)
.build();
});
() -> AssignmentVote.builder()
.user(user)
.first(first)
.second(second)
.round(nextRound)
.build()
);

vote.update(first, second);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,18 @@ public StudyDetailsResult findStudyDetails(Long studyId) {
}

@Transactional
public StudyResult configure(Long userId,
public void configure(Long userId,
Long studyId, ConfigureStudyCommand command) {
//null이면 그냥 오류


command.assertAnyNotNull();

Study study = studyRepository.findWithDifficultiesAndLeaderAndBookById(studyId)
.orElseThrow(() -> new NotFoundException(ErrorCode.STUDY_NOT_FOUND));

study.assertLeader(userId);

if (command.duplicated() != null) {

study.setDuplicated(command.duplicated());
}
study.setDuplicated(command.duplicated());

return StudyResult.fromEntity(study);
}

@Transactional(readOnly = true)
Expand Down Expand Up @@ -138,7 +135,6 @@ public void startVoting(Long userId, Long studyId) {
Study study = studyRepository.findById(
studyId)
.orElseThrow(() -> new NotFoundException(ErrorCode.STUDY_NOT_FOUND));
// 에러메세지가 다양해짐, 나중에 스터디원도 투표시작가능?

study.startVoting(userId);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
package com.bombombom.devs.external.study.service.dto.command;

import com.bombombom.devs.core.exception.ErrorCode;
import com.bombombom.devs.core.exception.InvalidInputException;
import lombok.Builder;

@Builder
public record ConfigureStudyCommand(
Boolean duplicated
) {


public void assertAnyNotNull() {
if (duplicated == null) {
throw new InvalidInputException(ErrorCode.ALL_IS_NULL);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public enum ErrorCode {
// BAD_REQUEST 400
INVALID_INPUT(BAD_REQUEST, 40000, "잘못된 요청입니다."),
NOT_NEXT_ROUND_IDX(BAD_REQUEST, 40001, "다음 라운드의 인덱스가 아닙니다."),
ALL_IS_NULL(BAD_REQUEST, 40002, "모든 설정 값이 널 입니다."),


// UNAUTHORIZED 401
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ public void canEditAssignment(Long userId, Integer roundIdx, Round nextRound) {

@Override
public void setDuplicated(Boolean duplicated) {
if (duplicated == null) {
return;
}

if (votingProcess != VotingProcess.READY) {
throw new BusinessRuleException(ErrorCode.VOTING_PROCESS_NOT_READY);
Expand Down

0 comments on commit e01d216

Please sign in to comment.