-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…itar 일렉 기타 매물 생성 API 구현
- Loading branch information
Showing
30 changed files
with
1,102 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.ajou.hertz.common.dto; | ||
|
||
import com.ajou.hertz.common.entity.Address; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
@Getter | ||
public class AddressDto { | ||
|
||
private String sido; | ||
private String sgg; | ||
private String emd; | ||
|
||
public static AddressDto from(Address address) { | ||
return new AddressDto(address.getSido(), address.getSgg(), address.getEmd()); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/com/ajou/hertz/common/dto/request/AddressRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.ajou.hertz.common.dto.request; | ||
|
||
import com.ajou.hertz.common.entity.Address; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import jakarta.validation.constraints.NotBlank; | ||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
@AllArgsConstructor(access = AccessLevel.PROTECTED) | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Setter | ||
@Getter | ||
public class AddressRequest { | ||
|
||
@Schema(description = "시/도", example = "서울특별시") | ||
@NotBlank | ||
private String sido; | ||
|
||
@Schema(description = "시/군/구", example = "강남구") | ||
@NotBlank | ||
private String sgg; | ||
|
||
@Schema(description = "읍/면/동", example = "청담동") | ||
@NotBlank | ||
private String emd; | ||
|
||
public Address toEntity() { | ||
return new Address(sido, sgg, emd); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/com/ajou/hertz/common/dto/response/AddressResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.ajou.hertz.common.dto.response; | ||
|
||
import com.ajou.hertz.common.dto.AddressDto; | ||
|
||
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 AddressResponse { | ||
|
||
@Schema(description = "시/도", example = "서울특별시") | ||
private String sido; | ||
|
||
@Schema(description = "시/군/구", example = "강남구") | ||
private String sgg; | ||
|
||
@Schema(description = "읍/면/동", example = "청담동") | ||
private String emd; | ||
|
||
public static AddressResponse from(AddressDto addressDto) { | ||
return new AddressResponse(addressDto.getSido(), addressDto.getSgg(), addressDto.getEmd()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 0 additions & 11 deletions
11
src/main/java/com/ajou/hertz/domain/instrument/constant/InstrumentCategory.java
This file was deleted.
Oops, something went wrong.
59 changes: 59 additions & 0 deletions
59
src/main/java/com/ajou/hertz/domain/instrument/controller/InstrumentControllerV1.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package com.ajou.hertz.domain.instrument.controller; | ||
|
||
import static com.ajou.hertz.common.constant.GlobalConstants.*; | ||
|
||
import java.net.URI; | ||
|
||
import org.springdoc.core.annotations.ParameterObject; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
import org.springframework.web.bind.annotation.ModelAttribute; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import com.ajou.hertz.common.auth.UserPrincipal; | ||
import com.ajou.hertz.domain.instrument.dto.ElectricGuitarDto; | ||
import com.ajou.hertz.domain.instrument.dto.request.CreateNewElectricGuitarRequest; | ||
import com.ajou.hertz.domain.instrument.dto.response.ElectricGuitarResponse; | ||
import com.ajou.hertz.domain.instrument.service.InstrumentCommandService; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import jakarta.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Tag(name = "중고 악기 관련 API") | ||
@RequiredArgsConstructor | ||
@RequestMapping("/v1/instruments") | ||
@RestController | ||
public class InstrumentControllerV1 { | ||
|
||
private final InstrumentCommandService instrumentCommandService; | ||
|
||
@Operation( | ||
summary = "일렉기타 매물 등록", | ||
description = """ | ||
<p>일렉기타 매물을 등록합니다. | ||
<p>요청 시 <strong>multipart/form-data</strong> content-type으로 요쳥해야 합니다. | ||
""" | ||
) | ||
@PostMapping( | ||
value = "/electric-guitars", | ||
headers = API_MINOR_VERSION_HEADER_NAME + "=" + 1, | ||
consumes = MediaType.MULTIPART_FORM_DATA_VALUE | ||
) | ||
public ResponseEntity<ElectricGuitarResponse> createNewInstrumentV1_1( | ||
@AuthenticationPrincipal UserPrincipal userPrincipal, | ||
@ParameterObject @ModelAttribute @Valid CreateNewElectricGuitarRequest createNewElectricGuitarRequest | ||
) { | ||
ElectricGuitarDto electricGuitar = instrumentCommandService.createNewElectricGuitar( | ||
userPrincipal.getUserId(), | ||
createNewElectricGuitarRequest | ||
); | ||
return ResponseEntity | ||
.created(URI.create("/instruments/" + electricGuitar.getId())) | ||
.body(ElectricGuitarResponse.from(electricGuitar)); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
src/main/java/com/ajou/hertz/domain/instrument/dto/ElectricGuitarDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
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.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.entity.ElectricGuitar; | ||
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 { | ||
|
||
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; | ||
|
||
public static ElectricGuitarDto from(ElectricGuitar 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(), | ||
electricGuitar.getBrand(), | ||
electricGuitar.getModel(), | ||
electricGuitar.getProductionYear(), | ||
electricGuitar.getColor(), | ||
electricGuitar.getImages().toDtos(), | ||
electricGuitar.getHashtags().toStrings() | ||
); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/com/ajou/hertz/domain/instrument/dto/InstrumentImageDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.ajou.hertz.domain.instrument.dto; | ||
|
||
import com.ajou.hertz.domain.instrument.entity.InstrumentImage; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
@Getter | ||
public class InstrumentImageDto { | ||
|
||
private Long id; | ||
private String name; | ||
private String url; | ||
|
||
public static InstrumentImageDto from(InstrumentImage instrumentImage) { | ||
return new InstrumentImageDto( | ||
instrumentImage.getId(), | ||
instrumentImage.getOriginalName(), | ||
instrumentImage.getUrl() | ||
); | ||
} | ||
} |
100 changes: 100 additions & 0 deletions
100
...ain/java/com/ajou/hertz/domain/instrument/dto/request/CreateNewElectricGuitarRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
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.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.entity.ElectricGuitar; | ||
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<MultipartFile> 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; | ||
|
||
@NotNull | ||
private ElectricGuitarBrand brand; | ||
|
||
@NotNull | ||
private ElectricGuitarModel model; | ||
|
||
@Schema(description = "생상연도", example = "2014") | ||
@NotNull | ||
private Short productionYear; | ||
|
||
@NotNull | ||
private GuitarColor color; | ||
|
||
@Schema(description = "해시태그(각 해시태그마다 최대 10글자)", example = "[\"펜더\", \"Fender\"]") | ||
private List<@NotBlank @Length(max = 10) String> hashtags; | ||
|
||
public ElectricGuitar toEntity(User seller) { | ||
return ElectricGuitar.create( | ||
seller, | ||
title, | ||
progressStatus, | ||
tradeAddress.toEntity(), | ||
qualityStatus, | ||
price, | ||
hasAnomaly, | ||
description, | ||
brand, | ||
model, | ||
productionYear, | ||
color | ||
); | ||
} | ||
} |
Oops, something went wrong.