Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

사용자 가입 시 신뢰도를 null로 설정 #536

Closed
wants to merge 6 commits into from
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public record ReadAuctionDto(
Long sellerId,
Long sellerProfileId,
String sellerName,
double sellerReliability,
Double sellerReliability,
boolean isSellerDeleted,
AuctionStatus auctionStatus
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public record SellerResponse(
Long id,
String image,
String nickname,
double reliability
Double reliability
) {

public static SellerResponse from(final ReadAuctionDto auctionDto) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private User findOrPersistUser(final Oauth2Type oauth2Type, final UserInformatio
final User user = User.builder()
.name(oauth2Type.calculateNickname(calculateRandomNumber()))
.profileImage(findDefaultProfileImage())
.reliability(0.0d)
.reliability(null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

질문

값 객체로 변경하게 된다면 null을 직접적으로 넣지 않고, 미리 null로 설정해 둔 값객체에 대한 static 필드를 사용하게 될까요?

Copy link
Collaborator Author

@kwonyj1022 kwonyj1022 Oct 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵 값객체 적용한 pr에서 User 생성 시 reliability가 null이면 static 필드를 사용하도록 구현되어 있습니다!

.oauthId(userInformationDto.findUserId())
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.ddang.ddang.image.application.util.ImageIdProcessor;
import com.ddang.ddang.user.domain.User;

public record ReadUserInChatRoomDto(Long id, String name, Long profileImageId, double reliability, boolean isDeleted) {
public record ReadUserInChatRoomDto(Long id, String name, Long profileImageId, Double reliability, boolean isDeleted) {

public static ReadUserInChatRoomDto from(final User user) {
return new ReadUserInChatRoomDto(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.ddang.ddang.image.application.util.ImageIdProcessor;
import com.ddang.ddang.user.domain.User;

public record ReadReporterDto(Long id, String name, Long profileImageId, double reliability, boolean isDeleted) {
public record ReadReporterDto(Long id, String name, Long profileImageId, Double reliability, boolean isDeleted) {

public static ReadReporterDto from(final User reporter) {
return new ReadReporterDto(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public record ReadUserInReportDto(
Long id,
String name,
Long profileImageId,
double reliability,
Double reliability,
String oauthId,
boolean isSellerDeleted
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public record ReadUserDto(
Long id,
String name,
Long profileImageId,
double reliability,
Double reliability,
String oauthId,
boolean isDeleted
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
@Entity
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Getter
@EqualsAndHashCode(of = "id")
@EqualsAndHashCode(of = "id", callSuper = false)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

칭찬

경고 억제 👍

@ToString(of = {"id", "name", "reliability", "oauthId", "deleted"})
@Table(name = "users")
public class User extends BaseTimeEntity {
Expand All @@ -42,7 +42,7 @@ public class User extends BaseTimeEntity {
@JoinColumn(name = "profile_image_id", foreignKey = @ForeignKey(name = "fk_user_profile_image"), nullable = false)
private ProfileImage profileImage;

private double reliability;
private Double reliability;

private String oauthId;

Expand All @@ -53,7 +53,7 @@ public class User extends BaseTimeEntity {
private User(
final String name,
final ProfileImage profileImage,
final double reliability,
final Double reliability,
final String oauthId
) {
this.name = name;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.ddang.ddang.user.application.dto.ReadUserDto;
import com.ddang.ddang.user.presentation.util.NameProcessor;

public record ReadUserResponse(String name, String profileImage, double reliability) {
public record ReadUserResponse(String name, String profileImage, Double reliability) {

public static ReadUserResponse from(final ReadUserDto readUserDto) {
return new ReadUserResponse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ public record SellerResponse(
Long id,
String image,
String nickname,
double reliability
Double reliability
) {
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
package com.ddang.ddang.auction.application;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given;

import com.ddang.ddang.auction.application.dto.CreateInfoAuctionDto;
import com.ddang.ddang.auction.application.dto.ReadAuctionDto;
import com.ddang.ddang.auction.application.dto.ReadAuctionsDto;
Expand All @@ -18,7 +12,6 @@
import com.ddang.ddang.image.domain.StoreImageProcessor;
import com.ddang.ddang.region.application.exception.RegionNotFoundException;
import com.ddang.ddang.user.application.exception.UserNotFoundException;
import java.util.List;
import org.assertj.core.api.SoftAssertions;
import org.junit.jupiter.api.DisplayNameGeneration;
import org.junit.jupiter.api.DisplayNameGenerator;
Expand All @@ -29,6 +22,14 @@
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Order;

import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given;

@IsolateDatabase
@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class)
@SuppressWarnings("NonAsciiCharacters")
Expand Down Expand Up @@ -195,6 +196,15 @@ class AuctionServiceTest extends AuctionServiceFixture {
.hasMessage("지정한 아이디에 대한 경매를 찾을 수 없습니다.");
}

@Test
void 지정한_아이디에_해당하는_경매의_판매자_신뢰도가_null이라면_서비스에서_반환하는_dto에서_판매자_신뢰도를_나타내는_부분도_null이다() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

선택

굉장히 자세한 메서드 네이밍이네요..!
그런데 해당 로직은 auction보다는 dto의 getter를 테스트하는 느낌이 더 강한 것 같습니다.
auctionServiceTest에서 진행해주신 이유가 있으신지 궁금합니다.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

혹시나 NPE가 발생하는지 궁금해서 개인적인 테스트를 해보았는데, 원래는 결과만 보고 롤백하려고 했는데 나중에 또 궁금할까 봐 있으면 좋을 것 같아서 커밋하였습니다. 처음 의도는 원래 커밋은 할 생각을 안 했고 그냥 개인적으로 확인차 테스트했던 거라 픽스처 클래스 만들고 하기 귀찮아서 있던 테스트에서 같이 했는데 커밋할 때는 또 생각 없이 해버렸네요ㅠ
그래서 결론은 dto 테스트로 옮기겠습니다~
예리하시네요 메리!

// when
final ReadAuctionDto actual = auctionService.readByAuctionId(신뢰도가_null인_판매자의_경매.getId());

// then
assertThat(actual.sellerReliability()).isNull();
}

@Test
void 첫번째_페이지의_경매_목록을_조회한다() {
// when
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.ddang.ddang.auction.application.fixture;

import com.ddang.ddang.auction.application.AuctionService;
import com.ddang.ddang.auction.application.dto.CreateAuctionDto;
import com.ddang.ddang.auction.domain.Auction;
import com.ddang.ddang.auction.domain.BidUnit;
import com.ddang.ddang.auction.domain.Price;
import com.ddang.ddang.auction.infrastructure.persistence.JpaAuctionRepository;
import com.ddang.ddang.bid.domain.Bid;
import com.ddang.ddang.bid.domain.BidPrice;
Expand All @@ -11,25 +12,24 @@
import com.ddang.ddang.category.infrastructure.persistence.JpaCategoryRepository;
import com.ddang.ddang.chat.domain.ChatRoom;
import com.ddang.ddang.chat.infrastructure.persistence.JpaChatRoomRepository;
import com.ddang.ddang.image.domain.AuctionImage;
import com.ddang.ddang.image.domain.ProfileImage;
import com.ddang.ddang.image.domain.dto.StoreImageDto;
import com.ddang.ddang.region.domain.Region;
import com.ddang.ddang.region.infrastructure.persistence.JpaRegionRepository;
import com.ddang.ddang.user.domain.User;
import com.ddang.ddang.user.infrastructure.persistence.JpaUserRepository;
import java.time.LocalDateTime;
import java.util.List;
import org.junit.jupiter.api.BeforeEach;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.mock.web.MockMultipartFile;

import java.time.LocalDateTime;
import java.util.List;

@SuppressWarnings("NonAsciiCharacters")
public class AuctionServiceFixture {

@Autowired
private AuctionService auctionService;

@Autowired
private JpaAuctionRepository auctionRepository;

Expand Down Expand Up @@ -58,11 +58,17 @@ public class AuctionServiceFixture {
.oauthId("12345")
.build();
protected User 구매자 = User.builder()
.name("구매자")
.profileImage(new ProfileImage("upload.png", "store.png"))
.reliability(4.7d)
.oauthId("54321")
.build();
.name("구매자")
.profileImage(new ProfileImage("upload.png", "store.png"))
.reliability(4.7d)
.oauthId("54321")
.build();
protected User 신뢰도가_null인_판매자 = User.builder()
.name("신뢰도가 null인 판매자")
.profileImage(new ProfileImage("upload.png", "store.png"))
.reliability(null)
.oauthId("99999")
.build();

private MockMultipartFile 경매_이미지_파일 = new MockMultipartFile(
"image.png",
Expand Down Expand Up @@ -90,6 +96,7 @@ public class AuctionServiceFixture {
protected Auction 종료되는_날이_3일_뒤인_경매;
protected Auction 입찰이_존재하는_경매;
protected Auction 종료된_경매;
protected Auction 신뢰도가_null인_판매자의_경매;
protected BidPrice 채팅방이_있는_경매_입찰_가격 = new BidPrice(10_000);
protected Bid 채팅방이_있는_경매_입찰;
protected Bid 입찰이_존재하는_경매_입찰;
Expand All @@ -109,7 +116,7 @@ void setUp() {

categoryRepository.save(가구_카테고리);

userRepository.saveAll(List.of(판매자, 구매자));
userRepository.saveAll(List.of(판매자, 구매자, 신뢰도가_null인_판매자));

유효한_경매_생성_dto = new CreateAuctionDto(
"제목",
Expand Down Expand Up @@ -224,7 +231,17 @@ void setUp() {
채팅방이_있는_경매.updateLastBid(채팅방이_있는_경매_입찰);
입찰이_존재하는_경매.updateLastBid(입찰이_존재하는_경매_입찰);

auctionRepository.saveAll(List.of(채팅방이_있는_경매, 종료되는_날이_3일_뒤인_경매, 입찰이_존재하는_경매, 종료된_경매));
신뢰도가_null인_판매자의_경매 = Auction.builder()
.title("신뢰도가 null인 판매자의 경매")
.description("신뢰도가 null인 판매자의 경매")
.subCategory(가구_서브_의자_카테고리)
.seller(신뢰도가_null인_판매자)
.bidUnit(new BidUnit(1_000))
.startPrice(new Price(10_000))
.closingTime(LocalDateTime.now().plusDays(3L))
.build();
신뢰도가_null인_판매자의_경매.addAuctionImages(List.of(new AuctionImage("auction.png", "auction.png")));
auctionRepository.saveAll(List.of(신뢰도가_null인_판매자의_경매, 채팅방이_있는_경매, 종료되는_날이_3일_뒤인_경매, 입찰이_존재하는_경매, 종료된_경매));

final ChatRoom 채팅방 = new ChatRoom(채팅방이_있는_경매, 구매자);

Expand Down
Loading