Skip to content

Commit 5afaf51

Browse files
committed
feat: #89 판매자 정보 조회에 악기 판매 내역 추가
1 parent a715e2d commit 5afaf51

File tree

6 files changed

+79
-5
lines changed

6 files changed

+79
-5
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
package com.ajou.hertz.domain.instrument.repository;
22

3+
import java.util.List;
4+
35
import org.springframework.data.jpa.repository.JpaRepository;
46

57
import com.ajou.hertz.domain.instrument.constant.InstrumentProgressStatus;
68
import com.ajou.hertz.domain.instrument.entity.Instrument;
79

810
public interface InstrumentRepository extends JpaRepository<Instrument, Long>, InstrumentRepositoryCustom {
911

10-
int countBySellerIdAndProgressStatus(Long sellerid, InstrumentProgressStatus progressStatus);
12+
int countBySellerIdAndProgressStatus(Long sellerId, InstrumentProgressStatus progressStatus);
1113

14+
List<Instrument> findAllBySellerId(Long sellerId);
1215
}

src/main/java/com/ajou/hertz/domain/instrument/service/InstrumentQueryService.java

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package com.ajou.hertz.domain.instrument.service;
22

3+
import java.util.List;
4+
import java.util.stream.Collectors;
5+
36
import org.springframework.data.domain.Page;
47
import org.springframework.data.domain.PageRequest;
58
import org.springframework.stereotype.Service;
@@ -200,7 +203,6 @@ public Page<AudioEquipmentDto> findAudioEquipmentDtos(
200203
* 판매자가 판매중인 물품의 수를 조회합니다
201204
*
202205
* @param sellerId 판매자 id
203-
*
204206
* @return 판매중인 물품의 수
205207
*/
206208
public int countSellingItemsBySellerId(Long sellerId) {
@@ -216,4 +218,18 @@ public int countSellingItemsBySellerId(Long sellerId) {
216218
public int countSoldItemsBySellerId(Long sellerId) {
217219
return instrumentRepository.countBySellerIdAndProgressStatus(sellerId, InstrumentProgressStatus.SOLD_OUT);
218220
}
221+
222+
/**
223+
* 판매자가 판매하는 악기 정보를 조회한다.
224+
*
225+
* @param sellerId 조회하고자 하는 판매자의 id
226+
* @return 조회된 악기 dto 목록
227+
*/
228+
public List<InstrumentDto> findAllBySellerId(Long sellerId) {
229+
List<Instrument> instruments = instrumentRepository.findAllBySellerId(sellerId);
230+
return instruments.stream()
231+
.map(InstrumentMapper::toDto)
232+
.collect(Collectors.toList());
233+
}
234+
219235
}

src/main/java/com/ajou/hertz/domain/user/controller/UserController.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import static com.ajou.hertz.common.constant.GlobalConstants.*;
44

55
import java.net.URI;
6+
import java.util.List;
67

78
import org.springframework.http.MediaType;
89
import org.springframework.http.ResponseEntity;
@@ -21,6 +22,7 @@
2122

2223
import com.ajou.hertz.common.auth.UserPrincipal;
2324
import com.ajou.hertz.common.validator.PhoneNumber;
25+
import com.ajou.hertz.domain.instrument.dto.InstrumentDto;
2426
import com.ajou.hertz.domain.instrument.service.InstrumentQueryService;
2527
import com.ajou.hertz.domain.user.dto.UserDto;
2628
import com.ajou.hertz.domain.user.dto.request.SignUpRequest;
@@ -187,7 +189,8 @@ public SellerInfoResponse getSellerInfoV1(
187189
UserDto userDto = userQueryService.getDtoById(userId);
188190
int sellingCount = instrumentQueryService.countSellingItemsBySellerId(userId);
189191
int soldCount = instrumentQueryService.countSoldItemsBySellerId(userId);
190-
return SellerInfoResponse.from(userDto, sellingCount, soldCount);
192+
List<InstrumentDto> createdInstruments = instrumentQueryService.findAllBySellerId(userId);
193+
return SellerInfoResponse.from(userDto, sellingCount, soldCount, createdInstruments);
191194
}
192195

193196
}

src/main/java/com/ajou/hertz/domain/user/dto/response/SellerInfoResponse.java

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package com.ajou.hertz.domain.user.dto.response;
22

33
import java.time.LocalDateTime;
4+
import java.util.List;
45

6+
import com.ajou.hertz.domain.instrument.dto.InstrumentDto;
57
import com.ajou.hertz.domain.user.dto.UserDto;
68

79
import io.swagger.v3.oas.annotations.media.Schema;
@@ -36,15 +38,21 @@ public class SellerInfoResponse {
3638
@Schema(description = "판매완료한 물품의 수", example = "10")
3739
private long soldItemCount;
3840

39-
public static SellerInfoResponse from(UserDto userDto, long sellingItemCount, long soldItemCount) {
41+
@Schema(description = "악기 판매 내역")
42+
private List<InstrumentDto> createdInstruments;
43+
44+
public static SellerInfoResponse from(UserDto userDto, long sellingItemCount, long soldItemCount,
45+
List<InstrumentDto> createdInstruments) {
4046
return new SellerInfoResponse(
4147
userDto.getId(),
4248
userDto.getEmail(),
4349
userDto.getProfileImageUrl(),
4450
userDto.getContactLink(),
4551
userDto.getCreatedAt(),
4652
sellingItemCount,
47-
soldItemCount
53+
soldItemCount,
54+
createdInstruments
4855
);
4956
}
57+
5058
}

src/test/java/com/ajou/hertz/unit/domain/instrument/service/InstrumentQueryServiceTest.java

+31
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
import static org.mockito.BDDMockito.*;
66

77
import java.time.LocalDate;
8+
import java.util.ArrayList;
89
import java.util.List;
910
import java.util.Optional;
1011
import java.util.Set;
12+
import java.util.stream.Collectors;
1113

1214
import org.junit.jupiter.api.DisplayName;
1315
import org.junit.jupiter.api.Test;
@@ -60,6 +62,7 @@
6062
import com.ajou.hertz.domain.instrument.electric_guitar.entity.ElectricGuitar;
6163
import com.ajou.hertz.domain.instrument.entity.Instrument;
6264
import com.ajou.hertz.domain.instrument.exception.InstrumentNotFoundByIdException;
65+
import com.ajou.hertz.domain.instrument.mapper.InstrumentMapper;
6366
import com.ajou.hertz.domain.instrument.repository.InstrumentRepository;
6467
import com.ajou.hertz.domain.instrument.service.InstrumentQueryService;
6568
import com.ajou.hertz.domain.user.constant.Gender;
@@ -401,6 +404,25 @@ class InstrumentQueryServiceTest {
401404
assertThat(actualResult).isEqualTo(expectedResult);
402405
}
403406

407+
@Test
408+
void 해당_유저의_악기_판매_내역을_조회한다() throws Exception {
409+
// given
410+
Long sellerId = 1L;
411+
List<Instrument> instrumentList = createInstrumentList();
412+
List<InstrumentDto> expectedResult = instrumentList.stream()
413+
.map(InstrumentMapper::toDto)
414+
.collect(Collectors.toList());
415+
given(instrumentRepository.findAllBySellerId(sellerId)).willReturn(instrumentList);
416+
417+
// when
418+
List<InstrumentDto> actualResult = sut.findAllBySellerId(sellerId);
419+
420+
// then
421+
then(instrumentRepository).should().findAllBySellerId(sellerId);
422+
verifyEveryMocksShouldHaveNoMoreInteractions();
423+
assertThat(actualResult.size()).isEqualTo(expectedResult.size());
424+
}
425+
404426
private void verifyEveryMocksShouldHaveNoMoreInteractions() {
405427
then(instrumentRepository).shouldHaveNoMoreInteractions();
406428
}
@@ -595,4 +617,13 @@ private AudioEquipmentFilterConditions createAudioEquipmentFilterConditions() th
595617
AudioEquipmentType.AUDIO_EQUIPMENT
596618
);
597619
}
620+
621+
private List<Instrument> createInstrumentList() throws Exception {
622+
List<Instrument> instruments = new ArrayList<>();
623+
User seller = createUser(1L);
624+
instruments.add(createElectricGuitar(1L, seller));
625+
instruments.add(createElectricGuitar(2L, seller));
626+
return instruments;
627+
}
628+
598629
}

