diff --git a/src/main/java/com/prototyne/Enterprise/web/controller/ProductController.java b/src/main/java/com/prototyne/Enterprise/web/controller/ProductController.java index 03bcf3c..6b2eb2b 100644 --- a/src/main/java/com/prototyne/Enterprise/web/controller/ProductController.java +++ b/src/main/java/com/prototyne/Enterprise/web/controller/ProductController.java @@ -1,10 +1,15 @@ package com.prototyne.Enterprise.web.controller; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; import com.prototyne.Enterprise.service.ProductService.ProductService; import com.prototyne.Enterprise.web.dto.ProductDTO; import com.prototyne.config.JwtManager; import com.prototyne.apiPayload.ApiResponse; import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.media.ArraySchema; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.servlet.http.HttpServletRequest; @@ -38,10 +43,9 @@ public ApiResponse> getProductsList(HttpServlet } // 시제품 등록 - @PostMapping(value = "/products", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) @Operation(summary = "시제품 등록 API - 인증 필수", description = "시제품 등록(추가)" + """ - + 1. 시제품 명 (productName) - 공백 시 에러 2. 설명 (contents - 공백 시 에러 3. 티켓 갯수 (reqTickets) @@ -50,12 +54,14 @@ public ApiResponse> getProductsList(HttpServlet 6. 출시예정일 (launchedDate) - 공백(null)이면 미정 7. 질문 목록 (1~5) 8. imageFiles : 제품 사진 (최대 3장) - + 요청 성공 시, 시제품 아이디(product_id) 반환""", security = {@SecurityRequirement(name = "session-token")}) + @PostMapping(value = "/products", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) public ApiResponse createProduct(HttpServletRequest token, - @Valid @RequestBody ProductDTO.CreateProductRequest productRequest, - @RequestPart(value = "imageFiles", required = false) List images){ + @Valid @RequestPart("productRequest") ProductDTO.CreateProductRequest productRequest, + @RequestPart(value = "imageFiles", required = false) List images) + { String oauthToken = jwtManager.getToken(token); Long productId = productService.createProduct(oauthToken, productRequest, images); return ApiResponse.onSuccess(productId); diff --git a/src/main/java/com/prototyne/Enterprise/web/dto/ProductDTO.java b/src/main/java/com/prototyne/Enterprise/web/dto/ProductDTO.java index 35d2788..7f48dcc 100644 --- a/src/main/java/com/prototyne/Enterprise/web/dto/ProductDTO.java +++ b/src/main/java/com/prototyne/Enterprise/web/dto/ProductDTO.java @@ -1,9 +1,12 @@ package com.prototyne.Enterprise.web.dto; +import com.fasterxml.jackson.annotation.JsonProperty; import com.prototyne.domain.enums.ProductCategory; import jakarta.validation.constraints.NotBlank; +import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; +import lombok.NoArgsConstructor; import java.time.LocalDate; @@ -12,8 +15,13 @@ public class ProductDTO { // 시제품 등록 요청 형식 @Builder @Getter + @NoArgsConstructor + @AllArgsConstructor public static class CreateProductRequest { + @JsonProperty("productInfo") private ProductInfo productInfo; + + @JsonProperty("questions") private Questions questions; // 질문 목록 } diff --git a/src/main/java/com/prototyne/config/SwaggerBeanConfig.java b/src/main/java/com/prototyne/config/SwaggerBeanConfig.java index df25b7b..e751089 100644 --- a/src/main/java/com/prototyne/config/SwaggerBeanConfig.java +++ b/src/main/java/com/prototyne/config/SwaggerBeanConfig.java @@ -10,9 +10,9 @@ public class SwaggerBeanConfig { public SwaggerBeanConfig(MappingJackson2HttpMessageConverter converter) { - // Content-Type에 ctetstream 허용 + // 스웨거에서 Content-Type에 ctetstream 허용 var supportedMediaTypes = new ArrayList<>(converter.getSupportedMediaTypes()); supportedMediaTypes.add(new MediaType("application", "octet-stream")); converter.setSupportedMediaTypes(supportedMediaTypes); } -} +} \ No newline at end of file diff --git a/src/main/java/com/prototyne/config/WebConfig.java b/src/main/java/com/prototyne/config/WebConfig.java index 252f7b4..693cc91 100644 --- a/src/main/java/com/prototyne/config/WebConfig.java +++ b/src/main/java/com/prototyne/config/WebConfig.java @@ -1,9 +1,13 @@ package com.prototyne.config; import org.springframework.context.annotation.Configuration; +import org.springframework.http.converter.HttpMessageConverter; +import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; import org.springframework.web.servlet.config.annotation.CorsRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; +import java.util.List; + @Configuration public class WebConfig implements WebMvcConfigurer { @@ -15,4 +19,10 @@ public void addCorsMappings(CorsRegistry registry) { .allowedHeaders("*") .allowCredentials(true); } + + @Override + public void extendMessageConverters(List> converters) { + // JSON Message Converter 추가 + converters.add(new MappingJackson2HttpMessageConverter()); + } }