-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [test] RetrieveCustomerServiceTest 구현 - RetrieveCustomerServiceTest.testRetrieveAllCustomers: 전체 구매자 조회 테스트 성공 * [feat] RetrieveCustomerService 구현 - RetrieveCustomerService.retrieveAllCustomers: 전체 구매자 조회 로직 * [test] CustomerApiControllerTest 수정 - CustomerApiControllerTest.testRetrieveCustomers: 전체 구매자 조회 테스트 * [feat] CustomerApiController 수정 - CustomerApiController.retrieveAllCustomers: 전체 구매자 조회 요청 처리 * [feat] RetrieveCustomerResponse 구현 * [refactor] VendorApiControllerTest 패키지 수정 * [test] RetrieveVendorServiceTest 구현 - RetrieveVendorServiceTest.testRetrieveVendors: 전체 판매자 조회 테스트 * [test] VendorApiControllerTest 수정 - VendorApiControllerTest.FindVendor: 전체 점주 조회 요청 테스트 * [feat] RetrieveVendorService 구현 - RetrieveVendorService.retrieveVendors: 전체 점주 조회 로직 * [feat] VendorApiController 수정 - VendorApiController.retrieveVendors: 전체 점주 조회 요청 처리 * [feat] RetrieveVendorResponse 구현 * [fix] RetrieveVendorServiceTest 수정 - assertEquals actual 과 expected 정확한 위치로 가도록 수정 * [feat] DTO 구현 - VendorDTO, CustomerDTO, PayAccountDTO * [refactor] DTO 구현에 따른 변경 적용 * [refactor] DTO 외부 종속 제거 - Vendor 와 Customer 가 보여주고 싶은 PayAccount의 정보가 다를 수 있으므로 각 DTO 안에 종속된 PayAccount 정보를 가지도록 수정
- Loading branch information
Showing
12 changed files
with
308 additions
and
6 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
src/main/java/camp/woowak/lab/customer/service/RetrieveCustomerService.java
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package camp.woowak.lab.customer.service; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import camp.woowak.lab.customer.repository.CustomerRepository; | ||
import camp.woowak.lab.customer.service.dto.CustomerDTO; | ||
|
||
@Service | ||
@Transactional(readOnly = true) | ||
public class RetrieveCustomerService { | ||
private final CustomerRepository customerRepository; | ||
|
||
public RetrieveCustomerService(CustomerRepository customerRepository) { | ||
this.customerRepository = customerRepository; | ||
} | ||
|
||
public List<CustomerDTO> retrieveAllCustomers() { | ||
return customerRepository.findAll().stream().map(CustomerDTO::new).toList(); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/main/java/camp/woowak/lab/customer/service/dto/CustomerDTO.java
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package camp.woowak.lab.customer.service.dto; | ||
|
||
import java.util.UUID; | ||
|
||
import camp.woowak.lab.customer.domain.Customer; | ||
import camp.woowak.lab.payaccount.domain.PayAccount; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class CustomerDTO { | ||
private final UUID id; | ||
private final String name; | ||
private final String email; | ||
private final String phone; | ||
private final PayAccountDTO payAccount; | ||
|
||
public CustomerDTO(Customer customer) { | ||
this.id = customer.getId(); | ||
this.name = customer.getName(); | ||
this.email = customer.getEmail(); | ||
this.phone = customer.getPhone(); | ||
this.payAccount = new PayAccountDTO(customer.getPayAccount()); | ||
} | ||
|
||
@Getter | ||
public static class PayAccountDTO { | ||
private final Long id; | ||
private final Long balance; | ||
|
||
public PayAccountDTO(PayAccount payAccount) { | ||
this.id = payAccount.getId(); | ||
this.balance = payAccount.getBalance(); | ||
} | ||
} | ||
} | ||
|
23 changes: 23 additions & 0 deletions
23
src/main/java/camp/woowak/lab/vendor/service/RetrieveVendorService.java
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package camp.woowak.lab.vendor.service; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import camp.woowak.lab.vendor.repository.VendorRepository; | ||
import camp.woowak.lab.vendor.service.dto.VendorDTO; | ||
|
||
@Service | ||
@Transactional(readOnly = true) | ||
public class RetrieveVendorService { | ||
private final VendorRepository vendorRepository; | ||
|
||
public RetrieveVendorService(VendorRepository vendorRepository) { | ||
this.vendorRepository = vendorRepository; | ||
} | ||
|
||
public List<VendorDTO> retrieveVendors() { | ||
return vendorRepository.findAll().stream().map(VendorDTO::new).toList(); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/main/java/camp/woowak/lab/vendor/service/dto/VendorDTO.java
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package camp.woowak.lab.vendor.service.dto; | ||
|
||
import java.util.UUID; | ||
|
||
import camp.woowak.lab.payaccount.domain.PayAccount; | ||
import camp.woowak.lab.vendor.domain.Vendor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class VendorDTO { | ||
private final UUID id; | ||
private final String name; | ||
private final String email; | ||
private final String phone; | ||
private final PayAccountDTO payAccount; | ||
|
||
public VendorDTO(Vendor vendor) { | ||
this.id = vendor.getId(); | ||
this.name = vendor.getName(); | ||
this.email = vendor.getEmail(); | ||
this.phone = vendor.getPhone(); | ||
this.payAccount = new PayAccountDTO(vendor.getPayAccount()); | ||
} | ||
|
||
@Getter | ||
public static class PayAccountDTO { | ||
private final Long id; | ||
private final Long balance; | ||
|
||
public PayAccountDTO(PayAccount payAccount) { | ||
this.id = payAccount.getId(); | ||
this.balance = payAccount.getBalance(); | ||
} | ||
} | ||
} |
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
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
8 changes: 8 additions & 0 deletions
8
src/main/java/camp/woowak/lab/web/dto/response/customer/RetrieveCustomerResponse.java
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package camp.woowak.lab.web.dto.response.customer; | ||
|
||
import java.util.List; | ||
|
||
import camp.woowak.lab.customer.service.dto.CustomerDTO; | ||
|
||
public record RetrieveCustomerResponse(List<CustomerDTO> customers) { | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/camp/woowak/lab/web/dto/response/vendor/RetrieveVendorResponse.java
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package camp.woowak.lab.web.dto.response.vendor; | ||
|
||
import java.util.List; | ||
|
||
import camp.woowak.lab.vendor.service.dto.VendorDTO; | ||
|
||
public record RetrieveVendorResponse(List<VendorDTO> vendors) { | ||
} |
40 changes: 40 additions & 0 deletions
40
src/test/java/camp/woowak/lab/customer/service/RetrieveCustomerServiceTest.java
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package camp.woowak.lab.customer.service; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.mockito.BDDMockito.*; | ||
|
||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
import camp.woowak.lab.customer.repository.CustomerRepository; | ||
import camp.woowak.lab.customer.service.dto.CustomerDTO; | ||
import camp.woowak.lab.fixture.CustomerFixture; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class RetrieveCustomerServiceTest implements CustomerFixture { | ||
@InjectMocks | ||
private RetrieveCustomerService retrieveCustomerService; | ||
|
||
@Mock | ||
private CustomerRepository customerRepository; | ||
|
||
@Test | ||
@DisplayName("전체 Customer 조회 테스트 - 성공") | ||
void testRetrieveAllCustomers() { | ||
// given | ||
given(customerRepository.findAll()).willReturn( | ||
List.of(createCustomer(UUID.randomUUID()), createCustomer(UUID.randomUUID()))); | ||
// when | ||
List<CustomerDTO> result = retrieveCustomerService.retrieveAllCustomers(); | ||
|
||
// then | ||
assertEquals(2, result.size()); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/test/java/camp/woowak/lab/vendor/service/RetrieveVendorServiceTest.java
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package camp.woowak.lab.vendor.service; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.mockito.BDDMockito.*; | ||
|
||
import java.util.List; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
import camp.woowak.lab.fixture.VendorFixture; | ||
import camp.woowak.lab.vendor.repository.VendorRepository; | ||
import camp.woowak.lab.vendor.service.dto.VendorDTO; | ||
import camp.woowak.lab.web.authentication.NoOpPasswordEncoder; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class RetrieveVendorServiceTest implements VendorFixture { | ||
@InjectMocks | ||
private RetrieveVendorService retrieveVendorService; | ||
|
||
@Mock | ||
private VendorRepository vendorRepository; | ||
|
||
@Test | ||
@DisplayName("전체 판매자 조회 테스트 - 성공") | ||
void testRetrieveVendors() { | ||
// given | ||
given(vendorRepository.findAll()).willReturn( | ||
List.of(createVendor(createPayAccount(), new NoOpPasswordEncoder()))); | ||
// when | ||
List<VendorDTO> result = retrieveVendorService.retrieveVendors(); | ||
// then | ||
assertEquals(1, result.size()); | ||
verify(vendorRepository).findAll(); | ||
} | ||
} |
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.