Skip to content

Commit

Permalink
Merge pull request #33 from thisishwan2/newDevRemote
Browse files Browse the repository at this point in the history
카카오 로그인 오류 해결
  • Loading branch information
thisishwan2 authored Nov 30, 2023
2 parents f094f0f + 5ccc5f0 commit f047ce8
Show file tree
Hide file tree
Showing 13 changed files with 227 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM openjdk:17-alpine
WORKDIR /app
COPY ./closeUp-0.0.1-SNAPSHOT.jar ./app.jar # ./ 없으면 안됨
COPY ./closeUp-0.0.1-SNAPSHOT.jar ./app.jar
ENTRYPOINT ["java", "-jar", "app.jar"]
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ dependencies {
// aws
implementation 'org.springframework.cloud:spring-cloud-starter-aws:2.2.6.RELEASE'

// aws sdk javax
implementation 'javax.xml.bind:jaxb-api:2.3.1'
}

// QueryDSL
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/farmSystem/closeUp/common/Result.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,13 @@ public enum Result {
// 포인트
LESS_THAN_MINIMUM_POINT(400, "5000원 이상부터 충전이 가능합니다."),
NOT_EQUAL_AMOUNT(400, "결제 금액이 일치하지 않습니다."),
NOT_FOUND_POINTHISTORY(404, "포인트 체결 내역이 존재하지 않습니다.");
NOT_FOUND_POINTHISTORY(404, "포인트 체결 내역이 존재하지 않습니다."),
// 플랫폼
NOTFOUND_PLATFORM(404, "해당 플랫폼이 존재하지 않습니다."),

// 관심사
NOTFOUND_INTEREST(404, "해당 관심사가 존재하지 않습니다."), FILE_UPLOAD_FAIL(404, "파일 업로드에 실패했습니다."),;


private final String message;
private final int status;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ public void onAuthenticationSuccess(HttpServletRequest request, HttpServletRespo
String redirectUrl = createToken(response, oAuth2User, targetUrl);
log.info("크리에이터 팔로우 페이지로 이동");
getRedirectStrategy().sendRedirect(request, response, redirectUrl);
} else if (oAuth2User.getUserRole() == UserRole.SIGNUP_CREATOR) { // 크리에이터가 추가정보는 입력했는데, 플랫폼 정보 및 관심사 설정안한경우
targetUrl = "http://localhost:8080/creator/interest";
String redirectUrl = createToken(response, oAuth2User, targetUrl);
log.info("크리에이터 플랫폼 및 이미지 검증 및 관심사 설정 페이지로 이동");
getRedirectStrategy().sendRedirect(request, response, redirectUrl);
}
} catch (Exception e) {
throw e;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception{
.requestMatchers("/health","/token/reissue", "/css/**","/images/**","/js/**","/favicon.ico","/h2-console/**").permitAll()
.requestMatchers("/user/sign-up/**").hasAnyRole(String.valueOf(UserRole.GUEST), String.valueOf(UserRole.SIGNUP_USER), String.valueOf(UserRole.FOLLOWED_USER), String.valueOf(UserRole.INTERESTED_USER))
.requestMatchers("/user/**").hasRole(String.valueOf(UserRole.USER))
.requestMatchers("/creator/**").hasRole("CREATOR")
.requestMatchers("/creator/sign-up/**").hasAnyRole(String.valueOf(UserRole.GUEST), String.valueOf(UserRole.SIGNUP_CREATOR))
.requestMatchers("/creator/**").hasRole(String.valueOf(UserRole.CREATOR))
.anyRequest().authenticated()
)

Expand Down
15 changes: 15 additions & 0 deletions src/main/java/farmSystem/closeUp/controller/UserController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@


import farmSystem.closeUp.common.CommonResponse;
import farmSystem.closeUp.dto.creator.request.PostCreatorSettingRequest;
import farmSystem.closeUp.dto.user.request.PostCreatorInfoRequest;
import farmSystem.closeUp.dto.user.request.UserFollowRequest;
import farmSystem.closeUp.dto.user.request.UserInfoRequest;
import farmSystem.closeUp.dto.user.request.UserInterestRequest;
Expand All @@ -15,6 +17,7 @@
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

Expand Down Expand Up @@ -59,4 +62,16 @@ public CommonResponse<PostSignUpResponse> signUpFollowBulk(@RequestBody @Valid f
public CommonResponse<PostSignUpResponse> signUpInterestBulk(@RequestBody @Valid final UserInterestRequest userInterestRequest){
return CommonResponse.success(userService.interestBulk(userInterestRequest));
}

// 크리에이터 회원가입
@PostMapping(value = "/creator/sign-up")
public CommonResponse<PostSignUpResponse> signUpCreator(@RequestPart @Valid final PostCreatorInfoRequest postCreatorInfoRequest, @RequestPart MultipartFile multipartFile){
return CommonResponse.success(userService.signUpCreator(postCreatorInfoRequest, multipartFile));
}

// 크리에이터 플랫폼, 활동 장르 설정 및 본인인증
@PostMapping(value = "/creator/sign-up/setting")
public CommonResponse<PostSignUpResponse> creatorSetting(@RequestPart @Valid final PostCreatorSettingRequest postCreatorSettingRequest, @RequestPart MultipartFile multipartFile){
return CommonResponse.success(userService.creatorSetting(postCreatorSettingRequest, multipartFile));
}
}
19 changes: 19 additions & 0 deletions src/main/java/farmSystem/closeUp/domain/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,30 @@ public void update(Long id, String nickname, String address, String phoneNumber,
this.userRole = userRole;
}

public void update(String nickname, String address, String phoneNumber, String profileImageUrl, String gender, String birthDay, String profileComment, UserRole userRole) {
this.nickName = nickname;
this.address = address;
this.phoneNumber = phoneNumber;
this.profileImageUrl = profileImageUrl;
this.gender = gender;
this.birthDay = birthDay;
this.userRole = userRole;
this.profileComment = profileComment;
}

public void setPlatform(Platform platform) {
this.platform = platform;
}

public void minusPoint(Long point) {
this.point -= point;
}

public void setProfileImageUrl(String fileName) {
this.profileImageUrl = fileName;
}

public void setVerificationImageUrl(String fileName) {
this.verificationImageUrl = fileName;
}
}
2 changes: 1 addition & 1 deletion src/main/java/farmSystem/closeUp/domain/UserRole.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
@Getter
@RequiredArgsConstructor
public enum UserRole {
GUEST("ROLE_GUEST"), USER("ROLE_USER"), CREATOR("ROLE_CREATOR"), SIGNUP_USER("ROLE_SIGNUP"), FOLLOWED_USER("ROLE_FOLLOW"), INTERESTED_USER("ROLE_INTEREST"); // oauth 첫 로그인시에는 Guest, 이후 추가 회원가입시 User
GUEST("ROLE_GUEST"), USER("ROLE_USER"), SIGNUP_CREATOR("ROLE_SIGNUP_CREATOR"),CREATOR("ROLE_CREATOR"), SIGNUP_USER("ROLE_SIGNUP"), FOLLOWED_USER("ROLE_FOLLOW"), INTERESTED_USER("ROLE_INTEREST"); // oauth 첫 로그인시에는 Guest, 이후 추가 회원가입시 User
private final String key;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package farmSystem.closeUp.dto.creator.request;

import lombok.Getter;

import java.util.List;

@Getter
public class PostCreatorSettingRequest {
private List<Long> interestIds;
private Long platformId;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package farmSystem.closeUp.dto.user.request;

import jakarta.validation.constraints.NotBlank;
import lombok.Getter;

@Getter
public class PostCreatorInfoRequest {
@NotBlank(message = "닉네임 입력은 필수입니다.")
private String nickname;
@NotBlank(message = "주소 입력은 필수입니다.")
private String address;
@NotBlank(message = "휴대전화번호 입력은 필수입니다.")
private String phoneNumber;

@NotBlank(message = "성별 입력은 필수입니다.")
private String gender;
@NotBlank(message = "생일 입력은 필수입니다.")
private String birthday;
@NotBlank(message = "한줄소개는 필수입니다.")
private String profileComment;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package farmSystem.closeUp.repository;

import farmSystem.closeUp.domain.Interest;
import org.springframework.data.jpa.repository.JpaRepository;

public interface InterestRepository extends JpaRepository<Interest, Long>{
}
49 changes: 45 additions & 4 deletions src/main/java/farmSystem/closeUp/service/S3UploadService.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
package farmSystem.closeUp.service;

import com.amazonaws.AmazonServiceException;
import com.amazonaws.HttpMethod;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.model.GeneratePresignedUrlRequest;
import com.amazonaws.services.s3.model.ObjectMetadata;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.net.URL;
import java.net.URLDecoder;
import java.util.Date;

@Service
@Slf4j
@RequiredArgsConstructor
public class S3UploadService {

Expand All @@ -18,14 +26,47 @@ public class S3UploadService {
@Value("${cloud.aws.s3.bucket}")
private String bucket;

public String saveFile(MultipartFile multipartFile) throws IOException {
String originalFilename = multipartFile.getOriginalFilename();
public String saveFile(MultipartFile multipartFile, String fileName) throws IOException {


ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentLength(multipartFile.getSize());
metadata.setContentType(multipartFile.getContentType());

amazonS3.putObject(bucket, originalFilename, multipartFile.getInputStream(), metadata);
return amazonS3.getUrl(bucket, originalFilename).toString();
amazonS3.putObject(bucket, fileName, multipartFile.getInputStream(), metadata);
return URLDecoder.decode(amazonS3.getUrl(bucket, fileName).toString(), "utf-8");
}

/* 2. 파일 삭제 */
public void delete (String keyName) {
try {
// deleteObject(버킷명, 키값)으로 객체 삭제
amazonS3.deleteObject(bucket, keyName);
} catch (AmazonServiceException e) {
log.error(e.toString());
}
}

/* 3. 파일의 presigned URL 반환 */
public String getPresignedURL (String keyName) {
String preSignedURL = "";
// presigned URL이 유효하게 동작할 만료기한 설정 (2분)
Date expiration = new Date();
Long expTimeMillis = expiration.getTime();
expTimeMillis += 1000 * 60 * 2;
expiration.setTime(expTimeMillis);

try {
// presigned URL 발급
GeneratePresignedUrlRequest generatePresignedUrlRequest = new GeneratePresignedUrlRequest(bucket, keyName)
.withMethod(HttpMethod.GET)
.withExpiration(expiration);
URL url = amazonS3.generatePresignedUrl(generatePresignedUrlRequest);
preSignedURL = url.toString();
} catch (Exception e) {
log.error(e.toString());
}

return preSignedURL;
}
}
Loading

0 comments on commit f047ce8

Please sign in to comment.