From fbc832bb095f1b3cf2d680970d8877a989d7d9bf Mon Sep 17 00:00:00 2001 From: yso8296 <66588512+yso8296@users.noreply.github.com> Date: Fri, 15 Nov 2024 21:56:14 +0900 Subject: [PATCH] =?UTF-8?q?Refactor:=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20?= =?UTF-8?q?=EB=B0=A9=EC=8B=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hackathon/nullnullteam/member/Gender.java | 2 +- .../hackathon/nullnullteam/member/Member.java | 2 ++ .../member/controller/MemberController.java | 9 +++--- .../member/controller/dto/MemberRequest.java | 28 +++++++++++++++++++ .../member/service/MemberService.java | 11 ++++---- .../member/service/MemberWriterService.java | 14 ++++++---- .../member/service/dto/MemberCommand.java | 18 ++++++++++++ 7 files changed, 68 insertions(+), 16 deletions(-) create mode 100644 src/main/java/com/hackathon/nullnullteam/member/controller/dto/MemberRequest.java create mode 100644 src/main/java/com/hackathon/nullnullteam/member/service/dto/MemberCommand.java diff --git a/src/main/java/com/hackathon/nullnullteam/member/Gender.java b/src/main/java/com/hackathon/nullnullteam/member/Gender.java index 43ff1db..4b29948 100644 --- a/src/main/java/com/hackathon/nullnullteam/member/Gender.java +++ b/src/main/java/com/hackathon/nullnullteam/member/Gender.java @@ -14,7 +14,7 @@ public enum Gender { } public static Gender fromString(String gender) { - if (gender.equals("male")) { + if (gender.equals("FEMALE")) { return MALE; } return FEMALE; diff --git a/src/main/java/com/hackathon/nullnullteam/member/Member.java b/src/main/java/com/hackathon/nullnullteam/member/Member.java index f9ab823..41777c4 100644 --- a/src/main/java/com/hackathon/nullnullteam/member/Member.java +++ b/src/main/java/com/hackathon/nullnullteam/member/Member.java @@ -34,4 +34,6 @@ public class Member extends BaseTimeEntity { @Enumerated(EnumType.STRING) private AnxietyLevel anxietyLevel; + + private String profile; } diff --git a/src/main/java/com/hackathon/nullnullteam/member/controller/MemberController.java b/src/main/java/com/hackathon/nullnullteam/member/controller/MemberController.java index 438e8a2..740e8c8 100644 --- a/src/main/java/com/hackathon/nullnullteam/member/controller/MemberController.java +++ b/src/main/java/com/hackathon/nullnullteam/member/controller/MemberController.java @@ -2,6 +2,7 @@ import com.hackathon.nullnullteam.global.annotation.Authenticate; import com.hackathon.nullnullteam.global.dto.GlobalResponse; +import com.hackathon.nullnullteam.member.controller.dto.MemberRequest; import com.hackathon.nullnullteam.member.controller.dto.MemberResponse; import com.hackathon.nullnullteam.member.service.MemberService; import com.hackathon.nullnullteam.member.service.dto.MemberModel; @@ -10,8 +11,10 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; @RestController @@ -31,10 +34,8 @@ public ResponseEntity login() { }*/ @GetMapping("/callback") - public ResponseEntity registerMember( - @RequestParam("token") String token - ) { - MemberModel.Login memberInfo = memberService.register(token); + public ResponseEntity registerMember(@RequestBody MemberRequest.Info request) { + MemberModel.Login memberInfo = memberService.register(request.toCommand()); return ResponseEntity.status(HttpStatus.CREATED) diff --git a/src/main/java/com/hackathon/nullnullteam/member/controller/dto/MemberRequest.java b/src/main/java/com/hackathon/nullnullteam/member/controller/dto/MemberRequest.java new file mode 100644 index 0000000..6aad61a --- /dev/null +++ b/src/main/java/com/hackathon/nullnullteam/member/controller/dto/MemberRequest.java @@ -0,0 +1,28 @@ +package com.hackathon.nullnullteam.member.controller.dto; + +import com.hackathon.nullnullteam.member.Gender; +import com.hackathon.nullnullteam.member.service.dto.MemberCommand; +import lombok.Builder; + +public class MemberRequest { + + @Builder + public record Info( + String name, + String gender, + int age, + String profile, + String email + ) { + + public MemberCommand.Info toCommand() { + return MemberCommand.Info.builder() + .name(name) + .gender(gender) + .age(age) + .profile(profile) + .email(email) + .build(); + } + } +} diff --git a/src/main/java/com/hackathon/nullnullteam/member/service/MemberService.java b/src/main/java/com/hackathon/nullnullteam/member/service/MemberService.java index cb36033..be39487 100644 --- a/src/main/java/com/hackathon/nullnullteam/member/service/MemberService.java +++ b/src/main/java/com/hackathon/nullnullteam/member/service/MemberService.java @@ -6,6 +6,7 @@ import com.hackathon.nullnullteam.member.infrastructure.apicaller.dto.KakaoAccount; import com.hackathon.nullnullteam.member.infrastructure.apicaller.dto.TokenInfoResponse; import com.hackathon.nullnullteam.member.infrastructure.apicaller.dto.UserInfoResponse; +import com.hackathon.nullnullteam.member.service.dto.MemberCommand; import com.hackathon.nullnullteam.member.service.dto.MemberModel; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -26,18 +27,18 @@ public String getCodeUrl() { } @Transactional - public MemberModel.Login register(String token) { - // 토큰 발급 + public MemberModel.Login register(MemberCommand.Info command) { + /* // 토큰 발급 String kakaoToken = token; // 카카오 사용자 정보 요청 UserInfoResponse userInfoResponse = memberApiCaller.extractUserInfo(kakaoToken); - KakaoAccount kakaoAccount = userInfoResponse.kakaoAccount(); + KakaoAccount kakaoAccount = userInfoResponse.kakaoAccount();*/ // Users 저장 및 중복 체크 - Member member = memberReaderService.findByEmail(kakaoAccount.email()) + Member member = memberReaderService.findByEmail(command.email()) .orElseGet(() -> { - Member newMember = memberWriterService.saveMember(userInfoResponse); + Member newMember = memberWriterService.saveMember(command); return newMember; }); diff --git a/src/main/java/com/hackathon/nullnullteam/member/service/MemberWriterService.java b/src/main/java/com/hackathon/nullnullteam/member/service/MemberWriterService.java index 78d386a..5260bd5 100644 --- a/src/main/java/com/hackathon/nullnullteam/member/service/MemberWriterService.java +++ b/src/main/java/com/hackathon/nullnullteam/member/service/MemberWriterService.java @@ -5,6 +5,7 @@ import com.hackathon.nullnullteam.member.infrastructure.apicaller.dto.KakaoAccount; import com.hackathon.nullnullteam.member.infrastructure.apicaller.dto.UserInfoResponse; import com.hackathon.nullnullteam.member.infrastructure.repository.MemberRepository; +import com.hackathon.nullnullteam.member.service.dto.MemberCommand; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -18,14 +19,15 @@ public class MemberWriterService { private final MemberRepository memberRepository; @Transactional - public Member saveMember(UserInfoResponse userInfoResponse) { - KakaoAccount kakaoAccount = userInfoResponse.kakaoAccount(); + public Member saveMember(MemberCommand.Info command) { +// KakaoAccount kakaoAccount = userInfoResponse.kakaoAccount(); Member member = memberRepository.save( Member.builder() - .name(kakaoAccount.name()) - .email(kakaoAccount.email()) - .age(LocalDate.now().getYear() - Integer.parseInt(kakaoAccount.birthYear())) - .gender(Gender.fromString(kakaoAccount.gender())) + .name(command.name()) + .age(command.age()) + .gender(Gender.fromString(command.gender())) + .profile(command.profile()) + .email(command.email()) .build()); return member; } diff --git a/src/main/java/com/hackathon/nullnullteam/member/service/dto/MemberCommand.java b/src/main/java/com/hackathon/nullnullteam/member/service/dto/MemberCommand.java new file mode 100644 index 0000000..1e5d3e8 --- /dev/null +++ b/src/main/java/com/hackathon/nullnullteam/member/service/dto/MemberCommand.java @@ -0,0 +1,18 @@ +package com.hackathon.nullnullteam.member.service.dto; + +import lombok.Builder; + +public class MemberCommand { + + @Builder + public record Info( + String name, + String gender, + int age, + String profile, + String email + ) { + + + } +}