src/test/java/com/ajou/hertz/unit/domain/user/controller/UserControllerTest.java

+13
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
import java.time.LocalDate;
1010
import java.time.LocalDateTime;
11+
import java.util.ArrayList;
12+
import java.util.List;
1113
import java.util.Set;
1214

1315
import org.junit.jupiter.api.DisplayName;
@@ -31,6 +33,7 @@
3133
import com.ajou.hertz.common.auth.JwtTokenProvider;
3234
import com.ajou.hertz.common.auth.UserPrincipal;
3335
import com.ajou.hertz.common.config.SecurityConfig;
36+
import com.ajou.hertz.domain.instrument.dto.InstrumentDto;
3437
import com.ajou.hertz.domain.instrument.service.InstrumentQueryService;
3538
import com.ajou.hertz.domain.user.constant.Gender;
3639
import com.ajou.hertz.domain.user.constant.RoleType;
@@ -307,9 +310,12 @@ public void securitySetUp() throws Exception {
307310
UserDto expectedResult = createUserDto(userId);
308311
int sellingCount = 2;
309312
int soldCount = 3;
313+
List<InstrumentDto> instrumentDtos = createInstrumentDtoList();
314+
310315
given(userQueryService.getDtoById(userId)).willReturn(expectedResult);
311316
given(instrumentQueryService.countSellingItemsBySellerId(userId)).willReturn(sellingCount);
312317
given(instrumentQueryService.countSoldItemsBySellerId(userId)).willReturn(soldCount);
318+
given(instrumentQueryService.findAllBySellerId(userId)).willReturn(instrumentDtos);
313319

314320
// when & then
315321
mvc.perform(
@@ -321,6 +327,7 @@ public void securitySetUp() throws Exception {
321327
then(userQueryService).should().getDtoById(userId);
322328
then(instrumentQueryService).should().countSellingItemsBySellerId(userId);
323329
then(instrumentQueryService).should().countSoldItemsBySellerId(userId);
330+
then(instrumentQueryService).should().findAllBySellerId(userId);
324331
verifyEveryMocksShouldHaveNoMoreInteractions();
325332
}
326333

@@ -370,4 +377,10 @@ private UserDto createUserDto() throws Exception {
370377
private UserDetails createTestUser(Long userId) throws Exception {
371378
return new UserPrincipal(createUserDto(userId));
372379
}
380+
381+
private List<InstrumentDto> createInstrumentDtoList() {
382+
List<InstrumentDto> instrumentDtos = new ArrayList<>();
383+
return instrumentDtos;
384+
}
385+
373386
}

0 commit comments

Comments
 (0)