Skip to content

Commit

Permalink
Merge pull request #161 from PROTOTYNE/develop
Browse files Browse the repository at this point in the history
[240929] - 04
  • Loading branch information
chock-cho authored Sep 29, 2024
2 parents bc3a32d + 1da5924 commit 90b808a
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -38,10 +43,9 @@ public ApiResponse<List<ProductDTO.ProductResponse>> getProductsList(HttpServlet
}

// 시제품 등록
@PostMapping(value = "/products", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
@Operation(summary = "시제품 등록 API - 인증 필수",
description = "시제품 등록(추가)" + """
1. 시제품 명 (productName) - 공백 시 에러
2. 설명 (contents - 공백 시 에러
3. 티켓 갯수 (reqTickets)
Expand All @@ -50,12 +54,14 @@ public ApiResponse<List<ProductDTO.ProductResponse>> 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<Long> createProduct(HttpServletRequest token,
@Valid @RequestBody ProductDTO.CreateProductRequest productRequest,
@RequestPart(value = "imageFiles", required = false) List<MultipartFile> images){
@Valid @RequestPart("productRequest") ProductDTO.CreateProductRequest productRequest,
@RequestPart(value = "imageFiles", required = false) List<MultipartFile> images)
{
String oauthToken = jwtManager.getToken(token);
Long productId = productService.createProduct(oauthToken, productRequest, images);
return ApiResponse.onSuccess(productId);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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; // 질문 목록
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/prototyne/config/SwaggerBeanConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
10 changes: 10 additions & 0 deletions src/main/java/com/prototyne/config/WebConfig.java
Original file line number Diff line number Diff line change
@@ -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 {

Expand All @@ -15,4 +19,10 @@ public void addCorsMappings(CorsRegistry registry) {
.allowedHeaders("*")
.allowCredentials(true);
}

@Override
public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
// JSON Message Converter 추가
converters.add(new MappingJackson2HttpMessageConverter());
}
}

0 comments on commit 90b808a

Please sign in to comment.