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
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.ddang.ddang.auction.application.dto;

import com.ddang.ddang.auction.application.dto.fixture.ReadAuctionDtoFixture;
import com.ddang.ddang.configuration.IsolateDatabase;
import org.junit.jupiter.api.DisplayNameGeneration;
import org.junit.jupiter.api.DisplayNameGenerator;
import org.junit.jupiter.api.Test;

import java.time.LocalDateTime;

import static org.assertj.core.api.Assertions.assertThat;

@IsolateDatabase
@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class)
@SuppressWarnings("NonAsciiCharacters")
class ReadAuctionDtoTest extends ReadAuctionDtoFixture {

@Test
void 지정한_아이디에_해당하는_경매의_판매자_신뢰도가_null이라면_서비스에서_반환하는_dto에서_판매자_신뢰도를_나타내는_부분도_null이다() {
// when
final ReadAuctionDto actual = ReadAuctionDto.of(신뢰도가_null인_판매자의_경매, LocalDateTime.now());

// then
assertThat(actual.sellerReliability()).isNull();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package com.ddang.ddang.auction.application.dto.fixture;

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.category.domain.Category;
import com.ddang.ddang.category.infrastructure.persistence.JpaCategoryRepository;
import com.ddang.ddang.image.domain.AuctionImage;
import com.ddang.ddang.image.domain.ProfileImage;
import com.ddang.ddang.region.infrastructure.persistence.JpaRegionRepository;
import com.ddang.ddang.user.domain.User;
import com.ddang.ddang.user.infrastructure.persistence.JpaUserRepository;
import org.junit.jupiter.api.BeforeEach;
import org.springframework.beans.factory.annotation.Autowired;

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

@SuppressWarnings("NonAsciiCharacters")
public class ReadAuctionDtoFixture {

@Autowired
private JpaAuctionRepository auctionRepository;

@Autowired
private JpaRegionRepository regionRepository;

@Autowired
private JpaCategoryRepository categoryRepository;

@Autowired
private JpaUserRepository userRepository;

private Category 가구_카테고리 = new Category("가구");
private Category 가구_서브_의자_카테고리 = new Category("의자");
protected User 신뢰도가_null인_판매자 = User.builder()
.name("신뢰도가 null인 판매자")
.profileImage(new ProfileImage("upload.png", "store.png"))
.reliability(null)
.oauthId("99999")
.build();
protected Auction 신뢰도가_null인_판매자의_경매;

@BeforeEach
void setUp() {
userRepository.save(신뢰도가_null인_판매자);

가구_카테고리.addSubCategory(가구_서브_의자_카테고리);
categoryRepository.save(가구_카테고리);

신뢰도가_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.save(신뢰도가_null인_판매자의_경매);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
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.infrastructure.persistence.JpaAuctionRepository;
Expand All @@ -17,19 +16,17 @@
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 +55,11 @@ 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();

private MockMultipartFile 경매_이미지_파일 = new MockMultipartFile(
"image.png",
Expand Down Expand Up @@ -223,7 +220,6 @@ void setUp() {

채팅방이_있는_경매.updateLastBid(채팅방이_있는_경매_입찰);
입찰이_존재하는_경매.updateLastBid(입찰이_존재하는_경매_입찰);

auctionRepository.saveAll(List.of(채팅방이_있는_경매, 종료되는_날이_3일_뒤인_경매, 입찰이_존재하는_경매, 종료된_경매));

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