Skip to content

Commit

Permalink
[UPDATE] 프론트 요청에 따라 리턴 데이터 구조 일부 수정 및 대응하는 Dto 추가, 소셜 로그인시 이메일이 기존에 다…
Browse files Browse the repository at this point in the history
…른 서비스를 통해서 사용중인 경우에 대한 예외처리 추가.
  • Loading branch information
m4a1carbin4 committed Sep 1, 2023
1 parent e1a08e3 commit 9f8e451
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/main/java/com/service/ttucktak/base/BaseErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public enum BaseErrorCode {
ALREADY_EXIST_ID(HttpStatus.CONFLICT.value(), "이미 존재하는 아이디입니다."),
ALREADY_EXIST_NICKNAME(HttpStatus.CONFLICT.value(), "이미 존재하는 닉네임입니다."),
ALREADY_EXIST_EMAIL(HttpStatus.CONFLICT.value(), "이미 존재하는 이메일입니다."),
ALREADY_USED_EMAIL(HttpStatus.CONFLICT.value(), "이미 사용중인 이메일입니다. 이전에 사용하시던 계정으로 사용해 주세요."),

/**
* 500 : INTERNAL SERVER ERROR
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ public BaseResponse<PostEmailConfirmResDto> emailConfirm(@Email @RequestParam St
@ApiResponses(value = {
@ApiResponse(responseCode = "404", description = "카카오 이메일 동의가 필요합니다.",
content = @Content(schema = @Schema(implementation = BaseResponse.class))),
@ApiResponse(responseCode = "409", description = "이미 사용중인 이메일입니다. 이전에 사용하시던 계정으로 사용해 주세요.",
content = @Content(schema = @Schema(implementation = BaseResponse.class))),
@ApiResponse(responseCode = "500", description = "Database Error | 예상치 못한 에러가 발생하였습니다. | 카카오 로그인 중 오류발생 서버에 문의",
content = @Content(schema = @Schema(implementation = BaseResponse.class))),
})
Expand All @@ -187,6 +189,8 @@ public BaseResponse<PostLoginRes> kakaoOauth2(@RequestParam("code") String authC
@ApiResponses(value = {
@ApiResponse(responseCode = "401", description = "구글 로그인 중 ID 토큰 검증 실패. 오류 발생.",
content = @Content(schema = @Schema(implementation = BaseResponse.class))),
@ApiResponse(responseCode = "409", description = "이미 사용중인 이메일입니다. 이전에 사용하시던 계정으로 사용해 주세요.",
content = @Content(schema = @Schema(implementation = BaseResponse.class))),
@ApiResponse(responseCode = "500", description = "Database Error | 예상치 못한 에러가 발생하였습니다. | 구글 로그인 중 GoogleIDToken Payload 과정에서 오류 발생. 서버에 문의. | 구글 JWT 토큰 인증 중 구글 시큐리티 문제 발생. | 구글 JWT 토큰 인증 중 IO 문제 발생.",
content = @Content(schema = @Schema(implementation = BaseResponse.class)))
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public BaseResponse<PatchNoticeResDto> patchNightNotice(@RequestBody PatchNotice
content = @Content(schema = @Schema(implementation = BaseResponse.class))),
})
@PatchMapping("/password")
public BaseResponse<PatchUserDataResDto> updateUserdata(@RequestBody PutPasswordUpdateDto reqDto, @RequestHeader(CustomHttpHeaders.AUTHORIZATION) String jwt) throws BaseException{
public BaseResponse<PatchUserPasswordDto> updateUserdata(@RequestBody PutPasswordUpdateDto reqDto, @RequestHeader(CustomHttpHeaders.AUTHORIZATION) String jwt) throws BaseException{
UUID userIdx;

try{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
@AllArgsConstructor
@NoArgsConstructor
public class PostLogoutRes {
@Schema(name = "isSuccess", example = "true", description = "회원가입 성공 여부")
@JsonProperty("isSuccess")
@Schema(name = "isSuccess", example = "true", description = "로그아웃 성공")
boolean isSuccess;
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public Member toMember() {
.nickname(nickname)
.accountType(AccountType.DEFAULT)
.adProvision(adProvision)
.profileImgUrl("default url") // Todo: default image url 설정 필요
.profileImgUrl("https://ttuckttak.s3.ap-northeast-2.amazonaws.com/profile/%E2%80%94Pngtree%E2%80%94vector+edit+profile+icon_4101351.png") // Todo: default image url 설정 필요
.pushApprove(true)
.refreshToken(null)
.nightApprove(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@
@AllArgsConstructor
public class PatchUserDataResDto {

@Schema(name = "isSuccess", example = "true", description = "회원가입 성공 여부")
@Schema(name = "isSuccess", example = "true", description = "")
@JsonProperty("isSuccess")
boolean isSuccess;

@Schema(name = "userData",description = "updated user data (nullable)")
UserDataDto userData;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.service.ttucktak.dto.member;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;

@Data
@AllArgsConstructor
public class PatchUserPasswordDto {

@Schema(name = "isSuccess", example = "true", description = "")
boolean isSuccess;

}
12 changes: 12 additions & 0 deletions src/main/java/com/service/ttucktak/entity/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
import com.service.ttucktak.base.AccountType;
import com.service.ttucktak.base.BaseEntity;
import com.service.ttucktak.dto.member.PatchUserDataReqDto;
import com.service.ttucktak.dto.member.UserDataDto;
import com.service.ttucktak.dto.member.UserDataUpdateDto;
import jakarta.persistence.*;
import lombok.*;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;

import java.text.ParseException;
Expand Down Expand Up @@ -91,6 +93,16 @@ public void updateUserProfile(UserDataUpdateDto dto) {
}
}

public UserDataDto asUserDataDto(){
return UserDataDto.builder()
.userName(nickname)
.email(userId)
.profileImgUrl(profileImgUrl)
.nightPushStatus(nightApprove)
.pushStatus(pushApprove)
.accountType(accountType).build();
}

public void updateProfileImageUrl(String uploadedUrl) {
this.profileImgUrl = uploadedUrl;
}
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/com/service/ttucktak/service/AuthService.java
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,10 @@ public PostLoginRes loginWithSocialAccount(SocialAccountUserInfo data, AccountTy
return memberRepository.save(newMember);
});

if (!member.getAccountType().equals(type)) {
throw new BaseException(BaseErrorCode.ALREADY_USED_EMAIL);
}

// --- 로그인 처리 ---
// 토큰을 발급받고, refresh token을 DB에 저장한다.
TokensDto token = generateToken(member.getUserId(), member.getUserId(), member.getMemberIdx(), data.getUserEmail());
Expand All @@ -235,7 +239,9 @@ public PostLoginRes loginWithSocialAccount(SocialAccountUserInfo data, AccountTy

return new PostLoginRes(member.getMemberIdx().toString(), token);

} catch (Exception e) {
}catch (BaseException e){
throw e;
}catch (Exception e) {
log.error(e.getMessage());
throw new BaseException(BaseErrorCode.DATABASE_ERROR);
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/service/ttucktak/service/MemberService.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,11 @@ public PatchUserDataResDto updateUserByUUID(UUID memberIdx, UserDataUpdateDto dt
throw new BaseException(BaseErrorCode.MEMBER_ERROR);
}

return new PatchUserDataResDto(true);
return new PatchUserDataResDto(true,currentUser.asUserDataDto());

}

public PatchUserDataResDto updateUserPasswordByUUID(UUID memberIdx, PutPasswordUpdateDto dto) throws BaseException {
public PatchUserPasswordDto updateUserPasswordByUUID(UUID memberIdx, PutPasswordUpdateDto dto) throws BaseException {

Optional<Member> res = memberRepository.findByMemberIdx(memberIdx);

Expand All @@ -182,7 +182,7 @@ public PatchUserDataResDto updateUserPasswordByUUID(UUID memberIdx, PutPasswordU
throw new BaseException(BaseErrorCode.PWUPDATE_ERROR);
}

return new PatchUserDataResDto(true);
return new PatchUserPasswordDto(true);

}

Expand Down

0 comments on commit 9f8e451

Please sign in to comment.