diff --git a/src/main/java/com/ajou/hertz/domain/instrument/controller/InstrumentControllerV1.java b/src/main/java/com/ajou/hertz/domain/instrument/controller/InstrumentControllerV1.java index 53afdfe..30d9352 100644 --- a/src/main/java/com/ajou/hertz/domain/instrument/controller/InstrumentControllerV1.java +++ b/src/main/java/com/ajou/hertz/domain/instrument/controller/InstrumentControllerV1.java @@ -14,8 +14,11 @@ import org.springframework.web.bind.annotation.RestController; import com.ajou.hertz.common.auth.UserPrincipal; +import com.ajou.hertz.domain.instrument.dto.BassGuitarDto; import com.ajou.hertz.domain.instrument.dto.ElectricGuitarDto; +import com.ajou.hertz.domain.instrument.dto.request.CreateNewBassGuitarRequest; import com.ajou.hertz.domain.instrument.dto.request.CreateNewElectricGuitarRequest; +import com.ajou.hertz.domain.instrument.dto.response.BassGuitarResponse; import com.ajou.hertz.domain.instrument.dto.response.ElectricGuitarResponse; import com.ajou.hertz.domain.instrument.service.InstrumentCommandService; @@ -44,7 +47,7 @@ public class InstrumentControllerV1 { headers = API_MINOR_VERSION_HEADER_NAME + "=" + 1, consumes = MediaType.MULTIPART_FORM_DATA_VALUE ) - public ResponseEntity createNewInstrumentV1_1( + public ResponseEntity createNewElectricGuitarV1_1( @AuthenticationPrincipal UserPrincipal userPrincipal, @ParameterObject @ModelAttribute @Valid CreateNewElectricGuitarRequest createNewElectricGuitarRequest ) { @@ -56,4 +59,29 @@ public ResponseEntity createNewInstrumentV1_1( .created(URI.create("/instruments/" + electricGuitar.getId())) .body(ElectricGuitarResponse.from(electricGuitar)); } + + @Operation( + summary = "베이스 기타 매물 등록", + description = """ +

베이스 기타 매물을 등록합니다. +

요청 시 multipart/form-data content-type으로 요쳥해야 합니다. + """ + ) + @PostMapping( + value = "/bass-guitars", + headers = API_MINOR_VERSION_HEADER_NAME + "=" + 1, + consumes = MediaType.MULTIPART_FORM_DATA_VALUE + ) + public ResponseEntity createNewBassGuitarV1_1( + @AuthenticationPrincipal UserPrincipal userPrincipal, + @ParameterObject @ModelAttribute @Valid CreateNewBassGuitarRequest createNewBassGuitarRequest + ) { + BassGuitarDto bassGuitar = instrumentCommandService.createNewBassGuitar( + userPrincipal.getUserId(), + createNewBassGuitarRequest + ); + return ResponseEntity + .created(URI.create("/instruments/" + bassGuitar.getId())) + .body(BassGuitarResponse.from(bassGuitar)); + } } diff --git a/src/main/java/com/ajou/hertz/domain/instrument/dto/BassGuitarDto.java b/src/main/java/com/ajou/hertz/domain/instrument/dto/BassGuitarDto.java new file mode 100644 index 0000000..4794e68 --- /dev/null +++ b/src/main/java/com/ajou/hertz/domain/instrument/dto/BassGuitarDto.java @@ -0,0 +1,74 @@ +package com.ajou.hertz.domain.instrument.dto; + +import java.util.List; + +import com.ajou.hertz.common.dto.AddressDto; +import com.ajou.hertz.domain.instrument.constant.BassGuitarBrand; +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.InstrumentProgressStatus; +import com.ajou.hertz.domain.instrument.entity.BassGuitar; +import com.ajou.hertz.domain.user.dto.UserDto; + +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +@Getter +public class BassGuitarDto extends InstrumentDto { + + private BassGuitarBrand brand; + private BassGuitarPickUp pickUp; + private BassGuitarPreAmplifier preAmplifier; + private GuitarColor color; + + private BassGuitarDto( + Long id, + UserDto seller, + String title, + InstrumentProgressStatus progressStatus, + AddressDto tradeAddress, + Short qualityStatus, + Integer price, + Boolean hasAnomaly, + String description, + List images, + List hashtags, + BassGuitarBrand brand, + BassGuitarPickUp pickUp, + BassGuitarPreAmplifier preAmplifier, + GuitarColor color + ) { + super( + id, seller, title, progressStatus, tradeAddress, qualityStatus, + price, hasAnomaly, description, images, hashtags + ); + this.brand = brand; + this.pickUp = pickUp; + this.preAmplifier = preAmplifier; + this.color = color; + } + + public static BassGuitarDto from(BassGuitar bassGuitar) { + InstrumentDto instrumentDto = InstrumentDto.from(bassGuitar); + return new BassGuitarDto( + instrumentDto.getId(), + instrumentDto.getSeller(), + instrumentDto.getTitle(), + instrumentDto.getProgressStatus(), + instrumentDto.getTradeAddress(), + instrumentDto.getQualityStatus(), + instrumentDto.getPrice(), + instrumentDto.getHasAnomaly(), + instrumentDto.getDescription(), + instrumentDto.getImages(), + instrumentDto.getHashtags(), + bassGuitar.getBrand(), + bassGuitar.getPickUp(), + bassGuitar.getPreAmplifier(), + bassGuitar.getColor() + ); + } +} diff --git a/src/main/java/com/ajou/hertz/domain/instrument/dto/ElectricGuitarDto.java b/src/main/java/com/ajou/hertz/domain/instrument/dto/ElectricGuitarDto.java index 542f656..865bdbd 100644 --- a/src/main/java/com/ajou/hertz/domain/instrument/dto/ElectricGuitarDto.java +++ b/src/main/java/com/ajou/hertz/domain/instrument/dto/ElectricGuitarDto.java @@ -11,48 +11,63 @@ import com.ajou.hertz.domain.user.dto.UserDto; import lombok.AccessLevel; -import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; -@AllArgsConstructor(access = AccessLevel.PRIVATE) @NoArgsConstructor(access = AccessLevel.PRIVATE) @Getter -public class ElectricGuitarDto { +public class ElectricGuitarDto extends InstrumentDto { - private Long id; - private UserDto seller; - private String title; - private InstrumentProgressStatus progressStatus; - private AddressDto tradeAddress; - private Short qualityStatus; - private Integer price; - private Boolean hasAnomaly; - private String description; private ElectricGuitarBrand brand; private ElectricGuitarModel model; private Short productionYear; private GuitarColor color; - private List images; - private List hashtags; + + private ElectricGuitarDto( + Long id, + UserDto seller, + String title, + InstrumentProgressStatus progressStatus, + AddressDto tradeAddress, + Short qualityStatus, + Integer price, + Boolean hasAnomaly, + String description, + ElectricGuitarBrand brand, + ElectricGuitarModel model, + Short productionYear, + GuitarColor color, + List images, + List hashtags + ) { + super( + id, seller, title, progressStatus, tradeAddress, qualityStatus, + price, hasAnomaly, description, images, hashtags + ); + this.brand = brand; + this.model = model; + this.productionYear = productionYear; + this.color = color; + } public static ElectricGuitarDto from(ElectricGuitar electricGuitar) { + InstrumentDto instrumentDto = InstrumentDto.from(electricGuitar); return new ElectricGuitarDto( - electricGuitar.getId(), - UserDto.from(electricGuitar.getSeller()), - electricGuitar.getTitle(), - electricGuitar.getProgressStatus(), - AddressDto.from(electricGuitar.getTradeAddress()), - electricGuitar.getQualityStatus(), - electricGuitar.getPrice(), - electricGuitar.getHasAnomaly(), - electricGuitar.getDescription(), + instrumentDto.getId(), + instrumentDto.getSeller(), + instrumentDto.getTitle(), + instrumentDto.getProgressStatus(), + instrumentDto.getTradeAddress(), + instrumentDto.getQualityStatus(), + instrumentDto.getPrice(), + instrumentDto.getHasAnomaly(), + instrumentDto.getDescription(), electricGuitar.getBrand(), electricGuitar.getModel(), electricGuitar.getProductionYear(), electricGuitar.getColor(), - electricGuitar.getImages().toDtos(), - electricGuitar.getHashtags().toStrings() + instrumentDto.getImages(), + instrumentDto.getHashtags() ); } } diff --git a/src/main/java/com/ajou/hertz/domain/instrument/dto/InstrumentDto.java b/src/main/java/com/ajou/hertz/domain/instrument/dto/InstrumentDto.java new file mode 100644 index 0000000..126daa7 --- /dev/null +++ b/src/main/java/com/ajou/hertz/domain/instrument/dto/InstrumentDto.java @@ -0,0 +1,47 @@ +package com.ajou.hertz.domain.instrument.dto; + +import java.util.List; + +import com.ajou.hertz.common.dto.AddressDto; +import com.ajou.hertz.domain.instrument.constant.InstrumentProgressStatus; +import com.ajou.hertz.domain.instrument.entity.Instrument; +import com.ajou.hertz.domain.user.dto.UserDto; + +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@AllArgsConstructor(access = AccessLevel.PROTECTED) +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@Getter +public class InstrumentDto { + + private Long id; + private UserDto seller; + private String title; + private InstrumentProgressStatus progressStatus; + private AddressDto tradeAddress; + private Short qualityStatus; + private Integer price; + private Boolean hasAnomaly; + private String description; + private List images; + private List hashtags; + + public static InstrumentDto from(Instrument instrument) { + return new InstrumentDto( + instrument.getId(), + UserDto.from(instrument.getSeller()), + instrument.getTitle(), + instrument.getProgressStatus(), + AddressDto.from(instrument.getTradeAddress()), + instrument.getQualityStatus(), + instrument.getPrice(), + instrument.getHasAnomaly(), + instrument.getDescription(), + instrument.getImages().toDtos(), + instrument.getHashtags().toStrings() + ); + } +} diff --git a/src/main/java/com/ajou/hertz/domain/instrument/dto/request/CreateNewBassGuitarRequest.java b/src/main/java/com/ajou/hertz/domain/instrument/dto/request/CreateNewBassGuitarRequest.java new file mode 100644 index 0000000..0c3ab88 --- /dev/null +++ b/src/main/java/com/ajou/hertz/domain/instrument/dto/request/CreateNewBassGuitarRequest.java @@ -0,0 +1,77 @@ +package com.ajou.hertz.domain.instrument.dto.request; + +import java.util.List; + +import org.springframework.web.multipart.MultipartFile; + +import com.ajou.hertz.common.dto.request.AddressRequest; +import com.ajou.hertz.domain.instrument.constant.BassGuitarBrand; +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.InstrumentProgressStatus; +import com.ajou.hertz.domain.instrument.entity.BassGuitar; +import com.ajou.hertz.domain.user.entity.User; + +import jakarta.validation.constraints.NotNull; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +@Setter // for multipart/form-data with @ModelAttribute +@Getter +public class CreateNewBassGuitarRequest extends CreateNewInstrumentRequest { + + @NotNull + private BassGuitarBrand brand; + + @NotNull + private BassGuitarPickUp pickUp; + + @NotNull + private BassGuitarPreAmplifier preAmplifier; + + @NotNull + private GuitarColor color; + + private CreateNewBassGuitarRequest( + String title, + InstrumentProgressStatus progressStatus, + AddressRequest tradeAddress, + Short qualityStatus, + Integer price, + Boolean hasAnomaly, + String description, + List images, + List hashtags, + BassGuitarBrand brand, + BassGuitarPickUp pickUp, + BassGuitarPreAmplifier preAmplifier, + GuitarColor color + ) { + super(title, progressStatus, tradeAddress, qualityStatus, price, hasAnomaly, description, images, hashtags); + this.brand = brand; + this.pickUp = pickUp; + this.preAmplifier = preAmplifier; + this.color = color; + } + + public BassGuitar toEntity(User seller) { + return BassGuitar.create( + seller, + getTitle(), + getProgressStatus(), + getTradeAddress().toEntity(), + getQualityStatus(), + getPrice(), + getHasAnomaly(), + getDescription(), + getBrand(), + getPickUp(), + getPreAmplifier(), + getColor() + ); + } +} diff --git a/src/main/java/com/ajou/hertz/domain/instrument/dto/request/CreateNewElectricGuitarRequest.java b/src/main/java/com/ajou/hertz/domain/instrument/dto/request/CreateNewElectricGuitarRequest.java index d440afc..130854b 100644 --- a/src/main/java/com/ajou/hertz/domain/instrument/dto/request/CreateNewElectricGuitarRequest.java +++ b/src/main/java/com/ajou/hertz/domain/instrument/dto/request/CreateNewElectricGuitarRequest.java @@ -2,7 +2,6 @@ import java.util.List; -import org.hibernate.validator.constraints.Length; import org.springframework.web.multipart.MultipartFile; import com.ajou.hertz.common.dto.request.AddressRequest; @@ -14,56 +13,16 @@ import com.ajou.hertz.domain.user.entity.User; import io.swagger.v3.oas.annotations.media.Schema; -import jakarta.validation.constraints.Max; -import jakarta.validation.constraints.Min; -import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotNull; -import jakarta.validation.constraints.Size; import lombok.AccessLevel; -import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; -@AllArgsConstructor(access = AccessLevel.PRIVATE) @NoArgsConstructor(access = AccessLevel.PRIVATE) @Setter // for multipart/form-data with @ModelAttribute @Getter -public class CreateNewElectricGuitarRequest { - - @Schema(description = "제목", example = "펜더 로드원 텔레캐스터") - @NotBlank - private String title; - - @Schema(description = "악기 사진") - @NotNull - @Size(min = 4, max = 7) - private List images; - - @NotNull - private InstrumentProgressStatus progressStatus; - - @Schema(description = "거래 장소") - @NotNull - private AddressRequest tradeAddress; - - @Schema(description = "악기 상태. 1~5 단계로 구성됩니다.", example = "3") - @NotNull - @Min(1) - @Max(5) - private Short qualityStatus; - - @Schema(description = "가격", example = "527000") - @NotNull - private Integer price; - - @Schema(description = "특이사항 유무", example = "true") - @NotNull - private Boolean hasAnomaly; - - @Schema(description = "특이사항 및 상세 설명. 내용이 없을 경우에는 빈 문자열로 요청하면 됩니다.", example = "14년 시리얼 펜더 로드원 50 텔레입니다. 기존 ...") - @NotNull - private String description; +public class CreateNewElectricGuitarRequest extends CreateNewInstrumentRequest { @NotNull private ElectricGuitarBrand brand; @@ -78,23 +37,42 @@ public class CreateNewElectricGuitarRequest { @NotNull private GuitarColor color; - @Schema(description = "해시태그(각 해시태그마다 최대 10글자)", example = "[\"펜더\", \"Fender\"]") - private List<@NotBlank @Length(max = 10) String> hashtags; + private CreateNewElectricGuitarRequest( + String title, + List images, + InstrumentProgressStatus progressStatus, + AddressRequest tradeAddress, + Short qualityStatus, + Integer price, + Boolean hasAnomaly, + String description, + ElectricGuitarBrand brand, + ElectricGuitarModel model, + Short productionYear, + GuitarColor color, + List hashtags + ) { + super(title, progressStatus, tradeAddress, qualityStatus, price, hasAnomaly, description, images, hashtags); + this.brand = brand; + this.model = model; + this.productionYear = productionYear; + this.color = color; + } public ElectricGuitar toEntity(User seller) { return ElectricGuitar.create( seller, - title, - progressStatus, - tradeAddress.toEntity(), - qualityStatus, - price, - hasAnomaly, - description, - brand, - model, - productionYear, - color + getTitle(), + getProgressStatus(), + getTradeAddress().toEntity(), + getQualityStatus(), + getPrice(), + getHasAnomaly(), + getDescription(), + getBrand(), + getModel(), + getProductionYear(), + getColor() ); } } diff --git a/src/main/java/com/ajou/hertz/domain/instrument/dto/request/CreateNewInstrumentRequest.java b/src/main/java/com/ajou/hertz/domain/instrument/dto/request/CreateNewInstrumentRequest.java new file mode 100644 index 0000000..8427499 --- /dev/null +++ b/src/main/java/com/ajou/hertz/domain/instrument/dto/request/CreateNewInstrumentRequest.java @@ -0,0 +1,69 @@ +package com.ajou.hertz.domain.instrument.dto.request; + +import java.util.List; + +import org.hibernate.validator.constraints.Length; +import org.springframework.web.multipart.MultipartFile; + +import com.ajou.hertz.common.dto.request.AddressRequest; +import com.ajou.hertz.domain.instrument.constant.InstrumentProgressStatus; +import com.ajou.hertz.domain.instrument.entity.Instrument; +import com.ajou.hertz.domain.user.entity.User; + +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.Max; +import jakarta.validation.constraints.Min; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@AllArgsConstructor(access = AccessLevel.PROTECTED) +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@Setter // for multipart/form-data with @ModelAttribute +@Getter +public abstract class CreateNewInstrumentRequest { + + @Schema(description = "제목", example = "펜더 로드원 텔레캐스터") + @NotBlank + private String title; + + @NotNull + private InstrumentProgressStatus progressStatus; + + @Schema(description = "거래 장소") + @NotNull + private AddressRequest tradeAddress; + + @Schema(description = "악기 상태. 1~5 단계로 구성됩니다.", example = "3") + @NotNull + @Min(1) + @Max(5) + private Short qualityStatus; + + @Schema(description = "가격", example = "527000") + @NotNull + private Integer price; + + @Schema(description = "특이사항 유무", example = "true") + @NotNull + private Boolean hasAnomaly; + + @Schema(description = "특이사항 및 상세 설명. 내용이 없을 경우에는 빈 문자열로 요청하면 됩니다.", example = "14년 시리얼 펜더 로드원 50 텔레입니다. 기존 ...") + @NotNull + private String description; + + @Schema(description = "악기 사진") + @NotNull + @Size(min = 4, max = 7) + private List images; + + @Schema(description = "해시태그(각 해시태그마다 최대 10글자)", example = "[\"펜더\", \"Fender\"]") + private List<@NotBlank @Length(max = 10) String> hashtags; + + public abstract T toEntity(User seller); +} 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 new file mode 100644 index 0000000..baca307 --- /dev/null +++ b/src/main/java/com/ajou/hertz/domain/instrument/dto/response/BassGuitarResponse.java @@ -0,0 +1,81 @@ +package com.ajou.hertz.domain.instrument.dto.response; + +import java.util.List; + +import com.ajou.hertz.common.dto.response.AddressResponse; +import com.ajou.hertz.domain.instrument.constant.BassGuitarBrand; +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.InstrumentProgressStatus; +import com.ajou.hertz.domain.instrument.dto.BassGuitarDto; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +@Getter +public class BassGuitarResponse extends InstrumentResponse { + + @Schema(description = "브랜드") + private BassGuitarBrand brand; + + @Schema(description = "픽업 종류") + private BassGuitarPickUp pickUp; + + @Schema(description = "프리앰프 종류") + private BassGuitarPreAmplifier preAmplifier; + + @Schema(description = "색상") + private GuitarColor color; + + public BassGuitarResponse( + Long id, + Long sellerId, + String title, + InstrumentProgressStatus progressStatus, + AddressResponse tradeAddress, + Short qualityStatus, + Integer price, + Boolean hasAnomaly, + String description, + List images, + List hashtags, + BassGuitarBrand brand, + BassGuitarPickUp pickUp, + BassGuitarPreAmplifier preAmplifier, + GuitarColor color + ) { + super( + id, sellerId, title, progressStatus, tradeAddress, qualityStatus, + price, hasAnomaly, description, images, hashtags + ); + this.brand = brand; + this.pickUp = pickUp; + this.preAmplifier = preAmplifier; + this.color = color; + } + + 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() + ); + } +} 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 a776aa7..1d6ac4f 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 @@ -11,41 +11,12 @@ import io.swagger.v3.oas.annotations.media.Schema; import lombok.AccessLevel; -import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; -@AllArgsConstructor(access = AccessLevel.PRIVATE) @NoArgsConstructor(access = AccessLevel.PRIVATE) @Getter -public class ElectricGuitarResponse { - - @Schema(description = "Id of instrument(electric guitar)", example = "2") - private Long id; - - @Schema(description = "Id of seller", example = "1") - private Long sellerId; - - @Schema(description = "제목", example = "펜더 로드원 텔레캐스터") - private String title; - - @Schema(description = "매물 진행 상태") - private InstrumentProgressStatus progressStatus; - - @Schema(description = "거래 장소") - private AddressResponse tradeAddress; - - @Schema(description = "악기 상태. 1~5의 값을 갖습니다.", example = "3") - private Short qualityStatus; - - @Schema(description = "가격", example = "527000") - private Integer price; - - @Schema(description = "특이사항 유무", example = "true") - private Boolean hasAnomaly; - - @Schema(description = "특이사항 및 상세 설명. 내용이 없을 경우에는 빈 문자열로 요청하면 됩니다.", example = "14년 시리얼 펜더 로드원 50 텔레입니다. 기존 ...") - private String description; +public class ElectricGuitarResponse extends InstrumentResponse { @Schema(description = "브랜드") private ElectricGuitarBrand brand; @@ -59,32 +30,50 @@ public class ElectricGuitarResponse { @Schema(description = "색상") private GuitarColor color; - @Schema(description = "악기 이미지") - private List images; - - @Schema(description = "해시태그", example = "[\"펜더\", \"Fender\"]") - private List hashtags; + private ElectricGuitarResponse( + Long id, + Long sellerId, + String title, + InstrumentProgressStatus progressStatus, + AddressResponse tradeAddress, + Short qualityStatus, + Integer price, + Boolean hasAnomaly, + String description, + List images, + List hashtags, + ElectricGuitarBrand brand, + ElectricGuitarModel model, + Short productionYear, + GuitarColor color + ) { + super( + id, sellerId, title, progressStatus, tradeAddress, qualityStatus, + price, hasAnomaly, description, images, hashtags); + this.brand = brand; + this.model = model; + this.productionYear = productionYear; + this.color = color; + } public static ElectricGuitarResponse from(ElectricGuitarDto electricGuitarDto) { + InstrumentResponse instrumentResponse = InstrumentResponse.from(electricGuitarDto); return new ElectricGuitarResponse( - electricGuitarDto.getId(), - electricGuitarDto.getSeller().getId(), - electricGuitarDto.getTitle(), - electricGuitarDto.getProgressStatus(), - AddressResponse.from(electricGuitarDto.getTradeAddress()), - electricGuitarDto.getQualityStatus(), - electricGuitarDto.getPrice(), - electricGuitarDto.getHasAnomaly(), - electricGuitarDto.getDescription(), + 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(), - electricGuitarDto.getImages() - .stream() - .map(InstrumentImageResponse::from) - .toList(), - electricGuitarDto.getHashtags() + electricGuitarDto.getColor() ); } } 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 new file mode 100644 index 0000000..927f72b --- /dev/null +++ b/src/main/java/com/ajou/hertz/domain/instrument/dto/response/InstrumentResponse.java @@ -0,0 +1,71 @@ +package com.ajou.hertz.domain.instrument.dto.response; + +import java.util.List; + +import com.ajou.hertz.common.dto.response.AddressResponse; +import com.ajou.hertz.domain.instrument.constant.InstrumentProgressStatus; +import com.ajou.hertz.domain.instrument.dto.InstrumentDto; + +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 InstrumentResponse { + + @Schema(description = "Id of instrument(electric guitar)", example = "2") + private Long id; + + @Schema(description = "Id of seller", example = "1") + private Long sellerId; + + @Schema(description = "제목", example = "펜더 로드원 텔레캐스터") + private String title; + + @Schema(description = "매물 진행 상태") + private InstrumentProgressStatus progressStatus; + + @Schema(description = "거래 장소") + private AddressResponse tradeAddress; + + @Schema(description = "악기 상태. 1~5의 값을 갖습니다.", example = "3") + private Short qualityStatus; + + @Schema(description = "가격", example = "527000") + private Integer price; + + @Schema(description = "특이사항 유무", example = "true") + private Boolean hasAnomaly; + + @Schema(description = "특이사항 및 상세 설명. 내용이 없을 경우에는 빈 문자열로 요청하면 됩니다.", example = "14년 시리얼 펜더 로드원 50 텔레입니다. 기존 ...") + private String description; + + @Schema(description = "악기 이미지") + private List images; + + @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() + ); + } +} diff --git a/src/main/java/com/ajou/hertz/domain/instrument/service/InstrumentCommandService.java b/src/main/java/com/ajou/hertz/domain/instrument/service/InstrumentCommandService.java index ca74785..bb50803 100644 --- a/src/main/java/com/ajou/hertz/domain/instrument/service/InstrumentCommandService.java +++ b/src/main/java/com/ajou/hertz/domain/instrument/service/InstrumentCommandService.java @@ -4,16 +4,25 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.multipart.MultipartFile; import com.ajou.hertz.common.file.service.FileService; +import com.ajou.hertz.domain.instrument.dto.BassGuitarDto; import com.ajou.hertz.domain.instrument.dto.ElectricGuitarDto; +import com.ajou.hertz.domain.instrument.dto.request.CreateNewBassGuitarRequest; import com.ajou.hertz.domain.instrument.dto.request.CreateNewElectricGuitarRequest; +import com.ajou.hertz.domain.instrument.dto.request.CreateNewInstrumentRequest; +import com.ajou.hertz.domain.instrument.entity.BassGuitar; import com.ajou.hertz.domain.instrument.entity.ElectricGuitar; +import com.ajou.hertz.domain.instrument.entity.Instrument; import com.ajou.hertz.domain.instrument.entity.InstrumentHashtag; import com.ajou.hertz.domain.instrument.entity.InstrumentImage; import com.ajou.hertz.domain.instrument.repository.InstrumentHashtagRepository; import com.ajou.hertz.domain.instrument.repository.InstrumentImageRepository; import com.ajou.hertz.domain.instrument.repository.InstrumentRepository; +import com.ajou.hertz.domain.instrument.strategy.BassGuitarCreationStrategy; +import com.ajou.hertz.domain.instrument.strategy.ElectricGuitarCreationStrategy; +import com.ajou.hertz.domain.instrument.strategy.InstrumentCreationStrategy; import com.ajou.hertz.domain.user.entity.User; import com.ajou.hertz.domain.user.service.UserQueryService; @@ -32,36 +41,47 @@ public class InstrumentCommandService { private final InstrumentHashtagRepository instrumentHashtagRepository; private final InstrumentImageRepository instrumentImageRepository; - public ElectricGuitarDto createNewElectricGuitar( + public ElectricGuitarDto createNewElectricGuitar(Long sellerId, CreateNewElectricGuitarRequest request) { + ElectricGuitar electricGuitar = createNewInstrument(sellerId, request, new ElectricGuitarCreationStrategy()); + return ElectricGuitarDto.from(electricGuitar); + } + + public BassGuitarDto createNewBassGuitar(Long sellerId, CreateNewBassGuitarRequest request) { + BassGuitar bassGuitar = createNewInstrument(sellerId, request, new BassGuitarCreationStrategy()); + return BassGuitarDto.from(bassGuitar); + } + + private > T createNewInstrument( Long sellerId, - CreateNewElectricGuitarRequest createNewElectricGuitarRequest + U request, + InstrumentCreationStrategy creationStrategy ) { - // 악기(Instrument) 매물 등록 User seller = userQueryService.getById(sellerId); - ElectricGuitar electricGuitar = instrumentRepository.save(createNewElectricGuitarRequest.toEntity(seller)); + T instrument = instrumentRepository.save(creationStrategy.createInstrument(seller, request)); + registerInstrumentImages(instrument, request.getImages()); + registerInstrumentHashtags(instrument, request.getHashtags()); + return instrument; + } - // 악기 이미지 등록 + private void registerInstrumentImages(Instrument instrument, List images) { List instrumentImages = fileService - .uploadFiles(createNewElectricGuitarRequest.getImages(), INSTRUMENT_IMAGE_UPLOAD_PATH) + .uploadFiles(images, INSTRUMENT_IMAGE_UPLOAD_PATH) .stream() .map(fileDto -> InstrumentImage.create( - electricGuitar, + instrument, fileDto.getOriginalName(), fileDto.getStoredName(), fileDto.getUrl() )).toList(); List savedInstrumentImages = instrumentImageRepository.saveAll(instrumentImages); - electricGuitar.getImages().addAll(savedInstrumentImages); + instrument.getImages().addAll(savedInstrumentImages); + } - // 악기 해시태그 등록 - List hashtags = createNewElectricGuitarRequest - .getHashtags() - .stream() - .map(hashtagContent -> InstrumentHashtag.create(electricGuitar, hashtagContent)) + private void registerInstrumentHashtags(Instrument instrument, List hashtags) { + List instrumentHashtags = hashtags.stream() + .map(hashtagContent -> InstrumentHashtag.create(instrument, hashtagContent)) .toList(); - List savedInstrumentHashtags = instrumentHashtagRepository.saveAll(hashtags); - electricGuitar.getHashtags().addAll(savedInstrumentHashtags); - - return ElectricGuitarDto.from(electricGuitar); + List savedInstrumentHashtags = instrumentHashtagRepository.saveAll(instrumentHashtags); + instrument.getHashtags().addAll(savedInstrumentHashtags); } } diff --git a/src/main/java/com/ajou/hertz/domain/instrument/strategy/BassGuitarCreationStrategy.java b/src/main/java/com/ajou/hertz/domain/instrument/strategy/BassGuitarCreationStrategy.java new file mode 100644 index 0000000..1971d76 --- /dev/null +++ b/src/main/java/com/ajou/hertz/domain/instrument/strategy/BassGuitarCreationStrategy.java @@ -0,0 +1,13 @@ +package com.ajou.hertz.domain.instrument.strategy; + +import com.ajou.hertz.domain.instrument.dto.request.CreateNewBassGuitarRequest; +import com.ajou.hertz.domain.instrument.entity.BassGuitar; +import com.ajou.hertz.domain.user.entity.User; + +public class BassGuitarCreationStrategy implements InstrumentCreationStrategy { + + @Override + public BassGuitar createInstrument(User seller, CreateNewBassGuitarRequest request) { + return request.toEntity(seller); + } +} diff --git a/src/main/java/com/ajou/hertz/domain/instrument/strategy/ElectricGuitarCreationStrategy.java b/src/main/java/com/ajou/hertz/domain/instrument/strategy/ElectricGuitarCreationStrategy.java new file mode 100644 index 0000000..d85c68a --- /dev/null +++ b/src/main/java/com/ajou/hertz/domain/instrument/strategy/ElectricGuitarCreationStrategy.java @@ -0,0 +1,14 @@ +package com.ajou.hertz.domain.instrument.strategy; + +import com.ajou.hertz.domain.instrument.dto.request.CreateNewElectricGuitarRequest; +import com.ajou.hertz.domain.instrument.entity.ElectricGuitar; +import com.ajou.hertz.domain.user.entity.User; + +public class ElectricGuitarCreationStrategy + implements InstrumentCreationStrategy { + + @Override + public ElectricGuitar createInstrument(User seller, CreateNewElectricGuitarRequest request) { + return request.toEntity(seller); + } +} diff --git a/src/main/java/com/ajou/hertz/domain/instrument/strategy/InstrumentCreationStrategy.java b/src/main/java/com/ajou/hertz/domain/instrument/strategy/InstrumentCreationStrategy.java new file mode 100644 index 0000000..fe95264 --- /dev/null +++ b/src/main/java/com/ajou/hertz/domain/instrument/strategy/InstrumentCreationStrategy.java @@ -0,0 +1,10 @@ +package com.ajou.hertz.domain.instrument.strategy; + +import com.ajou.hertz.domain.instrument.dto.request.CreateNewInstrumentRequest; +import com.ajou.hertz.domain.instrument.entity.Instrument; +import com.ajou.hertz.domain.user.entity.User; + +public interface InstrumentCreationStrategy> { + + T createInstrument(User seller, U request); +} diff --git a/src/test/java/com/ajou/hertz/unit/domain/instrument/controller/InstrumentControllerV1Test.java b/src/test/java/com/ajou/hertz/unit/domain/instrument/controller/InstrumentControllerV1Test.java index 43b48a5..8d4e41a 100644 --- a/src/test/java/com/ajou/hertz/unit/domain/instrument/controller/InstrumentControllerV1Test.java +++ b/src/test/java/com/ajou/hertz/unit/domain/instrument/controller/InstrumentControllerV1Test.java @@ -27,12 +27,17 @@ import com.ajou.hertz.common.dto.AddressDto; import com.ajou.hertz.common.dto.request.AddressRequest; import com.ajou.hertz.config.ControllerTestConfig; +import com.ajou.hertz.domain.instrument.constant.BassGuitarBrand; +import com.ajou.hertz.domain.instrument.constant.BassGuitarPickUp; +import com.ajou.hertz.domain.instrument.constant.BassGuitarPreAmplifier; 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.InstrumentProgressStatus; import com.ajou.hertz.domain.instrument.controller.InstrumentControllerV1; +import com.ajou.hertz.domain.instrument.dto.BassGuitarDto; import com.ajou.hertz.domain.instrument.dto.ElectricGuitarDto; +import com.ajou.hertz.domain.instrument.dto.request.CreateNewBassGuitarRequest; import com.ajou.hertz.domain.instrument.dto.request.CreateNewElectricGuitarRequest; import com.ajou.hertz.domain.instrument.service.InstrumentCommandService; import com.ajou.hertz.domain.user.constant.Gender; @@ -100,6 +105,52 @@ public InstrumentControllerV1Test(MockMvc mvc) { verifyEveryMocksShouldHaveNoMoreInteractions(); } + @Test + void 베이스_기타_정보가_주어지면_주어진_정보로_베이스_기타_매물을_등록한다() throws Exception { + // given + long sellerId = 1L; + CreateNewBassGuitarRequest bassGuitarRequest = createNewBassGuitarRequest(); + BassGuitarDto expectedResult = createBassGuitarDto(2L, sellerId); + given(instrumentCommandService.createNewBassGuitar( + eq(sellerId), any(CreateNewBassGuitarRequest.class) + )).willReturn(expectedResult); + + // when & then + mvc.perform( + multipart("/v1/instruments/bass-guitars") + .file("images[0]", bassGuitarRequest.getImages().get(0).getBytes()) + .file("images[1]", bassGuitarRequest.getImages().get(1).getBytes()) + .file("images[2]", bassGuitarRequest.getImages().get(2).getBytes()) + .file("images[3]", bassGuitarRequest.getImages().get(3).getBytes()) + .header(API_MINOR_VERSION_HEADER_NAME, 1) + .param("title", bassGuitarRequest.getTitle()) + .param("progressStatus", bassGuitarRequest.getProgressStatus().name()) + .param("tradeAddress.sido", bassGuitarRequest.getTradeAddress().getSido()) + .param("tradeAddress.sgg", bassGuitarRequest.getTradeAddress().getSgg()) + .param("tradeAddress.emd", bassGuitarRequest.getTradeAddress().getEmd()) + .param("qualityStatus", String.valueOf(bassGuitarRequest.getQualityStatus())) + .param("price", String.valueOf(bassGuitarRequest.getPrice())) + .param("hasAnomaly", String.valueOf(bassGuitarRequest.getHasAnomaly())) + .param("description", bassGuitarRequest.getDescription()) + .param("brand", bassGuitarRequest.getBrand().name()) + .param("pickUp", bassGuitarRequest.getPickUp().name()) + .param("preAmplifier", bassGuitarRequest.getPreAmplifier().name()) + .param("color", bassGuitarRequest.getColor().name()) + .with(user(createTestUser(sellerId))) + ) + .andExpect(status().isCreated()) + .andExpect(jsonPath("$.id").value(expectedResult.getId())) + .andExpect(jsonPath("$.sellerId").value(sellerId)) + .andExpect(jsonPath("$.images").isArray()) + .andExpect(jsonPath("$.images.size()").value(expectedResult.getImages().size())) + .andExpect(jsonPath("$.hashtags").isArray()) + .andExpect(jsonPath("$.hashtags.size()").value(expectedResult.getHashtags().size())); + then(instrumentCommandService) + .should() + .createNewBassGuitar(eq(sellerId), any(CreateNewBassGuitarRequest.class)); + verifyEveryMocksShouldHaveNoMoreInteractions(); + } + private void verifyEveryMocksShouldHaveNoMoreInteractions() { then(instrumentCommandService).shouldHaveNoMoreInteractions(); } @@ -173,6 +224,32 @@ private ElectricGuitarDto createElectricGuitarDto(long id, long sellerId) throws ); } + private BassGuitarDto createBassGuitarDto(long id, long sellerId) throws Exception { + Constructor bassGuitarDtoConstructor = BassGuitarDto.class.getDeclaredConstructor( + Long.class, UserDto.class, String.class, InstrumentProgressStatus.class, AddressDto.class, Short.class, + Integer.class, Boolean.class, String.class, List.class, List.class, + BassGuitarBrand.class, BassGuitarPickUp.class, BassGuitarPreAmplifier.class, GuitarColor.class + ); + bassGuitarDtoConstructor.setAccessible(true); + return bassGuitarDtoConstructor.newInstance( + id, + createUserDto(sellerId), + "Test electric guitar", + InstrumentProgressStatus.SELLING, + createAddressDto(), + (short)3, + 550000, + true, + "description", + List.of(), + List.of(), + BassGuitarBrand.FENDER, + BassGuitarPickUp.JAZZ, + BassGuitarPreAmplifier.ACTIVE, + GuitarColor.RED + ); + } + private AddressRequest createAddressRequest() throws Exception { Constructor addressRequestConstructor = AddressRequest.class.getDeclaredConstructor( String.class, String.class, String.class @@ -182,10 +259,11 @@ private AddressRequest createAddressRequest() throws Exception { } private CreateNewElectricGuitarRequest createElectricGuitarRequest() throws Exception { - Constructor createNewElectricGuitarRequestConstructor = CreateNewElectricGuitarRequest.class - .getDeclaredConstructor(String.class, List.class, InstrumentProgressStatus.class, AddressRequest.class, - Short.class, Integer.class, Boolean.class, String.class, ElectricGuitarBrand.class, - ElectricGuitarModel.class, Short.class, GuitarColor.class, List.class); + Constructor createNewElectricGuitarRequestConstructor = CreateNewElectricGuitarRequest.class.getDeclaredConstructor( + String.class, List.class, InstrumentProgressStatus.class, AddressRequest.class, + Short.class, Integer.class, Boolean.class, String.class, ElectricGuitarBrand.class, + ElectricGuitarModel.class, Short.class, GuitarColor.class, List.class + ); createNewElectricGuitarRequestConstructor.setAccessible(true); return createNewElectricGuitarRequestConstructor.newInstance( "Test electric guitar", @@ -203,4 +281,29 @@ private CreateNewElectricGuitarRequest createElectricGuitarRequest() throws Exce List.of("Fender", "Guitar") ); } + + private CreateNewBassGuitarRequest createNewBassGuitarRequest() throws Exception { + Constructor createNewBassGuitarRequestConstructor = + CreateNewBassGuitarRequest.class.getDeclaredConstructor( + String.class, InstrumentProgressStatus.class, AddressRequest.class, Short.class, + Integer.class, Boolean.class, String.class, List.class, List.class, + BassGuitarBrand.class, BassGuitarPickUp.class, BassGuitarPreAmplifier.class, GuitarColor.class + ); + createNewBassGuitarRequestConstructor.setAccessible(true); + return createNewBassGuitarRequestConstructor.newInstance( + "Title", + InstrumentProgressStatus.SELLING, + createAddressRequest(), + (short)3, + 550000, + true, + "description", + List.of(createMultipartFile(), createMultipartFile(), createMultipartFile(), createMultipartFile()), + List.of("Fender", "Guitar"), + BassGuitarBrand.FENDER, + BassGuitarPickUp.JAZZ, + BassGuitarPreAmplifier.ACTIVE, + GuitarColor.RED + ); + } } \ No newline at end of file diff --git a/src/test/java/com/ajou/hertz/unit/domain/instrument/service/InstrumentCommandServiceTest.java b/src/test/java/com/ajou/hertz/unit/domain/instrument/service/InstrumentCommandServiceTest.java index 7cec72d..4987b5d 100644 --- a/src/test/java/com/ajou/hertz/unit/domain/instrument/service/InstrumentCommandServiceTest.java +++ b/src/test/java/com/ajou/hertz/unit/domain/instrument/service/InstrumentCommandServiceTest.java @@ -22,12 +22,18 @@ import com.ajou.hertz.common.entity.Address; import com.ajou.hertz.common.file.dto.FileDto; import com.ajou.hertz.common.file.service.FileService; +import com.ajou.hertz.domain.instrument.constant.BassGuitarBrand; +import com.ajou.hertz.domain.instrument.constant.BassGuitarPickUp; +import com.ajou.hertz.domain.instrument.constant.BassGuitarPreAmplifier; 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.InstrumentProgressStatus; +import com.ajou.hertz.domain.instrument.dto.BassGuitarDto; import com.ajou.hertz.domain.instrument.dto.ElectricGuitarDto; +import com.ajou.hertz.domain.instrument.dto.request.CreateNewBassGuitarRequest; import com.ajou.hertz.domain.instrument.dto.request.CreateNewElectricGuitarRequest; +import com.ajou.hertz.domain.instrument.entity.BassGuitar; import com.ajou.hertz.domain.instrument.entity.ElectricGuitar; import com.ajou.hertz.domain.instrument.entity.Instrument; import com.ajou.hertz.domain.instrument.entity.InstrumentHashtag; @@ -72,7 +78,6 @@ class InstrumentCommandServiceTest { ElectricGuitar electricGuitar = createElectricGuitar(2L, seller); List instrumentImages = List.of(createInstrumentImage(3L, electricGuitar)); List instrumentHashtags = List.of(createInstrumentHashtag(4L, electricGuitar)); - List.of(); given(userQueryService.getById(sellerId)).willReturn(seller); given(instrumentRepository.save(any(Instrument.class))).willReturn(electricGuitar); given(fileService.uploadFiles(eq(electricGuitarRequest.getImages()), anyString())) @@ -99,6 +104,41 @@ class InstrumentCommandServiceTest { assertThat(result.getHashtags()).hasSize(instrumentHashtags.size()); } + @Test + void 베이스_기타의_정보가_주어지면_주어진_정보로_베이스_기타_매물을_등록한다() throws Exception { + // given + long sellerId = 1L; + CreateNewBassGuitarRequest bassGuitarRequest = createNewBassGuitarRequest(); + User seller = createUser(1L); + BassGuitar bassGuitar = createBassGuitar(2L, seller); + List instrumentImages = List.of(createInstrumentImage(3L, bassGuitar)); + List instrumentHashtags = List.of(createInstrumentHashtag(4L, bassGuitar)); + given(userQueryService.getById(sellerId)).willReturn(seller); + given(instrumentRepository.save(any(Instrument.class))).willReturn(bassGuitar); + given(fileService.uploadFiles(eq(bassGuitarRequest.getImages()), anyString())) + .willReturn(List.of(createFileDto())); + given(instrumentImageRepository.saveAll(ArgumentMatchers.>any())) + .willReturn(instrumentImages); + given(instrumentHashtagRepository.saveAll(ArgumentMatchers.>any())) + .willReturn(instrumentHashtags); + + // when + BassGuitarDto result = sut.createNewBassGuitar(sellerId, bassGuitarRequest); + + // then + then(userQueryService).should().getById(sellerId); + then(instrumentRepository).should().save(any(Instrument.class)); + then(fileService).should().uploadFiles(eq(bassGuitarRequest.getImages()), anyString()); + then(instrumentImageRepository).should().saveAll(ArgumentMatchers.>any()); + then(instrumentHashtagRepository).should().saveAll(ArgumentMatchers.>any()); + verifyEveryMocksShouldHaveNoMoreInteractions(); + assertThat(result) + .hasFieldOrPropertyWithValue("id", bassGuitar.getId()) + .hasFieldOrPropertyWithValue("seller.id", seller.getId()); + assertThat(result.getImages()).hasSize(instrumentImages.size()); + assertThat(result.getHashtags()).hasSize(instrumentHashtags.size()); + } + private void verifyEveryMocksShouldHaveNoMoreInteractions() { then(userQueryService).shouldHaveNoMoreInteractions(); then(fileService).shouldHaveNoMoreInteractions(); @@ -186,6 +226,30 @@ private ElectricGuitar createElectricGuitar(Long id, User seller) throws Excepti ); } + private BassGuitar createBassGuitar(long id, User seller) throws Exception { + Constructor bassGuitarConstructor = BassGuitar.class.getDeclaredConstructor( + Long.class, User.class, String.class, InstrumentProgressStatus.class, Address.class, + Short.class, Integer.class, Boolean.class, String.class, + BassGuitarBrand.class, BassGuitarPickUp.class, BassGuitarPreAmplifier.class, GuitarColor.class + ); + bassGuitarConstructor.setAccessible(true); + return bassGuitarConstructor.newInstance( + id, + seller, + "Test electric guitar", + InstrumentProgressStatus.SELLING, + createAddress(), + (short)3, + 550000, + true, + "description", + BassGuitarBrand.FENDER, + BassGuitarPickUp.JAZZ, + BassGuitarPreAmplifier.ACTIVE, + GuitarColor.RED + ); + } + private FileDto createFileDto() throws Exception { Constructor fileDtoConstructor = FileDto.class.getDeclaredConstructor( String.class, String.class, String.class @@ -203,13 +267,15 @@ private AddressRequest createAddressRequest() throws Exception { } private CreateNewElectricGuitarRequest createElectricGuitarRequest() throws Exception { - Constructor createNewElectricGuitarRequestConstructor = CreateNewElectricGuitarRequest.class - .getDeclaredConstructor(String.class, List.class, InstrumentProgressStatus.class, AddressRequest.class, + Constructor createNewElectricGuitarRequestConstructor = + CreateNewElectricGuitarRequest.class.getDeclaredConstructor( + String.class, List.class, InstrumentProgressStatus.class, AddressRequest.class, Short.class, Integer.class, Boolean.class, String.class, ElectricGuitarBrand.class, - ElectricGuitarModel.class, Short.class, GuitarColor.class, List.class); + ElectricGuitarModel.class, Short.class, GuitarColor.class, List.class + ); createNewElectricGuitarRequestConstructor.setAccessible(true); return createNewElectricGuitarRequestConstructor.newInstance( - "Test electric guitar", + "Title", List.of(createMultipartFile()), InstrumentProgressStatus.SELLING, createAddressRequest(), @@ -224,4 +290,29 @@ private CreateNewElectricGuitarRequest createElectricGuitarRequest() throws Exce List.of("Fender", "Guitar") ); } + + private CreateNewBassGuitarRequest createNewBassGuitarRequest() throws Exception { + Constructor createNewBassGuitarRequestConstructor = + CreateNewBassGuitarRequest.class.getDeclaredConstructor( + String.class, InstrumentProgressStatus.class, AddressRequest.class, Short.class, + Integer.class, Boolean.class, String.class, List.class, List.class, + BassGuitarBrand.class, BassGuitarPickUp.class, BassGuitarPreAmplifier.class, GuitarColor.class + ); + createNewBassGuitarRequestConstructor.setAccessible(true); + return createNewBassGuitarRequestConstructor.newInstance( + "Title", + InstrumentProgressStatus.SELLING, + createAddressRequest(), + (short)3, + 550000, + true, + "description", + List.of(createMultipartFile()), + List.of("Fender", "Guitar"), + BassGuitarBrand.FENDER, + BassGuitarPickUp.JAZZ, + BassGuitarPreAmplifier.ACTIVE, + GuitarColor.RED + ); + } }