Skip to content

Commit

Permalink
Merge pull request #104 from Ajou-Hertz/feature/#89-get-seller-info
Browse files Browse the repository at this point in the history
판매자 정보 조회에 악기 판매 내역 추가
  • Loading branch information
Wo-ogie authored Apr 11, 2024
2 parents 8164d6e + 5afaf51 commit 34da23e
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
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;
import com.ajou.hertz.domain.instrument.entity.Instrument;

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

int countBySellerIdAndProgressStatus(Long sellerid, InstrumentProgressStatus progressStatus);
int countBySellerIdAndProgressStatus(Long sellerId, InstrumentProgressStatus progressStatus);

List<Instrument> findAllBySellerId(Long sellerId);
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -200,7 +203,6 @@ public Page<AudioEquipmentDto> findAudioEquipmentDtos(
* 판매자가 판매중인 물품의 수를 조회합니다
*
* @param sellerId 판매자 id
*
* @return 판매중인 물품의 수
*/
public int countSellingItemsBySellerId(Long sellerId) {
Expand All @@ -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<InstrumentDto> findAllBySellerId(Long sellerId) {
List<Instrument> instruments = instrumentRepository.findAllBySellerId(sellerId);
return instruments.stream()
.map(InstrumentMapper::toDto)
.collect(Collectors.toList());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<InstrumentDto> createdInstruments = instrumentQueryService.findAllBySellerId(userId);
return SellerInfoResponse.from(userDto, sellingCount, soldCount, createdInstruments);
}

}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -36,15 +38,21 @@ public class SellerInfoResponse {
@Schema(description = "판매완료한 물품의 수", example = "10")
private long soldItemCount;

public static SellerInfoResponse from(UserDto userDto, long sellingItemCount, long soldItemCount) {
@Schema(description = "악기 판매 내역")
private List<InstrumentDto> createdInstruments;

public static SellerInfoResponse from(UserDto userDto, long sellingItemCount, long soldItemCount,
List<InstrumentDto> createdInstruments) {
return new SellerInfoResponse(
userDto.getId(),
userDto.getEmail(),
userDto.getProfileImageUrl(),
userDto.getContactLink(),
userDto.getCreatedAt(),
sellingItemCount,
soldItemCount
soldItemCount,
createdInstruments
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -401,6 +404,25 @@ class InstrumentQueryServiceTest {
assertThat(actualResult).isEqualTo(expectedResult);
}

@Test
void 해당_유저의_악기_판매_내역을_조회한다() throws Exception {
// given
Long sellerId = 1L;
List<Instrument> instrumentList = createInstrumentList();
List<InstrumentDto> expectedResult = instrumentList.stream()
.map(InstrumentMapper::toDto)
.collect(Collectors.toList());
given(instrumentRepository.findAllBySellerId(sellerId)).willReturn(instrumentList);

// when
List<InstrumentDto> actualResult = sut.findAllBySellerId(sellerId);

// then
then(instrumentRepository).should().findAllBySellerId(sellerId);
verifyEveryMocksShouldHaveNoMoreInteractions();
assertThat(actualResult.size()).isEqualTo(expectedResult.size());
}

private void verifyEveryMocksShouldHaveNoMoreInteractions() {
then(instrumentRepository).shouldHaveNoMoreInteractions();
}
Expand Down Expand Up @@ -595,4 +617,13 @@ private AudioEquipmentFilterConditions createAudioEquipmentFilterConditions() th
AudioEquipmentType.AUDIO_EQUIPMENT
);
}

private List<Instrument> createInstrumentList() throws Exception {
List<Instrument> instruments = new ArrayList<>();
User seller = createUser(1L);
instruments.add(createElectricGuitar(1L, seller));
instruments.add(createElectricGuitar(2L, seller));
return instruments;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -307,9 +310,12 @@ public void securitySetUp() throws Exception {
UserDto expectedResult = createUserDto(userId);
int sellingCount = 2;
int soldCount = 3;
List<InstrumentDto> 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(
Expand All @@ -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();
}

Expand Down Expand Up @@ -370,4 +377,10 @@ private UserDto createUserDto() throws Exception {
private UserDetails createTestUser(Long userId) throws Exception {
return new UserPrincipal(createUserDto(userId));
}

private List<InstrumentDto> createInstrumentDtoList() {
List<InstrumentDto> instrumentDtos = new ArrayList<>();
return instrumentDtos;
}

}

0 comments on commit 34da23e

Please sign in to comment.