Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.ftm.server.web.controller.auth;
package com.ftm.server.adapter.in.web.auth.controller;

import com.ftm.server.application.dto.command.UserLoginCommand;
import com.ftm.server.application.usecase.auth.UserLoginUseCase;
import com.ftm.server.adapter.in.web.auth.dto.request.GeneralLoginRequest;
import com.ftm.server.adapter.in.web.auth.dto.response.GeneralLoginResponse;
import com.ftm.server.application.command.auth.GeneralLoginCommand;
import com.ftm.server.application.port.in.auth.GeneralLoginUseCase;
import com.ftm.server.application.vo.auth.AuthenticatedUserVo;
import com.ftm.server.common.response.ApiResponse;
import com.ftm.server.common.response.enums.SuccessResponseCode;
import com.ftm.server.domain.vo.UserSummaryVo;
import com.ftm.server.web.dto.request.UserLoginRequest;
import com.ftm.server.web.dto.response.UserLoginResponse;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
Expand All @@ -18,17 +18,18 @@

@RestController
@RequiredArgsConstructor
public class UserLoginController {
public class GeneralLoginController {

private final UserLoginUseCase loginUseCase;
private final GeneralLoginUseCase generalLoginUseCase;

@PostMapping("/api/auth/login")
public ResponseEntity<ApiResponse<UserLoginResponse>> login(
@RequestBody UserLoginRequest request,
public ResponseEntity<ApiResponse<GeneralLoginResponse>> login(
@RequestBody GeneralLoginRequest request,
HttpServletRequest req,
HttpServletResponse res) {
UserSummaryVo vo = loginUseCase.login(UserLoginCommand.from(request), req, res);
AuthenticatedUserVo vo =
generalLoginUseCase.execute(GeneralLoginCommand.from(request), req, res);
return ResponseEntity.status(HttpStatus.OK)
.body(ApiResponse.success(SuccessResponseCode.OK, UserLoginResponse.from(vo)));
.body(ApiResponse.success(SuccessResponseCode.OK, GeneralLoginResponse.from(vo)));
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
package com.ftm.server.web.controller.auth;
package com.ftm.server.adapter.in.web.auth.controller;

import static com.ftm.server.common.consts.StaticConsts.*;
import static com.ftm.server.common.consts.StaticConsts.PENDING_SOCIAL_USER_SESSION_KEY;
import static com.ftm.server.common.consts.StaticConsts.PENDING_SOCIAL_USER_SESSION_TTL;

import com.ftm.server.application.dto.command.KakaoAuthCommand;
import com.ftm.server.application.usecase.auth.KakaoLoginUseCase;
import com.ftm.server.adapter.in.web.auth.dto.request.KakaoLoginRequest;
import com.ftm.server.adapter.in.web.auth.dto.response.SocialLoginResponse;
import com.ftm.server.application.command.auth.KakaoLoginCommand;
import com.ftm.server.application.port.in.auth.KakaoLoginUseCase;
import com.ftm.server.application.port.out.security.SecurityAuthenticationPort;
import com.ftm.server.application.vo.auth.PendingSocialUserVo;
import com.ftm.server.application.vo.auth.SocialLoginOutcomeVo;
import com.ftm.server.application.vo.auth.SocialLoginSuccessVo;
import com.ftm.server.common.response.ApiResponse;
import com.ftm.server.common.response.enums.SuccessResponseCode;
import com.ftm.server.domain.enums.SocialProvider;
import com.ftm.server.domain.vo.PendingSocialUserVo;
import com.ftm.server.domain.vo.SocialLoginOutcomeVo;
import com.ftm.server.domain.vo.SocialLoginSuccessVo;
import com.ftm.server.infrastructure.security.AuthenticationService;
import com.ftm.server.web.dto.request.KakaoLoginRequest;
import com.ftm.server.web.dto.response.SocialLoginResponse;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
Expand All @@ -29,29 +30,30 @@
public class KakaoLoginController {

private final KakaoLoginUseCase kakaoLoginUseCase;
private final AuthenticationService authenticationService;
private final SecurityAuthenticationPort securityAuthenticationPort;

@PostMapping("/api/auth/login/kakao")
public ResponseEntity<ApiResponse<SocialLoginResponse>> kakaoLogin(
@RequestBody KakaoLoginRequest request,
HttpServletRequest req,
HttpServletResponse res) {
SocialLoginOutcomeVo result = kakaoLoginUseCase.kakaoLogin(KakaoAuthCommand.from(request));
SocialLoginOutcomeVo result = kakaoLoginUseCase.execute(KakaoLoginCommand.from(request));

// 가입된 유저인 경우 로그인 처리
if (result.isRegistered()) {
SocialLoginSuccessVo loginUser = (SocialLoginSuccessVo) result;

Authentication auth =
authenticationService.createAuthenticationFromSocial(loginUser.getUser());
authenticationService.saveAuthenticatedSession(auth, req, res);
securityAuthenticationPort.createAuthenticationFromSocial(loginUser.getUser());
securityAuthenticationPort.saveAuthenticatedSession(auth, req, res);

return ResponseEntity.status(HttpStatus.OK)
.body(
ApiResponse.success(
SuccessResponseCode.OK,
SocialLoginResponse.from(
SocialProvider.KAKAO, loginUser.getUserSummaryVo())));
SocialProvider.KAKAO,
loginUser.getAuthenticatedUserVo())));
}

// 가입이 필요한 유저인 경우
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.ftm.server.web.controller.auth;
package com.ftm.server.adapter.in.web.auth.controller;

import com.ftm.server.common.response.ApiResponse;
import com.ftm.server.common.response.enums.SuccessResponseCode;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.ftm.server.web.dto.request;
package com.ftm.server.adapter.in.web.auth.dto.request;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public class UserLoginRequest {
public class GeneralLoginRequest {

private final String email;
private final String password;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.ftm.server.web.dto.request;
package com.ftm.server.adapter.in.web.auth.dto.request;

import lombok.AllArgsConstructor;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.ftm.server.adapter.in.web.auth.dto.response;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.ftm.server.application.vo.auth.AuthenticatedUserVo;
import java.time.LocalDateTime;
import lombok.Getter;

@Getter
public class GeneralLoginResponse {

private final Long id;
private final String nickname;
private final String profileImageUrl;
private final String mildLevelName;
private final String spicyLevelName;

@JsonFormat(pattern = "yyyy-MM-dd HH:mm", shape = JsonFormat.Shape.STRING)
private final LocalDateTime loginTime;

GeneralLoginResponse(AuthenticatedUserVo authenticatedUserVo) {
this.id = authenticatedUserVo.getId();
this.nickname = authenticatedUserVo.getNickname();
this.profileImageUrl = authenticatedUserVo.getProfileImageUrl();
this.mildLevelName = authenticatedUserVo.getMildLevelName();
this.spicyLevelName = authenticatedUserVo.getSpicyLevelName();
this.loginTime = LocalDateTime.now();
}

public static GeneralLoginResponse from(AuthenticatedUserVo authenticatedUserVo) {
return new GeneralLoginResponse(authenticatedUserVo);
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.ftm.server.web.dto.response;
package com.ftm.server.adapter.in.web.auth.dto.response;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.ftm.server.application.vo.auth.AuthenticatedUserVo;
import com.ftm.server.domain.enums.SocialProvider;
import com.ftm.server.domain.vo.UserSummaryVo;
import java.time.LocalDateTime;
import lombok.Getter;

Expand All @@ -19,18 +19,18 @@ public class SocialLoginResponse {
@JsonFormat(pattern = "yyyy-MM-dd HH:mm", shape = JsonFormat.Shape.STRING)
private final LocalDateTime loginTime;

SocialLoginResponse(SocialProvider socialProvider, UserSummaryVo userSummaryVo) {
this.id = userSummaryVo.getId();
this.nickname = userSummaryVo.getNickname();
SocialLoginResponse(SocialProvider socialProvider, AuthenticatedUserVo authenticatedUserVo) {
this.id = authenticatedUserVo.getId();
this.nickname = authenticatedUserVo.getNickname();
this.socialProvider = socialProvider;
this.profileImageUrl = userSummaryVo.getProfileImageUrl();
this.mildLevelName = userSummaryVo.getMildLevelName();
this.spicyLevelName = userSummaryVo.getSpicyLevelName();
this.profileImageUrl = authenticatedUserVo.getProfileImageUrl();
this.mildLevelName = authenticatedUserVo.getMildLevelName();
this.spicyLevelName = authenticatedUserVo.getSpicyLevelName();
this.loginTime = LocalDateTime.now();
}

public static SocialLoginResponse from(
SocialProvider socialProvider, UserSummaryVo userSummaryVo) {
return new SocialLoginResponse(socialProvider, userSummaryVo);
SocialProvider socialProvider, AuthenticatedUserVo authenticatedUserVo) {
return new SocialLoginResponse(socialProvider, authenticatedUserVo);
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.ftm.server.web.controller.user;
package com.ftm.server.adapter.in.web.user.controller;

import com.ftm.server.application.dto.command.EmailAuthenticationCommand;
import com.ftm.server.application.usecase.user.EmailAuthenticationUseCase;
import com.ftm.server.adapter.in.web.user.dto.request.EmailAuthenticationRequest;
import com.ftm.server.application.command.user.EmailAuthenticationCommand;
import com.ftm.server.application.port.in.user.EmailAuthenticationUseCase;
import com.ftm.server.common.response.ApiResponse;
import com.ftm.server.common.response.enums.SuccessResponseCode;
import com.ftm.server.web.dto.request.EmailAuthenticationRequest;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
Expand All @@ -22,7 +22,7 @@ public class EmailAuthenticationController {
@PostMapping("/api/users/email/authentication")
public ResponseEntity<ApiResponse<Object>> emailAuthenticationCodeSender(
@Valid @RequestBody EmailAuthenticationRequest request) {
emailAuthenticationUseCase.sendEmailAuthenticationCode(
emailAuthenticationUseCase.execute(
EmailAuthenticationCommand.from(request)); // command 객체 전달
return ResponseEntity.status(HttpStatus.OK)
.body(ApiResponse.success(SuccessResponseCode.OK));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.ftm.server.web.controller.user;
package com.ftm.server.adapter.in.web.user.controller;

import com.ftm.server.application.dto.query.EmailCodeVerificationQuery;
import com.ftm.server.application.usecase.user.EmailCodeVerificationUseCase;
import com.ftm.server.adapter.in.web.user.dto.request.EmailCodeVerificationRequest;
import com.ftm.server.adapter.in.web.user.dto.response.EmailCodeVerificationResponse;
import com.ftm.server.application.port.in.user.EmailCodeVerificationUseCase;
import com.ftm.server.application.query.EmailCodeVerificationQuery;
import com.ftm.server.common.response.ApiResponse;
import com.ftm.server.common.response.enums.SuccessResponseCode;
import com.ftm.server.web.dto.request.EmailCodeVerificationRequest;
import com.ftm.server.web.dto.response.EmailCodeVerificationResponse;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.ftm.server.web.controller.user;
package com.ftm.server.adapter.in.web.user.controller;

import com.ftm.server.application.dto.query.FindByEmailQuery;
import com.ftm.server.application.usecase.user.EmailDuplicationCheckUseCase;
import com.ftm.server.adapter.in.web.user.dto.response.EmailDuplicationCheckResponse;
import com.ftm.server.application.port.in.user.EmailDuplicationCheckUseCase;
import com.ftm.server.application.query.FindByEmailQuery;
import com.ftm.server.common.response.ApiResponse;
import com.ftm.server.common.response.enums.SuccessResponseCode;
import com.ftm.server.web.dto.response.EmailDuplicationCheckResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
Expand All @@ -26,7 +26,7 @@ public ResponseEntity<ApiResponse<EmailDuplicationCheckResponse>> emailDuplicati
ApiResponse.success(
SuccessResponseCode.OK,
EmailDuplicationCheckResponse.from(
emailDuplicationCheckUseCase.emailDuplicationCheck(
emailDuplicationCheckUseCase.execute(
FindByEmailQuery.of(email)))));
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.ftm.server.web.controller.user;
package com.ftm.server.adapter.in.web.user.controller;

import com.ftm.server.application.dto.command.GeneralUserSignupCommand;
import com.ftm.server.application.usecase.user.GeneralUserSignupUseCase;
import com.ftm.server.adapter.in.web.user.dto.request.GeneralUserSignupRequest;
import com.ftm.server.application.command.user.GeneralUserSignupCommand;
import com.ftm.server.application.port.in.user.GeneralUserSignupUseCase;
import com.ftm.server.common.response.ApiResponse;
import com.ftm.server.common.response.enums.SuccessResponseCode;
import com.ftm.server.web.dto.request.GeneralUserSignupRequest;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.ftm.server.web.controller.user;
package com.ftm.server.adapter.in.web.user.controller;

import com.ftm.server.application.usecase.user.GetUserSignupOptionsUseCase;
import com.ftm.server.adapter.in.web.user.dto.response.UserSignupOptionsResponse;
import com.ftm.server.application.port.in.user.GetUserSignupOptionsUseCase;
import com.ftm.server.common.response.ApiResponse;
import com.ftm.server.common.response.enums.SuccessResponseCode;
import com.ftm.server.web.dto.response.UserSignupOptionsResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package com.ftm.server.web.controller.user;
package com.ftm.server.adapter.in.web.user.controller;

import static com.ftm.server.common.consts.StaticConsts.PENDING_SOCIAL_USER_SESSION_KEY;

import com.ftm.server.application.dto.command.SocialUserSignupCommand;
import com.ftm.server.application.usecase.user.SocialUserSignupUseCase;
import com.ftm.server.adapter.in.web.user.dto.request.SocialUserSignupRequest;
import com.ftm.server.adapter.in.web.user.dto.response.SocialUserSignupResponse;
import com.ftm.server.application.command.user.SocialUserSignupCommand;
import com.ftm.server.application.port.in.user.SocialUserSignupUseCase;
import com.ftm.server.application.port.out.security.SecurityAuthenticationPort;
import com.ftm.server.application.vo.auth.PendingSocialUserVo;
import com.ftm.server.application.vo.user.SocialUserSignupSummaryVo;
import com.ftm.server.common.exception.CustomException;
import com.ftm.server.common.response.ApiResponse;
import com.ftm.server.common.response.enums.ErrorResponseCode;
import com.ftm.server.common.response.enums.SuccessResponseCode;
import com.ftm.server.domain.entity.User;
import com.ftm.server.domain.vo.PendingSocialUserVo;
import com.ftm.server.domain.vo.SocialUserSignupSummaryVo;
import com.ftm.server.infrastructure.security.AuthenticationService;
import com.ftm.server.web.dto.request.SocialUserSignupRequest;
import com.ftm.server.web.dto.response.SocialUserSignupResponse;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
Expand All @@ -32,7 +32,7 @@ public class SocialUserSignupController {

private final SocialUserSignupUseCase socialUserSignupUseCase;

private final AuthenticationService authenticationService;
private final SecurityAuthenticationPort securityAuthenticationPort;

@PostMapping("api/users/social")
public ResponseEntity<ApiResponse<SocialUserSignupResponse>> socialUserSignup(
Expand All @@ -59,8 +59,8 @@ public ResponseEntity<ApiResponse<SocialUserSignupResponse>> socialUserSignup(
session.invalidate();

// 인증 정보 저장
Authentication auth = authenticationService.createAuthenticationFromSocial(user);
authenticationService.saveAuthenticatedSession(auth, req, res);
Authentication auth = securityAuthenticationPort.createAuthenticationFromSocial(user);
securityAuthenticationPort.saveAuthenticatedSession(auth, req, res);

SocialUserSignupResponse response = SocialUserSignupResponse.from(summary);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.ftm.server.web.dto.request;
package com.ftm.server.adapter.in.web.user.dto.request;

import jakarta.validation.constraints.Pattern;
import lombok.Data;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.ftm.server.web.dto.request;
package com.ftm.server.adapter.in.web.user.dto.request;

import jakarta.validation.constraints.NotBlank;
import lombok.Data;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.ftm.server.web.dto.request;
package com.ftm.server.adapter.in.web.user.dto.request;

import com.ftm.server.domain.enums.AgeGroup;
import com.ftm.server.domain.enums.HashTag;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.ftm.server.web.dto.request;
package com.ftm.server.adapter.in.web.user.dto.request;

import com.ftm.server.domain.enums.AgeGroup;
import com.ftm.server.domain.enums.HashTag;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.ftm.server.web.dto.response;
package com.ftm.server.adapter.in.web.user.dto.response;

import com.ftm.server.domain.vo.EmailCodeVerificationVo;
import com.ftm.server.application.vo.user.EmailCodeVerificationVo;
import lombok.Data;

@Data
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.ftm.server.web.dto.response;
package com.ftm.server.adapter.in.web.user.dto.response;

import com.ftm.server.domain.vo.EmailDuplicationVo;
import com.ftm.server.application.vo.user.EmailDuplicationVo;
import lombok.Data;

@Data
Expand Down
Loading