-
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.
- Loading branch information
Showing
24 changed files
with
1,173 additions
and
93 deletions.
There are no files selected for viewing
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
6 changes: 6 additions & 0 deletions
6
src/main/java/com/palbang/unsemawang/common/util/file/dto/FileReferenceType.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,6 @@ | ||
package com.palbang.unsemawang.common.util.file.dto; | ||
|
||
public enum FileReferenceType { | ||
MEMBER_PROFILE_IMG, | ||
COMMUNITY_BOARD | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/com/palbang/unsemawang/common/util/file/dto/FileRequest.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,22 @@ | ||
package com.palbang.unsemawang.common.util.file.dto; | ||
|
||
/** | ||
* 해당 파일이 필요한 곳의 정보로 파일을 요청 | ||
* of 메서드 사용해주세요 | ||
* @param referenceType 참조할 테이블명_파일유형 e.g FileReferenceType.MEMBER_PROFILE_IMAGE | ||
* @param referenceId 참조할 컬럼 ID (Long) | ||
* @param referenceStringId 참조할 컬럼 ID (String) | ||
*/ | ||
public record FileRequest( | ||
FileReferenceType referenceType, | ||
Long referenceId, | ||
String referenceStringId | ||
) { | ||
public static FileRequest of(FileReferenceType referenceType, Long referenceId) { | ||
return new FileRequest(referenceType, referenceId, null); | ||
} | ||
|
||
public static FileRequest of(FileReferenceType referenceType, String referenceStringId) { | ||
return new FileRequest(referenceType, null, referenceStringId); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/com/palbang/unsemawang/common/util/file/entity/File.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,37 @@ | ||
package com.palbang.unsemawang.common.util.file.entity; | ||
|
||
import java.time.LocalDate; | ||
|
||
import com.palbang.unsemawang.common.entity.BaseEntity; | ||
import com.palbang.unsemawang.common.util.file.dto.FileReferenceType; | ||
|
||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Entity | ||
@Builder | ||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class File extends BaseEntity { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
private String s3Key; | ||
private String type; | ||
private long size; | ||
|
||
private FileReferenceType referenceType; | ||
private Long referenceId; | ||
private String referenceStringId; | ||
|
||
private boolean isDeleted; | ||
private LocalDate expireDate; | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/palbang/unsemawang/common/util/file/exception/FileDeleteException.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,15 @@ | ||
package com.palbang.unsemawang.common.util.file.exception; | ||
|
||
public class FileDeleteException extends RuntimeException { | ||
|
||
public FileDeleteException() { | ||
} | ||
|
||
public FileDeleteException(String message) { | ||
super(message); | ||
} | ||
|
||
public FileDeleteException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/palbang/unsemawang/common/util/file/exception/FileNotFoundException.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,12 @@ | ||
package com.palbang.unsemawang.common.util.file.exception; | ||
|
||
public class FileNotFoundException extends RuntimeException { | ||
|
||
public FileNotFoundException(String message) { | ||
super(message); | ||
} | ||
|
||
public FileNotFoundException() { | ||
} | ||
|
||
} |
8 changes: 8 additions & 0 deletions
8
...ain/java/com/palbang/unsemawang/common/util/file/exception/FileSizeExceededException.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,8 @@ | ||
package com.palbang.unsemawang.common.util.file.exception; | ||
|
||
public class FileSizeExceededException extends RuntimeException { | ||
|
||
public FileSizeExceededException(String message) { | ||
super(message); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/palbang/unsemawang/common/util/file/exception/FileUploadException.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,15 @@ | ||
package com.palbang.unsemawang.common.util.file.exception; | ||
|
||
public class FileUploadException extends RuntimeException { | ||
|
||
public FileUploadException() { | ||
} | ||
|
||
public FileUploadException(String message) { | ||
super(message); | ||
} | ||
|
||
public FileUploadException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...in/java/com/palbang/unsemawang/common/util/file/exception/InvalidFileFormatException.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,11 @@ | ||
package com.palbang.unsemawang.common.util.file.exception; | ||
|
||
public class InvalidFileFormatException extends RuntimeException { | ||
public InvalidFileFormatException(String message) { | ||
super(message); | ||
} | ||
|
||
public InvalidFileFormatException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/palbang/unsemawang/common/util/file/repository/FileRepository.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,10 @@ | ||
package com.palbang.unsemawang.common.util.file.repository; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import com.palbang.unsemawang.common.util.file.entity.File; | ||
|
||
@Repository | ||
public interface FileRepository extends JpaRepository<File, Long>, FileRepositoryCustom { | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/palbang/unsemawang/common/util/file/repository/FileRepositoryCustom.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,10 @@ | ||
package com.palbang.unsemawang.common.util.file.repository; | ||
|
||
import java.util.List; | ||
|
||
import com.palbang.unsemawang.common.util.file.dto.FileRequest; | ||
import com.palbang.unsemawang.common.util.file.entity.File; | ||
|
||
public interface FileRepositoryCustom { | ||
List<File> findFilesByFileReference(FileRequest fileRequest); | ||
} |
46 changes: 46 additions & 0 deletions
46
...ain/java/com/palbang/unsemawang/common/util/file/repository/FileRepositoryCustomImpl.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,46 @@ | ||
package com.palbang.unsemawang.common.util.file.repository; | ||
|
||
import static com.palbang.unsemawang.common.util.file.entity.QFile.*; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.stereotype.Repository; | ||
|
||
import com.palbang.unsemawang.common.util.file.dto.FileRequest; | ||
import com.palbang.unsemawang.common.util.file.entity.File; | ||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@Repository | ||
@RequiredArgsConstructor | ||
public class FileRepositoryCustomImpl implements FileRepositoryCustom { | ||
|
||
private final JPAQueryFactory queryFactory; | ||
|
||
@Override | ||
public List<File> findFilesByFileReference(FileRequest fileRequest) { | ||
|
||
if (fileRequest.referenceStringId() == null) { | ||
return queryFactory | ||
.select(file) | ||
.from(file) | ||
.where( | ||
file.referenceId.eq(fileRequest.referenceId()) | ||
.and(file.referenceType.eq(fileRequest.referenceType())) | ||
) | ||
.orderBy(file.id.asc()) | ||
.fetch(); | ||
} else { | ||
return queryFactory | ||
.select(file) | ||
.from(file) | ||
.where( | ||
file.referenceStringId.eq(fileRequest.referenceStringId()) | ||
.and(file.referenceType.eq(fileRequest.referenceType())) | ||
) | ||
.orderBy(file.id.asc()) | ||
.fetch(); | ||
} | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
src/main/java/com/palbang/unsemawang/common/util/file/service/FileService.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,74 @@ | ||
package com.palbang.unsemawang.common.util.file.service; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
import com.palbang.unsemawang.common.util.file.dto.FileRequest; | ||
|
||
public interface FileService { | ||
|
||
/** | ||
* 이미지 업로드 | ||
* @param file 업로드 할 이미지 파일 | ||
* @param fileRequest ReferenceType과 ReferenceId 입력 | ||
*/ | ||
void uploadImage(MultipartFile file, FileRequest fileRequest); | ||
|
||
/** | ||
* 프로필 이미지 url 반환 | ||
* @param referenceId 참조된 회원 id, referenceId로 사용된 id | ||
* @return 해당 회원의 프로필 이미지 or 디폴트 프로필 이미지 | ||
*/ | ||
String getProfileImgUrl(String referenceId); | ||
|
||
/** | ||
* 파일 url 리스트 반환 | ||
* @param fileRequest ReferenceType(참조 테이블명)과 ReferenceId(참조 id) 입력 | ||
* @return 파일 url 리스트 | ||
*/ | ||
List<String> getFileUrls(FileRequest fileRequest); | ||
|
||
/** | ||
* 이미지 수정 : 이미지는 반드시 하나여야 함 | ||
* @param file 수정된 파일 | ||
* @param fileRequest 수정할 위치: ReferenceType, ReferenceId | ||
*/ | ||
void updateImage(MultipartFile file, FileRequest fileRequest); | ||
|
||
/** | ||
* 이미지 수정 : 여러 개의 이미지 중 하나를 수정 | ||
* @param file 수정된 파일 | ||
* @param updateTargetId 수정할 파일 id | ||
*/ | ||
void updateImageById(MultipartFile file, Long updateTargetId); | ||
|
||
/** | ||
* 이미지 수정 : 여러개의 이미지 전체 삭제 후 전체 추가 | ||
* @param files 이미지 리스트 | ||
* @param fileRequest 수정할 위치 | ||
*/ | ||
void updateImagesAtOnce(List<MultipartFile> files, FileRequest fileRequest); | ||
|
||
/** | ||
* 파일 삭제 | ||
* @param fileRequest 삭제할 파일 위치: ReferenceType, ReferenceId | ||
* @return 삭제 여부 | ||
*/ | ||
boolean deleteFile(FileRequest fileRequest); | ||
|
||
/** | ||
* 파일 삭제 여러개 | ||
* @param fileRequest 삭제할 파일 위치: ReferenceType, ReferenceId | ||
* @return 삭제 여부 | ||
*/ | ||
boolean deleteFiles(FileRequest fileRequest); | ||
|
||
/** | ||
* 파일 삭제 아이디로 | ||
* @param fileId 삭제할 파일 아이디 | ||
* @return 삭제 여부 | ||
*/ | ||
boolean deleteFileById(Long fileId); | ||
|
||
} |
Oops, something went wrong.