Skip to content

Commit

Permalink
feat: #89 판매자 정보 조회 API 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
tinon1004 committed Mar 27, 2024
1 parent 9821467 commit 2b53a1f
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

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 {

long countBySellerIdAndProgressStatus(Long sellerid, InstrumentProgressStatus progressStatus);

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.ajou.hertz.domain.instrument.audio_equipment.dto.request.AudioEquipmentFilterConditions;
import com.ajou.hertz.domain.instrument.bass_guitar.dto.BassGuitarDto;
import com.ajou.hertz.domain.instrument.bass_guitar.dto.request.BassGuitarFilterConditions;
import com.ajou.hertz.domain.instrument.constant.InstrumentProgressStatus;
import com.ajou.hertz.domain.instrument.constant.InstrumentSortOption;
import com.ajou.hertz.domain.instrument.dto.InstrumentDto;
import com.ajou.hertz.domain.instrument.effector.dto.EffectorDto;
Expand Down Expand Up @@ -194,4 +195,25 @@ public Page<AudioEquipmentDto> findAudioEquipmentDtos(
.findAudioEquipments(page, pageSize, sort, filterConditions)
.map(InstrumentMapper::toAmplifierDto);
}

/**
* 판매자가 판매중인 물품의 수를 조회합니다
*
* @param sellerId 판매자 id
*
* @return 판매중인 물품의 수
*/
public long countSellingItemsBySellerId(Long sellerId) {
return instrumentRepository.countBySellerIdAndProgressStatus(sellerId, InstrumentProgressStatus.SELLING);
}

/**
* 판매자가 판매완료한 물품들을 조회한다
*
* @param sellerId 판매자 id
* @return 판매완료한 물품의 수
*/
public long countSoldItemsBySellerId(Long sellerId) {
return instrumentRepository.countBySellerIdAndProgressStatus(sellerId, InstrumentProgressStatus.SOLD_OUT);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
Expand All @@ -20,10 +21,12 @@

import com.ajou.hertz.common.auth.UserPrincipal;
import com.ajou.hertz.common.validator.PhoneNumber;
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;
import com.ajou.hertz.domain.user.dto.request.UpdateContactLinkRequest;
import com.ajou.hertz.domain.user.dto.request.UpdatePasswordRequest;
import com.ajou.hertz.domain.user.dto.response.SellerInfoResponse;
import com.ajou.hertz.domain.user.dto.response.UserEmailResponse;
import com.ajou.hertz.domain.user.dto.response.UserExistenceResponse;
import com.ajou.hertz.domain.user.dto.response.UserResponse;
Expand Down Expand Up @@ -52,6 +55,7 @@ public class UserController {

private final UserCommandService userCommandService;
private final UserQueryService userQueryService;
private final InstrumentQueryService instrumentQueryService;

@Operation(
summary = "내 정보 조회",
Expand Down Expand Up @@ -171,5 +175,20 @@ public UserResponse updatePasswordV1(
return UserResponse.from(userUpdated);
}

@Operation(
summary = "판매자 정보 조회",
description = "판매자 정보(유저 정보 + 판매 중인 매물 수 + 판매 완료 매물 수)를 조회합니다.",
security = @SecurityRequirement(name = "access-token")
)
@GetMapping(value = "/{userId}/seller", headers = API_VERSION_HEADER_NAME + "=" + 1)
public SellerInfoResponse getSellerInfoV1(
@PathVariable Long userId
) {
UserDto userDto = userQueryService.getDtoById(userId);
long sellingCount = instrumentQueryService.countSellingItemsBySellerId(userId);
long soldCount = instrumentQueryService.countSoldItemsBySellerId(userId);
return SellerInfoResponse.from(userDto, sellingCount, soldCount);
}

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.ajou.hertz.domain.user.dto.response;

import java.time.LocalDateTime;

import com.ajou.hertz.domain.user.dto.UserDto;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@AllArgsConstructor(access = AccessLevel.PROTECTED)
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Getter
public class SellerInfoResponse {

@Schema(description = "Id of user", example = "1")
private Long id;

@Schema(description = "이메일", example = "[email protected]")
private String email;

@Schema(description = "프로필 이미지 url", example = "https://user-profile-image")
private String profileImage;

@Schema(description = "연락 수단", example = "https://contack-link")
private String contactLink;

@Schema(description = "가입일", example = "2024.01.01")
private LocalDateTime createdAt;

@Schema(description = "판매중인 물품의 수", example = "10")
private long sellingItemCount;

@Schema(description = "판매완료한 물품의 수", example = "10")
private long soldItemCount;

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

0 comments on commit 2b53a1f

Please sign in to comment.