From 6d090c81c5ddf861e4021a43f18868b4f163a223 Mon Sep 17 00:00:00 2001 From: JaeUk Jeong Date: Wed, 13 Mar 2024 12:37:19 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20#80=20=EC=95=85=EA=B8=B0=20response=20D?= =?UTF-8?q?TO=EC=97=90=20=EC=B9=B4=ED=85=8C=EA=B3=A0=EB=A6=AC=20=ED=95=84?= =?UTF-8?q?=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AcousticAndClassicGuitarResponse.java | 32 ++++------ .../dto/response/AmplifierResponse.java | 30 ++++------ .../dto/response/AudioEquipmentResponse.java | 26 +++------ .../dto/response/BassGuitarResponse.java | 32 ++++------ .../dto/response/EffectorResponse.java | 28 ++++----- .../dto/response/ElectricGuitarResponse.java | 33 +++++------ .../dto/response/InstrumentResponse.java | 58 +++++++++++++------ .../response/InstrumentSummaryResponse.java | 5 ++ .../controller/InstrumentControllerTest.java | 11 ++-- 9 files changed, 119 insertions(+), 136 deletions(-) diff --git a/src/main/java/com/ajou/hertz/domain/instrument/dto/response/AcousticAndClassicGuitarResponse.java b/src/main/java/com/ajou/hertz/domain/instrument/dto/response/AcousticAndClassicGuitarResponse.java index 7edd750..10c9a52 100644 --- a/src/main/java/com/ajou/hertz/domain/instrument/dto/response/AcousticAndClassicGuitarResponse.java +++ b/src/main/java/com/ajou/hertz/domain/instrument/dto/response/AcousticAndClassicGuitarResponse.java @@ -7,6 +7,7 @@ import com.ajou.hertz.domain.instrument.constant.AcousticAndClassicGuitarModel; import com.ajou.hertz.domain.instrument.constant.AcousticAndClassicGuitarPickUp; import com.ajou.hertz.domain.instrument.constant.AcousticAndClassicGuitarWood; +import com.ajou.hertz.domain.instrument.constant.InstrumentCategory; import com.ajou.hertz.domain.instrument.constant.InstrumentProgressStatus; import com.ajou.hertz.domain.instrument.dto.AcousticAndClassicGuitarDto; @@ -49,8 +50,8 @@ private AcousticAndClassicGuitarResponse( AcousticAndClassicGuitarPickUp pickUp ) { super( - id, sellerId, title, progressStatus, tradeAddress, qualityStatus, - price, hasAnomaly, description, images, hashtags + id, sellerId, InstrumentCategory.ACOUSTIC_AND_CLASSIC_GUITAR, title, progressStatus, tradeAddress, + qualityStatus, price, hasAnomaly, description, images, hashtags ); this.brand = brand; this.model = model; @@ -58,24 +59,15 @@ private AcousticAndClassicGuitarResponse( this.pickUp = pickUp; } + private AcousticAndClassicGuitarResponse(AcousticAndClassicGuitarDto acousticAndClassicGuitarDto) { + super(acousticAndClassicGuitarDto); + this.brand = acousticAndClassicGuitarDto.getBrand(); + this.model = acousticAndClassicGuitarDto.getModel(); + this.wood = acousticAndClassicGuitarDto.getWood(); + this.pickUp = acousticAndClassicGuitarDto.getPickUp(); + } + public static AcousticAndClassicGuitarResponse from(AcousticAndClassicGuitarDto acousticAndClassicGuitarDto) { - InstrumentResponse instrumentResponse = InstrumentResponse.from(acousticAndClassicGuitarDto); - return new AcousticAndClassicGuitarResponse( - instrumentResponse.getId(), - instrumentResponse.getSellerId(), - instrumentResponse.getTitle(), - instrumentResponse.getProgressStatus(), - instrumentResponse.getTradeAddress(), - instrumentResponse.getQualityStatus(), - instrumentResponse.getPrice(), - instrumentResponse.getHasAnomaly(), - instrumentResponse.getDescription(), - instrumentResponse.getImages(), - instrumentResponse.getHashtags(), - acousticAndClassicGuitarDto.getBrand(), - acousticAndClassicGuitarDto.getModel(), - acousticAndClassicGuitarDto.getWood(), - acousticAndClassicGuitarDto.getPickUp() - ); + return new AcousticAndClassicGuitarResponse(acousticAndClassicGuitarDto); } } diff --git a/src/main/java/com/ajou/hertz/domain/instrument/dto/response/AmplifierResponse.java b/src/main/java/com/ajou/hertz/domain/instrument/dto/response/AmplifierResponse.java index 7011b1a..50019b9 100644 --- a/src/main/java/com/ajou/hertz/domain/instrument/dto/response/AmplifierResponse.java +++ b/src/main/java/com/ajou/hertz/domain/instrument/dto/response/AmplifierResponse.java @@ -6,6 +6,7 @@ import com.ajou.hertz.domain.instrument.constant.AmplifierBrand; import com.ajou.hertz.domain.instrument.constant.AmplifierType; import com.ajou.hertz.domain.instrument.constant.AmplifierUsage; +import com.ajou.hertz.domain.instrument.constant.InstrumentCategory; import com.ajou.hertz.domain.instrument.constant.InstrumentProgressStatus; import com.ajou.hertz.domain.instrument.dto.AmplifierDto; @@ -44,31 +45,22 @@ private AmplifierResponse( AmplifierUsage usage ) { super( - id, sellerId, title, progressStatus, tradeAddress, qualityStatus, - price, hasAnomaly, description, images, hashtags + id, sellerId, InstrumentCategory.AMPLIFIER, title, progressStatus, tradeAddress, + qualityStatus, price, hasAnomaly, description, images, hashtags ); this.type = type; this.brand = brand; this.usage = usage; } + private AmplifierResponse(AmplifierDto amplifierDto) { + super(amplifierDto); + this.type = amplifierDto.getType(); + this.brand = amplifierDto.getBrand(); + this.usage = amplifierDto.getUsage(); + } + public static AmplifierResponse from(AmplifierDto amplifierDto) { - InstrumentResponse instrumentResponse = InstrumentResponse.from(amplifierDto); - return new AmplifierResponse( - instrumentResponse.getId(), - instrumentResponse.getSellerId(), - instrumentResponse.getTitle(), - instrumentResponse.getProgressStatus(), - instrumentResponse.getTradeAddress(), - instrumentResponse.getQualityStatus(), - instrumentResponse.getPrice(), - instrumentResponse.getHasAnomaly(), - instrumentResponse.getDescription(), - instrumentResponse.getImages(), - instrumentResponse.getHashtags(), - amplifierDto.getType(), - amplifierDto.getBrand(), - amplifierDto.getUsage() - ); + return new AmplifierResponse(amplifierDto); } } diff --git a/src/main/java/com/ajou/hertz/domain/instrument/dto/response/AudioEquipmentResponse.java b/src/main/java/com/ajou/hertz/domain/instrument/dto/response/AudioEquipmentResponse.java index c545e20..8ae354d 100644 --- a/src/main/java/com/ajou/hertz/domain/instrument/dto/response/AudioEquipmentResponse.java +++ b/src/main/java/com/ajou/hertz/domain/instrument/dto/response/AudioEquipmentResponse.java @@ -4,6 +4,7 @@ import com.ajou.hertz.common.dto.response.AddressResponse; import com.ajou.hertz.domain.instrument.constant.AudioEquipmentType; +import com.ajou.hertz.domain.instrument.constant.InstrumentCategory; import com.ajou.hertz.domain.instrument.constant.InstrumentProgressStatus; import com.ajou.hertz.domain.instrument.dto.AudioEquipmentDto; @@ -34,27 +35,18 @@ private AudioEquipmentResponse( AudioEquipmentType type ) { super( - id, sellerId, title, progressStatus, tradeAddress, qualityStatus, - price, hasAnomaly, description, images, hashtags + id, sellerId, InstrumentCategory.AUDIO_EQUIPMENT, title, progressStatus, tradeAddress, + qualityStatus, price, hasAnomaly, description, images, hashtags ); this.type = type; } + private AudioEquipmentResponse(AudioEquipmentDto audioEquipmentDto) { + super(audioEquipmentDto); + this.type = audioEquipmentDto.getType(); + } + public static AudioEquipmentResponse from(AudioEquipmentDto audioEquipmentDto) { - InstrumentResponse instrumentResponse = InstrumentResponse.from(audioEquipmentDto); - return new AudioEquipmentResponse( - instrumentResponse.getId(), - instrumentResponse.getSellerId(), - instrumentResponse.getTitle(), - instrumentResponse.getProgressStatus(), - instrumentResponse.getTradeAddress(), - instrumentResponse.getQualityStatus(), - instrumentResponse.getPrice(), - instrumentResponse.getHasAnomaly(), - instrumentResponse.getDescription(), - instrumentResponse.getImages(), - instrumentResponse.getHashtags(), - audioEquipmentDto.getType() - ); + return new AudioEquipmentResponse(audioEquipmentDto); } } diff --git a/src/main/java/com/ajou/hertz/domain/instrument/dto/response/BassGuitarResponse.java b/src/main/java/com/ajou/hertz/domain/instrument/dto/response/BassGuitarResponse.java index 7fec6f6..abc1fb8 100644 --- a/src/main/java/com/ajou/hertz/domain/instrument/dto/response/BassGuitarResponse.java +++ b/src/main/java/com/ajou/hertz/domain/instrument/dto/response/BassGuitarResponse.java @@ -7,6 +7,7 @@ import com.ajou.hertz.domain.instrument.constant.BassGuitarPickUp; import com.ajou.hertz.domain.instrument.constant.BassGuitarPreAmplifier; import com.ajou.hertz.domain.instrument.constant.GuitarColor; +import com.ajou.hertz.domain.instrument.constant.InstrumentCategory; import com.ajou.hertz.domain.instrument.constant.InstrumentProgressStatus; import com.ajou.hertz.domain.instrument.dto.BassGuitarDto; @@ -49,8 +50,8 @@ private BassGuitarResponse( GuitarColor color ) { super( - id, sellerId, title, progressStatus, tradeAddress, qualityStatus, - price, hasAnomaly, description, images, hashtags + id, sellerId, InstrumentCategory.BASS_GUITAR, title, progressStatus, tradeAddress, + qualityStatus, price, hasAnomaly, description, images, hashtags ); this.brand = brand; this.pickUp = pickUp; @@ -58,24 +59,15 @@ private BassGuitarResponse( this.color = color; } + private BassGuitarResponse(BassGuitarDto bassGuitarDto) { + super(bassGuitarDto); + this.brand = bassGuitarDto.getBrand(); + this.pickUp = bassGuitarDto.getPickUp(); + this.preAmplifier = bassGuitarDto.getPreAmplifier(); + this.color = bassGuitarDto.getColor(); + } + public static BassGuitarResponse from(BassGuitarDto bassGuitarDto) { - InstrumentResponse instrumentResponse = InstrumentResponse.from(bassGuitarDto); - return new BassGuitarResponse( - instrumentResponse.getId(), - instrumentResponse.getSellerId(), - instrumentResponse.getTitle(), - instrumentResponse.getProgressStatus(), - instrumentResponse.getTradeAddress(), - instrumentResponse.getQualityStatus(), - instrumentResponse.getPrice(), - instrumentResponse.getHasAnomaly(), - instrumentResponse.getDescription(), - instrumentResponse.getImages(), - instrumentResponse.getHashtags(), - bassGuitarDto.getBrand(), - bassGuitarDto.getPickUp(), - bassGuitarDto.getPreAmplifier(), - bassGuitarDto.getColor() - ); + return new BassGuitarResponse(bassGuitarDto); } } diff --git a/src/main/java/com/ajou/hertz/domain/instrument/dto/response/EffectorResponse.java b/src/main/java/com/ajou/hertz/domain/instrument/dto/response/EffectorResponse.java index dadfc16..54b856e 100644 --- a/src/main/java/com/ajou/hertz/domain/instrument/dto/response/EffectorResponse.java +++ b/src/main/java/com/ajou/hertz/domain/instrument/dto/response/EffectorResponse.java @@ -5,6 +5,7 @@ import com.ajou.hertz.common.dto.response.AddressResponse; import com.ajou.hertz.domain.instrument.constant.EffectorFeature; import com.ajou.hertz.domain.instrument.constant.EffectorType; +import com.ajou.hertz.domain.instrument.constant.InstrumentCategory; import com.ajou.hertz.domain.instrument.constant.InstrumentProgressStatus; import com.ajou.hertz.domain.instrument.dto.EffectorDto; @@ -39,29 +40,20 @@ private EffectorResponse( EffectorFeature feature ) { super( - id, sellerId, title, progressStatus, tradeAddress, qualityStatus, - price, hasAnomaly, description, images, hashtags + id, sellerId, InstrumentCategory.EFFECTOR, title, progressStatus, tradeAddress, + qualityStatus, price, hasAnomaly, description, images, hashtags ); this.type = type; this.feature = feature; } + private EffectorResponse(EffectorDto effectorDto) { + super(effectorDto); + this.type = effectorDto.getType(); + this.feature = effectorDto.getFeature(); + } + public static EffectorResponse from(EffectorDto effectorDto) { - InstrumentResponse instrumentResponse = InstrumentResponse.from(effectorDto); - return new EffectorResponse( - instrumentResponse.getId(), - instrumentResponse.getSellerId(), - instrumentResponse.getTitle(), - instrumentResponse.getProgressStatus(), - instrumentResponse.getTradeAddress(), - instrumentResponse.getQualityStatus(), - instrumentResponse.getPrice(), - instrumentResponse.getHasAnomaly(), - instrumentResponse.getDescription(), - instrumentResponse.getImages(), - instrumentResponse.getHashtags(), - effectorDto.getType(), - effectorDto.getFeature() - ); + return new EffectorResponse(effectorDto); } } diff --git a/src/main/java/com/ajou/hertz/domain/instrument/dto/response/ElectricGuitarResponse.java b/src/main/java/com/ajou/hertz/domain/instrument/dto/response/ElectricGuitarResponse.java index 1d6ac4f..3d39a4f 100644 --- a/src/main/java/com/ajou/hertz/domain/instrument/dto/response/ElectricGuitarResponse.java +++ b/src/main/java/com/ajou/hertz/domain/instrument/dto/response/ElectricGuitarResponse.java @@ -6,6 +6,7 @@ import com.ajou.hertz.domain.instrument.constant.ElectricGuitarBrand; import com.ajou.hertz.domain.instrument.constant.ElectricGuitarModel; import com.ajou.hertz.domain.instrument.constant.GuitarColor; +import com.ajou.hertz.domain.instrument.constant.InstrumentCategory; import com.ajou.hertz.domain.instrument.constant.InstrumentProgressStatus; import com.ajou.hertz.domain.instrument.dto.ElectricGuitarDto; @@ -48,32 +49,24 @@ private ElectricGuitarResponse( GuitarColor color ) { super( - id, sellerId, title, progressStatus, tradeAddress, qualityStatus, - price, hasAnomaly, description, images, hashtags); + id, sellerId, InstrumentCategory.ELECTRIC_GUITAR, title, progressStatus, tradeAddress, + qualityStatus, price, hasAnomaly, description, images, hashtags + ); this.brand = brand; this.model = model; this.productionYear = productionYear; this.color = color; } + private ElectricGuitarResponse(ElectricGuitarDto electricGuitarDto) { + super(electricGuitarDto); + this.brand = electricGuitarDto.getBrand(); + this.model = electricGuitarDto.getModel(); + this.productionYear = electricGuitarDto.getProductionYear(); + this.color = electricGuitarDto.getColor(); + } + public static ElectricGuitarResponse from(ElectricGuitarDto electricGuitarDto) { - InstrumentResponse instrumentResponse = InstrumentResponse.from(electricGuitarDto); - return new ElectricGuitarResponse( - instrumentResponse.getId(), - instrumentResponse.getSellerId(), - instrumentResponse.getTitle(), - instrumentResponse.getProgressStatus(), - instrumentResponse.getTradeAddress(), - instrumentResponse.getQualityStatus(), - instrumentResponse.getPrice(), - instrumentResponse.getHasAnomaly(), - instrumentResponse.getDescription(), - instrumentResponse.getImages(), - instrumentResponse.getHashtags(), - electricGuitarDto.getBrand(), - electricGuitarDto.getModel(), - electricGuitarDto.getProductionYear(), - electricGuitarDto.getColor() - ); + return new ElectricGuitarResponse(electricGuitarDto); } } diff --git a/src/main/java/com/ajou/hertz/domain/instrument/dto/response/InstrumentResponse.java b/src/main/java/com/ajou/hertz/domain/instrument/dto/response/InstrumentResponse.java index 927f72b..b364fd9 100644 --- a/src/main/java/com/ajou/hertz/domain/instrument/dto/response/InstrumentResponse.java +++ b/src/main/java/com/ajou/hertz/domain/instrument/dto/response/InstrumentResponse.java @@ -3,6 +3,7 @@ import java.util.List; import com.ajou.hertz.common.dto.response.AddressResponse; +import com.ajou.hertz.domain.instrument.constant.InstrumentCategory; import com.ajou.hertz.domain.instrument.constant.InstrumentProgressStatus; import com.ajou.hertz.domain.instrument.dto.InstrumentDto; @@ -15,7 +16,7 @@ @AllArgsConstructor(access = AccessLevel.PROTECTED) @NoArgsConstructor(access = AccessLevel.PROTECTED) @Getter -public class InstrumentResponse { +public abstract class InstrumentResponse { @Schema(description = "Id of instrument(electric guitar)", example = "2") private Long id; @@ -23,6 +24,9 @@ public class InstrumentResponse { @Schema(description = "Id of seller", example = "1") private Long sellerId; + @Schema(description = "종류") + private InstrumentCategory category; + @Schema(description = "제목", example = "펜더 로드원 텔레캐스터") private String title; @@ -50,22 +54,40 @@ public class InstrumentResponse { @Schema(description = "해시태그", example = "[\"펜더\", \"Fender\"]") private List hashtags; - public static InstrumentResponse from(InstrumentDto instrumentDto) { - return new InstrumentResponse( - instrumentDto.getId(), - instrumentDto.getSeller().getId(), - instrumentDto.getTitle(), - instrumentDto.getProgressStatus(), - AddressResponse.from(instrumentDto.getTradeAddress()), - instrumentDto.getQualityStatus(), - instrumentDto.getPrice(), - instrumentDto.getHasAnomaly(), - instrumentDto.getDescription(), - instrumentDto.getImages() - .stream() - .map(InstrumentImageResponse::from) - .toList(), - instrumentDto.getHashtags() - ); + protected InstrumentResponse(InstrumentDto instrumentDto) { + this.id = instrumentDto.getId(); + this.sellerId = instrumentDto.getSeller().getId(); + this.category = instrumentDto.getCategory(); + this.title = instrumentDto.getTitle(); + this.progressStatus = instrumentDto.getProgressStatus(); + this.tradeAddress = AddressResponse.from(instrumentDto.getTradeAddress()); + this.qualityStatus = instrumentDto.getQualityStatus(); + this.price = instrumentDto.getPrice(); + this.hasAnomaly = instrumentDto.getHasAnomaly(); + this.description = instrumentDto.getDescription(); + this.images = instrumentDto.getImages().stream() + .map(InstrumentImageResponse::from) + .toList(); + this.hashtags = instrumentDto.getHashtags(); } + + // public static InstrumentResponse from(InstrumentDto instrumentDto) { + // return new InstrumentResponse( + // instrumentDto.getId(), + // instrumentDto.getSeller().getId(), + // instrumentDto.getCategory(), + // instrumentDto.getTitle(), + // instrumentDto.getProgressStatus(), + // AddressResponse.from(instrumentDto.getTradeAddress()), + // instrumentDto.getQualityStatus(), + // instrumentDto.getPrice(), + // instrumentDto.getHasAnomaly(), + // instrumentDto.getDescription(), + // instrumentDto.getImages() + // .stream() + // .map(InstrumentImageResponse::from) + // .toList(), + // instrumentDto.getHashtags() + // ); + // } } diff --git a/src/main/java/com/ajou/hertz/domain/instrument/dto/response/InstrumentSummaryResponse.java b/src/main/java/com/ajou/hertz/domain/instrument/dto/response/InstrumentSummaryResponse.java index 0964c39..adfafce 100644 --- a/src/main/java/com/ajou/hertz/domain/instrument/dto/response/InstrumentSummaryResponse.java +++ b/src/main/java/com/ajou/hertz/domain/instrument/dto/response/InstrumentSummaryResponse.java @@ -1,6 +1,7 @@ package com.ajou.hertz.domain.instrument.dto.response; import com.ajou.hertz.common.dto.response.AddressResponse; +import com.ajou.hertz.domain.instrument.constant.InstrumentCategory; import com.ajou.hertz.domain.instrument.constant.InstrumentProgressStatus; import com.ajou.hertz.domain.instrument.dto.InstrumentDto; @@ -18,6 +19,9 @@ public class InstrumentSummaryResponse { @Schema(description = "Id of instrument(electric guitar)", example = "2") private Long id; + @Schema(description = "종류") + private InstrumentCategory category; + @Schema(description = "제목", example = "펜더 로드원 텔레캐스터") private String title; @@ -36,6 +40,7 @@ public class InstrumentSummaryResponse { public static InstrumentSummaryResponse from(InstrumentDto instrumentDto) { return new InstrumentSummaryResponse( instrumentDto.getId(), + instrumentDto.getCategory(), instrumentDto.getTitle(), instrumentDto.getProgressStatus(), AddressResponse.from(instrumentDto.getTradeAddress()), diff --git a/src/test/java/com/ajou/hertz/unit/domain/instrument/controller/InstrumentControllerTest.java b/src/test/java/com/ajou/hertz/unit/domain/instrument/controller/InstrumentControllerTest.java index ce56e6e..21b4e51 100644 --- a/src/test/java/com/ajou/hertz/unit/domain/instrument/controller/InstrumentControllerTest.java +++ b/src/test/java/com/ajou/hertz/unit/domain/instrument/controller/InstrumentControllerTest.java @@ -45,6 +45,7 @@ import com.ajou.hertz.domain.instrument.constant.ElectricGuitarBrand; import com.ajou.hertz.domain.instrument.constant.ElectricGuitarModel; import com.ajou.hertz.domain.instrument.constant.GuitarColor; +import com.ajou.hertz.domain.instrument.constant.InstrumentCategory; import com.ajou.hertz.domain.instrument.constant.InstrumentProgressStatus; import com.ajou.hertz.domain.instrument.constant.InstrumentSortOption; import com.ajou.hertz.domain.instrument.controller.InstrumentController; @@ -100,12 +101,11 @@ public InstrumentControllerTest(MockMvc mvc) { long userId = 1L; int page = 0; int pageSize = 10; - InstrumentFilterConditions filterConditions = createInstrumentFilterConditions(); InstrumentSortOption sortOption = InstrumentSortOption.CREATED_BY_DESC; Page expectedResult = new PageImpl<>(List.of( - createBassGuitarDto(2L, userId), + createElectricGuitarDto(2L, userId), createBassGuitarDto(3L, userId), - createBassGuitarDto(4L, userId) + createAcousticAndClassicGuitarDto(4L, userId) )); given(instrumentQueryService.findInstruments(page, pageSize, sortOption)).willReturn(expectedResult); @@ -123,7 +123,10 @@ public InstrumentControllerTest(MockMvc mvc) { .andExpect(status().isOk()) .andExpect(jsonPath("$.numberOfElements").value(expectedResult.getNumberOfElements())) .andExpect(jsonPath("$.content").isArray()) - .andExpect(jsonPath("$.content", hasSize(expectedResult.getNumberOfElements()))); + .andExpect(jsonPath("$.content", hasSize(expectedResult.getNumberOfElements()))) + .andExpect(jsonPath("$.content[0].category").value(InstrumentCategory.ELECTRIC_GUITAR.name())) + .andExpect(jsonPath("$.content[1].category").value(InstrumentCategory.BASS_GUITAR.name())) + .andExpect(jsonPath("$.content[2].category").value(InstrumentCategory.ACOUSTIC_AND_CLASSIC_GUITAR.name())); then(instrumentQueryService).should().findInstruments(page, pageSize, sortOption); verifyEveryMocksShouldHaveNoMoreInteractions(); }