Skip to content

Commit

Permalink
feat: 리뷰 등록시 userService 로직 추가 (#224)
Browse files Browse the repository at this point in the history
  • Loading branch information
choidongkuen committed Feb 16, 2024
1 parent 1761924 commit 7ec6b2e
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions src/main/java/net/teumteum/user/service/UserService.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package net.teumteum.user.service;

import java.time.LocalDateTime;
import java.util.List;
import lombok.RequiredArgsConstructor;
import net.teumteum.core.security.Authenticated;
import net.teumteum.core.security.service.JwtService;
import net.teumteum.core.security.service.RedisService;
import net.teumteum.core.security.service.SecurityService;
import net.teumteum.meeting.domain.Meeting;
import net.teumteum.meeting.domain.MeetingConnector;
import net.teumteum.user.domain.BalanceGameType;
import net.teumteum.user.domain.InterestQuestion;
Expand Down Expand Up @@ -109,7 +111,10 @@ public void logout(Long userId) {

@Transactional
public void registerReview(Long meetingId, Long currentUserId, ReviewRegisterRequest request) {
checkMeetingExistence(meetingId);
var meeting = getMeeting(meetingId);

checkMeetingIsClosed(meeting);
checkUserParticipationInMeeting(meeting, currentUserId);
checkUserNotRegisterSelfReview(request, currentUserId);

request.reviews()
Expand Down Expand Up @@ -157,12 +162,9 @@ private void checkUserExistence(Authenticated authenticated, String oauthId) {
);
}

private void checkMeetingExistence(Long meetingId) {
Assert.isTrue(meetingConnector.existById(meetingId),
() -> {
throw new IllegalArgumentException("meetingId에 해당하는 meeting을 찾을 수 없습니다. \"" + meetingId + "\"");
}
);
private Meeting getMeeting(Long meetingId) {
return meetingConnector.findById(meetingId)
.orElseThrow(() -> new IllegalArgumentException("meetingId에 해당하는 모임을 찾을 수 없습니다. \"" + meetingId + "\""));
}

private void checkUserNotRegisterSelfReview(ReviewRegisterRequest request, Long currentUserId) {
Expand All @@ -172,4 +174,16 @@ private void checkUserNotRegisterSelfReview(ReviewRegisterRequest request, Long
}
);
}

private void checkUserParticipationInMeeting(Meeting meeting, Long userId) {
if (!meeting.getParticipantUserIds().contains(userId)) {
throw new IllegalArgumentException("모임에 참여하지 않은 회원입니다.");
}
}

private void checkMeetingIsClosed(Meeting meeting) {
if (!LocalDateTime.now().isAfter(meeting.getPromiseDateTime())) {
throw new IllegalArgumentException("해당 모임은 아직 종료되지 않았습니다.");
}
}
}

0 comments on commit 7ec6b2e

Please sign in to comment.