From c2596d1853d20cd7752e4da02a20262922c2ace1 Mon Sep 17 00:00:00 2001 From: yeonjy Date: Mon, 17 Jun 2024 18:26:31 +0900 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20nickname=20=EB=B3=80=EA=B2=BD=20api?= =?UTF-8?q?=20AuthController=EB=A1=9C=20=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/member/api/MemberController.java | 13 ------------- .../global/oauth2/controller/AuthController.java | 15 +++++++++++++++ 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/member/api/MemberController.java b/backend/core/src/main/java/com/rollthedice/backend/domain/member/api/MemberController.java index 59284ff2..63411b19 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/domain/member/api/MemberController.java +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/member/api/MemberController.java @@ -16,19 +16,6 @@ public class MemberController implements MemberApi{ private final MemberService memberService; - @PostMapping("") - public ResponseEntity updateMember(@LoginMemberEmail String email, - @RequestBody MemberUpdateDto memberUpdateDto) { - MemberServiceDto memberServiceDto = memberUpdateDto.toServiceDto(email); - - if (memberService.isDuplicatedNickname(memberServiceDto)) { - return ResponseEntity.status(HttpStatus.CONFLICT).build(); - } - memberService.update(memberServiceDto); - - return ResponseEntity.status(HttpStatus.OK).build(); - } - @ResponseStatus(HttpStatus.OK) @GetMapping("") @Override diff --git a/backend/core/src/main/java/com/rollthedice/backend/global/oauth2/controller/AuthController.java b/backend/core/src/main/java/com/rollthedice/backend/global/oauth2/controller/AuthController.java index 18a20501..5a38e5b1 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/global/oauth2/controller/AuthController.java +++ b/backend/core/src/main/java/com/rollthedice/backend/global/oauth2/controller/AuthController.java @@ -1,23 +1,38 @@ package com.rollthedice.backend.global.oauth2.controller; +import com.rollthedice.backend.domain.member.dto.MemberUpdateDto; +import com.rollthedice.backend.domain.member.service.MemberService; +import com.rollthedice.backend.global.annotation.LoginMemberEmail; import com.rollthedice.backend.global.oauth2.dto.LoginRequest; import com.rollthedice.backend.global.oauth2.service.AuthService; import jakarta.servlet.http.HttpServletResponse; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; +@Slf4j @RestController @RequiredArgsConstructor public class AuthController { private final AuthService authService; + private final MemberService memberService; @PostMapping("/login") public ResponseEntity login(@RequestBody LoginRequest request, HttpServletResponse response) { authService.authenticateOrRegisterUser(request, response); return new ResponseEntity<>(HttpStatus.OK); } + + @PostMapping("/oauth2/sign-up") + public ResponseEntity updateMember(@LoginMemberEmail String email, + @RequestBody MemberUpdateDto memberUpdateDto) { + memberService.update(memberUpdateDto); + + return ResponseEntity.status(HttpStatus.OK).build(); + } + } \ No newline at end of file From c61f0bd282b052ce5347d6643541d3955c95d6f2 Mon Sep 17 00:00:00 2001 From: yeonjy Date: Mon, 17 Jun 2024 18:27:31 +0900 Subject: [PATCH 2/3] =?UTF-8?q?refactor:=20member=20update=20logic=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/domain/member/service/MemberService.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/member/service/MemberService.java b/backend/core/src/main/java/com/rollthedice/backend/domain/member/service/MemberService.java index ea9e1072..1b5a1962 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/domain/member/service/MemberService.java +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/member/service/MemberService.java @@ -1,6 +1,7 @@ package com.rollthedice.backend.domain.member.service; import com.rollthedice.backend.domain.member.dto.MemberServiceDto; +import com.rollthedice.backend.domain.member.dto.MemberUpdateDto; import com.rollthedice.backend.domain.member.dto.response.MemberResponse; import com.rollthedice.backend.domain.member.entity.Member; import com.rollthedice.backend.domain.member.exception.MemberNotFoundException; @@ -11,9 +12,11 @@ import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +@Slf4j @RequiredArgsConstructor @Service public class MemberService { @@ -27,8 +30,9 @@ public boolean isDuplicatedNickname(MemberServiceDto memberServiceDto) { } @Transactional - public void update(MemberServiceDto memberServiceDto) { - findByEmail(memberServiceDto.getEmail()).update(memberServiceDto); + public void update(MemberUpdateDto memberUpdateDto) { + Member loginMember = authService.getMember(); + loginMember.signUp(memberUpdateDto.getNickname()); } @Transactional(readOnly = true) From de9d3562016a15490e26bcb6517d59064fce172a Mon Sep 17 00:00:00 2001 From: yeonjy Date: Mon, 17 Jun 2024 18:27:55 +0900 Subject: [PATCH 3/3] =?UTF-8?q?fix:=20user=20=EC=A0=95=EB=B3=B4=20?= =?UTF-8?q?=EB=AA=A8=EB=91=90=20=EB=B0=9B=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/global/oauth2/OAuthAttributes.java | 2 +- .../backend/global/oauth2/service/AuthService.java | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/backend/core/src/main/java/com/rollthedice/backend/global/oauth2/OAuthAttributes.java b/backend/core/src/main/java/com/rollthedice/backend/global/oauth2/OAuthAttributes.java index f3aacaa1..2dfcb75c 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/global/oauth2/OAuthAttributes.java +++ b/backend/core/src/main/java/com/rollthedice/backend/global/oauth2/OAuthAttributes.java @@ -41,7 +41,7 @@ public Member toEntity(SocialType socialType, OAuth2UserInfo oauth2UserInfo) { .email(oauth2UserInfo.getEmail()) .nickname(oauth2UserInfo.getNickname()) .imageUrl(oauth2UserInfo.getImageUrl()) - .role(Role.GUEST) + .role(Role.USER) .status(Status.ACTIVE) .build(); } diff --git a/backend/core/src/main/java/com/rollthedice/backend/global/oauth2/service/AuthService.java b/backend/core/src/main/java/com/rollthedice/backend/global/oauth2/service/AuthService.java index 3d150356..85bcaef7 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/global/oauth2/service/AuthService.java +++ b/backend/core/src/main/java/com/rollthedice/backend/global/oauth2/service/AuthService.java @@ -41,8 +41,8 @@ private Member registerMember(SocialType socialType, OAuth2UserInfo userInfo) { Member member = Member.builder() .socialType(socialType) .oauthId(userInfo.getId()) - .email(UUID.randomUUID() + "@socialUser.com") - .nickname(String.valueOf(UUID.randomUUID())) + .email(userInfo.getEmail()) + .nickname(userInfo.getNickname()) .imageUrl(userInfo.getImageUrl()) .role(Role.USER) .build(); @@ -51,10 +51,9 @@ private Member registerMember(SocialType socialType, OAuth2UserInfo userInfo) { } public Member getMember() { - Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); - UserDetails userDetails = (UserDetails) authentication.getPrincipal(); - return memberRepository.findByEmail(userDetails.getUsername()).orElseThrow(MemberNotFoundException::new); + String username = authentication.getName(); + return memberRepository.findByEmail(username).orElseThrow(MemberNotFoundException::new); } }