Skip to content

Commit

Permalink
refactor : 소셜로그인 반영으로 인한 일부 로직 수정 (service, memberContoller)
Browse files Browse the repository at this point in the history
  • Loading branch information
HandmadeCloud committed Jan 15, 2024
1 parent d177869 commit cb7250e
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,18 @@
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.programmers.lime.domains.member.api.dto.request.MemberCheckEmailRequest;
import com.programmers.lime.domains.member.api.dto.request.MemberCheckNicknameRequest;
import com.programmers.lime.domains.member.api.dto.request.MemberLoginRequest;
import com.programmers.lime.domains.member.api.dto.request.MemberSignupRequest;
import com.programmers.lime.domains.member.api.dto.request.MemberUpdatePasswordRequest;
import com.programmers.lime.domains.member.api.dto.request.MemberUpdateProfileRequest;
import com.programmers.lime.domains.member.api.dto.response.AccessTokenResponse;
import com.programmers.lime.domains.member.api.dto.response.MemberCheckEmailResponse;
import com.programmers.lime.domains.member.api.dto.response.MemberCheckJwtResponse;
import com.programmers.lime.domains.member.api.dto.response.MemberCheckNicknameResponse;
import com.programmers.lime.domains.member.api.dto.response.MemberGetMyPageResponse;
import com.programmers.lime.domains.member.api.dto.response.MemberLoginResponse;
import com.programmers.lime.domains.member.application.MemberService;
import com.programmers.lime.domains.member.application.dto.response.MemberCheckJwtServiceResponse;
import com.programmers.lime.domains.member.application.dto.response.MemberLoginServiceResponse;
import com.programmers.lime.domains.member.model.MyPage;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;

Expand All @@ -62,35 +54,6 @@ public ResponseEntity<MemberCheckJwtResponse> checkJwtToken() {
return ResponseEntity.ok(response);
}

@Operation(summary = "회원가입", description = "MemberSignupRequest 을 이용하여 회원가입을 합니다.")
@PostMapping("/signup")
public ResponseEntity<Void> signup(@Valid @RequestBody final MemberSignupRequest request) {
memberService.signup(request.toLoginInfo(), request.nickname());

return ResponseEntity.ok().build();
}

@Operation(summary = "로그인", description = "MemberLoginRequest 을 이용하여 로그인을 합니다.")
@PostMapping("/login")
public ResponseEntity<MemberLoginResponse> login(
HttpServletResponse httpServletResponse,
@Valid @RequestBody final MemberLoginRequest request
) {
final MemberLoginServiceResponse serviceResponse = memberService.login(request.toLoginInfo());
final MemberLoginResponse response = MemberLoginResponse.from(serviceResponse);

final ResponseCookie cookie = ResponseCookie.from("refresh-token", serviceResponse.refreshToken())
.maxAge(COOKIE_AGE_SECONDS)
.secure(true)
.httpOnly(true)
.sameSite("None")
.path("/")
.build();
httpServletResponse.addHeader(SET_COOKIE, cookie.toString());

return ResponseEntity.ok(response);
}

