From f18dbdcb156edd9d23fb6e6531c722f7847bd187 Mon Sep 17 00:00:00 2001 From: hs12 Date: Mon, 8 Jan 2024 13:31:38 +0900 Subject: [PATCH] =?UTF-8?q?refactor=20:=20=EC=BD=94=EB=93=9C=20=EB=A6=AC?= =?UTF-8?q?=ED=8F=AC=EB=A9=A7=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../waiting/controller/MemberWaitingController.java | 9 ++++++--- .../prgrms/catchtable/waiting/dto/WaitingMapper.java | 10 +++++----- .../dto/response/OwnerWaitingListResponse.java | 6 ++++-- .../waiting/dto/response/OwnerWaitingResponse.java | 6 ++++-- .../waitingline/RedisWaitingLineRepository.java | 2 +- .../waiting/service/OwnerWaitingService.java | 1 - .../prgrms/catchtable/owner/fixture/OwnerFixture.java | 11 +++++------ .../controller/OwnerWaitingControllerTest.java | 1 + .../catchtable/waiting/fixture/WaitingFixture.java | 6 ++---- .../waiting/repository/WaitingRepositoryTest.java | 2 +- .../waiting/service/OwnerWaitingServiceTest.java | 3 ++- 11 files changed, 31 insertions(+), 26 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/waiting/controller/MemberWaitingController.java b/src/main/java/com/prgrms/catchtable/waiting/controller/MemberWaitingController.java index 6a0e32a1..dac21df7 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/controller/MemberWaitingController.java +++ b/src/main/java/com/prgrms/catchtable/waiting/controller/MemberWaitingController.java @@ -26,7 +26,8 @@ public class MemberWaitingController { public ResponseEntity createWaiting(@PathVariable("shopId") Long shopId, @PathVariable("memberId") Long memberId, @Valid @RequestBody CreateWaitingRequest request) { - MemberWaitingResponse response = memberWaitingService.createWaiting(shopId, memberId, request); + MemberWaitingResponse response = memberWaitingService.createWaiting(shopId, memberId, + request); return ResponseEntity.ok(response); } @@ -38,13 +39,15 @@ public ResponseEntity postponeWaiting( } @DeleteMapping("/{memberId}") - public ResponseEntity cancelWaiting(@PathVariable("memberId") Long memberId) { + public ResponseEntity cancelWaiting( + @PathVariable("memberId") Long memberId) { MemberWaitingResponse response = memberWaitingService.cancelWaiting(memberId); return ResponseEntity.ok(response); } @GetMapping("/{memberId}") - public ResponseEntity getWaiting(@PathVariable("memberId") Long memberId) { + public ResponseEntity getWaiting( + @PathVariable("memberId") Long memberId) { MemberWaitingResponse response = memberWaitingService.getWaiting(memberId); return ResponseEntity.ok(response); } diff --git a/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java b/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java index 52416bf7..75c0e134 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java +++ b/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java @@ -40,7 +40,7 @@ public static MemberWaitingResponse toWaitingResponse(Waiting waiting, Long rank .build(); } - public static OwnerWaitingResponse toOwnerWaitingResponse(Waiting waiting, Long rank){ + public static OwnerWaitingResponse toOwnerWaitingResponse(Waiting waiting, Long rank) { return OwnerWaitingResponse.builder() .waitingId(waiting.getId()) .waitingNumber(waiting.getWaitingNumber()) @@ -49,11 +49,11 @@ public static OwnerWaitingResponse toOwnerWaitingResponse(Waiting waiting, Long .build(); } - public static OwnerWaitingListResponse toOwnerWaitingListResponse(List waitings){ - long rank=1L; + public static OwnerWaitingListResponse toOwnerWaitingListResponse(List waitings) { + long rank = 1L; List list = new ArrayList<>(); - for (Waiting waiting : waitings){ - list.add(toOwnerWaitingResponse(waiting,rank++)); + for (Waiting waiting : waitings) { + list.add(toOwnerWaitingResponse(waiting, rank++)); } return new OwnerWaitingListResponse(list); } diff --git a/src/main/java/com/prgrms/catchtable/waiting/dto/response/OwnerWaitingListResponse.java b/src/main/java/com/prgrms/catchtable/waiting/dto/response/OwnerWaitingListResponse.java index 70af4cb2..d02d6e81 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/dto/response/OwnerWaitingListResponse.java +++ b/src/main/java/com/prgrms/catchtable/waiting/dto/response/OwnerWaitingListResponse.java @@ -4,6 +4,8 @@ import lombok.Builder; @Builder -public record OwnerWaitingListResponse ( +public record OwnerWaitingListResponse( List shopWaitings -){} +) { + +} diff --git a/src/main/java/com/prgrms/catchtable/waiting/dto/response/OwnerWaitingResponse.java b/src/main/java/com/prgrms/catchtable/waiting/dto/response/OwnerWaitingResponse.java index 763236bb..e3c04197 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/dto/response/OwnerWaitingResponse.java +++ b/src/main/java/com/prgrms/catchtable/waiting/dto/response/OwnerWaitingResponse.java @@ -3,9 +3,11 @@ import lombok.Builder; @Builder -public record OwnerWaitingResponse ( +public record OwnerWaitingResponse( Long waitingId, int waitingNumber, Long rank, int peopleCount -){} +) { + +} diff --git a/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepository.java b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepository.java index 92d7b09a..2a936994 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepository.java +++ b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepository.java @@ -43,7 +43,7 @@ public Object execute(RedisOperations operations) }); } - public List getShopWaitingIdsInOrder(Long shopId){ + public List getShopWaitingIdsInOrder(Long shopId) { List stringList = redisTemplate.opsForList().range("s" + shopId, 0, -1); if (stringList == null) { throw new BadRequestCustomException(WAITING_DOES_NOT_EXIST); diff --git a/src/main/java/com/prgrms/catchtable/waiting/service/OwnerWaitingService.java b/src/main/java/com/prgrms/catchtable/waiting/service/OwnerWaitingService.java index 00681ac5..d99c5300 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/service/OwnerWaitingService.java +++ b/src/main/java/com/prgrms/catchtable/waiting/service/OwnerWaitingService.java @@ -9,7 +9,6 @@ import com.prgrms.catchtable.waiting.domain.Waiting; import com.prgrms.catchtable.waiting.dto.response.OwnerWaitingListResponse; import com.prgrms.catchtable.waiting.repository.WaitingRepository; -import com.prgrms.catchtable.waiting.repository.waitingline.RedisWaitingLineRepository; import com.prgrms.catchtable.waiting.repository.waitingline.WaitingLineRepository; import java.util.List; import lombok.RequiredArgsConstructor; diff --git a/src/test/java/com/prgrms/catchtable/owner/fixture/OwnerFixture.java b/src/test/java/com/prgrms/catchtable/owner/fixture/OwnerFixture.java index 570b7904..bc360e20 100644 --- a/src/test/java/com/prgrms/catchtable/owner/fixture/OwnerFixture.java +++ b/src/test/java/com/prgrms/catchtable/owner/fixture/OwnerFixture.java @@ -1,7 +1,8 @@ package com.prgrms.catchtable.owner.fixture; +import static com.prgrms.catchtable.member.domain.Gender.MALE; + import com.prgrms.catchtable.common.data.shop.ShopData; -import com.prgrms.catchtable.member.domain.Gender; import com.prgrms.catchtable.owner.domain.Owner; import com.prgrms.catchtable.owner.dto.request.JoinOwnerRequest; import com.prgrms.catchtable.owner.dto.request.LoginOwnerRequest; @@ -9,8 +10,6 @@ import java.time.LocalDate; import org.springframework.test.util.ReflectionTestUtils; -import static com.prgrms.catchtable.member.domain.Gender.MALE; - public class OwnerFixture { @@ -29,7 +28,7 @@ public static Owner getOwner(String email, String password) { return owner; } - public static Owner getOwner(Shop shop){ + public static Owner getOwner(Shop shop) { Owner owner = Owner.builder() .name("ownerA") .email("email") @@ -43,7 +42,7 @@ public static Owner getOwner(Shop shop){ return owner; } - public static JoinOwnerRequest getJoinOwnerRequest(String email, String password){ + public static JoinOwnerRequest getJoinOwnerRequest(String email, String password) { return JoinOwnerRequest.builder() .name("ownerA") .email(email) @@ -54,7 +53,7 @@ public static JoinOwnerRequest getJoinOwnerRequest(String email, String password .build(); } - public static LoginOwnerRequest getLoginOwnerRequest(String email, String password){ + public static LoginOwnerRequest getLoginOwnerRequest(String email, String password) { return LoginOwnerRequest.builder() .email(email) .password(password) diff --git a/src/test/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingControllerTest.java b/src/test/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingControllerTest.java index 6cdaf1c8..c52a55a3 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingControllerTest.java @@ -28,6 +28,7 @@ import org.springframework.data.redis.core.StringRedisTemplate; class OwnerWaitingControllerTest extends BaseIntegrationTest { + @Autowired private MemberRepository memberRepository; @Autowired diff --git a/src/test/java/com/prgrms/catchtable/waiting/fixture/WaitingFixture.java b/src/test/java/com/prgrms/catchtable/waiting/fixture/WaitingFixture.java index 2f888593..b663c2c6 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/fixture/WaitingFixture.java +++ b/src/test/java/com/prgrms/catchtable/waiting/fixture/WaitingFixture.java @@ -1,12 +1,10 @@ package com.prgrms.catchtable.waiting.fixture; -import static com.prgrms.catchtable.waiting.domain.WaitingStatus.*; +import static com.prgrms.catchtable.waiting.domain.WaitingStatus.COMPLETED; import com.prgrms.catchtable.member.domain.Member; import com.prgrms.catchtable.shop.domain.Shop; import com.prgrms.catchtable.waiting.domain.Waiting; -import com.prgrms.catchtable.waiting.domain.WaitingStatus; -import java.time.LocalDateTime; import org.springframework.test.util.ReflectionTestUtils; public class WaitingFixture { @@ -22,7 +20,7 @@ public static Waiting waiting(Member member, Shop shop, int waitingNumber) { public static Waiting completedWaiting(Member member, Shop shop, int waitingNumber) { Waiting waiting = waiting(member, shop, waitingNumber); - ReflectionTestUtils.setField(waiting, "status", COMPLETED) ; + ReflectionTestUtils.setField(waiting, "status", COMPLETED); return waiting; } } \ No newline at end of file diff --git a/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java b/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java index 0e45655b..91d68de5 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java @@ -81,7 +81,7 @@ void countByShopAndCreatedAtBetween() { @DisplayName("멤버의 아이디 리스트로 Waiting을 조회 가능하다.") @Test - void findByIdsWithMember(){ + void findByIdsWithMember() { Waiting waiting1 = WaitingFixture.waiting(member1, shop, 1); Waiting waiting2 = WaitingFixture.waiting(member2, shop, 2); Waiting waiting3 = WaitingFixture.waiting(member3, shop, 3); diff --git a/src/test/java/com/prgrms/catchtable/waiting/service/OwnerWaitingServiceTest.java b/src/test/java/com/prgrms/catchtable/waiting/service/OwnerWaitingServiceTest.java index 76d17a79..49ee9e9c 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/service/OwnerWaitingServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/service/OwnerWaitingServiceTest.java @@ -48,7 +48,8 @@ void getOwnerAllWaiting() { given(ownerRepository.findById(1L)).willReturn(Optional.of(owner)); given(owner.getShop()).willReturn(shop); given(shop.getId()).willReturn(1L); - given(waitingLineRepository.getShopWaitingIdsInOrder(any(Long.class))).willReturn(waitingIds); + given(waitingLineRepository.getShopWaitingIdsInOrder(any(Long.class))).willReturn( + waitingIds); given(waitingRepository.findByIds(waitingIds)).willReturn(List.of(waiting)); //when