-
Notifications
You must be signed in to change notification settings - Fork 0
#9 Member 패키지 리팩터링 및 테스트 작성 #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| package com.example.interviewPrep.quiz.emitter.repository; | ||
|
|
||
| import org.springframework.stereotype.Service; | ||
|
|
||
| @Service | ||
| public class EmitterService { | ||
|
|
||
| private final EmitterRepository emitterRepository; | ||
|
|
||
| public EmitterService(EmitterRepository emitterRepository){ | ||
| this.emitterRepository = emitterRepository; | ||
| } | ||
|
|
||
| public void deleteMemberEmitter(String memberId){ | ||
| emitterRepository.deleteById(memberId); | ||
| } | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,75 +1,81 @@ | ||
| package com.example.interviewPrep.quiz.member.controller; | ||
|
|
||
| import com.example.interviewPrep.quiz.member.domain.Member; | ||
| import com.example.interviewPrep.quiz.member.dto.*; | ||
| import com.example.interviewPrep.quiz.member.service.AuthenticationService; | ||
| import com.example.interviewPrep.quiz.member.service.MemberService; | ||
| import com.example.interviewPrep.quiz.member.social.service.OauthService; | ||
| import com.example.interviewPrep.quiz.response.ResultResponse; | ||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.http.HttpHeaders; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.security.core.Authentication; | ||
| import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
| import org.springframework.web.bind.annotation.*; | ||
|
|
||
| import javax.servlet.http.HttpServletRequest; | ||
| import javax.servlet.http.HttpServletResponse; | ||
| import javax.validation.Valid; | ||
| import javax.validation.constraints.NotNull; | ||
|
|
||
| @RestController | ||
| @RequestMapping("/members/") | ||
| @RequiredArgsConstructor | ||
| @CrossOrigin(origins = "*") | ||
| @Slf4j | ||
| public class MemberController { | ||
| private final AuthenticationService authService; | ||
| private final MemberService memberService; | ||
| private final OauthService oauthService; | ||
|
|
||
| @PostMapping("signup") | ||
| public ResultResponse<?> signUp(@RequestBody SignUpRequestDTO memberDTO) throws Exception { | ||
| public MemberController(AuthenticationService authService, MemberService memberService, OauthService oauthService){ | ||
| this.authService = authService; | ||
| this.memberService = memberService; | ||
| this.oauthService = oauthService; | ||
| } | ||
|
|
||
| @PostMapping("/api/v1/members/signup") | ||
| public ResultResponse<Member> signUp(@RequestBody SignUpRequestDTO memberDTO) throws Exception { | ||
| return ResultResponse.success(memberService.createMember(memberDTO)); | ||
| } | ||
|
|
||
| @GetMapping("userInfo") | ||
| public ResultResponse<?> getUserInfo(){ | ||
| @GetMapping("/api/v1/members/userInfo") | ||
| public ResultResponse<Member> getUserInfo(){ | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 장점 단점
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 멘토링 시간에 말씀 드리긴 했지만, 이 구조는 api를 사용하는 클라이언트 입장에서 가장 불편을 크게 느끼는 구조에요, 공통된 레이어가 꼭 필요하거나 (페이징 응답이라던지) 합의 된 경우가 아니라면 응답객체를 그대로 리턴하는 걸 추천합니다!
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 응답 객체를 그대로 리턴 |
||
| return ResultResponse.success(memberService.getUserInfo()); | ||
| } | ||
|
|
||
| @PostMapping("login") | ||
| public ResultResponse<?> login(@RequestBody @NotNull LoginRequestDTO memberDTO, HttpServletResponse response){ | ||
| @PostMapping("/api/v1/members/login") | ||
| public ResultResponse<LoginResponseDTO> login(@RequestBody @NotNull LoginRequestDTO memberDTO, HttpServletResponse response){ | ||
| return ResultResponse.success(authService.login(memberDTO, response)); | ||
| } | ||
|
|
||
| @PutMapping("/change") | ||
| public ResultResponse<?> changeNickNameAndEmail(@RequestBody @NotNull MemberDTO memberDTO){ | ||
| return ResultResponse.success(memberService.changeNickNameAndEmail(memberDTO)); | ||
| @PutMapping("/api/v1/members/change") | ||
| public ResultResponse<Member> updateNickNameAndEmail(@RequestBody @NotNull MemberDTO memberDTO, @AuthenticationPrincipal Authentication authentication){ | ||
| return ResultResponse.success(memberService.updateNickNameAndEmail(memberDTO, authentication)); | ||
| } | ||
|
|
||
| @PutMapping("/password/change") | ||
| public ResultResponse<?> changePassword(@RequestBody @NotNull MemberDTO memberDTO){ | ||
| return ResultResponse.success(memberService.changePassword(memberDTO)); | ||
| @PutMapping("/api/v1/members/password/change") | ||
| public ResultResponse<Member> updatePassword(@RequestBody @NotNull MemberDTO memberDTO){ | ||
| return ResultResponse.success(memberService.updatePassword(memberDTO)); | ||
| } | ||
|
|
||
| @GetMapping(value="auth/{socialType}") | ||
| @GetMapping("/api/v1/members/auth/{socialType}") | ||
| public void socialLoginType(@PathVariable String socialType){ | ||
| oauthService.request(socialType); | ||
| } | ||
|
|
||
| @GetMapping(value="auth/{socialType}/callback") | ||
| public ResultResponse<?> callback(@PathVariable String socialType, @RequestParam(name="code") String code){ | ||
| @GetMapping("/api/v1/members/auth/{socialType}/callback") | ||
| public ResultResponse<LoginResponseDTO> callback(@PathVariable String socialType, @RequestParam(name="code") String code){ | ||
| return ResultResponse.success(oauthService.socialLogin(socialType, code)); | ||
| } | ||
|
|
||
| @GetMapping(value="logout") | ||
| @GetMapping("/api/v1/members/logout") | ||
| public ResultResponse<?> logout(HttpServletRequest request){ | ||
| String accessToken = request.getHeader(HttpHeaders.AUTHORIZATION); | ||
| authService.logout(accessToken); | ||
| return ResultResponse.success(ResponseEntity.noContent().build()); | ||
| } | ||
|
|
||
|
|
||
| @GetMapping(value="reissue") | ||
| @GetMapping("/api/v1/members/reissue") | ||
| public ResultResponse<LoginResponseDTO> reissueToken(@CookieValue(value="refreshToken", defaultValue = "0" ) String cookie){ | ||
| return ResultResponse.success(authService.reissue(cookie)); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,19 @@ | ||
| package com.example.interviewPrep.quiz.member.dto; | ||
|
|
||
| import lombok.AllArgsConstructor; | ||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| @Builder | ||
| @Getter | ||
| @AllArgsConstructor | ||
| @NoArgsConstructor | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 넵 확인했습니다~ |
||
| public class LoginRequestDTO { | ||
|
|
||
| String email; | ||
| String password; | ||
|
|
||
| public LoginRequestDTO(String email, String password){ | ||
| this.email = email; | ||
| this.password = password; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,22 +5,34 @@ | |
| import javax.validation.constraints.NotNull; | ||
|
|
||
| @Getter | ||
| @Builder | ||
| @AllArgsConstructor | ||
| @NoArgsConstructor | ||
| public class MemberDTO { | ||
|
|
||
| private Long id; | ||
|
|
||
| @NotNull | ||
| private String email; | ||
| @NotNull | ||
|
|
||
| private String password; | ||
| @NotNull | ||
|
|
||
| private String nickName; | ||
| @NotNull | ||
|
|
||
| private String newPassword; | ||
| @NotNull | ||
|
|
||
| private String type; | ||
|
|
||
| @Builder | ||
| public MemberDTO(Long id, String email, String password, String nickName, String newPassword, String type) { | ||
| if (email == null || password == null || nickName == null || newPassword == null || type == null) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 생성자에서 잡아주실거면 위에 |
||
| throw new NullPointerException(); | ||
| } | ||
| this.id = id; | ||
| this.email = email; | ||
| this.password = password; | ||
| this.nickName = nickName; | ||
| this.newPassword = newPassword; | ||
| this.type = type; | ||
| } | ||
|
|
||
|
|
||
|
|
||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,18 @@ | ||
| package com.example.interviewPrep.quiz.member.dto; | ||
|
|
||
| import lombok.Getter; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @Getter | ||
| @RequiredArgsConstructor | ||
| public enum Role { | ||
|
|
||
| MENTOR("ROLE_MENTOR", "멘토"), | ||
| USER("ROLE_USER", "일반 사용자"); | ||
|
|
||
| private final String key; | ||
| private final String title; | ||
|
|
||
| Role(String key, String title) { | ||
| this.key = key; | ||
| this.title = title; | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
근데 뒤에 throws Excpetion은 무슨 역할을 하고 있을까요 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
아무런 역할을 하고 있지 않아서 제외시켰습니다