Skip to content

Commit

Permalink
[DEV-40] FileMetaData 기능 구현 (#136)
Browse files Browse the repository at this point in the history
  • Loading branch information
5uhwann authored Oct 8, 2024
1 parent 646ba90 commit e9ae374
Show file tree
Hide file tree
Showing 28 changed files with 160 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.fasterxml.jackson.annotation.JsonFormat;
import ddingdong.ddingdongBE.domain.documents.service.dto.query.AdminDocumentQuery;
import ddingdong.ddingdongBE.file.dto.FileResponse;
import ddingdong.ddingdongBE.file.service.dto.FileResponse;
import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Schema;
import java.time.LocalDate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.fasterxml.jackson.annotation.JsonFormat;
import ddingdong.ddingdongBE.domain.documents.service.dto.query.DocumentQuery;
import ddingdong.ddingdongBE.file.dto.FileResponse;
import ddingdong.ddingdongBE.file.service.dto.FileResponse;
import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Schema;
import java.time.LocalDate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import ddingdong.ddingdongBE.domain.documents.service.dto.query.AdminDocumentListQuery;
import ddingdong.ddingdongBE.domain.documents.service.dto.query.AdminDocumentQuery;
import ddingdong.ddingdongBE.domain.fileinformation.service.FileInformationService;
import ddingdong.ddingdongBE.file.dto.FileResponse;
import ddingdong.ddingdongBE.file.service.dto.FileResponse;
import ddingdong.ddingdongBE.file.service.FileService;
import java.util.List;
import lombok.RequiredArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import ddingdong.ddingdongBE.domain.documents.service.dto.query.DocumentListQuery;
import ddingdong.ddingdongBE.domain.documents.service.dto.query.DocumentQuery;
import ddingdong.ddingdongBE.domain.fileinformation.service.FileInformationService;
import ddingdong.ddingdongBE.file.dto.FileResponse;
import ddingdong.ddingdongBE.file.service.dto.FileResponse;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package ddingdong.ddingdongBE.domain.documents.service.dto.query;

import ddingdong.ddingdongBE.domain.documents.entity.Document;
import ddingdong.ddingdongBE.file.dto.FileResponse;
import ddingdong.ddingdongBE.file.service.dto.FileResponse;
import java.time.LocalDate;
import java.util.List;
import lombok.Builder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.fasterxml.jackson.annotation.JsonFormat;
import ddingdong.ddingdongBE.domain.documents.entity.Document;
import ddingdong.ddingdongBE.file.dto.FileResponse;
import ddingdong.ddingdongBE.file.service.dto.FileResponse;
import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Schema;
import java.time.LocalDate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import ddingdong.ddingdongBE.domain.fileinformation.entity.FileTypeCategory;
import ddingdong.ddingdongBE.domain.fileinformation.repository.FileInformationRepository;
import ddingdong.ddingdongBE.file.FileStore;
import ddingdong.ddingdongBE.file.dto.FileResponse;
import ddingdong.ddingdongBE.file.dto.UploadFileDto;
import ddingdong.ddingdongBE.file.service.dto.FileResponse;
import ddingdong.ddingdongBE.file.service.dto.UploadFileDto;
import java.util.List;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package ddingdong.ddingdongBE.domain.filemetadata.entity;

public enum FileCategory {
CLUB_PROFILE_IMAGE,
CLUB_INTRODUCTION_IMAGE
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package ddingdong.ddingdongBE.domain.filemetadata.entity;

import ddingdong.ddingdongBE.common.BaseEntity;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.Id;
import java.util.UUID;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class FileMetaData extends BaseEntity {

@Id
@Column(length = 16)
private UUID fileId;

@Enumerated(EnumType.STRING)
@Column(nullable = false)
private FileCategory fileCategory;

@Column(nullable = false)
private String fileName;

@Builder
public FileMetaData(FileCategory fileCategory, UUID fileId, String fileName) {
this.fileId = fileId;
this.fileCategory = fileCategory;
this.fileName = fileName;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package ddingdong.ddingdongBE.domain.filemetadata.repository;

import ddingdong.ddingdongBE.domain.filemetadata.entity.FileMetaData;
import java.util.UUID;
import org.springframework.data.jpa.repository.JpaRepository;

public interface FileMetaDataRepository extends JpaRepository<FileMetaData, UUID> {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package ddingdong.ddingdongBE.domain.filemetadata.service;

import ddingdong.ddingdongBE.domain.filemetadata.entity.FileMetaData;
import java.util.UUID;

public interface FacadeFileMetaDataService {

FileMetaData getFileUrlWithMetaData(UUID fileId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package ddingdong.ddingdongBE.domain.filemetadata.service;

import ddingdong.ddingdongBE.domain.filemetadata.entity.FileMetaData;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional(readOnly = true)
@RequiredArgsConstructor
public class FacadeFileMetaDataServiceImpl implements FacadeFileMetaDataService {

private final FileMetaDataService fileMetaDataService;

@Override
public FileMetaData getFileUrlWithMetaData(UUID fileId) {
return fileMetaDataService.getByFileId(fileId);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package ddingdong.ddingdongBE.domain.filemetadata.service;

import ddingdong.ddingdongBE.domain.filemetadata.entity.FileMetaData;
import java.util.UUID;

public interface FileMetaDataService {

void create(FileMetaData fileMetaData);

FileMetaData getByFileId(UUID fileId);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package ddingdong.ddingdongBE.domain.filemetadata.service;

import ddingdong.ddingdongBE.common.exception.PersistenceException.ResourceNotFound;
import ddingdong.ddingdongBE.domain.filemetadata.entity.FileMetaData;
import ddingdong.ddingdongBE.domain.filemetadata.repository.FileMetaDataRepository;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional(readOnly = true)
@RequiredArgsConstructor
public class GeneralFileMetaDataService implements FileMetaDataService {

private final FileMetaDataRepository fileMetaDataRepository;

@Transactional
@Override
public void create(FileMetaData fileMetaData) {
fileMetaDataRepository.save(fileMetaData);
}

@Override
public FileMetaData getByFileId(UUID fileId) {
return fileMetaDataRepository.findById(fileId)
.orElseThrow(() -> new ResourceNotFound("FimeMetaData(fileId=" + fileId + "를 찾을 수 없습니다."));
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package ddingdong.ddingdongBE.domain.notice.controller.dto.response;

import ddingdong.ddingdongBE.domain.notice.entity.Notice;
import ddingdong.ddingdongBE.file.dto.FileResponse;
import ddingdong.ddingdongBE.file.service.dto.FileResponse;
import java.time.LocalDateTime;
import java.util.List;
import lombok.AccessLevel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import ddingdong.ddingdongBE.domain.notice.repository.NoticeRepository;
import ddingdong.ddingdongBE.domain.user.entity.User;
import ddingdong.ddingdongBE.file.FileStore;
import ddingdong.ddingdongBE.file.dto.FileResponse;
import ddingdong.ddingdongBE.file.service.dto.FileResponse;

import java.util.List;
import java.util.NoSuchElementException;
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/ddingdong/ddingdongBE/file/AwsS3FileStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.amazonaws.services.s3.model.ObjectMetadata;
import com.amazonaws.services.s3.model.PutObjectRequest;

import ddingdong.ddingdongBE.file.dto.UploadFileDto;
import ddingdong.ddingdongBE.file.service.dto.UploadFileDto;

import java.io.IOException;
import java.net.URLEncoder;
Expand All @@ -19,6 +19,7 @@
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

//TODO: 리팩토링 후 제거
@Component
@RequiredArgsConstructor
public class AwsS3FileStore implements FileStore {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/ddingdong/ddingdongBE/file/FileStore.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package ddingdong.ddingdongBE.file;

import ddingdong.ddingdongBE.file.dto.UploadFileDto;
import ddingdong.ddingdongBE.file.service.dto.UploadFileDto;

import java.util.List;
import org.springframework.web.multipart.MultipartFile;

//TODO: 리팩토링 후 제거
public interface FileStore {

List<UploadFileDto> storeFile(List<MultipartFile> multipartFile, String fileType, String filePath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ public record UploadUrlResponse(

@Schema(description = "presignedUrl", example = "https://test-bucket.s3.amazonaws.com/test/jpg/image.jpg")
String uploadUrl,
@Schema(description = "업로드 파일 이름(UUID)", example = "9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d")
String uploadFileName
@Schema(description = "업로드 파일 식별자(UUID)", example = "9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d")
String fileId
) {

public static UploadUrlResponse of(String uploadUrl, String uploadFileName) {
public static UploadUrlResponse of(String uploadUrl, String fileId) {
return UploadUrlResponse.builder()
.uploadUrl(uploadUrl)
.uploadFileName(uploadFileName)
.fileId(fileId)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import ddingdong.ddingdongBE.common.exception.ParsingExcelFileException.NonExcelFile;
import ddingdong.ddingdongBE.domain.club.entity.Club;
import ddingdong.ddingdongBE.domain.club.entity.ClubMember;
import ddingdong.ddingdongBE.file.dto.ExcelClubMemberDto;
import ddingdong.ddingdongBE.file.service.dto.ExcelClubMemberDto;
import java.awt.Color;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
import ddingdong.ddingdongBE.domain.fileinformation.entity.FileTypeCategory;
import ddingdong.ddingdongBE.domain.fileinformation.service.FileInformationService;
import ddingdong.ddingdongBE.file.FileStore;
import ddingdong.ddingdongBE.file.dto.UploadFileDto;
import ddingdong.ddingdongBE.file.service.dto.UploadFileDto;
import java.util.List;

import lombok.RequiredArgsConstructor;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ddingdong.ddingdongBE.file.dto;
package ddingdong.ddingdongBE.file.service.dto;

import ddingdong.ddingdongBE.common.exception.InvalidatedMappingException.InvalidatedEnumValue;
import ddingdong.ddingdongBE.domain.club.entity.Club;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ddingdong.ddingdongBE.file.dto;
package ddingdong.ddingdongBE.file.service.dto;

import ddingdong.ddingdongBE.domain.fileinformation.entity.FileInformation;
import io.swagger.v3.oas.annotations.media.Schema;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package ddingdong.ddingdongBE.file.dto;
package ddingdong.ddingdongBE.file.service.dto;

import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

//TODO: 리팩토링 후 제거
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class UploadFileDto {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
create table file_meta_data
(
file_id binary(16) not null
primary key,
created_at timestamp null,
updated_at timestamp null,
file_category varchar(255) not null,
file_name varchar(255) not null
);
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import ddingdong.ddingdongBE.domain.documents.service.dto.command.UpdateDocumentCommand;
import ddingdong.ddingdongBE.domain.documents.service.dto.query.AdminDocumentListQuery;
import ddingdong.ddingdongBE.domain.documents.service.dto.query.AdminDocumentQuery;
import ddingdong.ddingdongBE.file.dto.FileResponse;
import ddingdong.ddingdongBE.file.service.dto.FileResponse;
import java.time.LocalDate;
import java.util.List;
import org.junit.jupiter.api.DisplayName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import ddingdong.ddingdongBE.common.support.WithMockAuthenticatedUser;
import ddingdong.ddingdongBE.domain.documents.service.dto.query.DocumentListQuery;
import ddingdong.ddingdongBE.domain.documents.service.dto.query.DocumentQuery;
import ddingdong.ddingdongBE.file.dto.FileResponse;
import ddingdong.ddingdongBE.file.service.dto.FileResponse;
import java.time.LocalDate;
import java.util.List;
import org.junit.jupiter.api.DisplayName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void generatePreSignedUrl() throws MalformedURLException {
"^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-7[0-9A-Fa-f]{3}-[89ab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"
);
assertThat(uploadUrlResponse.uploadUrl()).isEqualTo(expectedUrl.toString());
assertThat(Pattern.matches(UUID7_PATTERN.pattern(), uploadUrlResponse.uploadFileName())).isTrue();
assertThat(Pattern.matches(UUID7_PATTERN.pattern(), uploadUrlResponse.fileId())).isTrue();
}

@DisplayName("s3 uploadedFileUrl을 조회한다.")
Expand Down

0 comments on commit e9ae374

Please sign in to comment.