-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/dev' into fix/#57-sse
- Loading branch information
Showing
18 changed files
with
358 additions
and
41 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
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
54 changes: 54 additions & 0 deletions
54
src/main/java/codesquad/fineants/spring/api/S3/service/AmazonS3Service.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,54 @@ | ||
package codesquad.fineants.spring.api.S3.service; | ||
|
||
import java.io.File; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.util.Optional; | ||
import java.util.UUID; | ||
|
||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
import com.amazonaws.services.s3.AmazonS3; | ||
import com.amazonaws.services.s3.model.CannedAccessControlList; | ||
import com.amazonaws.services.s3.model.PutObjectRequest; | ||
|
||
import codesquad.fineants.spring.api.errors.errorcode.MemberErrorCode; | ||
import codesquad.fineants.spring.api.errors.exception.BadRequestException; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class AmazonS3Service { | ||
private final AmazonS3 amazonS3; | ||
@Value("${aws.s3.bucket}") | ||
private String bucketName; | ||
|
||
@Transactional | ||
public String upload(MultipartFile multipartFile) { | ||
File file = convertMultiPartFileToFile(multipartFile).orElseThrow( | ||
() -> new BadRequestException(MemberErrorCode.PROFILE_IMAGE_UPLOAD_FAIL)); | ||
// random file name | ||
String key = UUID.randomUUID() + file.getName(); | ||
// put S3 | ||
amazonS3.putObject(new PutObjectRequest(bucketName, key, file).withCannedAcl( | ||
CannedAccessControlList.PublicRead)); | ||
// get S3 | ||
String path = amazonS3.getUrl(bucketName, key).toString(); | ||
// delete object | ||
file.delete(); | ||
return path; | ||
} | ||
|
||
private Optional<File> convertMultiPartFileToFile(MultipartFile file) { | ||
File convertedFile = new File(file.getOriginalFilename()); | ||
try (FileOutputStream fos = new FileOutputStream(convertedFile)) { | ||
fos.write(file.getBytes()); | ||
} catch (IOException e) { | ||
throw new BadRequestException(MemberErrorCode.PROFILE_IMAGE_UPLOAD_FAIL); | ||
} | ||
return Optional.of(convertedFile); | ||
} | ||
} |
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
14 changes: 14 additions & 0 deletions
14
src/main/java/codesquad/fineants/spring/api/member/request/LoginRequest.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,14 @@ | ||
package codesquad.fineants.spring.api.member.request; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
@AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
public class LoginRequest { | ||
private String email; | ||
private String password; | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/codesquad/fineants/spring/api/member/request/SignUpRequest.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,17 @@ | ||
package codesquad.fineants.spring.api.member.request; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
@AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
public class SignUpRequest { | ||
private String nickname; | ||
private String email; | ||
private String password; | ||
private String passwordConfirm; | ||
private String verificationCode; | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/codesquad/fineants/spring/api/member/request/VerifyEmailRequest.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,13 @@ | ||
package codesquad.fineants.spring.api.member.request; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
@AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
public class VerifyEmailRequest { | ||
private String email; | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/codesquad/fineants/spring/api/member/response/LoginResponse.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 codesquad.fineants.spring.api.member.response; | ||
|
||
import codesquad.fineants.domain.jwt.Jwt; | ||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
|
||
@AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
public class LoginResponse { | ||
private Jwt jwt; | ||
private OauthMemberResponse user; | ||
|
||
public static LoginResponse from(Jwt jwt, OauthMemberResponse user) { | ||
return new LoginResponse(jwt, user); | ||
} | ||
} |
Oops, something went wrong.