Skip to content

Commit

Permalink
Merge pull request #54 from Ajou-Hertz/feature/#52-create-bass-guitar
Browse files Browse the repository at this point in the history
베이스 기타 매물 생성 API 구현
  • Loading branch information
tinon1004 authored Feb 27, 2024
2 parents a43cd92 + 1f3e95c commit da96054
Show file tree
Hide file tree
Showing 16 changed files with 837 additions and 157 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -44,7 +47,7 @@ public class InstrumentControllerV1 {
headers = API_MINOR_VERSION_HEADER_NAME + "=" + 1,
consumes = MediaType.MULTIPART_FORM_DATA_VALUE
)
public ResponseEntity<ElectricGuitarResponse> createNewInstrumentV1_1(
public ResponseEntity<ElectricGuitarResponse> createNewElectricGuitarV1_1(
@AuthenticationPrincipal UserPrincipal userPrincipal,
@ParameterObject @ModelAttribute @Valid CreateNewElectricGuitarRequest createNewElectricGuitarRequest
) {
Expand All @@ -56,4 +59,29 @@ public ResponseEntity<ElectricGuitarResponse> createNewInstrumentV1_1(
.created(URI.create("/instruments/" + electricGuitar.getId()))
.body(ElectricGuitarResponse.from(electricGuitar));
}

@Operation(
summary = "베이스 기타 매물 등록",
description = """
<p>베이스 기타 매물을 등록합니다.
<p>요청 시 <strong>multipart/form-data</strong> content-type으로 요쳥해야 합니다.
"""
)
@PostMapping(
value = "/bass-guitars",
headers = API_MINOR_VERSION_HEADER_NAME + "=" + 1,
consumes = MediaType.MULTIPART_FORM_DATA_VALUE
)
public ResponseEntity<BassGuitarResponse> 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));
}
}
Original file line number Diff line number Diff line change
@@ -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<InstrumentImageDto> images,
List<String> 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()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<InstrumentImageDto> images;
private List<String> 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<InstrumentImageDto> images,
List<String> 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()
);
}
}
Original file line number Diff line number Diff line change
@@ -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<InstrumentImageDto> images;
private List<String> 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()
);
}
}
Original file line number Diff line number Diff line change
@@ -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<BassGuitar> {

@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<MultipartFile> images,
List<String> 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()
);
}
}
Loading

0 comments on commit da96054

Please sign in to comment.