Skip to content

Commit

Permalink
RAC-100 feat : 프로필 사진 등록 및 멘토 회원가입
Browse files Browse the repository at this point in the history
RAC-100 feat : 프로필 사진 등록 및 멘토 회원가입
  • Loading branch information
ywj9811 authored Nov 3, 2023
2 parents 86686c0 + 0a5d892 commit a424dfc
Show file tree
Hide file tree
Showing 28 changed files with 350 additions and 101 deletions.
7 changes: 7 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ dependencies {
annotationProcessor "com.querydsl:querydsl-apt:5.0.0:jakarta"
annotationProcessor "jakarta.annotation:jakarta.annotation-api"
annotationProcessor "jakarta.persistence:jakarta.persistence-api"

// aws s3
implementation 'org.springframework.cloud:spring-cloud-starter-aws:2.2.6.RELEASE'

// https://mvnrepository.com/artifact/org.mockito/mockito-core
testImplementation 'org.mockito:mockito-core:5.6.0'

}

tasks.named('test') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.Optional;

@Builder
@Getter
@NoArgsConstructor
@AllArgsConstructor
public class AuthUserResponse {
private User user;
private Optional<User> user;
private Long socialId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import com.postgraduate.domain.auth.application.dto.res.AuthUserResponse;
import com.postgraduate.domain.user.domain.entity.User;

import java.util.Optional;

public class AuthMapper {
public static AuthUserResponse mapToAuthUser(User user, Long socialId) {
public static AuthUserResponse mapToAuthUser(Optional<User> user, Long socialId) {
return AuthUserResponse.builder()
.user(user)
.socialId(socialId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.postgraduate.domain.auth.application.dto.res.KakaoUserInfoResponse;
import com.postgraduate.domain.auth.application.dto.req.SignUpRequest;
import com.postgraduate.domain.auth.application.mapper.AuthMapper;
import com.postgraduate.domain.user.application.usecase.UserCheckUseCase;
import com.postgraduate.domain.user.application.mapper.UserMapper;
import com.postgraduate.domain.user.domain.entity.User;
import com.postgraduate.domain.user.domain.service.UserGetService;
import com.postgraduate.domain.user.domain.service.UserSaveService;
Expand All @@ -18,7 +18,6 @@
@RequiredArgsConstructor
public class KakaoSignInUseCase {
private final KakaoAccessTokenUseCase kakaoTokenUseCase;
private final UserCheckUseCase userCheckUseCase;
private final UserSaveService userSaveService;
private final UserGetService userGetService;

Expand All @@ -27,17 +26,12 @@ public AuthUserResponse getUser(String token) {
KakaoUserInfoResponse userInfo = kakaoTokenUseCase.getUserInfo(token);
Long socialId = userInfo.getId();
Optional<User> user = userGetService.bySocialId(socialId);
if (user.isEmpty()) {
return AuthMapper.mapToAuthUser(null, socialId);
}
return AuthMapper.mapToAuthUser(user.get(), null);
return AuthMapper.mapToAuthUser(user, socialId);
}

public AuthUserResponse signUp(SignUpRequest request) {
if (userCheckUseCase.isDuplicatedNickName(request.getNickName())) {
throw new RuntimeException("중복예외");
}
User user = userSaveService.saveUser(request);
return AuthMapper.mapToAuthUser(user, null);
public User signUp(SignUpRequest request) {
User user = UserMapper.mapToUser(request);
userSaveService.saveUser(user);
return user;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.postgraduate.domain.auth.application.dto.res.JwtTokenResponse;
import com.postgraduate.domain.auth.application.usecase.jwt.JwtUseCase;
import com.postgraduate.domain.auth.application.usecase.kakao.KakaoSignInUseCase;
import com.postgraduate.domain.user.domain.entity.User;
import com.postgraduate.global.auth.AuthDetails;
import com.postgraduate.global.dto.ResponseDto;
import io.swagger.v3.oas.annotations.Operation;
Expand All @@ -31,20 +32,20 @@ public class AuthController {

@PostMapping("/login")
@Operation(summary = "카카오 로그인", description = "회원인 경우 JWT를, 회원이 아닌 경우 socialId를 반환합니다(회원가입은 진행하지 않습니다).")
public ResponseDto<?> getUserDetails(@RequestBody KakaoLoginRequest request) {
public ResponseDto<?> authLogin(@RequestBody KakaoLoginRequest request) {
AuthUserResponse authUser = kakaoSignInUseCase.getUser(request.getAccessToken());
if (authUser.getSocialId() != null) {
if (authUser.getUser().isEmpty())
return ResponseDto.create(AUTH_NONE.getCode(), NOT_REGISTERED_USER_MESSAGE.getMessage(), authUser);
}
JwtTokenResponse jwtToken = jwtUseCase.signIn(authUser.getUser());

JwtTokenResponse jwtToken = jwtUseCase.signIn(authUser.getUser().get());
return ResponseDto.create(AUTH_ALREADY.getCode(), SUCCESS_AUTH_MESSAGE.getMessage(), jwtToken);
}

@PostMapping("/signup")
@Operation(summary = "회원가입", description = "로그인 API에서 반환한 socialId와 닉네임을 함께 보내주세요.")
public ResponseDto<JwtTokenResponse> signUpUser(@RequestBody SignUpRequest request) {
AuthUserResponse authUser = kakaoSignInUseCase.signUp(request);
JwtTokenResponse jwtToken = jwtUseCase.signIn(authUser.getUser());
User user = kakaoSignInUseCase.signUp(request);
JwtTokenResponse jwtToken = jwtUseCase.signIn(user);
return ResponseDto.create(AUTH_CREATE.getCode(), SUCCESS_AUTH_MESSAGE.getMessage(), jwtToken);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.postgraduate.domain.image.application.dto;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@AllArgsConstructor
@NoArgsConstructor
public class PreSignedUrlRequest {
private String fileName;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.postgraduate.domain.image.application.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Builder
@Getter
@NoArgsConstructor
@AllArgsConstructor
public class PreSignedUrlResponse {
private String preSignedUrl;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.postgraduate.domain.image.application.usecase;

import com.postgraduate.domain.image.application.dto.PreSignedUrlRequest;
import com.postgraduate.domain.image.application.dto.PreSignedUrlResponse;
import com.postgraduate.global.config.s3.S3Service;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class PreSignedUseCase {
private final S3Service s3Service;

public PreSignedUrlResponse getProfileUrl(PreSignedUrlRequest preSignedUrlRequest) {
if (preSignedUrlRequest.getFileName().isEmpty())
throw new IllegalArgumentException(); //TODO : 빈값이 들어올 경우 예외 처리
String preSignedUrl = s3Service.getProfilePreSignedUrl(preSignedUrlRequest.getFileName());
return new PreSignedUrlResponse(preSignedUrl);
}

public PreSignedUrlResponse getCertificationUrl(PreSignedUrlRequest preSignedUrlRequest) {
if (preSignedUrlRequest.getFileName().isEmpty())
throw new IllegalArgumentException(); //TODO : 빈값이 들어올 경우 예외 처리
String preSignedUrl = s3Service.getCertificationPreSignedUrl(preSignedUrlRequest.getFileName());
return new PreSignedUrlResponse(preSignedUrl);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.postgraduate.domain.image.presentation;

import com.postgraduate.domain.image.application.dto.PreSignedUrlRequest;
import com.postgraduate.domain.image.application.dto.PreSignedUrlResponse;
import com.postgraduate.domain.image.application.usecase.PreSignedUseCase;
import com.postgraduate.global.dto.ResponseDto;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import static com.postgraduate.domain.image.presentation.constant.ImageResponseCode.IMAGE_CREATE;
import static com.postgraduate.domain.image.presentation.constant.ImageResponseMessage.ISSUE_URL;

@RestController
@RequiredArgsConstructor
@RequestMapping("/image")
@Tag(name = "IMAGE Controller")
public class ImageController {
private final PreSignedUseCase preSignedUseCase;

@PostMapping("/url/profile")
@Operation(description = "USER Profile 등록 URL API - 이미지 풀네임으로 주세요 xxx.확장자, 이미지 이름을 유니크하게 만들어주세요 UUID+파일명 등등")
public ResponseDto<PreSignedUrlResponse> getProfileUrl(@RequestBody PreSignedUrlRequest preSignedUrlRequest) {
PreSignedUrlResponse profileUrl = preSignedUseCase.getProfileUrl(preSignedUrlRequest);
return ResponseDto.create(IMAGE_CREATE.getCode(), ISSUE_URL.getMessage(), profileUrl);
}

@PostMapping("/url/certification")
@Operation(description = "Senior 학생증 인증 등록 URL API - 이미지 풀네임으로 주세요 xxx.확장자, 이미지 이름을 유니크하게 만들어주세요 UUID+파일명 등등")
public ResponseDto<PreSignedUrlResponse> getCertificationUrl(@RequestBody PreSignedUrlRequest preSignedUrlRequest) {
PreSignedUrlResponse certificationUrl = preSignedUseCase.getCertificationUrl(preSignedUrlRequest);
return ResponseDto.create(IMAGE_CREATE.getCode(), ISSUE_URL.getMessage(), certificationUrl);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.postgraduate.domain.image.presentation.constant;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
@RequiredArgsConstructor
public enum ImageResponseCode {
IMAGE_FIND("IMG200"),
IMAGE_UPDATE("IMG201"),
IMAGE_CREATE("IMG202"),
IMAGE_DELETE("IMG203");
private final String code;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.postgraduate.domain.image.presentation.constant;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
@RequiredArgsConstructor
public enum ImageResponseMessage {
ISSUE_URL("URL발급에 성공하였습니다.");
private final String message;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,4 @@ public class SeniorProfileRequest {
private String chatLink;
@NotNull
private String time;
@NotNull
private int term;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.postgraduate.domain.senior.application.usecase;

import com.postgraduate.domain.senior.application.dto.req.SeniorSignUpRequest;
import com.postgraduate.domain.senior.application.mapper.SeniorMapper;
import com.postgraduate.domain.senior.domain.entity.Senior;
import com.postgraduate.domain.senior.domain.service.SeniorSaveService;
import com.postgraduate.domain.user.domain.entity.User;
import com.postgraduate.domain.user.domain.entity.constant.Role;
Expand All @@ -22,6 +24,7 @@ public class SeniorSignUpUseCase {
public void signUp(AuthDetails authDetails, SeniorSignUpRequest request) {
User user = securityUtils.getLoggedInUser(authDetails);
userUpdateService.updateRole(user.getUserId(), Role.SENIOR);
seniorSaveService.saveSenior(user, request);
Senior senior = SeniorMapper.mapToSenior(user, request);
seniorSaveService.saveSenior(senior);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
import com.postgraduate.domain.senior.application.dto.req.SeniorProfileRequest;
import com.postgraduate.domain.senior.domain.entity.Senior;
import com.postgraduate.domain.senior.domain.service.SeniorGetService;
import com.postgraduate.domain.senior.domain.service.SeniorSaveService;
import com.postgraduate.domain.senior.domain.service.SeniorUpdateService;
import com.postgraduate.domain.user.domain.entity.User;
import com.postgraduate.domain.user.domain.service.UserGetService;
import com.postgraduate.global.auth.AuthDetails;
import com.postgraduate.global.config.security.util.SecurityUtils;
import lombok.RequiredArgsConstructor;
Expand All @@ -16,13 +15,13 @@
@Transactional
@RequiredArgsConstructor
public class SeniorUpdateUseCase {
private final SeniorSaveService seniorSaveService;
private final SeniorGetService seniorGetService;
private final SeniorUpdateService seniorUpdateService;
private final SecurityUtils securityUtils;

public void updateProfile(AuthDetails authDetails, SeniorProfileRequest request) {
public void updateProfile(AuthDetails authDetails, SeniorProfileRequest profileRequest) {
User user = securityUtils.getLoggedInUser(authDetails);
Senior senior = seniorGetService.byUser(user);
seniorSaveService.saveSenior(senior, request);
seniorUpdateService.updateSeniorProfile(senior, profileRequest);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.postgraduate.domain.senior.domain.entity;

import com.postgraduate.domain.senior.application.dto.req.SeniorProfileRequest;
import com.postgraduate.domain.user.domain.entity.User;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
Expand Down Expand Up @@ -54,6 +55,7 @@ public class Senior {
@Column(nullable = false)
private String bank;

@Column(nullable = false)
private String certification;

@Column(nullable = false)
Expand All @@ -65,11 +67,10 @@ public class Senior {
@Column(nullable = false)
private int hit;

public void updateProfile(String info, String target, String chatLink, String time, int term) {
this.info = info;
this.target = target;
this.chatLink = chatLink;
this.time = time;
this.term = term;
public void updateProfile(SeniorProfileRequest profileRequest) {
this.info = profileRequest.getInfo();
this.target = profileRequest.getTarget();
this.chatLink = profileRequest.getChatLink();
this.time = profileRequest.getTime();
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
package com.postgraduate.domain.senior.domain.service;

import com.postgraduate.domain.senior.application.dto.req.SeniorProfileRequest;
import com.postgraduate.domain.senior.application.dto.req.SeniorSignUpRequest;
import com.postgraduate.domain.senior.application.mapper.SeniorMapper;
import com.postgraduate.domain.senior.domain.entity.Senior;
import com.postgraduate.domain.senior.domain.entity.repository.SeniorRepository;
import com.postgraduate.domain.user.domain.entity.User;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

Expand All @@ -14,13 +10,7 @@
public class SeniorSaveService {
private final SeniorRepository seniorRepository;

public Senior saveSenior(User user, SeniorSignUpRequest request) {
Senior senior = SeniorMapper.mapToSenior(user, request);
return seniorRepository.save(senior);
}

public Senior saveSenior(Senior senior, SeniorProfileRequest request) {
senior.updateProfile(request.getInfo(), request.getTarget(), request.getChatLink(), request.getTime(), request.getTerm());
public Senior saveSenior(Senior senior) {
return seniorRepository.save(senior);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.postgraduate.domain.senior.domain.service;

import com.postgraduate.domain.senior.application.dto.req.SeniorProfileRequest;
import com.postgraduate.domain.senior.domain.entity.Senior;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@RequiredArgsConstructor
@Service
public class SeniorUpdateService {

public void updateSeniorProfile(Senior senior, SeniorProfileRequest profileRequest) {
senior.updateProfile(profileRequest);
}
}
Loading

0 comments on commit a424dfc

Please sign in to comment.