-
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.
csv 파일 업로드 dependency 및 기능 추가 (#328)
- Loading branch information
1 parent
6444b1f
commit 8cb6e2f
Showing
17 changed files
with
127 additions
and
39 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
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
17 changes: 0 additions & 17 deletions
17
src/main/java/com/spaceclub/global/annotation/profanity/BadWordExceptionMessage.java
This file was deleted.
Oops, something went wrong.
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
22 changes: 22 additions & 0 deletions
22
src/main/java/com/spaceclub/global/annotation/profanity/ProfanityExceptionMessage.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.spaceclub.global.annotation.profanity; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public enum ProfanityExceptionMessage { | ||
|
||
FAIL_BAD_WORD_SETUP("비속어 목록 Trie 생성 실패"), | ||
BAD_WORD_DETECTED("비속어가 발견 되었습니다"), | ||
INVALID_EXTENSION("md,txt 파일만 업로드 가능합니다."), | ||
FAILED_TO_SAVE("금칙어 저장에 실패하였습니다."), | ||
BAD_WORD_ALREADY_EXISTS("이미 존재하는 금칙어입니다."), | ||
FAILED_TO_CREATE_CSV("CSV 파일 생성에 실패하였습니다.") | ||
; | ||
|
||
private final String message; | ||
|
||
ProfanityExceptionMessage(String message) { | ||
this.message = message; | ||
} | ||
|
||
} |
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
52 changes: 52 additions & 0 deletions
52
src/main/java/com/spaceclub/global/aws/s3/S3FileUploader.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,52 @@ | ||
package com.spaceclub.global.aws.s3; | ||
|
||
import com.amazonaws.services.s3.AmazonS3; | ||
import com.amazonaws.services.s3.model.CannedAccessControlList; | ||
import com.amazonaws.services.s3.model.ObjectMetadata; | ||
import com.amazonaws.services.s3.model.PutObjectRequest; | ||
import com.spaceclub.global.aws.S3Properties; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.time.LocalDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
|
||
import static com.spaceclub.global.exception.GlobalExceptionCode.FAIL_FILE_UPLOAD; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class S3FileUploader { | ||
|
||
private static final String DATE_FORMAT = "yyyyMMdd_HHmmss"; | ||
private static final String CSV_FILE_NAME = "profanity_info"; | ||
|
||
private final AmazonS3 amazonS3; | ||
private final S3Properties s3Properties; | ||
|
||
public String uploadProfanityInfo(String content) { | ||
final String timestamp = LocalDateTime.now().format(DateTimeFormatter.ofPattern(DATE_FORMAT)); | ||
String csvFileKey = new FileNameCreator(s3Properties).createCSVFileKey(S3Folder.PROFANITY_INFO, CSV_FILE_NAME, timestamp); | ||
ObjectMetadata objectMetaData = createMetaData(content); | ||
|
||
try (InputStream inputStream = new ByteArrayInputStream(content.getBytes())) { | ||
final PutObjectRequest request = new PutObjectRequest(s3Properties.fileBucket(), csvFileKey, inputStream, objectMetaData) | ||
.withCannedAcl(CannedAccessControlList.PublicRead); | ||
amazonS3.putObject(request); | ||
|
||
return s3Properties.url() + csvFileKey; | ||
} catch (IOException e) { | ||
throw new IllegalStateException(FAIL_FILE_UPLOAD.toString()); | ||
} | ||
} | ||
|
||
private ObjectMetadata createMetaData(String content) { | ||
ObjectMetadata objectMetaData = new ObjectMetadata(); | ||
objectMetaData.setContentType("text/csv"); | ||
objectMetaData.setContentLength(content.length()); | ||
return objectMetaData; | ||
} | ||
|
||
} |
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
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