Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BE] 아마존 S3 , 아마존 SES 구현 #19

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
cbb4e3b
[BE] feat : 회원 DB 엔티티, Repository 구성
320Hwany Mar 13, 2024
a249f7d
[BE] feat : 생성한 예약 DB 엔티티, Repository 구성
320Hwany Mar 13, 2024
eb9578c
[BE] feat : 참여한 예약 DB 엔티티, Repository 구성
320Hwany Mar 13, 2024
b91e409
[BE] feat : 초대 링크 DB 엔티티, Repository 구성
320Hwany Mar 13, 2024
8ffa286
Merge pull request #6 from U2DJ2/feat/persistence-setting
320Hwany Mar 13, 2024
cf06746
[BE] style : 엔티티 생성자 들여쓰기 변경
320Hwany Mar 13, 2024
0717038
[BE] feat : 공통 응답 객체 설계 및 테스트
jerry3269 Mar 15, 2024
41c18fe
[BE] style : Response 파라미터 불변으로 변경
jerry3269 Mar 15, 2024
0092f4a
[BE] feat : status code 400, 401, 403, 404, 405 예외 클래스 생성
320Hwany Mar 15, 2024
fe5cc1f
[BE] feat : ApiRestControllerAdvice 구성
320Hwany Mar 15, 2024
1f9fca3
Merge pull request #9 from U2DJ2/feat/exception-handling
320Hwany Mar 15, 2024
a84b544
[BE] feat : BaseTimeEntity 구성, LoginType 삭제
320Hwany Mar 16, 2024
5b7ef10
[BE] feat : DB 엔티티, repository 추가(대학교, 카테고리, 인증번호)
320Hwany Mar 16, 2024
db9cf52
[BE] feat : 대학교, 카테고리 연관관계 추가
320Hwany Mar 16, 2024
3a9a729
Merge pull request #11 from U2DJ2/feat/persistence-setting
320Hwany Mar 16, 2024
bdaf797
Merge branch 'backend-main' of https://github.com/U2DJ2/booki-today i…
Anak-2 Mar 21, 2024
5bc7d2f
[BE] feat : 아마존 S3와 파일 업로드 삭제 및 아마존 SES 메일 전송 기능 추가
Anak-2 Mar 21, 2024
e0eb120
[BE] feat : AWS S3 파일 삭제 기능 수정 및 리팩토링
Anak-2 Mar 21, 2024
d38309b
[BE] feat : 파일 컨트롤러 테스트 코드 작성
Anak-2 Mar 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions backend/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,16 @@ dependencies {

// prometheus
runtimeOnly 'io.micrometer:micrometer-registry-prometheus'

//thymeleaf
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'

//mail
implementation 'org.springframework.boot:spring-boot-starter-mail'
implementation 'com.amazonaws:aws-java-sdk-ses:1.12.408'

//AWS S3
implementation 'org.springframework.cloud:spring-cloud-starter-aws:2.2.6.RELEASE'
}

