-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor : CardService 메서드 정리 * refactor : GroupService 역할 분리 * feat : ImageFileService * refactor : service 코드 도메인으로 이동 * refactor : fileService 제거 * refactor : CardService가 ImageFile을 다루도록 수정 * refactor : CardService 리팩토링 * refactor : Profile Image 요청 루트 경로 수정 * feat : resource handler에 utf8 decode resolver 추가
- Loading branch information
Showing
31 changed files
with
265 additions
and
274 deletions.
There are no files selected for viewing
File renamed without changes
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
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
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
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
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
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
4 changes: 2 additions & 2 deletions
4
server/src/main/java/com/giggle/samehere/card/domain/CardItemRepository.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
63 changes: 63 additions & 0 deletions
63
server/src/main/java/com/giggle/samehere/card/domain/ImageFile.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,63 @@ | ||
package com.giggle.samehere.card.domain; | ||
|
||
import com.giggle.samehere.card.exception.FileUploadException; | ||
import java.io.InputStream; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.StandardCopyOption; | ||
import java.time.LocalDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
import java.util.UUID; | ||
import org.springframework.util.StringUtils; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
public class ImageFile { | ||
|
||
private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd.HH:mm:ss"); | ||
|
||
private final Path filePath; | ||
|
||
private ImageFile(Path filePath) { | ||
this.filePath = filePath; | ||
} | ||
|
||
public static ImageFile pathOf(String filePath) { | ||
return new ImageFile(Path.of(filePath)); | ||
} | ||
|
||
public static ImageFile save(Path directoryPath, MultipartFile multipartFile) { | ||
try (InputStream inputStream = multipartFile.getInputStream()) { | ||
if (!Files.exists(directoryPath)) { | ||
Files.createDirectories(directoryPath); | ||
} | ||
final Path filePath = filePath(directoryPath, multipartFile); | ||
Files.copy(inputStream, filePath, StandardCopyOption.REPLACE_EXISTING); | ||
return new ImageFile(filePath); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
throw new FileUploadException(); | ||
} | ||
} | ||
|
||
public static ImageFile save(String directoryPath, MultipartFile multipartFile) { | ||
return save(Path.of(directoryPath), multipartFile); | ||
} | ||
|
||
private static Path filePath(Path directoryPath, MultipartFile multipartFile) { | ||
final String prefix = LocalDateTime.now().format(DATE_TIME_FORMATTER) + ":"; | ||
final String fileName = prefix+StringUtils.cleanPath(multipartFile.getOriginalFilename()); | ||
final Path path = directoryPath.resolve(fileName); | ||
return uniquePath(path); | ||
} | ||
|
||
private static Path uniquePath(Path path) { | ||
if (Files.exists(path)) { | ||
return uniquePath(Path.of(path + UUID.randomUUID().toString().substring(0, 5))); | ||
} | ||
return path; | ||
} | ||
|
||
public Path path() { | ||
return filePath; | ||
} | ||
} |
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
Oops, something went wrong.