@Operation(summary = "로그인 연장", description = "Refresh Token 을 이용하여 Access Token 을 재발급 받습니다.")
@PostMapping("/refresh")
public ResponseEntity<AccessTokenResponse> extendLogin(
Expand Down Expand Up @@ -127,14 +90,6 @@ public ResponseEntity<Void> updateProfile(@Valid @RequestBody final MemberUpdate
return ResponseEntity.ok().build();
}

@Operation(summary = "비밀번호 변경", description = "MemberUpdatePasswordRequest 을 이용하여 비밀번호를 변경합니다.")
@PutMapping("/password")
public ResponseEntity<Void> updatePassword(@Valid @RequestBody final MemberUpdatePasswordRequest request) {
memberService.updatePassword(request.password());

return ResponseEntity.ok().build();
}

@Operation(summary = "닉네임 중복 확인", description = "MemberCheckNicknameRequest 을 이용하여 닉네임 중복 확인을 합니다.")
@PostMapping("/check/nickname")
public ResponseEntity<MemberCheckNicknameResponse> checkNickname(
Expand All @@ -145,17 +100,6 @@ public ResponseEntity<MemberCheckNicknameResponse> checkNickname(
return ResponseEntity.ok().build();
}

@Operation(summary = "이메일 인증", description = "MemberCheckEmailRequest 을 이용하여 이메일 중복 확인을 한 후 이메일 인증번호를 보냅니다.")
@PostMapping("/check/email")
public ResponseEntity<MemberCheckEmailResponse> checkEmail(
@Valid @RequestBody final MemberCheckEmailRequest request
) {
final String code = memberService.checkEmail(request.email());
final MemberCheckEmailResponse response = new MemberCheckEmailResponse(code);

return ResponseEntity.ok(response);
}

@Operation(summary = "마이페이지 조회", description = "닉네임을 이용하여 마이페이지를 조회합니다.")
@GetMapping("/{nickname}")
public ResponseEntity<MemberGetMyPageResponse> getMyPage(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@
import org.springframework.web.multipart.MultipartFile;

import com.programmers.lime.domains.member.application.dto.response.MemberCheckJwtServiceResponse;
import com.programmers.lime.domains.member.application.dto.response.MemberLoginServiceResponse;
import com.programmers.lime.domains.member.domain.Member;
import com.programmers.lime.domains.member.domain.vo.LoginInfo;
import com.programmers.lime.domains.member.implementation.MemberAppender;
import com.programmers.lime.domains.member.implementation.MemberChecker;
import com.programmers.lime.domains.member.implementation.MemberModifier;
import com.programmers.lime.domains.member.implementation.MemberReader;
Expand All @@ -20,7 +17,6 @@
import com.programmers.lime.error.BusinessException;
import com.programmers.lime.error.ErrorCode;
import com.programmers.lime.global.util.MemberUtils;
import com.programmers.lime.mail.EmailSender;
import com.programmers.lime.s3.S3Manager;

import lombok.RequiredArgsConstructor;
Expand All @@ -32,43 +28,18 @@ public class MemberService {
public static final String DIRECTORY = "bucketback-static";
public static final String RESIZED_DIRECTORY = "resized";

private final MemberAppender memberAppender;
private final MemberReader memberReader;
private final MemberRemover memberRemover;
private final MemberModifier memberModifier;
private final MemberSecurityManager memberSecurityManager;
private final MemberChecker memberChecker;
private final EmailSender emailSender;
private final S3Manager s3Manager;
private final MemberUtils memberUtils;

public MemberCheckJwtServiceResponse checkJwtToken() {
return memberSecurityManager.checkJwtToken();
}

public void signup(
final LoginInfo loginInfo,
final String nickname
) {
memberChecker.checkEmailDuplication(loginInfo.getEmail());
memberChecker.checkNicknameDuplication(nickname);
final String encodedPassword = memberSecurityManager.encodePassword(loginInfo.getPassword());

memberAppender.append(loginInfo.getEmail(), encodedPassword, nickname);
}

public MemberLoginServiceResponse login(final LoginInfo loginInfo) {
final String email = loginInfo.getEmail();
final String rawPassword = loginInfo.getPassword();
final Member member = memberReader.readByEmail(email);

if (member.isDeleted()) {
throw new BusinessException(ErrorCode.MEMBER_DELETED);
}

return memberSecurityManager.login(rawPassword, member);
}

public String extendLogin(
final String refreshToken,
final String authorizationHeader
Expand All @@ -95,23 +66,10 @@ public void updateProfile(
memberModifier.modifyProfile(member, nickname, introduction);
}

public void updatePassword(final String password) {
final Member member = memberUtils.getCurrentMember();
final String encodedPassword = memberSecurityManager.encodePassword(password);

memberModifier.modifyPassword(member, encodedPassword);
}

public void checkNickname(final String nickname) {
memberChecker.checkNicknameDuplication(nickname);
}

public String checkEmail(final String email) {
memberChecker.checkEmailDuplication(email);

return emailSender.send(email);
}

public MyPage getMyPage(final String nickname) {
Member member = memberReader.readByNickname(nickname);
if (member.isDeleted()) {
Expand Down

0 comments on commit cb7250e

Please sign in to comment.