tasks.named('test') {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package booki_today.application.file;

import booki_today.dto.file.FileAddRequest;
import booki_today.dto.file.FileDeleteRequest;
import booki_today.implement.file.FileRemover;
import booki_today.implement.file.FileUploader;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

@Service
public class AmazonS3Service implements FileService{

private final FileUploader fileUploader;
private final FileRemover fileRemover;

public AmazonS3Service(final FileUploader fileUploader, final FileRemover fileRemover) {
this.fileUploader = fileUploader;
this.fileRemover = fileRemover;
}

public void uploadFile(FileAddRequest fileAddRequest, MultipartFile multipartFile){
fileUploader.uploadFile(fileAddRequest, multipartFile);
}

public void deleteFile(FileDeleteRequest fileDeleteRequest){
fileRemover.deleteFile(fileDeleteRequest);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package booki_today.application.file;

import booki_today.dto.file.FileAddRequest;
import booki_today.dto.file.FileDeleteRequest;
import booki_today.implement.file.FileRemover;
import booki_today.implement.file.FileUploader;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

public interface FileService {

void uploadFile(FileAddRequest fileAddRequest, MultipartFile multipartFile);

void deleteFile(FileDeleteRequest fileDeleteRequest);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package booki_today.application.mail;

import booki_today.dto.mail.MailSendRequest;
import booki_today.implement.mail.MailSender;
import org.springframework.stereotype.Service;

@Service
public class AmazonSesService implements MailService{

private final MailSender mailSender;

public AmazonSesService(final MailSender mailSender) {
this.mailSender = mailSender;
}

public void send(final MailSendRequest mailSendRequest) {
mailSender.send(mailSendRequest);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package booki_today.application.mail;

import booki_today.dto.mail.MailSendRequest;

public interface MailService {

void send(final MailSendRequest mailSendRequest);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package booki_today.domain.category;

public enum CategoryType {

UNIVERSITY, CLUB, DEPARTMENT
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package booki_today.domain.created_booki;

public enum BookiType {

RAFFLE, FIFO
}
6 changes: 6 additions & 0 deletions backend/src/main/java/booki_today/domain/member/Gender.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package booki_today.domain.member;

public enum Gender {

MALE, FEMALE, UNKNOWN
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package booki_today.domain.participated_booki;

public enum ParticipatedStatus {

NOT_PARTICIPATED, PENDING, PARTICIPATING, REJECTED, COMPLETED
}
10 changes: 10 additions & 0 deletions backend/src/main/java/booki_today/dto/file/FileAddRequest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package booki_today.dto.file;

import lombok.Builder;

@Builder
public record FileAddRequest(
String uploadFilePath,
String studentId
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package booki_today.dto.file;

public record FileDeleteRequest(
String uploadFilePath,
String fileName
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package booki_today.dto.file;

public record FileInfoResponse(
String uploadFileUrl
) {
}
10 changes: 10 additions & 0 deletions backend/src/main/java/booki_today/dto/mail/MailSendRequest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package booki_today.dto.mail;

import java.util.List;

public record MailSendRequest(
String subject,
String content,
List<String> to
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package booki_today.global.annotation;


import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface Association {
}
15 changes: 15 additions & 0 deletions backend/src/main/java/booki_today/global/annotation/Implement.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package booki_today.global.annotation;

import org.springframework.stereotype.Component;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Component
public @interface Implement {
}

46 changes: 46 additions & 0 deletions backend/src/main/java/booki_today/global/config/AwsConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package booki_today.global.config;

import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.regions.Regions;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import com.amazonaws.services.simpleemail.AmazonSimpleEmailService;
import com.amazonaws.services.simpleemail.AmazonSimpleEmailServiceClientBuilder;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class AwsConfig {

@Value("${cloud.aws.credentials.access-key}")
private String accessKey;

@Value("${cloud.aws.credentials.secret-key}")
private String secretKey;

@Value("${cloud.aws.s3.bucket}")
private String bucketName;

private AWSCredentials getAWSCredentials() {
return new BasicAWSCredentials(accessKey, secretKey);
}

@Bean
public AmazonSimpleEmailService amazonSimpleEmailService() {
return AmazonSimpleEmailServiceClientBuilder.standard()
.withRegion(Regions.AP_NORTHEAST_2)
.withCredentials(new AWSStaticCredentialsProvider(getAWSCredentials()))
.build();
}

@Bean
public AmazonS3 amazonS3() {
return AmazonS3ClientBuilder.standard()
.withRegion(Regions.AP_NORTHEAST_2)
.withCredentials(new AWSStaticCredentialsProvider(getAWSCredentials()))
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package booki_today.global.constant;

public enum FileExceptionConstant {

FILE_UPLOAD_ERROR("파일 업로드 도중에 에러가 발생했습니다. 관리자에게 문의 바랍니다."),
FILE_DELETE_ERROR("파일 삭제 도중에 에러가 발생했습니다. 관리자에게 문의 바랍니다.");
private final String message;

FileExceptionConstant(final String message) {
this.message = message;
}

public String message() {
return message;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package booki_today.global.constant;

public enum MailExceptionConstant {

MAIL_SEND_ERROR("메일 전송 도중에 에러가 발생했습니다. 관리자에게 문의 바랍니다.");

private final String message;

MailExceptionConstant(final String message) {
this.message = message;
}

public String message() {
return message;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package booki_today.global.constant;

public enum SpringExceptionConstant {

METHOD_ARGUMENT_TYPE_MISMATCH("HTTP 파라미터 타입이 일치하지 않습니다."),
MISSING_SERVLET_REQUEST_PARAMETER("HTTP 필수 파라미터가 누락되었습니다."),
NO_HANDLER_FOUND("HTTP 요청을 처리할 컨트롤러가 존재하지 않습니다."),
METHOD_NOT_ALLOWED("HTTP 메소드 형식이 일치하지 않습니다.");

private final String message;

SpringExceptionConstant(final String message) {
this.message = message;
}

public String message() {
return message;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package booki_today.global.constant;

public enum StatusCodeConstant {

OK("200"),
BAD_REQUEST("400"),
UNAUTHORIZED("401"),
FORBIDDEN("403"),
NOT_FOUND("404"),
METHOD_NOT_ALLOWED("405"),
INTERNAL_SERVER("500");

private final String statusCode;

StatusCodeConstant(final String statusCode) {
this.statusCode = statusCode;
}

public String statusCode() {
return statusCode;
}
}
Loading
Loading