From 92ef4a7d1b3b97735707fc9aca87a5aac68b85ab Mon Sep 17 00:00:00 2001 From: chaewonkim Date: Sat, 13 Jul 2024 06:27:57 +0900 Subject: [PATCH 1/7] [fix] #54 add Transactional in service --- .../java/org/kkumulkkum/server/external/NaverService.java | 2 ++ .../kkumulkkum/server/service/meeting/MeetingService.java | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/src/main/java/org/kkumulkkum/server/external/NaverService.java b/src/main/java/org/kkumulkkum/server/external/NaverService.java index 0147c62..235ebb9 100644 --- a/src/main/java/org/kkumulkkum/server/external/NaverService.java +++ b/src/main/java/org/kkumulkkum/server/external/NaverService.java @@ -7,6 +7,7 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpStatusCode; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; import org.springframework.web.client.RestClient; @@ -28,6 +29,7 @@ public class NaverService { @Value("${naver.location-search-url}") private String naverLocationSearchUrl; + @Transactional(readOnly = true) public List getLocations(String query) { try { NaverLocationResponse naverLocationResponse = locationSearch(requestMap(query)); diff --git a/src/main/java/org/kkumulkkum/server/service/meeting/MeetingService.java b/src/main/java/org/kkumulkkum/server/service/meeting/MeetingService.java index 60091a3..18f4935 100644 --- a/src/main/java/org/kkumulkkum/server/service/meeting/MeetingService.java +++ b/src/main/java/org/kkumulkkum/server/service/meeting/MeetingService.java @@ -17,6 +17,7 @@ import org.kkumulkkum.server.service.member.MemberSaver; import org.kkumulkkum.server.service.user.UserRetriever; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import java.security.SecureRandom; import java.util.List; @@ -32,6 +33,7 @@ public class MeetingService { private final MemberSaver memberSaver; private final MemberRetreiver memberRetreiver; + @Transactional public CreatedMeetingDto createMeeting( Long userId, MeetingCreateDto meetingCreateDto ) { @@ -51,6 +53,7 @@ public CreatedMeetingDto createMeeting( return new CreatedMeetingDto(meeting.getId(), meeting.getInvitationCode()); } + @Transactional public void registerMeeting(Long userId, MeetingRegisterDto meetingRegisterDto) { Meeting meeting = meetingRetriever.findByInvitationCode(meetingRegisterDto.invitationCode()); Member member = Member.builder() @@ -63,15 +66,18 @@ public void registerMeeting(Long userId, MeetingRegisterDto meetingRegisterDto) memberSaver.save(member); } + @Transactional(readOnly = true) public MeetingsDto getMeetings(Long userId) { List meetings = meetingRetriever.findAllByUserId(userId); return MeetingsDto.of(meetings); } + @Transactional(readOnly = true) public MeetingDto getMeeting(Long meetingId) { return MeetingDto.of(meetingRetriever.findById(meetingId)); } + @Transactional(readOnly = true) public MembersDto getMembers(Long meetingId) { List members = memberRetreiver.findAllByMeetingId(meetingId); return MembersDto.of(members); From b4262cb265c38932214740771b327c437aa3d5f6 Mon Sep 17 00:00:00 2001 From: chaewonkim Date: Mon, 15 Jul 2024 01:26:38 +0900 Subject: [PATCH 2/7] [fix] #54 edit dto method name (from/of) --- .../kkumulkkum/server/dto/meeting/response/MeetingDto.java | 2 +- .../kkumulkkum/server/dto/meeting/response/MeetingsDto.java | 6 +++--- .../kkumulkkum/server/dto/member/response/MembersDto.java | 2 +- .../dto/participant/ParticipantStatusUserInfoDto.java | 2 +- src/main/java/org/kkumulkkum/server/dto/test/TestDto.java | 2 +- .../kkumulkkum/server/service/meeting/MeetingService.java | 6 +++--- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/kkumulkkum/server/dto/meeting/response/MeetingDto.java b/src/main/java/org/kkumulkkum/server/dto/meeting/response/MeetingDto.java index a43508b..a6e5caa 100644 --- a/src/main/java/org/kkumulkkum/server/dto/meeting/response/MeetingDto.java +++ b/src/main/java/org/kkumulkkum/server/dto/meeting/response/MeetingDto.java @@ -13,7 +13,7 @@ public record MeetingDto ( int metCount, String invitationCode ) { - public static MeetingDto of(Meeting meeting) { + public static MeetingDto from(Meeting meeting) { return new MeetingDto( meeting.getId(), meeting.getName(), diff --git a/src/main/java/org/kkumulkkum/server/dto/meeting/response/MeetingsDto.java b/src/main/java/org/kkumulkkum/server/dto/meeting/response/MeetingsDto.java index ec1bf2d..b718d8b 100644 --- a/src/main/java/org/kkumulkkum/server/dto/meeting/response/MeetingsDto.java +++ b/src/main/java/org/kkumulkkum/server/dto/meeting/response/MeetingsDto.java @@ -9,11 +9,11 @@ public record MeetingsDto ( List meetings ) { - public static MeetingsDto of(List meetings) { + public static MeetingsDto from(List meetings) { return new MeetingsDto( meetings.size(), meetings.stream() - .map(MeetingDto::of) + .map(MeetingDto::from) .toList() ); } @@ -23,7 +23,7 @@ public record MeetingDto ( String name, int memberCount ) { - public static MeetingDto of(Meeting meeting) { + public static MeetingDto from(Meeting meeting) { return new MeetingDto( meeting.getId(), meeting.getName(), diff --git a/src/main/java/org/kkumulkkum/server/dto/member/response/MembersDto.java b/src/main/java/org/kkumulkkum/server/dto/member/response/MembersDto.java index 184a677..3875f92 100644 --- a/src/main/java/org/kkumulkkum/server/dto/member/response/MembersDto.java +++ b/src/main/java/org/kkumulkkum/server/dto/member/response/MembersDto.java @@ -6,7 +6,7 @@ public record MembersDto( int memberCount, List members ) { - public static MembersDto of(List members) { + public static MembersDto from(List members) { return new MembersDto( members.size(), members diff --git a/src/main/java/org/kkumulkkum/server/dto/participant/ParticipantStatusUserInfoDto.java b/src/main/java/org/kkumulkkum/server/dto/participant/ParticipantStatusUserInfoDto.java index 8dc7219..698355b 100644 --- a/src/main/java/org/kkumulkkum/server/dto/participant/ParticipantStatusUserInfoDto.java +++ b/src/main/java/org/kkumulkkum/server/dto/participant/ParticipantStatusUserInfoDto.java @@ -11,7 +11,7 @@ public record ParticipantStatusUserInfoDto( LocalDateTime departureAt, LocalDateTime arrivalAt ) { - public static ParticipantStatusUserInfoDto from( + public static ParticipantStatusUserInfoDto of( Long participantId, Long memberId, String name, diff --git a/src/main/java/org/kkumulkkum/server/dto/test/TestDto.java b/src/main/java/org/kkumulkkum/server/dto/test/TestDto.java index 696f249..b7825f9 100644 --- a/src/main/java/org/kkumulkkum/server/dto/test/TestDto.java +++ b/src/main/java/org/kkumulkkum/server/dto/test/TestDto.java @@ -3,7 +3,7 @@ public record TestDto( String test ) { - public static TestDto of (String test) { + public static TestDto from(String test) { return new TestDto(test); } } diff --git a/src/main/java/org/kkumulkkum/server/service/meeting/MeetingService.java b/src/main/java/org/kkumulkkum/server/service/meeting/MeetingService.java index 18f4935..54df011 100644 --- a/src/main/java/org/kkumulkkum/server/service/meeting/MeetingService.java +++ b/src/main/java/org/kkumulkkum/server/service/meeting/MeetingService.java @@ -69,18 +69,18 @@ public void registerMeeting(Long userId, MeetingRegisterDto meetingRegisterDto) @Transactional(readOnly = true) public MeetingsDto getMeetings(Long userId) { List meetings = meetingRetriever.findAllByUserId(userId); - return MeetingsDto.of(meetings); + return MeetingsDto.from(meetings); } @Transactional(readOnly = true) public MeetingDto getMeeting(Long meetingId) { - return MeetingDto.of(meetingRetriever.findById(meetingId)); + return MeetingDto.from(meetingRetriever.findById(meetingId)); } @Transactional(readOnly = true) public MembersDto getMembers(Long meetingId) { List members = memberRetreiver.findAllByMeetingId(meetingId); - return MembersDto.of(members); + return MembersDto.from(members); } private String generateInvitationCode() { From 95a09768353bcebfa509adf5ae7801b5dfbb84b0 Mon Sep 17 00:00:00 2001 From: chaewonkim Date: Mon, 15 Jul 2024 02:18:58 +0900 Subject: [PATCH 3/7] [fix] #54 add final in arguments --- .../server/controller/LocationController.java | 2 +- .../server/controller/MeetingController.java | 14 +++--- .../controller/ParticipantController.java | 12 ++--- .../server/controller/PromiseController.java | 8 +-- .../service/meeting/MeetingRetriever.java | 8 +-- .../service/meeting/MeetingService.java | 14 ++++-- .../service/member/MemberRetreiver.java | 12 +++-- .../participant/ParticipantEditor.java | 10 +++- .../participant/ParticipantRetriever.java | 16 ++++-- .../service/participant/ParticipantSaver.java | 6 +-- .../participant/ParticipantService.java | 49 ++++++++++++++----- .../server/service/promise/PromiseEditor.java | 2 +- .../service/promise/PromiseRetriever.java | 41 ++++++++++++---- .../server/service/promise/PromiseSaver.java | 2 +- .../service/promise/PromiseService.java | 17 +++++-- .../server/service/user/UserRetriever.java | 10 +++- .../server/service/user/UserService.java | 12 +++-- .../service/userInfo/UserInfoEditor.java | 12 +++-- 18 files changed, 169 insertions(+), 78 deletions(-) diff --git a/src/main/java/org/kkumulkkum/server/controller/LocationController.java b/src/main/java/org/kkumulkkum/server/controller/LocationController.java index c1a9424..28ceaf2 100644 --- a/src/main/java/org/kkumulkkum/server/controller/LocationController.java +++ b/src/main/java/org/kkumulkkum/server/controller/LocationController.java @@ -20,7 +20,7 @@ public class LocationController { @GetMapping("/locations") public ResponseEntity> getLocations( - @RequestParam(name="q") String query + @RequestParam(name="q") final String query ) { return ResponseEntity.ok(naverService.getLocations(query)); } diff --git a/src/main/java/org/kkumulkkum/server/controller/MeetingController.java b/src/main/java/org/kkumulkkum/server/controller/MeetingController.java index 97a63a3..c3e4ec2 100644 --- a/src/main/java/org/kkumulkkum/server/controller/MeetingController.java +++ b/src/main/java/org/kkumulkkum/server/controller/MeetingController.java @@ -25,8 +25,8 @@ public class MeetingController { @PostMapping("/meetings") public ResponseEntity createMeeting( - @UserId Long userId, - @Valid @RequestBody MeetingCreateDto meetingCreateDto + @UserId final Long userId, + @Valid @RequestBody final MeetingCreateDto meetingCreateDto ) { CreatedMeetingDto createdMeetingDto = meetingService.createMeeting(userId, meetingCreateDto); return ResponseEntity @@ -36,8 +36,8 @@ public ResponseEntity createMeeting( @PostMapping("/meetings/register") public ResponseEntity registerMeeting( - @UserId Long userId, - @Valid @RequestBody MeetingRegisterDto meetingRegisterDto + @UserId final Long userId, + @Valid @RequestBody final MeetingRegisterDto meetingRegisterDto ) { meetingService.registerMeeting(userId, meetingRegisterDto); return ResponseEntity.ok().build(); @@ -45,7 +45,7 @@ public ResponseEntity registerMeeting( @GetMapping("/meetings") public ResponseEntity getMeetings( - @UserId Long userId + @UserId final Long userId ) { return ResponseEntity.ok(meetingService.getMeetings(userId)); } @@ -53,7 +53,7 @@ public ResponseEntity getMeetings( @IsMember(meetingIdParamIndex = 0) @GetMapping("/meetings/{meetingId}") public ResponseEntity getMeeting( - @PathVariable Long meetingId + @PathVariable final Long meetingId ) { return ResponseEntity.ok(meetingService.getMeeting(meetingId)); } @@ -61,7 +61,7 @@ public ResponseEntity getMeeting( @IsMember(meetingIdParamIndex = 0) @GetMapping("/meetings/{meetingId}/members") public ResponseEntity getMembers( - @PathVariable Long meetingId + @PathVariable final Long meetingId ) { return ResponseEntity.ok(meetingService.getMembers(meetingId)); } diff --git a/src/main/java/org/kkumulkkum/server/controller/ParticipantController.java b/src/main/java/org/kkumulkkum/server/controller/ParticipantController.java index 67c25f2..45efd56 100644 --- a/src/main/java/org/kkumulkkum/server/controller/ParticipantController.java +++ b/src/main/java/org/kkumulkkum/server/controller/ParticipantController.java @@ -20,8 +20,8 @@ public class ParticipantController { @PatchMapping("/promises/{promiseId}/preperation") public ResponseEntity preparePromise( - @UserId Long userId, - @PathVariable Long promiseId + @UserId final Long userId, + @PathVariable final Long promiseId ) { participantService.preparePromise(userId, promiseId); return ResponseEntity.ok().build(); @@ -29,8 +29,8 @@ public ResponseEntity preparePromise( @PatchMapping("/promises/{promiseId}/departure") public ResponseEntity departurePromise( - @UserId Long userId, - @PathVariable Long promiseId + @UserId final Long userId, + @PathVariable final Long promiseId ) { participantService.departurePromise(userId, promiseId); return ResponseEntity.ok().build(); @@ -38,8 +38,8 @@ public ResponseEntity departurePromise( @PatchMapping("/promises/{promiseId}/arrival") public ResponseEntity arrivalPromise( - @UserId Long userId, - @PathVariable Long promiseId + @UserId final Long userId, + @PathVariable final Long promiseId ) { participantService.arrivalPromise(userId, promiseId); return ResponseEntity.ok().build(); diff --git a/src/main/java/org/kkumulkkum/server/controller/PromiseController.java b/src/main/java/org/kkumulkkum/server/controller/PromiseController.java index ba1c153..8d07fd5 100644 --- a/src/main/java/org/kkumulkkum/server/controller/PromiseController.java +++ b/src/main/java/org/kkumulkkum/server/controller/PromiseController.java @@ -26,9 +26,9 @@ public class PromiseController { @IsMember(meetingIdParamIndex = 1) @PostMapping("/meetings/{meetingId}/promises") public ResponseEntity createPromise( - @UserId Long userId, - @PathVariable Long meetingId, - @Valid @RequestBody PromiseCreateDto createPromiseDto + @UserId final Long userId, + @PathVariable final Long meetingId, + @Valid @RequestBody final PromiseCreateDto createPromiseDto ) { Long promiseId = promiseService.createPromise(userId, meetingId, createPromiseDto); return ResponseEntity.created(URI.create(promiseId.toString())).build(); @@ -37,7 +37,7 @@ public ResponseEntity createPromise( @IsParticipant(promiseIdParamIndex = 0) @PatchMapping("/promises/{promiseId}/completion") public ResponseEntity completePromise( - @PathVariable Long promiseId + @PathVariable final Long promiseId ) { promiseService.completePromise(promiseId); return ResponseEntity.ok().build(); diff --git a/src/main/java/org/kkumulkkum/server/service/meeting/MeetingRetriever.java b/src/main/java/org/kkumulkkum/server/service/meeting/MeetingRetriever.java index f82d331..28508c3 100644 --- a/src/main/java/org/kkumulkkum/server/service/meeting/MeetingRetriever.java +++ b/src/main/java/org/kkumulkkum/server/service/meeting/MeetingRetriever.java @@ -15,20 +15,20 @@ public class MeetingRetriever { private final MeetingRepository meetingRepository; - public boolean existsByInvitationCode(String invitationCode) { + public boolean existsByInvitationCode(final String invitationCode) { return meetingRepository.existsByInvitationCode(invitationCode); } - public Meeting findByInvitationCode(String invitationCode) { + public Meeting findByInvitationCode(final String invitationCode) { return meetingRepository.findByInvitationCode(invitationCode) .orElseThrow(() -> new MeetingException(MeetingErrorCode.NOT_FOUND_MEETING)); } - public List findAllByUserId(Long userId) { + public List findAllByUserId(final Long userId) { return meetingRepository.findAllByUserId(userId); } - public Meeting findById(Long meetingId) { + public Meeting findById(final Long meetingId) { return meetingRepository.findById(meetingId) .orElseThrow(() -> new MeetingException(MeetingErrorCode.NOT_FOUND_MEETING)); } diff --git a/src/main/java/org/kkumulkkum/server/service/meeting/MeetingService.java b/src/main/java/org/kkumulkkum/server/service/meeting/MeetingService.java index 54df011..010cf8d 100644 --- a/src/main/java/org/kkumulkkum/server/service/meeting/MeetingService.java +++ b/src/main/java/org/kkumulkkum/server/service/meeting/MeetingService.java @@ -35,7 +35,8 @@ public class MeetingService { @Transactional public CreatedMeetingDto createMeeting( - Long userId, MeetingCreateDto meetingCreateDto + final Long userId, + final MeetingCreateDto meetingCreateDto ) { String invitationCode = generateInvitationCode(); @@ -54,7 +55,10 @@ public CreatedMeetingDto createMeeting( } @Transactional - public void registerMeeting(Long userId, MeetingRegisterDto meetingRegisterDto) { + public void registerMeeting( + final Long userId, + final MeetingRegisterDto meetingRegisterDto + ) { Meeting meeting = meetingRetriever.findByInvitationCode(meetingRegisterDto.invitationCode()); Member member = Member.builder() .meeting(meeting) @@ -67,18 +71,18 @@ public void registerMeeting(Long userId, MeetingRegisterDto meetingRegisterDto) } @Transactional(readOnly = true) - public MeetingsDto getMeetings(Long userId) { + public MeetingsDto getMeetings(final Long userId) { List meetings = meetingRetriever.findAllByUserId(userId); return MeetingsDto.from(meetings); } @Transactional(readOnly = true) - public MeetingDto getMeeting(Long meetingId) { + public MeetingDto getMeeting(final Long meetingId) { return MeetingDto.from(meetingRetriever.findById(meetingId)); } @Transactional(readOnly = true) - public MembersDto getMembers(Long meetingId) { + public MembersDto getMembers(final Long meetingId) { List members = memberRetreiver.findAllByMeetingId(meetingId); return MembersDto.from(members); } diff --git a/src/main/java/org/kkumulkkum/server/service/member/MemberRetreiver.java b/src/main/java/org/kkumulkkum/server/service/member/MemberRetreiver.java index 0ef45ea..1deff3e 100644 --- a/src/main/java/org/kkumulkkum/server/service/member/MemberRetreiver.java +++ b/src/main/java/org/kkumulkkum/server/service/member/MemberRetreiver.java @@ -13,15 +13,21 @@ public class MemberRetreiver { private final MemberRepository memberRepository; - public boolean existsByMeetingIdAndUserId(Long meetingId, Long userId) { + public boolean existsByMeetingIdAndUserId( + final Long meetingId, + final Long userId + ) { return memberRepository.existsByMeetingIdAndUserId(meetingId, userId); } - public List findAllByMeetingId(Long meetingId) { + public List findAllByMeetingId(final Long meetingId) { return memberRepository.findAllByMeetingId(meetingId); } - public boolean existsByPromiseIdAndUserId(Long promiseId, Long userId) { + public boolean existsByPromiseIdAndUserId( + final Long promiseId, + final Long userId + ) { return memberRepository.existsByPromiseIdAndUserId(promiseId, userId); } } diff --git a/src/main/java/org/kkumulkkum/server/service/participant/ParticipantEditor.java b/src/main/java/org/kkumulkkum/server/service/participant/ParticipantEditor.java index 02a8839..caf5a76 100644 --- a/src/main/java/org/kkumulkkum/server/service/participant/ParticipantEditor.java +++ b/src/main/java/org/kkumulkkum/server/service/participant/ParticipantEditor.java @@ -21,11 +21,17 @@ public void arrivalPromise(final Participant participant) { participant.arrivalPromise(); } - public void updatePreparationTime(Participant participant, PreparationInfoDto preparationInfoDto) { + public void updatePreparationTime( + final Participant participant, + final PreparationInfoDto preparationInfoDto + ) { participant.updatePreparationTime(preparationInfoDto.preparationTime()); } - public void updateTravelTime(Participant participant, PreparationInfoDto preparationInfoDto) { + public void updateTravelTime( + final Participant participant, + final PreparationInfoDto preparationInfoDto + ) { participant.updateTravelTime(preparationInfoDto.travelTime()); } } diff --git a/src/main/java/org/kkumulkkum/server/service/participant/ParticipantRetriever.java b/src/main/java/org/kkumulkkum/server/service/participant/ParticipantRetriever.java index defc504..cd92cff 100644 --- a/src/main/java/org/kkumulkkum/server/service/participant/ParticipantRetriever.java +++ b/src/main/java/org/kkumulkkum/server/service/participant/ParticipantRetriever.java @@ -17,24 +17,30 @@ public class ParticipantRetriever { private final ParticipantRepository participantRepository; - public Participant findByPromiseIdAndUserId(Long promiseId, Long userId) { + public Participant findByPromiseIdAndUserId( + final Long promiseId, + final Long userId + ) { return participantRepository.findByPromiseIdAndUserId(promiseId, userId) .orElseThrow(() -> new ParticipantException(ParticipantErrorCode.NOT_JOINED_PROMISE)); } - public List findAllByPromiseId(Long promiseId) { + public List findAllByPromiseId(final Long promiseId) { return participantRepository.findAllByPromiseId(promiseId); } - public List findAllByPromiseIdWithUserInfo(Long promiseId) { + public List findAllByPromiseIdWithUserInfo(final Long promiseId) { return participantRepository.findAllByPromiseIdWithUserInfo(promiseId); } - public List findAllLateComersByPromiseId(Long promiseId) { + public List findAllLateComersByPromiseId(final Long promiseId) { return participantRepository.findAllLateComersByPromiseId(promiseId); } - public boolean existsByPromiseIdAndUserId(Long promiseId, Long userId) { + public boolean existsByPromiseIdAndUserId( + final Long promiseId, + final Long userId + ) { return participantRepository.existsByPromiseIdAndUserId(promiseId, userId); } } diff --git a/src/main/java/org/kkumulkkum/server/service/participant/ParticipantSaver.java b/src/main/java/org/kkumulkkum/server/service/participant/ParticipantSaver.java index 8f06300..8012b6d 100644 --- a/src/main/java/org/kkumulkkum/server/service/participant/ParticipantSaver.java +++ b/src/main/java/org/kkumulkkum/server/service/participant/ParticipantSaver.java @@ -13,11 +13,7 @@ public class ParticipantSaver { private final ParticipantRepository participantRepository; - public void save(Participant participant) { - participantRepository.save(participant); - } - - public void saveAll(List participants) { + public void saveAll(final List participants) { participantRepository.saveAll(participants); } } diff --git a/src/main/java/org/kkumulkkum/server/service/participant/ParticipantService.java b/src/main/java/org/kkumulkkum/server/service/participant/ParticipantService.java index 6b7fc82..71dd72f 100644 --- a/src/main/java/org/kkumulkkum/server/service/participant/ParticipantService.java +++ b/src/main/java/org/kkumulkkum/server/service/participant/ParticipantService.java @@ -28,7 +28,10 @@ public class ParticipantService { private final PromiseRetriever promiseRetriever; @Transactional - public void preparePromise(final Long userId, final Long promiseId) { + public void preparePromise( + final Long userId, + final Long promiseId + ) { Participant participant = participantRetriever.findByPromiseIdAndUserId(promiseId, userId); if (!validateState(participant, "preperation")) { throw new ParticipantException(ParticipantErrorCode.INVALID_STATE); @@ -37,7 +40,10 @@ public void preparePromise(final Long userId, final Long promiseId) { } @Transactional - public void departurePromise(final Long userId, final Long promiseId) { + public void departurePromise( + final Long userId, + final Long promiseId + ) { Participant participant = participantRetriever.findByPromiseIdAndUserId(promiseId, userId); if (!validateState(participant, "departure")) { throw new ParticipantException(ParticipantErrorCode.INVALID_STATE); @@ -46,7 +52,10 @@ public void departurePromise(final Long userId, final Long promiseId) { } @Transactional - public void arrivalPromise(final Long userId, final Long promiseId) { + public void arrivalPromise( + final Long userId, + final Long promiseId + ) { Participant participant = participantRetriever.findByPromiseIdAndUserId(promiseId, userId); if (!validateState(participant, "arrival")) { throw new ParticipantException(ParticipantErrorCode.INVALID_STATE); @@ -55,7 +64,10 @@ public void arrivalPromise(final Long userId, final Long promiseId) { } @Transactional(readOnly = true) - public PreparationStatusDto getPreparation(final Long userId, final Long promiseId) { + public PreparationStatusDto getPreparation( + final Long userId, + final Long promiseId + ) { Participant participant = participantRetriever.findByPromiseIdAndUserId(promiseId, userId); return PreparationStatusDto.from(participant); } @@ -71,7 +83,11 @@ public ParticipantsDto getParticipants(final Long promiseId) { } @Transactional - public void insertPreparationInfo(final Long userId, final Long promiseId, final PreparationInfoDto preparationInfoDto) { + public void insertPreparationInfo( + final Long userId, + final Long promiseId, + final PreparationInfoDto preparationInfoDto + ) { Participant participant = participantRetriever.findByPromiseIdAndUserId(promiseId, userId); participantEditor.updatePreparationTime(participant, preparationInfoDto); participantEditor.updateTravelTime(participant, preparationInfoDto); @@ -89,12 +105,19 @@ public LateComersDto getLateComers(final Long promiseId) { return LateComersDto.of( promise, lateComers.stream() - .map(lateComer -> LateComerDto.of(lateComer.participantId(), lateComer.name(), lateComer.profileImg())) + .map(lateComer -> LateComerDto.of( + lateComer.participantId(), + lateComer.name(), + lateComer.profileImg()) + ) .collect(Collectors.toList()) ); } - private boolean validateState(final Participant participant, final String status) { + private boolean validateState( + final Participant participant, + final String status + ) { switch (status) { case "preperation": return isNull(participant.getPreparationStartAt()) @@ -113,24 +136,24 @@ && isNotNull(participant.getDepartureAt()) } } - private boolean isNull(LocalDateTime time) { + private boolean isNull(final LocalDateTime time) { return time == null; } - private boolean isNotNull(LocalDateTime time) { + private boolean isNotNull(final LocalDateTime time) { return time != null; } - private ParticipantDto createParticipantDto(ParticipantStatusUserInfoDto dto) { + private ParticipantDto createParticipantDto(final ParticipantStatusUserInfoDto dto) { String state = determineState(dto.preparationAt(), dto.departureAt(), dto.arrivalAt()); // 상태 결정 로직 호출 return ParticipantDto.of(dto.participantId(), dto.memberId(), dto.name(), dto.profileImg(), state); } private String determineState( - LocalDateTime preparationAt, - LocalDateTime departureAt, - LocalDateTime arrivalAt + final LocalDateTime preparationAt, + final LocalDateTime departureAt, + final LocalDateTime arrivalAt ) { if (arrivalAt != null) { return "도착"; diff --git a/src/main/java/org/kkumulkkum/server/service/promise/PromiseEditor.java b/src/main/java/org/kkumulkkum/server/service/promise/PromiseEditor.java index fac4dba..71b3df5 100644 --- a/src/main/java/org/kkumulkkum/server/service/promise/PromiseEditor.java +++ b/src/main/java/org/kkumulkkum/server/service/promise/PromiseEditor.java @@ -6,7 +6,7 @@ @Component public class PromiseEditor { - public void completePromise(Promise promise) { + public void completePromise(final Promise promise) { promise.complete(); } } diff --git a/src/main/java/org/kkumulkkum/server/service/promise/PromiseRetriever.java b/src/main/java/org/kkumulkkum/server/service/promise/PromiseRetriever.java index cc4f344..ea5a796 100644 --- a/src/main/java/org/kkumulkkum/server/service/promise/PromiseRetriever.java +++ b/src/main/java/org/kkumulkkum/server/service/promise/PromiseRetriever.java @@ -19,31 +19,54 @@ public class PromiseRetriever { private final PromiseRepository promiseRepository; - public List findAllByMeetingId(Long meetingId) { + public List findAllByMeetingId(final Long meetingId) { return promiseRepository.findAllByMeetingId(meetingId); } - public Promise findById(Long id) { + public Promise findById(final Long id) { return promiseRepository.findById(id) .orElseThrow(() -> new PromiseException(PromiseErrorCode.NOT_FOUND_PROMISE)); } - public List findNextPromiseByUserId(Long userId, LocalDateTime startOfDay, LocalDateTime startOfNextDay) { - return promiseRepository.findNextPromiseByUserId(userId, startOfDay, startOfNextDay, PageRequest.of(0,1)); + public List findNextPromiseByUserId( + final Long userId, + final LocalDateTime startOfDay, + final LocalDateTime startOfNextDay + ) { + return promiseRepository.findNextPromiseByUserId( + userId, + startOfDay, + startOfNextDay, + PageRequest.of(0,1) + ); } - public List findUpcomingPromisesExcludingNext(Long userId, Promise nextPromise, int limit) { - Page promisePage = promiseRepository.findUpcomingPromisesExcludingNext(userId, nextPromise.getId(), PageRequest.of(0, limit)); + public List findUpcomingPromisesExcludingNext( + final Long userId, + final Promise nextPromise, + final int limit + ) { + Page promisePage = promiseRepository.findUpcomingPromisesExcludingNext( + userId, + nextPromise.getId(), + PageRequest.of(0, limit) + ); return promisePage.stream().collect(Collectors.toList()); } - public List findUpcomingPromises(Long userId, int limit) { - Page promisePage = promiseRepository.findUpcomingPromises(userId, PageRequest.of(0, limit)); + public List findUpcomingPromises( + final Long userId, + final int limit + ) { + Page promisePage = promiseRepository.findUpcomingPromises( + userId, + PageRequest.of(0, limit) + ); return promisePage.stream().collect(Collectors.toList()); } - public boolean existsByArrivedAtIsNull(Long promiseId) { + public boolean existsByArrivedAtIsNull(final Long promiseId) { return promiseRepository.existsByArrivedAtIsNull(promiseId); } diff --git a/src/main/java/org/kkumulkkum/server/service/promise/PromiseSaver.java b/src/main/java/org/kkumulkkum/server/service/promise/PromiseSaver.java index 5e96271..81cfc01 100644 --- a/src/main/java/org/kkumulkkum/server/service/promise/PromiseSaver.java +++ b/src/main/java/org/kkumulkkum/server/service/promise/PromiseSaver.java @@ -11,7 +11,7 @@ public class PromiseSaver { private final PromiseRepository promiseRepository; - public void save(Promise promise) { + public void save(final Promise promise) { promiseRepository.save(promise); } } diff --git a/src/main/java/org/kkumulkkum/server/service/promise/PromiseService.java b/src/main/java/org/kkumulkkum/server/service/promise/PromiseService.java index 39ad26e..b275fc0 100644 --- a/src/main/java/org/kkumulkkum/server/service/promise/PromiseService.java +++ b/src/main/java/org/kkumulkkum/server/service/promise/PromiseService.java @@ -34,7 +34,11 @@ public class PromiseService { private final EntityManager entityManager; @Transactional - public Long createPromise(Long userId, Long meetingId, PromiseCreateDto createPromiseDto) { + public Long createPromise( + final Long userId, + final Long meetingId, + final PromiseCreateDto createPromiseDto + ) { Promise promise = Promise.builder() .meeting(entityManager.getReference(Meeting.class, meetingId)) .name(createPromiseDto.name()) @@ -62,7 +66,7 @@ public Long createPromise(Long userId, Long meetingId, PromiseCreateDto createPr } @Transactional - public void completePromise(Long promiseId) { + public void completePromise(final Long promiseId) { Promise promise = promiseRetriever.findById(promiseId); if (promise.getTime().isAfter(LocalDateTime.now())) { throw new PromiseException(PromiseErrorCode.NOT_PAST_DUE); @@ -112,12 +116,17 @@ public MainPromisesDto getUpcomingPromises(final Long userId) { List nextPromise = promiseRetriever.findNextPromiseByUserId(userId, startOfDay, startOfNextDay); if (!nextPromise.isEmpty()) { - return MainPromisesDto.from(promiseRetriever.findUpcomingPromisesExcludingNext(userId, nextPromise.get(0), 4)); + return MainPromisesDto.from( + promiseRetriever.findUpcomingPromisesExcludingNext(userId, nextPromise.get(0), 4) + ); } return MainPromisesDto.from(promiseRetriever.findUpcomingPromises(userId, 4)); } - private void updateUserInfo(Participant participant, LocalDateTime promiseTime) { + private void updateUserInfo( + final Participant participant, + final LocalDateTime promiseTime + ) { UserInfo userInfo = userInfoRetriever.findByParticipantId(participant.getId()); userInfo.addPromiseCount(); if (promiseTime.isBefore(participant.getArrivalAt())) { diff --git a/src/main/java/org/kkumulkkum/server/service/user/UserRetriever.java b/src/main/java/org/kkumulkkum/server/service/user/UserRetriever.java index ec0f018..0c61c0a 100644 --- a/src/main/java/org/kkumulkkum/server/service/user/UserRetriever.java +++ b/src/main/java/org/kkumulkkum/server/service/user/UserRetriever.java @@ -19,11 +19,17 @@ public User findById(final Long userId) { .orElseThrow(() -> new UserException(UserErrorCode.NOT_FOUND_USER)); } - public boolean existsByProviderIdAndProvider(final String providerId, final Provider provider) { + public boolean existsByProviderIdAndProvider( + final String providerId, + final Provider provider + ) { return userRepository.existsByProviderIdAndProvider(providerId, provider); } - public User findByProviderIdAndProvider(final String providerId, final Provider provider) { + public User findByProviderIdAndProvider( + final String providerId, + final Provider provider + ) { return userRepository.findByProviderIdAndProvider(providerId, provider) .orElseThrow(() -> new UserException(UserErrorCode.NOT_FOUND_USER)); } diff --git a/src/main/java/org/kkumulkkum/server/service/user/UserService.java b/src/main/java/org/kkumulkkum/server/service/user/UserService.java index 15a7e80..cc97b46 100644 --- a/src/main/java/org/kkumulkkum/server/service/user/UserService.java +++ b/src/main/java/org/kkumulkkum/server/service/user/UserService.java @@ -30,7 +30,8 @@ public class UserService { @Transactional public void updateImage( - final Long userId, final ImageUpdateDto imageUpdateDto + final Long userId, + final ImageUpdateDto imageUpdateDto ) { UserInfo userInfo = userInfoRetriever.findByUserId(userId); @@ -45,7 +46,9 @@ public void updateImage( } try { - userInfoEditor.updateImage(userInfo, s3Service.uploadImage(PROFILE_S3_UPLOAD_FOLDER, imageUpdateDto.image())); + userInfoEditor.updateImage( + userInfo, s3Service.uploadImage(PROFILE_S3_UPLOAD_FOLDER, imageUpdateDto.image()) + ); } catch (AwsException e) { throw new AwsException(e.getErrorCode()); } catch (RuntimeException | IOException e) { @@ -72,7 +75,10 @@ public void deleteImage(final Long userId) { } @Transactional - public UserNameDto updateName(final Long userId, final NameUpdateDto nameUpdateDto) { + public UserNameDto updateName( + final Long userId, + final NameUpdateDto nameUpdateDto + ) { UserInfo userInfo = userInfoRetriever.findByUserId(userId); userInfoEditor.updateName(userInfo, nameUpdateDto.name()); diff --git a/src/main/java/org/kkumulkkum/server/service/userInfo/UserInfoEditor.java b/src/main/java/org/kkumulkkum/server/service/userInfo/UserInfoEditor.java index 8fa31cf..225c832 100644 --- a/src/main/java/org/kkumulkkum/server/service/userInfo/UserInfoEditor.java +++ b/src/main/java/org/kkumulkkum/server/service/userInfo/UserInfoEditor.java @@ -6,15 +6,21 @@ @Component public class UserInfoEditor { - public void updateImage(UserInfo userInfo, String imageUrl) { + public void updateImage( + final UserInfo userInfo, + final String imageUrl + ) { userInfo.updateImage(imageUrl); } - public void deleteImage(UserInfo userInfo) { + public void deleteImage(final UserInfo userInfo) { userInfo.deleteImage(); } - public void updateName(UserInfo userInfo, String name) { + public void updateName( + final UserInfo userInfo, + final String name + ) { userInfo.updateName(name); } } From 1e98364d98aac42de8df503588ec0eeef846314f Mon Sep 17 00:00:00 2001 From: chaewonkim Date: Mon, 15 Jul 2024 02:19:12 +0900 Subject: [PATCH 4/7] [fix] #54 delete unnecessary service class --- .../kkumulkkum/server/service/member/MemberService.java | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 src/main/java/org/kkumulkkum/server/service/member/MemberService.java diff --git a/src/main/java/org/kkumulkkum/server/service/member/MemberService.java b/src/main/java/org/kkumulkkum/server/service/member/MemberService.java deleted file mode 100644 index 630702a..0000000 --- a/src/main/java/org/kkumulkkum/server/service/member/MemberService.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.kkumulkkum.server.service.member; - -import org.springframework.stereotype.Service; - -@Service -public class MemberService { -} From e45e586f9e15f2ae654cc057408d17f0210adefe Mon Sep 17 00:00:00 2001 From: chaewonkim Date: Mon, 15 Jul 2024 02:20:53 +0900 Subject: [PATCH 5/7] [fix] #54 change return value to void --- .../java/org/kkumulkkum/server/service/user/UserSaver.java | 4 ++-- .../org/kkumulkkum/server/service/userInfo/UserInfoSaver.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/kkumulkkum/server/service/user/UserSaver.java b/src/main/java/org/kkumulkkum/server/service/user/UserSaver.java index d4133b4..27e8f71 100644 --- a/src/main/java/org/kkumulkkum/server/service/user/UserSaver.java +++ b/src/main/java/org/kkumulkkum/server/service/user/UserSaver.java @@ -11,8 +11,8 @@ public class UserSaver { private final UserRepository userRepository; - public User save(final User user){ - return userRepository.save(user); + public void save(final User user){ + userRepository.save(user); } } diff --git a/src/main/java/org/kkumulkkum/server/service/userInfo/UserInfoSaver.java b/src/main/java/org/kkumulkkum/server/service/userInfo/UserInfoSaver.java index dea9ed9..771b5c0 100644 --- a/src/main/java/org/kkumulkkum/server/service/userInfo/UserInfoSaver.java +++ b/src/main/java/org/kkumulkkum/server/service/userInfo/UserInfoSaver.java @@ -11,8 +11,8 @@ public class UserInfoSaver { private final UserInfoRepository userInfoRepository; - public UserInfo save(final UserInfo user){ - return userInfoRepository.save(user); + public void save(final UserInfo user){ + userInfoRepository.save(user); } } From 997c062fa58ee8af0d620099c0fd51bf3d2fd5bf Mon Sep 17 00:00:00 2001 From: chaewonkim Date: Mon, 15 Jul 2024 02:43:12 +0900 Subject: [PATCH 6/7] [fix] #54 edit dto method name (from/of) --- .../kkumulkkum/server/domain/Participant.java | 15 ++++++------- .../org/kkumulkkum/server/domain/Promise.java | 21 ++++++++++--------- .../org/kkumulkkum/server/domain/User.java | 10 +++++---- .../kkumulkkum/server/domain/UserInfo.java | 10 +++++---- 4 files changed, 31 insertions(+), 25 deletions(-) diff --git a/src/main/java/org/kkumulkkum/server/domain/Participant.java b/src/main/java/org/kkumulkkum/server/domain/Participant.java index 246869c..9437c65 100644 --- a/src/main/java/org/kkumulkkum/server/domain/Participant.java +++ b/src/main/java/org/kkumulkkum/server/domain/Participant.java @@ -36,13 +36,14 @@ public class Participant extends BaseTimeEntity { private Member member; @Builder - public Participant(LocalDateTime preparationStartAt, - LocalDateTime departureAt, - LocalDateTime arrivalAt, - int preparationTime, - int travelTime, - Promise promise, - Member member + public Participant( + LocalDateTime preparationStartAt, + LocalDateTime departureAt, + LocalDateTime arrivalAt, + int preparationTime, + int travelTime, + Promise promise, + Member member ) { this.preparationStartAt = preparationStartAt; this.departureAt = departureAt; diff --git a/src/main/java/org/kkumulkkum/server/domain/Promise.java b/src/main/java/org/kkumulkkum/server/domain/Promise.java index b6a5e36..86833cf 100644 --- a/src/main/java/org/kkumulkkum/server/domain/Promise.java +++ b/src/main/java/org/kkumulkkum/server/domain/Promise.java @@ -44,16 +44,17 @@ public class Promise extends BaseTimeEntity { private Meeting meeting; @Builder - public Promise(String name, - LocalDateTime time, - DressUpLevel dressUpLevel, - String penalty, - String placeName, - Double x, - Double y, - String address, - String roadAddress, - Meeting meeting + public Promise( + String name, + LocalDateTime time, + DressUpLevel dressUpLevel, + String penalty, + String placeName, + Double x, + Double y, + String address, + String roadAddress, + Meeting meeting ) { this.name = name; this.time = time; diff --git a/src/main/java/org/kkumulkkum/server/domain/User.java b/src/main/java/org/kkumulkkum/server/domain/User.java index 108837d..f1d5358 100644 --- a/src/main/java/org/kkumulkkum/server/domain/User.java +++ b/src/main/java/org/kkumulkkum/server/domain/User.java @@ -27,10 +27,12 @@ public class User extends BaseTimeEntity { private Role role; @Builder - public User(Long id, - Provider provider, - String providerId, - Role role) { + public User( + Long id, + Provider provider, + String providerId, + Role role + ) { this.id = id; this.provider = provider; this.providerId = providerId; diff --git a/src/main/java/org/kkumulkkum/server/domain/UserInfo.java b/src/main/java/org/kkumulkkum/server/domain/UserInfo.java index 8787877..d2ba684 100644 --- a/src/main/java/org/kkumulkkum/server/domain/UserInfo.java +++ b/src/main/java/org/kkumulkkum/server/domain/UserInfo.java @@ -36,10 +36,12 @@ public class UserInfo extends BaseTimeEntity { private User user; @Builder - public UserInfo(String name, - String profileImg, - String email, - User user) { + public UserInfo( + String name, + String profileImg, + String email, + User user + ) { this.name = name; this.profileImg = profileImg; this.email = email; From 802699b4a493ec9af210fd6d83d274d20c7f7b59 Mon Sep 17 00:00:00 2001 From: chaewonkim Date: Mon, 15 Jul 2024 02:52:27 +0900 Subject: [PATCH 7/7] [fix] #54 fix mismatched field type --- .../org/kkumulkkum/server/domain/Participant.java | 12 ++++++------ .../dto/participant/request/PreparationInfoDto.java | 4 ++-- .../participant/response/PreparationStatusDto.java | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/kkumulkkum/server/domain/Participant.java b/src/main/java/org/kkumulkkum/server/domain/Participant.java index 9437c65..df0ff32 100644 --- a/src/main/java/org/kkumulkkum/server/domain/Participant.java +++ b/src/main/java/org/kkumulkkum/server/domain/Participant.java @@ -23,9 +23,9 @@ public class Participant extends BaseTimeEntity { private LocalDateTime arrivalAt; - private int preparationTime; + private Integer preparationTime; - private int travelTime; + private Integer travelTime; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "promise_id") @@ -40,8 +40,8 @@ public Participant( LocalDateTime preparationStartAt, LocalDateTime departureAt, LocalDateTime arrivalAt, - int preparationTime, - int travelTime, + Integer preparationTime, + Integer travelTime, Promise promise, Member member ) { @@ -66,11 +66,11 @@ public void arrivalPromise() { this.arrivalAt = LocalDateTime.now(); } - public void updatePreparationTime(int preparationTime) { + public void updatePreparationTime(Integer preparationTime) { this.preparationTime = preparationTime; } - public void updateTravelTime(int travelTime) { + public void updateTravelTime(Integer travelTime) { this.travelTime = travelTime; } } diff --git a/src/main/java/org/kkumulkkum/server/dto/participant/request/PreparationInfoDto.java b/src/main/java/org/kkumulkkum/server/dto/participant/request/PreparationInfoDto.java index d54b370..7ee79a5 100644 --- a/src/main/java/org/kkumulkkum/server/dto/participant/request/PreparationInfoDto.java +++ b/src/main/java/org/kkumulkkum/server/dto/participant/request/PreparationInfoDto.java @@ -4,8 +4,8 @@ public record PreparationInfoDto( @Size(max = 1440) - int preparationTime, + Integer preparationTime, @Size(max = 1440) - int travelTime + Integer travelTime ) { } diff --git a/src/main/java/org/kkumulkkum/server/dto/participant/response/PreparationStatusDto.java b/src/main/java/org/kkumulkkum/server/dto/participant/response/PreparationStatusDto.java index a7469ca..148df35 100644 --- a/src/main/java/org/kkumulkkum/server/dto/participant/response/PreparationStatusDto.java +++ b/src/main/java/org/kkumulkkum/server/dto/participant/response/PreparationStatusDto.java @@ -6,8 +6,8 @@ import java.time.LocalDateTime; public record PreparationStatusDto( - int preparationTime, - int travelTime, + Integer preparationTime, + Integer travelTime, @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "a h:mm", locale = "en") LocalDateTime preparationStartAt, @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "a h:mm", locale = "en")