From 5afaf51dbc47a083d08d2ea7c05189dc35182bf1 Mon Sep 17 00:00:00 2001 From: tinon1004 Date: Thu, 11 Apr 2024 00:17:54 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20#89=20=ED=8C=90=EB=A7=A4=EC=9E=90=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=20=EC=A1=B0=ED=9A=8C=EC=97=90=20=EC=95=85?= =?UTF-8?q?=EA=B8=B0=20=ED=8C=90=EB=A7=A4=20=EB=82=B4=EC=97=AD=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/InstrumentRepository.java | 5 ++- .../service/InstrumentQueryService.java | 18 ++++++++++- .../user/controller/UserController.java | 5 ++- .../user/dto/response/SellerInfoResponse.java | 12 +++++-- .../service/InstrumentQueryServiceTest.java | 31 +++++++++++++++++++ .../user/controller/UserControllerTest.java | 13 ++++++++ 6 files changed, 79 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/ajou/hertz/domain/instrument/repository/InstrumentRepository.java b/src/main/java/com/ajou/hertz/domain/instrument/repository/InstrumentRepository.java index 32c6be4..dd8186c 100644 --- a/src/main/java/com/ajou/hertz/domain/instrument/repository/InstrumentRepository.java +++ b/src/main/java/com/ajou/hertz/domain/instrument/repository/InstrumentRepository.java @@ -1,5 +1,7 @@ package com.ajou.hertz.domain.instrument.repository; +import java.util.List; + import org.springframework.data.jpa.repository.JpaRepository; import com.ajou.hertz.domain.instrument.constant.InstrumentProgressStatus; @@ -7,6 +9,7 @@ public interface InstrumentRepository extends JpaRepository, InstrumentRepositoryCustom { - int countBySellerIdAndProgressStatus(Long sellerid, InstrumentProgressStatus progressStatus); + int countBySellerIdAndProgressStatus(Long sellerId, InstrumentProgressStatus progressStatus); + List findAllBySellerId(Long sellerId); } diff --git a/src/main/java/com/ajou/hertz/domain/instrument/service/InstrumentQueryService.java b/src/main/java/com/ajou/hertz/domain/instrument/service/InstrumentQueryService.java index db5f358..dd72e3e 100644 --- a/src/main/java/com/ajou/hertz/domain/instrument/service/InstrumentQueryService.java +++ b/src/main/java/com/ajou/hertz/domain/instrument/service/InstrumentQueryService.java @@ -1,5 +1,8 @@ package com.ajou.hertz.domain.instrument.service; +import java.util.List; +import java.util.stream.Collectors; + import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.stereotype.Service; @@ -200,7 +203,6 @@ public Page findAudioEquipmentDtos( * 판매자가 판매중인 물품의 수를 조회합니다 * * @param sellerId 판매자 id - * * @return 판매중인 물품의 수 */ public int countSellingItemsBySellerId(Long sellerId) { @@ -216,4 +218,18 @@ public int countSellingItemsBySellerId(Long sellerId) { public int countSoldItemsBySellerId(Long sellerId) { return instrumentRepository.countBySellerIdAndProgressStatus(sellerId, InstrumentProgressStatus.SOLD_OUT); } + + /** + * 판매자가 판매하는 악기 정보를 조회한다. + * + * @param sellerId 조회하고자 하는 판매자의 id + * @return 조회된 악기 dto 목록 + */ + public List findAllBySellerId(Long sellerId) { + List instruments = instrumentRepository.findAllBySellerId(sellerId); + return instruments.stream() + .map(InstrumentMapper::toDto) + .collect(Collectors.toList()); + } + } diff --git a/src/main/java/com/ajou/hertz/domain/user/controller/UserController.java b/src/main/java/com/ajou/hertz/domain/user/controller/UserController.java index 8d584ab..5abf1b7 100644 --- a/src/main/java/com/ajou/hertz/domain/user/controller/UserController.java +++ b/src/main/java/com/ajou/hertz/domain/user/controller/UserController.java @@ -3,6 +3,7 @@ import static com.ajou.hertz.common.constant.GlobalConstants.*; import java.net.URI; +import java.util.List; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; @@ -21,6 +22,7 @@ import com.ajou.hertz.common.auth.UserPrincipal; import com.ajou.hertz.common.validator.PhoneNumber; +import com.ajou.hertz.domain.instrument.dto.InstrumentDto; import com.ajou.hertz.domain.instrument.service.InstrumentQueryService; import com.ajou.hertz.domain.user.dto.UserDto; import com.ajou.hertz.domain.user.dto.request.SignUpRequest; @@ -187,7 +189,8 @@ public SellerInfoResponse getSellerInfoV1( UserDto userDto = userQueryService.getDtoById(userId); int sellingCount = instrumentQueryService.countSellingItemsBySellerId(userId); int soldCount = instrumentQueryService.countSoldItemsBySellerId(userId); - return SellerInfoResponse.from(userDto, sellingCount, soldCount); + List createdInstruments = instrumentQueryService.findAllBySellerId(userId); + return SellerInfoResponse.from(userDto, sellingCount, soldCount, createdInstruments); } } diff --git a/src/main/java/com/ajou/hertz/domain/user/dto/response/SellerInfoResponse.java b/src/main/java/com/ajou/hertz/domain/user/dto/response/SellerInfoResponse.java index a240cff..6d49b0f 100644 --- a/src/main/java/com/ajou/hertz/domain/user/dto/response/SellerInfoResponse.java +++ b/src/main/java/com/ajou/hertz/domain/user/dto/response/SellerInfoResponse.java @@ -1,7 +1,9 @@ package com.ajou.hertz.domain.user.dto.response; import java.time.LocalDateTime; +import java.util.List; +import com.ajou.hertz.domain.instrument.dto.InstrumentDto; import com.ajou.hertz.domain.user.dto.UserDto; import io.swagger.v3.oas.annotations.media.Schema; @@ -36,7 +38,11 @@ public class SellerInfoResponse { @Schema(description = "판매완료한 물품의 수", example = "10") private long soldItemCount; - public static SellerInfoResponse from(UserDto userDto, long sellingItemCount, long soldItemCount) { + @Schema(description = "악기 판매 내역") + private List createdInstruments; + + public static SellerInfoResponse from(UserDto userDto, long sellingItemCount, long soldItemCount, + List createdInstruments) { return new SellerInfoResponse( userDto.getId(), userDto.getEmail(), @@ -44,7 +50,9 @@ public static SellerInfoResponse from(UserDto userDto, long sellingItemCount, lo userDto.getContactLink(), userDto.getCreatedAt(), sellingItemCount, - soldItemCount + soldItemCount, + createdInstruments ); } + } diff --git a/src/test/java/com/ajou/hertz/unit/domain/instrument/service/InstrumentQueryServiceTest.java b/src/test/java/com/ajou/hertz/unit/domain/instrument/service/InstrumentQueryServiceTest.java index fc0ffd9..2331804 100644 --- a/src/test/java/com/ajou/hertz/unit/domain/instrument/service/InstrumentQueryServiceTest.java +++ b/src/test/java/com/ajou/hertz/unit/domain/instrument/service/InstrumentQueryServiceTest.java @@ -5,9 +5,11 @@ import static org.mockito.BDDMockito.*; import java.time.LocalDate; +import java.util.ArrayList; import java.util.List; import java.util.Optional; import java.util.Set; +import java.util.stream.Collectors; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -60,6 +62,7 @@ import com.ajou.hertz.domain.instrument.electric_guitar.entity.ElectricGuitar; import com.ajou.hertz.domain.instrument.entity.Instrument; import com.ajou.hertz.domain.instrument.exception.InstrumentNotFoundByIdException; +import com.ajou.hertz.domain.instrument.mapper.InstrumentMapper; import com.ajou.hertz.domain.instrument.repository.InstrumentRepository; import com.ajou.hertz.domain.instrument.service.InstrumentQueryService; import com.ajou.hertz.domain.user.constant.Gender; @@ -401,6 +404,25 @@ class InstrumentQueryServiceTest { assertThat(actualResult).isEqualTo(expectedResult); } + @Test + void 해당_유저의_악기_판매_내역을_조회한다() throws Exception { + // given + Long sellerId = 1L; + List instrumentList = createInstrumentList(); + List expectedResult = instrumentList.stream() + .map(InstrumentMapper::toDto) + .collect(Collectors.toList()); + given(instrumentRepository.findAllBySellerId(sellerId)).willReturn(instrumentList); + + // when + List actualResult = sut.findAllBySellerId(sellerId); + + // then + then(instrumentRepository).should().findAllBySellerId(sellerId); + verifyEveryMocksShouldHaveNoMoreInteractions(); + assertThat(actualResult.size()).isEqualTo(expectedResult.size()); + } + private void verifyEveryMocksShouldHaveNoMoreInteractions() { then(instrumentRepository).shouldHaveNoMoreInteractions(); } @@ -595,4 +617,13 @@ private AudioEquipmentFilterConditions createAudioEquipmentFilterConditions() th AudioEquipmentType.AUDIO_EQUIPMENT ); } + + private List createInstrumentList() throws Exception { + List instruments = new ArrayList<>(); + User seller = createUser(1L); + instruments.add(createElectricGuitar(1L, seller)); + instruments.add(createElectricGuitar(2L, seller)); + return instruments; + } + } diff --git a/src/test/java/com/ajou/hertz/unit/domain/user/controller/UserControllerTest.java b/src/test/java/com/ajou/hertz/unit/domain/user/controller/UserControllerTest.java index 4c2cbe2..9640766 100644 --- a/src/test/java/com/ajou/hertz/unit/domain/user/controller/UserControllerTest.java +++ b/src/test/java/com/ajou/hertz/unit/domain/user/controller/UserControllerTest.java @@ -8,6 +8,8 @@ import java.time.LocalDate; import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; import java.util.Set; import org.junit.jupiter.api.DisplayName; @@ -31,6 +33,7 @@ import com.ajou.hertz.common.auth.JwtTokenProvider; import com.ajou.hertz.common.auth.UserPrincipal; import com.ajou.hertz.common.config.SecurityConfig; +import com.ajou.hertz.domain.instrument.dto.InstrumentDto; import com.ajou.hertz.domain.instrument.service.InstrumentQueryService; import com.ajou.hertz.domain.user.constant.Gender; import com.ajou.hertz.domain.user.constant.RoleType; @@ -307,9 +310,12 @@ public void securitySetUp() throws Exception { UserDto expectedResult = createUserDto(userId); int sellingCount = 2; int soldCount = 3; + List instrumentDtos = createInstrumentDtoList(); + given(userQueryService.getDtoById(userId)).willReturn(expectedResult); given(instrumentQueryService.countSellingItemsBySellerId(userId)).willReturn(sellingCount); given(instrumentQueryService.countSoldItemsBySellerId(userId)).willReturn(soldCount); + given(instrumentQueryService.findAllBySellerId(userId)).willReturn(instrumentDtos); // when & then mvc.perform( @@ -321,6 +327,7 @@ public void securitySetUp() throws Exception { then(userQueryService).should().getDtoById(userId); then(instrumentQueryService).should().countSellingItemsBySellerId(userId); then(instrumentQueryService).should().countSoldItemsBySellerId(userId); + then(instrumentQueryService).should().findAllBySellerId(userId); verifyEveryMocksShouldHaveNoMoreInteractions(); } @@ -370,4 +377,10 @@ private UserDto createUserDto() throws Exception { private UserDetails createTestUser(Long userId) throws Exception { return new UserPrincipal(createUserDto(userId)); } + + private List createInstrumentDtoList() { + List instrumentDtos = new ArrayList<>(); + return instrumentDtos; + } + } \ No newline at end of file