Skip to content

Commit

Permalink
Merge pull request #30 from Ong-gi-Jong-gi/feature/TSK-36/Recap
Browse files Browse the repository at this point in the history
CORS domain update & S3 directory for FileType
  • Loading branch information
minjoon-98 authored Jul 10, 2024
2 parents 45fbbad + dece21c commit dabe06e
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 16 deletions.
13 changes: 7 additions & 6 deletions src/main/java/ongjong/namanmoo/domain/Lucky.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@


import jakarta.persistence.*;
import lombok.Getter;
import lombok.Setter;
import lombok.*;
import ongjong.namanmoo.domain.answer.FaceTimeAnswer;
import java.util.List;

@Entity
@Getter
@Setter
@Getter @Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class Lucky {

@Id
Expand All @@ -27,10 +28,10 @@ public class Lucky {

private boolean running;

@Builder.Default
@Enumerated(EnumType.STRING)
private ChallengeLength lifetime = ChallengeLength.THIRTY_DAYS; // 행운이 기본 수명 ( 30일 단위 챌린지 )

@OneToMany(mappedBy = "lucky")
private List<FaceTimeAnswer> faceTimeAnswers;

}
}
3 changes: 1 addition & 2 deletions src/main/java/ongjong/namanmoo/domain/VoiceMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
import java.sql.Timestamp;

@Entity
@Getter
@Setter
@Getter @Setter
public class VoiceMessage {

@Id
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/ongjong/namanmoo/domain/answer/Answer.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@


@Entity
@Getter
@Setter
@Getter @Setter
@RequiredArgsConstructor
public class Answer {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
import ongjong.namanmoo.domain.Lucky;

@Entity
@Getter
@Setter
@Getter @Setter
public class FaceTimeAnswer {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class CorsConfig {
@Bean
public CorsConfigurationSource corsConfigurationSource() {
CorsConfiguration configuration = new CorsConfiguration();
configuration.setAllowedOrigins(List.of("http://localhost:5173")); // 요청을 허용할 출처
configuration.setAllowedOrigins(List.of("http://localhost:5173", "https://www.mooluck.site")); // 요청을 허용할 출처
configuration.setAllowedMethods(List.of("GET", "POST", "PUT", "DELETE", "OPTIONS")); // 허용할 HTTP 메서드
configuration.setAllowedHeaders(List.of("*")); // 허용할 헤더
configuration.setExposedHeaders(List.of("Authorization", "Authorization-refresh")); // 클라이언트에게 노출할 헤더 명시
Expand Down
26 changes: 23 additions & 3 deletions src/main/java/ongjong/namanmoo/service/AwsS3Service.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ public String uploadFile(MultipartFile multipartFile) throws IOException {
File uploadFile = convertFile(multipartFile)
.orElseThrow(() -> new IllegalArgumentException("MultipartFile -> File convert fail"));

String fileName = generateFileName(uploadFile);
String fileType = determineFileType(multipartFile);
String fileName = generateFileName(uploadFile, fileType);

log.debug("Uploading file to S3: {}", fileName);
String uploadImageUrl = uploadFileToS3(uploadFile, fileName);
Expand All @@ -80,6 +81,24 @@ public String uploadFile(MultipartFile multipartFile) throws IOException {
return uploadImageUrl;
}

/**
* 파일 타입을 결정하는 메소드.
*
* @param multipartFile 파일
* @return 파일 타입 (image/audio/video)
*/
private String determineFileType(MultipartFile multipartFile) {
String contentType = multipartFile.getContentType();
if (contentType != null && contentType.startsWith("image")) {
return "image";
} else if (contentType != null && contentType.startsWith("audio")) {
return "audio";
} else if (contentType != null && contentType.startsWith("video")) {
return "video";
}
throw new IllegalArgumentException("Unsupported file type: " + contentType);
}

/**
* MultipartFile을 File 객체로 변환하는 메소드.
*
Expand All @@ -105,10 +124,11 @@ private Optional<File> convertFile(MultipartFile file) throws IOException {
* 업로드될 파일의 고유한 파일 이름을 생성하는 메소드.
*
* @param uploadFile 업로드할 파일
* @param fileType 파일 타입 (image/audio/video)
* @return String 고유한 파일 이름
*/
private String generateFileName(File uploadFile) {
return UUID.randomUUID() + "_" + uploadFile.getName();
private String generateFileName(File uploadFile, String fileType) {
return fileType + "/" + UUID.randomUUID() + "_" + uploadFile.getName();
}

/**
Expand Down

0 comments on commit dabe06e

Please sign in to comment.