-
Notifications
You must be signed in to change notification settings - Fork 3
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
refactor: 방/루틴 전체 리팩토링 #143
Merged
Merged
Changes from 8 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
bd89f04
feat: ClockHolder LocalDate 추가
Shin-Jae-Yoon a58f56e
refactor: RoomService 리팩토링
Shin-Jae-Yoon 3c20938
refactor: SearchService 리팩토링
Shin-Jae-Yoon ac0a1de
refactor: 방 입장, 퇴장 리팩토링
Shin-Jae-Yoon 3ff5d17
refactor: CertifiactionService 리팩토링
Shin-Jae-Yoon 73c7e7e
refactor: RoomController 리팩토링
Shin-Jae-Yoon 65ce795
test: InventorySearchRepository 테스트 추가
Shin-Jae-Yoon c1b39f8
Merge branch 'develop' into refactor/#130-room-refactor
Shin-Jae-Yoon ee6e613
Merge branch 'develop' into refactor/#130-room-refactor
Shin-Jae-Yoon b4519ec
refactor: merge 메서드 네이밍
Shin-Jae-Yoon f923a7f
refactor: ParticipantMapper 코드리뷰 반영
Shin-Jae-Yoon 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
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 | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -1,7 +1,9 @@ | ||||||||||
package com.moabam.api.application.room; | ||||||||||
|
||||||||||
import static com.moabam.api.domain.image.ImageType.*; | ||||||||||
import static com.moabam.global.error.model.ErrorMessage.*; | ||||||||||
import static com.moabam.global.error.model.ErrorMessage.DUPLICATED_DAILY_MEMBER_CERTIFICATION; | ||||||||||
import static com.moabam.global.error.model.ErrorMessage.INVALID_CERTIFY_TIME; | ||||||||||
import static com.moabam.global.error.model.ErrorMessage.PARTICIPANT_NOT_FOUND; | ||||||||||
import static com.moabam.global.error.model.ErrorMessage.ROUTINE_NOT_FOUND; | ||||||||||
|
||||||||||
import java.time.LocalDate; | ||||||||||
import java.time.LocalDateTime; | ||||||||||
|
@@ -12,9 +14,7 @@ | |||||||||
|
||||||||||
import org.springframework.stereotype.Service; | ||||||||||
import org.springframework.transaction.annotation.Transactional; | ||||||||||
import org.springframework.web.multipart.MultipartFile; | ||||||||||
|
||||||||||
import com.moabam.api.application.image.ImageService; | ||||||||||
import com.moabam.api.application.member.MemberService; | ||||||||||
import com.moabam.api.application.room.mapper.CertificationsMapper; | ||||||||||
import com.moabam.api.domain.bug.BugType; | ||||||||||
|
@@ -42,7 +42,9 @@ | |||||||||
@Service | ||||||||||
@RequiredArgsConstructor | ||||||||||
@Transactional(readOnly = true) | ||||||||||
public class RoomCertificationService { | ||||||||||
public class CertificationService { | ||||||||||
|
||||||||||
private static final int REQUIRED_ROOM_CERTIFICATION = 75; | ||||||||||
|
||||||||||
private final RoutineRepository routineRepository; | ||||||||||
private final CertificationRepository certificationRepository; | ||||||||||
|
@@ -51,12 +53,11 @@ public class RoomCertificationService { | |||||||||
private final DailyRoomCertificationRepository dailyRoomCertificationRepository; | ||||||||||
private final DailyMemberCertificationRepository dailyMemberCertificationRepository; | ||||||||||
private final MemberService memberService; | ||||||||||
private final ImageService imageService; | ||||||||||
private final ClockHolder clockHolder; | ||||||||||
|
||||||||||
@Transactional | ||||||||||
public void certifyRoom(Long memberId, Long roomId, List<MultipartFile> multipartFiles) { | ||||||||||
LocalDate today = LocalDate.now(); | ||||||||||
public void certifyRoom(Long memberId, Long roomId, List<String> imageUrls) { | ||||||||||
LocalDate today = clockHolder.date(); | ||||||||||
Participant participant = participantSearchRepository.findOne(memberId, roomId) | ||||||||||
.orElseThrow(() -> new NotFoundException(PARTICIPANT_NOT_FOUND)); | ||||||||||
Room room = participant.getRoom(); | ||||||||||
|
@@ -70,47 +71,17 @@ public void certifyRoom(Long memberId, Long roomId, List<MultipartFile> multipar | |||||||||
validateCertifyTime(clockHolder.times(), room.getCertifyTime()); | ||||||||||
validateAlreadyCertified(memberId, roomId, today); | ||||||||||
|
||||||||||
DailyMemberCertification dailyMemberCertification = CertificationsMapper.toDailyMemberCertification(memberId, | ||||||||||
roomId, participant); | ||||||||||
dailyMemberCertificationRepository.save(dailyMemberCertification); | ||||||||||
|
||||||||||
member.increaseTotalCertifyCount(); | ||||||||||
participant.updateCertifyCount(); | ||||||||||
|
||||||||||
List<String> result = imageService.uploadImages(multipartFiles, CERTIFICATION); | ||||||||||
saveNewCertifications(result, memberId); | ||||||||||
certifyMember(memberId, roomId, participant, member, imageUrls); | ||||||||||
|
||||||||||
Optional<DailyRoomCertification> dailyRoomCertification = | ||||||||||
certificationsSearchRepository.findDailyRoomCertification(roomId, today); | ||||||||||
|
||||||||||
if (dailyRoomCertification.isEmpty()) { | ||||||||||
List<DailyMemberCertification> dailyMemberCertifications = | ||||||||||
certificationsSearchRepository.findSortedDailyMemberCertifications(roomId, today); | ||||||||||
double completePercentage = calculateCompletePercentage(dailyMemberCertifications.size(), | ||||||||||
room.getCurrentUserCount()); | ||||||||||
|
||||||||||
if (completePercentage >= 75) { | ||||||||||
DailyRoomCertification createDailyRoomCertification = CertificationsMapper.toDailyRoomCertification( | ||||||||||
roomId, today); | ||||||||||
|
||||||||||
dailyRoomCertificationRepository.save(createDailyRoomCertification); | ||||||||||
|
||||||||||
int expAppliedRoomLevel = getRoomLevelAfterExpApply(roomLevel, room); | ||||||||||
|
||||||||||
List<Long> memberIds = dailyMemberCertifications.stream() | ||||||||||
.map(DailyMemberCertification::getMemberId) | ||||||||||
.toList(); | ||||||||||
|
||||||||||
memberService.getRoomMembers(memberIds) | ||||||||||
.forEach(completedMember -> completedMember.getBug().increaseBug(bugType, expAppliedRoomLevel)); | ||||||||||
|
||||||||||
return; | ||||||||||
} | ||||||||||
certifyRoomIfAvailable(roomId, today, room, bugType, roomLevel); | ||||||||||
return; | ||||||||||
} | ||||||||||
|
||||||||||
if (dailyRoomCertification.isPresent()) { | ||||||||||
member.getBug().increaseBug(bugType, roomLevel); | ||||||||||
} | ||||||||||
member.getBug().increaseBug(bugType, roomLevel); | ||||||||||
} | ||||||||||
|
||||||||||
public boolean existsMemberCertification(Long memberId, Long roomId, LocalDate date) { | ||||||||||
|
@@ -138,7 +109,17 @@ private void validateAlreadyCertified(Long memberId, Long roomId, LocalDate toda | |||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
private void saveNewCertifications(List<String> imageUrls, Long memberId) { | ||||||||||
private void certifyMember(Long memberId, Long roomId, Participant participant, Member member, List<String> urls) { | ||||||||||
DailyMemberCertification dailyMemberCertification = CertificationsMapper.toDailyMemberCertification(memberId, | ||||||||||
roomId, participant); | ||||||||||
dailyMemberCertificationRepository.save(dailyMemberCertification); | ||||||||||
member.increaseTotalCertifyCount(); | ||||||||||
participant.updateCertifyCount(); | ||||||||||
|
||||||||||
saveNewCertifications(memberId, urls); | ||||||||||
} | ||||||||||
|
||||||||||
private void saveNewCertifications(Long memberId, List<String> imageUrls) { | ||||||||||
List<Certification> certifications = new ArrayList<>(); | ||||||||||
|
||||||||||
for (String imageUrl : imageUrls) { | ||||||||||
|
@@ -153,6 +134,23 @@ private void saveNewCertifications(List<String> imageUrls, Long memberId) { | |||||||||
certificationRepository.saveAll(certifications); | ||||||||||
} | ||||||||||
|
||||||||||
private void certifyRoomIfAvailable(Long roomId, LocalDate today, Room room, BugType bugType, int roomLevel) { | ||||||||||
List<DailyMemberCertification> dailyMemberCertifications = | ||||||||||
certificationsSearchRepository.findSortedDailyMemberCertifications(roomId, today); | ||||||||||
double completePercentage = calculateCompletePercentage(dailyMemberCertifications.size(), | ||||||||||
room.getCurrentUserCount()); | ||||||||||
|
||||||||||
if (completePercentage >= REQUIRED_ROOM_CERTIFICATION) { | ||||||||||
DailyRoomCertification createDailyRoomCertification = CertificationsMapper.toDailyRoomCertification( | ||||||||||
roomId, today); | ||||||||||
|
||||||||||
dailyRoomCertificationRepository.save(createDailyRoomCertification); | ||||||||||
int expAppliedRoomLevel = getRoomLevelAfterExpApply(roomLevel, room); | ||||||||||
|
||||||||||
provideBugToCompletedMembers(bugType, dailyMemberCertifications, expAppliedRoomLevel); | ||||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
private double calculateCompletePercentage(int certifiedMembersCount, int currentsMembersCount) { | ||||||||||
double completePercentage = ((double)certifiedMembersCount / currentsMembersCount) * 100; | ||||||||||
|
||||||||||
|
@@ -169,4 +167,14 @@ private int getRoomLevelAfterExpApply(int roomLevel, Room room) { | |||||||||
|
||||||||||
return room.getLevel(); | ||||||||||
} | ||||||||||
|
||||||||||
private void provideBugToCompletedMembers(BugType bugType, List<DailyMemberCertification> dailyMemberCertifications, | ||||||||||
int expAppliedRoomLevel) { | ||||||||||
List<Long> memberIds = dailyMemberCertifications.stream() | ||||||||||
.map(DailyMemberCertification::getMemberId) | ||||||||||
.toList(); | ||||||||||
Comment on lines
+173
to
+175
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.
Suggested change
C: StreamUtils 만들어놓은 것 적용할 수 있을듯! 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. XX : 난 안쓰는게 더 조아! (제 말 아님) |
||||||||||
|
||||||||||
memberService.getRoomMembers(memberIds) | ||||||||||
.forEach(completedMember -> completedMember.getBug().increaseBug(bugType, expAppliedRoomLevel)); | ||||||||||
} | ||||||||||
} |
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
Oops, something went wrong.
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.
오 분리하셨군요 좋습니다!