diff --git a/src/main/java/com/sideProject/PlanIT/common/modules/FileHandler.java b/src/main/java/com/sideProject/PlanIT/common/modules/FileHandler.java index 51fedc0..24fd7ab 100644 --- a/src/main/java/com/sideProject/PlanIT/common/modules/FileHandler.java +++ b/src/main/java/com/sideProject/PlanIT/common/modules/FileHandler.java @@ -11,6 +11,8 @@ import java.io.File; import java.io.FileInputStream; import java.io.IOException; +import java.util.Arrays; +import java.util.List; import java.util.UUID; @Component @@ -29,7 +31,12 @@ public String saveFile(MultipartFile file) { File dest = new File(fileStorageDir + File.separator + fileName); file.transferTo(dest); - return fileName; + String fileExtension = getFileExtension(fileName); + if (isImageFile(fileExtension)) { + return "/image/" + fileName; + } else { + return "/file/" + fileName; + } } catch (IOException e) { log.error(e.getMessage()); return "이미지 업로드 오류 발생"; @@ -56,4 +63,18 @@ private String getUniqueFileName(String fileName) { return UUID.randomUUID() + fileName; } + private String getFileExtension(String fileName) { + int lastIndex = fileName.lastIndexOf('.'); + if (lastIndex > 0) { + return fileName.substring(lastIndex + 1); + } + return ""; + } + + private boolean isImageFile(String fileExtension) { + // 이미지 파일 확장자 리스트 + List imageExtensions = Arrays.asList("jpg", "jpeg", "png", "gif"); + return imageExtensions.contains(fileExtension.toLowerCase()); + } + } diff --git a/src/main/java/com/sideProject/PlanIT/config/SecurityConfig.java b/src/main/java/com/sideProject/PlanIT/config/SecurityConfig.java index eb49fa3..47e8e83 100644 --- a/src/main/java/com/sideProject/PlanIT/config/SecurityConfig.java +++ b/src/main/java/com/sideProject/PlanIT/config/SecurityConfig.java @@ -59,7 +59,7 @@ public CorsConfiguration getCorsConfiguration(HttpServletRequest request) { .exceptionHandling((exceptionHandling) -> exceptionHandling.authenticationEntryPoint(jwtAuthenticationEntryPoint)) .authorizeHttpRequests((authorizeRequests) -> authorizeRequests - .requestMatchers("/member/signin", "/member/signup", "/member/refresh", "/member/email/**").permitAll() + .requestMatchers("/member/signin", "/member/signup", "/member/refresh", "/member/email/**", "/login/**").permitAll() .requestMatchers("/admin/**").hasAnyAuthority("ADMIN") .anyRequest().authenticated() ) diff --git a/src/main/java/com/sideProject/PlanIT/domain/file/controller/FileController.java b/src/main/java/com/sideProject/PlanIT/domain/file/controller/FileController.java index 4383650..2336f3d 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/file/controller/FileController.java +++ b/src/main/java/com/sideProject/PlanIT/domain/file/controller/FileController.java @@ -10,14 +10,12 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import java.io.IOException; @RestController @RequiredArgsConstructor -@RequestMapping("/file") public class FileController { private final FileHandler fileHandler; @@ -35,7 +33,7 @@ public ResponseEntity loadImage(@PathVariable String image_name) { } } - @GetMapping("/{file_name}") + @GetMapping("/file/{file_name}") public ResponseEntity loadFile(@PathVariable String file_name) { try { byte[] fileBytes = fileHandler.loadFile(file_name); diff --git a/src/main/java/com/sideProject/PlanIT/domain/product/controller/ProductAdminController.java b/src/main/java/com/sideProject/PlanIT/domain/product/controller/ProductAdminController.java index f1b3e27..b23d8c1 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/product/controller/ProductAdminController.java +++ b/src/main/java/com/sideProject/PlanIT/domain/product/controller/ProductAdminController.java @@ -18,7 +18,7 @@ public ApiResponse createProduct(@RequestBody ProductRequestDto product return ApiResponse.ok(productService.createProduct(productRequestDto)); } - @PutMapping("/{product_id}") + @DeleteMapping("/{product_id}") public ApiResponse stopSelling(@PathVariable Long product_id) { return ApiResponse.ok(productService.stopProductSell(product_id)); }