Skip to content

Commit

Permalink
Merge pull request #153 from PlanIt-Project/BE_feature#152
Browse files Browse the repository at this point in the history
Fix: 파일 처리 관련 수정 및 상품 판매 중지 HTTP 메서드 변경
  • Loading branch information
moonjin-kim authored Apr 5, 2024
2 parents b75f261 + 7b7de92 commit db6165e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 "이미지 업로드 오류 발생";
Expand All @@ -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<String> imageExtensions = Arrays.asList("jpg", "jpeg", "png", "gif");
return imageExtensions.contains(fileExtension.toLowerCase());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -35,7 +33,7 @@ public ResponseEntity<byte[]> loadImage(@PathVariable String image_name) {
}
}

@GetMapping("/{file_name}")
@GetMapping("/file/{file_name}")
public ResponseEntity<byte[]> loadFile(@PathVariable String file_name) {
try {
byte[] fileBytes = fileHandler.loadFile(file_name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public ApiResponse<Product> createProduct(@RequestBody ProductRequestDto product
return ApiResponse.ok(productService.createProduct(productRequestDto));
}

@PutMapping("/{product_id}")
@DeleteMapping("/{product_id}")
public ApiResponse<String> stopSelling(@PathVariable Long product_id) {
return ApiResponse.ok(productService.stopProductSell(product_id));
}
Expand Down

0 comments on commit db6165e

Please sign in to comment.