최초 커밋!
This commit is contained in:
29
front/src/main/java/app/module/front/FrontApplication.java
Normal file
29
front/src/main/java/app/module/front/FrontApplication.java
Normal file
@@ -0,0 +1,29 @@
|
||||
package app.module.front;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
|
||||
import org.springframework.cache.annotation.EnableCaching;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableCaching
|
||||
@ComponentScan(basePackages = "app.module")
|
||||
public class FrontApplication extends SpringBootServletInitializer {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(FrontApplication.class, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* maven jar 배포시 필요없지만, war 배포를 선택한 경우 configure 오버라이드가 필요하기에 선언.
|
||||
*
|
||||
* @param builder
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
|
||||
return builder.sources(FrontApplication.class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
package app.module.front.config;
|
||||
|
||||
import app.module.core.config.adapters.web.interceptor.URIAuthorizeInterceptor;
|
||||
import app.module.core.config.application.enums.PublicAccess;
|
||||
import app.module.front.config.adapters.web.interceptor.FrontURIInterceptor;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.stream.Collectors;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||
import org.springframework.web.servlet.LocaleResolver;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
import org.springframework.web.servlet.i18n.CookieLocaleResolver;
|
||||
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;
|
||||
|
||||
@Configuration
|
||||
@RequiredArgsConstructor
|
||||
public class FrontWebMvcConfig implements WebMvcConfigurer {
|
||||
|
||||
private final FrontURIInterceptor frontURIInterceptor;
|
||||
private final URIAuthorizeInterceptor uriAuthorizeInterceptor;
|
||||
@Value("${path.upload.public}")
|
||||
private String publicPath;
|
||||
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
registry
|
||||
.addInterceptor(frontURIInterceptor)
|
||||
.excludePathPatterns(
|
||||
Arrays.stream(PublicAccess.values())
|
||||
// 로그인 페이지의 경우, currentURI 정보를 얻기 위해 실행되야 한다.
|
||||
.filter(publicAccess -> !publicAccess.getPath().equals("/login"))
|
||||
.map(PublicAccess::getPath)
|
||||
.collect(Collectors.toList()))
|
||||
.excludePathPatterns("/api/**"); // api 는 currentURI 정보가 없기에 skip;
|
||||
|
||||
// registry
|
||||
// .addInterceptor(uriAuthorizeInterceptor)
|
||||
// .addPathPatterns("/**")
|
||||
// .excludePathPatterns(
|
||||
// Arrays.stream(PublicAccess.values())
|
||||
// .map(PublicAccess::getPath)
|
||||
// .collect(Collectors.toList()))
|
||||
// // 익명 사용자 접근 허용 URI 는 인증체크 대상에서 제외
|
||||
// .excludePathPatterns(FrontPublicAccess.getInstance().getURIs());
|
||||
|
||||
registry.addInterceptor(localeChangeInterceptor());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
registry
|
||||
.addResourceHandler("/content-disposition/inline/**")
|
||||
.addResourceLocations("file:///" + publicPath + "/")
|
||||
.setCachePeriod(20);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
|
||||
converters.add(new MappingJackson2HttpMessageConverter());
|
||||
}
|
||||
|
||||
@Bean
|
||||
public LocaleResolver localeResolver() {
|
||||
CookieLocaleResolver slr = new CookieLocaleResolver();
|
||||
slr.setDefaultLocale(Locale.getDefault());
|
||||
slr.setCookieName("lang");
|
||||
return slr;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public LocaleChangeInterceptor localeChangeInterceptor() {
|
||||
LocaleChangeInterceptor lci = new LocaleChangeInterceptor();
|
||||
lci.setParamName("lang");
|
||||
return lci;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
package app.module.front.config.adapters.web.interceptor;
|
||||
|
||||
import app.module.core.config.adapters.web.interceptor.model.URITopTierVO;
|
||||
import app.module.core.config.application.enums.AppType;
|
||||
import app.module.core.config.application.exception.NoMatchingURIException;
|
||||
import app.module.core.config.application.util.CommonUtil;
|
||||
import app.module.core.usecase.uri.ancestry.ports.URIAncestryPortIn;
|
||||
import app.module.core.usecase.uri.currentmatch.ports.URICurrentMatchingPortIn;
|
||||
import app.module.core.usecase.uri.currentmatch.ports.application.domain.URICurrentMatching;
|
||||
import app.module.core.usecase.uri.toptier.ports.URITopTierPortIn;
|
||||
import app.module.core.usecase.uri.toptier.ports.application.domain.URITopTier;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import java.util.stream.Collectors;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class FrontURIInterceptor implements HandlerInterceptor {
|
||||
|
||||
private final URICurrentMatchingPortIn uriCurrentMatchingPortIn;
|
||||
private final URIAncestryPortIn uriAncestryPortIn;
|
||||
private final URITopTierPortIn topTierPortIn;
|
||||
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
|
||||
Object handler)
|
||||
throws Exception {
|
||||
String requestURI = request.getRequestURI();
|
||||
|
||||
URICurrentMatching currentURI = uriCurrentMatchingPortIn.connect(AppType.FRONT, requestURI);
|
||||
if (currentURI == null) {
|
||||
// spring boot 2.6.x 에서는 인터셉터에서 throw exception 이 동작안했기에 아래 코드가 필요했음.
|
||||
// request.setAttribute("message", String.format("매핑되는 않은 URI - %s", requestURI));
|
||||
// request.setAttribute("exception", "NoMatchingURIException");
|
||||
// request.getRequestDispatcher("/error/interceptor").forward(request, response);
|
||||
// return false;
|
||||
|
||||
// spring boot 3.4.x 에서는 throw exception 이 가능!
|
||||
throw new NoMatchingURIException(String.format("매핑되는 않은 URI - %s", requestURI));
|
||||
}
|
||||
|
||||
request.setAttribute("currentURI", currentURI);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postHandle(
|
||||
HttpServletRequest request,
|
||||
HttpServletResponse response,
|
||||
Object handler,
|
||||
ModelAndView modelAndView)
|
||||
throws Exception {
|
||||
|
||||
if (modelAndView == null) {
|
||||
log.info("POST_HANDLE_END::since modelAndView is null");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!CommonUtil.isAjaxRequest(request)) {
|
||||
URITopTier topTierOutput = topTierPortIn.connect(AppType.FRONT);
|
||||
modelAndView.addObject("topNode", recursiveMapping(topTierOutput));
|
||||
|
||||
if (modelAndView.getModelMap().getAttribute("currentURI") == null) {
|
||||
modelAndView.addObject("currentURI", request.getAttribute("currentURI"));
|
||||
}
|
||||
|
||||
modelAndView.addObject(
|
||||
"menuHierarchy", uriAncestryPortIn.connect(AppType.FRONT, request.getRequestURI()));
|
||||
}
|
||||
}
|
||||
|
||||
private URITopTierVO recursiveMapping(URITopTier output) {
|
||||
return new URITopTierVO(
|
||||
output.getId(),
|
||||
output.getText(),
|
||||
output.getUri(),
|
||||
output.getShowOnNavi(),
|
||||
CollectionUtils.emptyIfNull(output.getChildren()).stream()
|
||||
.map(this::recursiveMapping)
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package app.module.front.config.application.security;
|
||||
|
||||
import app.module.core.config.application.enums.SocialType;
|
||||
import app.module.front.usecase.user.social.processSocialLogin.ports.ProcessSocialLoginPortIn;
|
||||
import app.module.front.usecase.user.social.processSocialLogin.ports.application.domain.ProcessSocialLoginCmd;
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.security.oauth2.client.userinfo.DefaultOAuth2UserService;
|
||||
import org.springframework.security.oauth2.client.userinfo.OAuth2UserRequest;
|
||||
import org.springframework.security.oauth2.client.userinfo.OAuth2UserService;
|
||||
import org.springframework.security.oauth2.core.OAuth2AuthenticationException;
|
||||
import org.springframework.security.oauth2.core.user.OAuth2User;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class CustomOAuth2UserService implements OAuth2UserService<OAuth2UserRequest, OAuth2User> {
|
||||
|
||||
private final ProcessSocialLoginPortIn processSocialLoginPortIn;
|
||||
|
||||
@Override
|
||||
public OAuth2User loadUser(OAuth2UserRequest userRequest) throws OAuth2AuthenticationException {
|
||||
OAuth2UserService<OAuth2UserRequest, OAuth2User> delegate = new DefaultOAuth2UserService();
|
||||
OAuth2User oAuth2User = delegate.loadUser(userRequest);
|
||||
|
||||
String registrationId = userRequest.getClientRegistration().getRegistrationId();
|
||||
SocialType socialType =
|
||||
Arrays.stream(SocialType.values())
|
||||
.filter(type -> type.getRegistrationId().equals(registrationId))
|
||||
.findFirst()
|
||||
.orElseThrow(() -> new RuntimeException("Social type not found"));
|
||||
String userNameAttributeName =
|
||||
userRequest
|
||||
.getClientRegistration()
|
||||
.getProviderDetails()
|
||||
.getUserInfoEndpoint()
|
||||
.getUserNameAttributeName();
|
||||
|
||||
Map<String, Object> attributes = oAuth2User.getAttributes();
|
||||
|
||||
return processSocialLoginPortIn
|
||||
.operate(new ProcessSocialLoginCmd(socialType, userNameAttributeName, attributes))
|
||||
.orElseThrow();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
package app.module.front.config.application.security;
|
||||
|
||||
import app.module.core.config.adapters.web.security.domain.CorePrivilege;
|
||||
import app.module.core.config.adapters.web.security.domain.CoreRole;
|
||||
import app.module.core.usecase.user.findUser.ports.FindUserPortIn;
|
||||
import app.module.core.usecase.user.findUser.ports.application.domain.FindUser;
|
||||
import app.module.core.usecase.user.findUser.ports.application.domain.FindUserCmd;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Collection;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class FrontDetailService implements UserDetailsService {
|
||||
|
||||
private final FindUserPortIn findUserPortIn;
|
||||
@Value("${app.front.password.validity.period.days}")
|
||||
private long passwordValidPeriodDays;
|
||||
|
||||
@Override
|
||||
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
|
||||
FindUser findUser =
|
||||
findUserPortIn
|
||||
.operate(new FindUserCmd(username))
|
||||
.orElseThrow(() -> new UsernameNotFoundException("Invalid username or password."));
|
||||
|
||||
boolean accountLocked = Optional.ofNullable(findUser.getAccountLocked()).orElse(false);
|
||||
boolean accountDisabled = Optional.ofNullable(findUser.getAccountDisabled()).orElse(false);
|
||||
|
||||
return new FrontUser(
|
||||
findUser.getId(),
|
||||
findUser.getPassword(),
|
||||
!accountDisabled,
|
||||
true,
|
||||
isCredentialsNonExpired(findUser.getPasswordUpdatedAt()),
|
||||
!accountLocked,
|
||||
getAuthorities(findUser.getRoles()),
|
||||
findUser.getNickname(),
|
||||
passwordValidPeriodDays - getDaysPassedFrom(findUser.getPasswordUpdatedAt()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Authorities (Role + Privileges) 합성. Role 과 Privileges 는 1:N 매핑되지만, 이 메서드를 통해 동일한 depth 로 배열에
|
||||
* 담겨 반환된다. 즉, Privilege 는 또다른 종류의 Role 로 볼 수 있다.
|
||||
*
|
||||
* @param roles
|
||||
* @return authorities
|
||||
*/
|
||||
private Collection<? extends GrantedAuthority> getAuthorities(Collection<CoreRole> roles) {
|
||||
return Stream.concat(getRoles(roles), getPrivileges(roles))
|
||||
.map(SimpleGrantedAuthority::new)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private Stream<String> getRoles(Collection<CoreRole> roles) {
|
||||
return roles.stream().map(CoreRole::getId);
|
||||
}
|
||||
|
||||
private Stream<String> getPrivileges(Collection<CoreRole> roles) {
|
||||
return roles.stream()
|
||||
.flatMap(roleOutput -> roleOutput.getPrivileges().stream())
|
||||
.map(CorePrivilege::getId);
|
||||
}
|
||||
|
||||
// 패스워드 만료 여부체크. 이 기능이 필요하지 않다면 항상 true 를 반환하도록 변경하면 된다.
|
||||
private boolean isCredentialsNonExpired(LocalDateTime passwordUpdatedAt) {
|
||||
// return passwordValidPeriodDays == -1
|
||||
// || getDaysPassedFrom(passwordUpdatedAt) <= passwordValidPeriodDays;
|
||||
return true;
|
||||
}
|
||||
|
||||
// 패스워드 만료일 정보를 반환. 이 기능이 필요하지 않다면 항상 0L 을 반환하도록 변경하면 된다.
|
||||
private long getDaysPassedFrom(LocalDateTime passwordUpdatedAt) {
|
||||
// return Duration.between(passwordUpdatedAt, LocalDateTime.now()).toDays();
|
||||
return 0L;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package app.module.front.config.application.security;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class FrontPublicAccess {
|
||||
|
||||
private static final FrontPublicAccess INSTANCE = new FrontPublicAccess();
|
||||
|
||||
private List<String> publicAccessURIs = new ArrayList<>();
|
||||
|
||||
private FrontPublicAccess() {
|
||||
}
|
||||
|
||||
public static FrontPublicAccess getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
public List<String> getURIs() {
|
||||
return publicAccessURIs;
|
||||
}
|
||||
|
||||
public void setURIs(List<String> uris) {
|
||||
publicAccessURIs.addAll(uris);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
package app.module.front.config.application.security;
|
||||
|
||||
import app.module.core.config.adapters.web.security.entrypoint.CustomAuthenticationEntryPoint;
|
||||
import app.module.core.config.application.enums.PublicAccess;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.sql.DataSource;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||
import org.springframework.security.core.session.SessionRegistry;
|
||||
import org.springframework.security.core.session.SessionRegistryImpl;
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
import org.springframework.security.web.SecurityFilterChain;
|
||||
import org.springframework.security.web.authentication.rememberme.JdbcTokenRepositoryImpl;
|
||||
import org.springframework.security.web.authentication.rememberme.PersistentTokenRepository;
|
||||
import org.springframework.security.web.session.HttpSessionEventPublisher;
|
||||
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
|
||||
|
||||
@Configuration
|
||||
@EnableWebSecurity
|
||||
@RequiredArgsConstructor
|
||||
public class FrontSecurityConfig {
|
||||
|
||||
private final FrontDetailService frontDetailService;
|
||||
private final DataSource dataSource;
|
||||
private final BCryptPasswordEncoder passwordEncoder;
|
||||
private final CustomOAuth2UserService customOAuth2UserService;
|
||||
private final CustomAuthenticationEntryPoint customAuthenticationEntryPoint;
|
||||
@Value("${app.front.session.maximum.num}")
|
||||
private Integer maxSessionNum;
|
||||
|
||||
@Bean
|
||||
public PersistentTokenRepository persistentTokenRepository() {
|
||||
JdbcTokenRepositoryImpl jdbcTokenRepository = new JdbcTokenRepositoryImpl();
|
||||
jdbcTokenRepository.setDataSource(dataSource);
|
||||
return jdbcTokenRepository;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DaoAuthenticationProvider authenticationProvider() {
|
||||
DaoAuthenticationProvider auth = new DaoAuthenticationProvider();
|
||||
auth.setUserDetailsService(frontDetailService);
|
||||
auth.setPasswordEncoder(passwordEncoder);
|
||||
return auth;
|
||||
}
|
||||
|
||||
// 중복 로그인 방지를 위해 선언
|
||||
@Bean
|
||||
public SessionRegistry sessionRegistry() {
|
||||
return new SessionRegistryImpl();
|
||||
}
|
||||
|
||||
// 중복 로그인 방지를 위해 선언
|
||||
@Bean
|
||||
public ServletListenerRegistrationBean httpSessionEventPublisher() {
|
||||
return new ServletListenerRegistrationBean(new HttpSessionEventPublisher());
|
||||
}
|
||||
|
||||
@Bean
|
||||
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
|
||||
|
||||
List<String> publicAccess =
|
||||
Arrays.stream(PublicAccess.values())
|
||||
.map(PublicAccess::getPath)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// front - 익명 사용자 접근 허용 URI 등록 (admin 과 달리 공개/비공개 URL 이 존재한다)
|
||||
FrontPublicAccess.getInstance().setURIs(List.of("/", "/user/register"));
|
||||
|
||||
http.authorizeHttpRequests(
|
||||
(auth) ->
|
||||
auth.requestMatchers(publicAccess.toArray(String[]::new))
|
||||
.permitAll()
|
||||
.requestMatchers(
|
||||
FrontPublicAccess.getInstance().getURIs().toArray(String[]::new))
|
||||
.permitAll()
|
||||
.anyRequest()
|
||||
.hasAuthority("FRONT_ACCESS"))
|
||||
.exceptionHandling(
|
||||
exception ->
|
||||
exception.defaultAuthenticationEntryPointFor(
|
||||
customAuthenticationEntryPoint, new AntPathRequestMatcher("/api/**")))
|
||||
.formLogin(fLogin -> fLogin.loginPage("/login"))
|
||||
.rememberMe(
|
||||
remMe ->
|
||||
remMe
|
||||
.tokenValiditySeconds(1209600)
|
||||
.userDetailsService(frontDetailService)
|
||||
.tokenRepository(persistentTokenRepository()))
|
||||
.logout(
|
||||
logout ->
|
||||
logout
|
||||
.invalidateHttpSession(true)
|
||||
.clearAuthentication(true)
|
||||
.logoutRequestMatcher(new AntPathRequestMatcher("/logout")))
|
||||
.sessionManagement(
|
||||
session -> session.maximumSessions(maxSessionNum).maxSessionsPreventsLogin(false))
|
||||
.oauth2Login(
|
||||
config ->
|
||||
config
|
||||
.loginPage("/login")
|
||||
.userInfoEndpoint(
|
||||
userInfoEndpointConfig ->
|
||||
userInfoEndpointConfig.userService(customOAuth2UserService)));
|
||||
|
||||
return http.build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package app.module.front.config.application.security;
|
||||
|
||||
import java.util.Collection;
|
||||
import lombok.Getter;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.core.userdetails.User;
|
||||
|
||||
@Getter
|
||||
public class FrontUser extends User {
|
||||
|
||||
private String nickname;
|
||||
private long remainPasswordDays;
|
||||
|
||||
public FrontUser(
|
||||
String username,
|
||||
String password,
|
||||
boolean enabled,
|
||||
boolean accountNonExpired,
|
||||
boolean credentialsNonExpired,
|
||||
boolean accountNonLocked,
|
||||
Collection<? extends GrantedAuthority> authorities,
|
||||
String nickName,
|
||||
long remainPasswordDays) {
|
||||
super(
|
||||
username,
|
||||
password,
|
||||
enabled,
|
||||
accountNonExpired,
|
||||
credentialsNonExpired,
|
||||
accountNonLocked,
|
||||
authorities);
|
||||
this.nickname = nickName;
|
||||
this.remainPasswordDays = remainPasswordDays;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package app.module.front.usecase.article.comment.createArticleComment.adapter.web;
|
||||
|
||||
import app.module.core.usecase.article.comment.createArticleComment.ports.CreateArticleCommentPortIn;
|
||||
import app.module.core.usecase.article.comment.createArticleComment.ports.application.domain.CreateArticleComment;
|
||||
import app.module.core.usecase.article.comment.createArticleComment.ports.application.domain.CreateArticleCommentCmd;
|
||||
import app.module.front.usecase.article.comment.createArticleComment.adapter.web.model.CreateArticleCommentReqVO;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
class CreateArticleCommentController {
|
||||
|
||||
private final CreateArticleCommentPortIn createArticleCommentPortIn;
|
||||
|
||||
@PostMapping(path = "/api/front/board/articles/comment/create")
|
||||
ResponseEntity<?> operate(@Valid CreateArticleCommentReqVO reqVO, BindingResult bindingResult) {
|
||||
if (bindingResult.hasErrors()) {
|
||||
return ResponseEntity.status(HttpStatus.UNPROCESSABLE_ENTITY)
|
||||
.body(bindingResult.getFieldErrors());
|
||||
}
|
||||
|
||||
CreateArticleComment comment =
|
||||
createArticleCommentPortIn.operate(
|
||||
new CreateArticleCommentCmd(reqVO.getArticleId(), reqVO.getCommentContent()))
|
||||
.orElseThrow();
|
||||
|
||||
return ResponseEntity.status(HttpStatus.OK).body(comment);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package app.module.front.usecase.article.comment.createArticleComment.adapter.web.model;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.apache.commons.text.StringEscapeUtils;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode
|
||||
public class CreateArticleCommentReqVO {
|
||||
|
||||
private Long articleId;
|
||||
@NotBlank(message = "{valid.article.comment.required}")
|
||||
private String commentContent;
|
||||
|
||||
public String getCommentContent() {
|
||||
return StringEscapeUtils.escapeHtml4(commentContent);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package app.module.front.usecase.article.comment.getArticleComments.adapter.web;
|
||||
|
||||
import app.module.core.usecase.article.comment.getArticleComments.ports.GetArticleCommentsPortIn;
|
||||
import app.module.core.usecase.article.comment.getArticleComments.ports.application.domain.GetArticleComments;
|
||||
import app.module.core.usecase.article.comment.getArticleComments.ports.application.domain.GetArticleCommentsCmd;
|
||||
import app.module.front.usecase.article.comment.getArticleComments.adapter.web.model.GetArticleCommentsReqVO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.web.PageableDefault;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
class GetArticleCommentsController {
|
||||
|
||||
private final GetArticleCommentsPortIn getArticleCommentsPortIn;
|
||||
|
||||
@GetMapping(path = "/api/front/board/articles/comments")
|
||||
ResponseEntity<?> operate(
|
||||
@PageableDefault(sort = "id", direction = Sort.Direction.DESC, page = 0, size = 10) Pageable pageable,
|
||||
GetArticleCommentsReqVO reqVO) {
|
||||
|
||||
Page<GetArticleComments> comments =
|
||||
getArticleCommentsPortIn.operate(pageable,
|
||||
new GetArticleCommentsCmd(reqVO.getArticleId()));
|
||||
|
||||
return ResponseEntity.status(HttpStatus.OK).body(comments);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package app.module.front.usecase.article.comment.getArticleComments.adapter.web.model;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode
|
||||
public class GetArticleCommentsReqVO {
|
||||
|
||||
private Long articleId;
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package app.module.front.usecase.article.comment.removeArticleComment.adapter.web;
|
||||
|
||||
import app.module.core.usecase.article.comment.removeArticleComment.ports.RemoveArticleCommentPortIn;
|
||||
import app.module.core.usecase.article.comment.removeArticleComment.ports.application.domain.RemoveArticleCommentCmd;
|
||||
import app.module.front.usecase.article.comment.removeArticleComment.adapter.web.model.RemoveArticleCommentReqVO;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
class RemoveArticleCommentController {
|
||||
|
||||
private final RemoveArticleCommentPortIn removeArticleCommentPortIn;
|
||||
|
||||
@DeleteMapping(path = "/api/front/board/articles/comment/remove")
|
||||
ResponseEntity<?> operate(@Valid RemoveArticleCommentReqVO reqVO, BindingResult bindingResult) {
|
||||
if (bindingResult.hasErrors()) {
|
||||
return ResponseEntity.status(HttpStatus.UNPROCESSABLE_ENTITY)
|
||||
.body(bindingResult.getFieldErrors());
|
||||
}
|
||||
|
||||
removeArticleCommentPortIn.operate(new RemoveArticleCommentCmd(reqVO.getRemoveId()));
|
||||
|
||||
return ResponseEntity.status(HttpStatus.OK).body(reqVO);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package app.module.front.usecase.article.comment.removeArticleComment.adapter.web.model;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode
|
||||
public class RemoveArticleCommentReqVO {
|
||||
|
||||
private Long removeId;
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package app.module.front.usecase.article.comment.updateArticleComment.adapter.web;
|
||||
|
||||
import app.module.core.usecase.article.comment.updateArticleComment.ports.UpdateArticleCommentPortIn;
|
||||
import app.module.core.usecase.article.comment.updateArticleComment.ports.application.domain.UpdateArticleComment;
|
||||
import app.module.core.usecase.article.comment.updateArticleComment.ports.application.domain.UpdateArticleCommentCmd;
|
||||
import app.module.front.usecase.article.comment.updateArticleComment.adapter.web.model.UpdateArticleCommentReqVO;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
class UpdateArticleCommentController {
|
||||
|
||||
private final UpdateArticleCommentPortIn updateArticleCommentPortIn;
|
||||
|
||||
@PutMapping(path = "/api/front/board/articles/comment/update")
|
||||
ResponseEntity<?> operate(@Valid UpdateArticleCommentReqVO reqVO, BindingResult bindingResult) {
|
||||
if (bindingResult.hasErrors()) {
|
||||
return ResponseEntity.status(HttpStatus.UNPROCESSABLE_ENTITY)
|
||||
.body(bindingResult.getFieldErrors());
|
||||
}
|
||||
|
||||
UpdateArticleComment comment =
|
||||
updateArticleCommentPortIn.operate(
|
||||
new UpdateArticleCommentCmd(
|
||||
reqVO.getCommentId(),
|
||||
reqVO.getCommentContent(),
|
||||
reqVO.getArticleId()))
|
||||
.orElseThrow();
|
||||
|
||||
return ResponseEntity.status(HttpStatus.OK).body(comment);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package app.module.front.usecase.article.comment.updateArticleComment.adapter.web.model;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.apache.commons.text.StringEscapeUtils;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode
|
||||
public class UpdateArticleCommentReqVO {
|
||||
|
||||
private Long commentId;
|
||||
@NotBlank(message = "{valid.article.comment.required}")
|
||||
private String commentContent;
|
||||
private Long articleId;
|
||||
|
||||
public String getCommentContent() {
|
||||
return StringEscapeUtils.escapeHtml4(commentContent);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package app.module.front.usecase.article.createArticle.adapters.web;
|
||||
|
||||
import app.module.core.usecase.article.createArticle.ports.CreateArticlePortIn;
|
||||
import app.module.core.usecase.article.createArticle.ports.application.domain.CreateArticle;
|
||||
import app.module.core.usecase.article.createArticle.ports.application.domain.CreateArticleCmd;
|
||||
import app.module.front.usecase.article.createArticle.adapters.web.model.CreateArticleReqVO;
|
||||
import app.module.front.usecase.article.createArticle.adapters.web.validator.CreateArticleValidator;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
class CreateArticleController {
|
||||
|
||||
private final CreateArticlePortIn createArticlePortIn;
|
||||
private final CreateArticleValidator createArticleValidator;
|
||||
|
||||
@PostMapping(path = "/api/front/board/articles/create")
|
||||
ResponseEntity<?> operate(@Valid CreateArticleReqVO reqVO, BindingResult bindingResult) {
|
||||
createArticleValidator.validate(reqVO, bindingResult);
|
||||
|
||||
if (bindingResult.hasErrors()) {
|
||||
return ResponseEntity.status(HttpStatus.UNPROCESSABLE_ENTITY)
|
||||
.body(bindingResult.getFieldErrors());
|
||||
}
|
||||
|
||||
CreateArticle article =
|
||||
createArticlePortIn
|
||||
.operate(
|
||||
new CreateArticleCmd(
|
||||
reqVO.getTitle(),
|
||||
reqVO.getContent(),
|
||||
reqVO.getVisible(),
|
||||
reqVO.getStartDate(),
|
||||
reqVO.getEndDate(),
|
||||
reqVO.getFileMappingId()))
|
||||
.orElseThrow();
|
||||
|
||||
return ResponseEntity.status(HttpStatus.OK).body(article);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package app.module.front.usecase.article.createArticle.adapters.web.model;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.apache.commons.text.StringEscapeUtils;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode
|
||||
public class CreateArticleReqVO {
|
||||
|
||||
@NotBlank(message = "{valid.common.required}")
|
||||
private String title;
|
||||
|
||||
@NotBlank(message = "{valid.common.required}")
|
||||
private String content;
|
||||
|
||||
@NotNull(message = "{valid.common.required}")
|
||||
private Boolean visible;
|
||||
|
||||
@NotNull(message = "{valid.common.required}")
|
||||
private LocalDateTime startDate;
|
||||
|
||||
@NotNull(message = "{valid.common.required}")
|
||||
private LocalDateTime endDate;
|
||||
|
||||
private List<String> fileMappingId;
|
||||
|
||||
public String getTitle() {
|
||||
return StringEscapeUtils.escapeHtml4(title);
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return StringEscapeUtils.escapeHtml4(content);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package app.module.front.usecase.article.createArticle.adapters.web.validator;
|
||||
|
||||
import app.module.core.config.application.util.MessageUtil;
|
||||
import app.module.front.usecase.article.createArticle.adapters.web.model.CreateArticleReqVO;
|
||||
import java.time.LocalDateTime;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.validation.Errors;
|
||||
import org.springframework.validation.Validator;
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class CreateArticleValidator implements Validator {
|
||||
|
||||
private final MessageUtil messageUtil;
|
||||
|
||||
@Override
|
||||
public boolean supports(Class<?> clazz) {
|
||||
return CreateArticleReqVO.class.equals(clazz);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate(Object target, Errors errors) {
|
||||
CreateArticleReqVO vo = (CreateArticleReqVO) target;
|
||||
|
||||
LocalDateTime startDate = vo.getStartDate();
|
||||
LocalDateTime endDate = vo.getEndDate();
|
||||
|
||||
// 게시일 날짜 체크
|
||||
if (startDate == null) {
|
||||
errors.rejectValue(
|
||||
"startDate", "valid.common.required",
|
||||
messageUtil.getMessage("valid.common.required"));
|
||||
}
|
||||
|
||||
if (endDate == null) {
|
||||
errors.rejectValue(
|
||||
"endDate", "valid.common.required",
|
||||
messageUtil.getMessage("valid.common.required"));
|
||||
}
|
||||
|
||||
if (startDate != null && endDate != null) {
|
||||
if (!startDate.isBefore(endDate)) {
|
||||
errors.rejectValue(
|
||||
"startDate",
|
||||
"valid.common.date.invalid",
|
||||
messageUtil.getMessage("valid.common.date.invalid"));
|
||||
errors.rejectValue(
|
||||
"endDate",
|
||||
"valid.common.date.invalid",
|
||||
messageUtil.getMessage("valid.common.date.invalid"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package app.module.front.usecase.article.createArticleUI;
|
||||
|
||||
import app.module.front.usecase.article.createArticleUI.model.CreateArticleUIReqVO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
|
||||
@Controller
|
||||
@RequiredArgsConstructor
|
||||
class CreateArticleUIController {
|
||||
|
||||
@GetMapping(path = "/board/articles/create")
|
||||
String operate(
|
||||
Model model,
|
||||
@ModelAttribute("reqVO") CreateArticleUIReqVO reqVO) {
|
||||
|
||||
return "board/articles/create";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package app.module.front.usecase.article.createArticleUI.model;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode
|
||||
public class CreateArticleUIReqVO {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package app.module.front.usecase.article.getArticle.adapters.web;
|
||||
|
||||
import app.module.core.usecase.article.getArticle.ports.GetArticlePortIn;
|
||||
import app.module.core.usecase.article.getArticle.ports.application.domain.GetArticleCmd;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
class GetArticleController {
|
||||
|
||||
private final GetArticlePortIn getArticlePortIn;
|
||||
|
||||
@GetMapping(path = "/api/front/board/articles/{id}")
|
||||
ResponseEntity<?> operate(@PathVariable Long id) {
|
||||
return ResponseEntity.status(HttpStatus.OK)
|
||||
.body(getArticlePortIn.operate(new GetArticleCmd(id)).orElseThrow());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package app.module.front.usecase.article.getArticleUI.adapters.web;
|
||||
|
||||
import app.module.core.config.application.util.CommonUtil;
|
||||
import app.module.core.usecase.article.getArticle.ports.GetArticlePortIn;
|
||||
import app.module.core.usecase.article.getArticle.ports.application.domain.GetArticle;
|
||||
import app.module.core.usecase.article.getArticle.ports.application.domain.GetArticleCmd;
|
||||
import app.module.front.usecase.article.getArticleUI.adapters.web.model.GetArticleUIReqVO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
|
||||
@Controller
|
||||
@RequiredArgsConstructor
|
||||
class GetArticleUIController {
|
||||
|
||||
private final GetArticlePortIn getArticlePortIn;
|
||||
|
||||
@GetMapping(path = "/board/articles/{id}")
|
||||
String operate(
|
||||
Model model,
|
||||
@PathVariable @ModelAttribute("id") Long id,
|
||||
@ModelAttribute("reqVO") GetArticleUIReqVO reqVO) {
|
||||
|
||||
GetArticle getArticle =
|
||||
getArticlePortIn.operate(new GetArticleCmd(id)).orElseThrow();
|
||||
|
||||
// 로그인 사용자와 게시물 작성자가 동일한지 체크
|
||||
model.addAttribute("isAuthor",
|
||||
getArticle.getCreatedBy().equals(CommonUtil.getLoginUsername()));
|
||||
model.addAttribute("article", getArticle);
|
||||
|
||||
return "board/articles/{id}";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package app.module.front.usecase.article.getArticleUI.adapters.web.model;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode
|
||||
public class GetArticleUIReqVO {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package app.module.front.usecase.article.getArticles.adapters.web;
|
||||
|
||||
import app.module.core.usecase.article.getArticles.ports.GetArticlesPortIn;
|
||||
import app.module.core.usecase.article.getArticles.ports.application.domain.GetArticles;
|
||||
import app.module.core.usecase.article.getArticles.ports.application.domain.GetArticlesCmd;
|
||||
import app.module.front.usecase.article.getArticles.adapters.web.model.GetArticlesReqVO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.web.PageableDefault;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
class GetArticlesController {
|
||||
|
||||
private final GetArticlesPortIn getArticlesPortIn;
|
||||
|
||||
@GetMapping(path = "/api/board/articles")
|
||||
ResponseEntity<?> operate(@PageableDefault Pageable pageable, GetArticlesReqVO reqVO) {
|
||||
Page<GetArticles> articles =
|
||||
getArticlesPortIn.operate(
|
||||
pageable,
|
||||
new GetArticlesCmd(
|
||||
reqVO.getSearchField(), reqVO.getSearchValue(), reqVO.getSearchOpen()));
|
||||
|
||||
return ResponseEntity.status(HttpStatus.OK).body(articles);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package app.module.front.usecase.article.getArticles.adapters.web.model;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode
|
||||
public class GetArticlesReqVO {
|
||||
|
||||
private String searchField;
|
||||
private String searchValue;
|
||||
private String searchOpen;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package app.module.front.usecase.article.getArticlesUI;
|
||||
|
||||
import app.module.core.usecase.uicode.list.ports.UICodeListPortIn;
|
||||
import app.module.front.usecase.article.getArticlesUI.model.GetArticlesUIReqVO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
|
||||
@Controller
|
||||
@RequiredArgsConstructor
|
||||
class GetArticlesUIController {
|
||||
|
||||
private final UICodeListPortIn uiCodeListPortIn;
|
||||
|
||||
@GetMapping(path = "/board/articles")
|
||||
String operate(
|
||||
Model model,
|
||||
@ModelAttribute("reqVO") GetArticlesUIReqVO reqVO) {
|
||||
|
||||
model.addAttribute("pageRows", uiCodeListPortIn.connect("code.pageable.rows"));
|
||||
|
||||
return "board/articles";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package app.module.front.usecase.article.getArticlesUI.model;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.thymeleaf.util.StringUtils;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode
|
||||
public class GetArticlesUIReqVO {
|
||||
|
||||
private Integer page;
|
||||
private String sort;
|
||||
private Integer size;
|
||||
private String searchField;
|
||||
private String searchValue;
|
||||
private String searchOpen;
|
||||
|
||||
public Integer getPage() {
|
||||
// 요청 페이지 넘버 - 초기값 `0`
|
||||
return page != null ? page : 0;
|
||||
}
|
||||
|
||||
public String getSort() {
|
||||
// 정렬 값 - 초기값 `orderNo 내림차순`
|
||||
return StringUtils.isEmpty(sort) ? "orderNo,DESC" : sort;
|
||||
}
|
||||
|
||||
public Integer getSize() {
|
||||
// 페이지 당 아이템 수 - 초기값 `10`
|
||||
return size != null ? size : 10;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package app.module.front.usecase.article.removeArticles.adapters.web;
|
||||
|
||||
import app.module.core.usecase.article.removeArticles.ports.RemoveArticlesPortIn;
|
||||
import app.module.core.usecase.article.removeArticles.ports.application.domain.RemoveArticlesCmd;
|
||||
import app.module.front.usecase.article.removeArticles.adapters.web.model.RemoveArticlesReqVO;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
class RemoveArticlesController {
|
||||
|
||||
private final RemoveArticlesPortIn removeArticlesPortIn;
|
||||
|
||||
@DeleteMapping(path = "/api/front/board/articles/remove")
|
||||
ResponseEntity<?> operate(@Valid RemoveArticlesReqVO reqVO, BindingResult bindingResult) {
|
||||
if (bindingResult.hasErrors()) {
|
||||
return ResponseEntity.status(HttpStatus.UNPROCESSABLE_ENTITY)
|
||||
.body(bindingResult.getFieldErrors());
|
||||
}
|
||||
|
||||
removeArticlesPortIn.operate(new RemoveArticlesCmd(reqVO.getSelectIds()));
|
||||
|
||||
return ResponseEntity.status(HttpStatus.OK).body(reqVO);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package app.module.front.usecase.article.removeArticles.adapters.web.model;
|
||||
|
||||
import java.util.Set;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode
|
||||
public class RemoveArticlesReqVO {
|
||||
|
||||
private Set<Long> selectIds;
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package app.module.front.usecase.article.updateArticle.adapters.web;
|
||||
|
||||
import app.module.core.usecase.article.updateArticle.ports.UpdateArticlePortIn;
|
||||
import app.module.core.usecase.article.updateArticle.ports.application.domain.UpdateArticleCmd;
|
||||
import app.module.front.usecase.article.updateArticle.adapters.web.model.UpdateArticleReqVO;
|
||||
import app.module.front.usecase.article.updateArticle.adapters.web.validator.UpdateArticleValidator;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
class UpdateArticleController {
|
||||
|
||||
private final UpdateArticlePortIn updateArticlePortIn;
|
||||
private final UpdateArticleValidator updateArticleValidator;
|
||||
|
||||
@PutMapping(path = "/api/front/board/articles/update")
|
||||
ResponseEntity<?> operate(@Valid UpdateArticleReqVO reqVO, BindingResult bindingResult) {
|
||||
updateArticleValidator.validate(reqVO, bindingResult);
|
||||
|
||||
if (bindingResult.hasErrors()) {
|
||||
return ResponseEntity.status(HttpStatus.UNPROCESSABLE_ENTITY)
|
||||
.body(bindingResult.getFieldErrors());
|
||||
}
|
||||
|
||||
updateArticlePortIn.operate(
|
||||
new UpdateArticleCmd(
|
||||
reqVO.getId(),
|
||||
reqVO.getTitle(),
|
||||
reqVO.getContent(),
|
||||
reqVO.getVisible(),
|
||||
reqVO.getOrderNo(),
|
||||
reqVO.getStartDate(),
|
||||
reqVO.getEndDate(),
|
||||
reqVO.getFileMappingId()));
|
||||
|
||||
return ResponseEntity.status(HttpStatus.OK).body(reqVO);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package app.module.front.usecase.article.updateArticle.adapters.web.model;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.apache.commons.text.StringEscapeUtils;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode
|
||||
public class UpdateArticleReqVO {
|
||||
|
||||
@NotNull(message = "{valid.common.required}")
|
||||
private Long id;
|
||||
|
||||
@NotBlank(message = "{valid.common.required}")
|
||||
private String title;
|
||||
|
||||
@NotBlank(message = "{valid.common.required}")
|
||||
private String content;
|
||||
|
||||
@NotNull(message = "{valid.common.required}")
|
||||
private Boolean visible;
|
||||
|
||||
@NotNull(message = "{valid.common.required}")
|
||||
private Integer orderNo;
|
||||
|
||||
@NotNull(message = "{valid.common.required}")
|
||||
private LocalDateTime startDate;
|
||||
|
||||
@NotNull(message = "{valid.common.required}")
|
||||
private LocalDateTime endDate;
|
||||
|
||||
private List<String> fileMappingId;
|
||||
|
||||
public String getTitle() {
|
||||
return StringEscapeUtils.escapeHtml4(title);
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return StringEscapeUtils.escapeHtml4(content);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package app.module.front.usecase.article.updateArticle.adapters.web.validator;
|
||||
|
||||
import app.module.core.config.application.util.MessageUtil;
|
||||
import app.module.front.usecase.article.updateArticle.adapters.web.model.UpdateArticleReqVO;
|
||||
import java.time.LocalDateTime;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.validation.Errors;
|
||||
import org.springframework.validation.Validator;
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class UpdateArticleValidator implements Validator {
|
||||
|
||||
private final MessageUtil messageUtil;
|
||||
|
||||
@Override
|
||||
public boolean supports(Class<?> clazz) {
|
||||
return UpdateArticleReqVO.class.equals(clazz);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate(Object target, Errors errors) {
|
||||
UpdateArticleReqVO vo = (UpdateArticleReqVO) target;
|
||||
|
||||
LocalDateTime startDate = vo.getStartDate();
|
||||
LocalDateTime endDate = vo.getEndDate();
|
||||
|
||||
// 게시일 날짜 체크
|
||||
if (startDate == null) {
|
||||
errors.rejectValue(
|
||||
"startDate", "valid.common.required",
|
||||
messageUtil.getMessage("valid.common.required"));
|
||||
}
|
||||
|
||||
if (endDate == null) {
|
||||
errors.rejectValue(
|
||||
"endDate", "valid.common.required",
|
||||
messageUtil.getMessage("valid.common.required"));
|
||||
}
|
||||
|
||||
if (startDate != null && endDate != null) {
|
||||
if (!startDate.isBefore(endDate)) {
|
||||
errors.rejectValue(
|
||||
"startDate",
|
||||
"valid.common.date.invalid",
|
||||
messageUtil.getMessage("valid.common.date.invalid"));
|
||||
errors.rejectValue(
|
||||
"endDate",
|
||||
"valid.common.date.invalid",
|
||||
messageUtil.getMessage("valid.common.date.invalid"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package app.module.front.usecase.article.updateArticleUI.adapters.web;
|
||||
|
||||
import app.module.core.config.application.util.CommonUtil;
|
||||
import app.module.core.usecase.article.getArticle.ports.GetArticlePortIn;
|
||||
import app.module.core.usecase.article.getArticle.ports.application.domain.GetArticleCmd;
|
||||
import app.module.front.usecase.article.updateArticleUI.adapters.web.model.UpdateArticleUIReqVO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
|
||||
@Controller
|
||||
@RequiredArgsConstructor
|
||||
class UpdateArticleUIController {
|
||||
|
||||
private final GetArticlePortIn getArticlePortIn;
|
||||
|
||||
@GetMapping(path = "/board/articles/update/{id}")
|
||||
String operate(
|
||||
Model model,
|
||||
@PathVariable @ModelAttribute("id") Long id,
|
||||
@ModelAttribute("reqVO") UpdateArticleUIReqVO reqVO) {
|
||||
|
||||
getArticlePortIn.operate(new GetArticleCmd(id))
|
||||
.filter(article -> article.getCreatedBy().equals(CommonUtil.getLoginUsername()))
|
||||
.orElseThrow(() -> new RuntimeException("수정 권한이 없는 사용자입니다."));
|
||||
|
||||
return "board/articles/update/{id}";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package app.module.front.usecase.article.updateArticleUI.adapters.web.model;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode
|
||||
public class UpdateArticleUIReqVO {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package app.module.front.usecase.editor.adapters.web;
|
||||
|
||||
import app.module.core.config.application.enums.FileUploadType;
|
||||
import app.module.core.usecase.file.saveToStorage.ports.SaveToStoragePortIn;
|
||||
import app.module.core.usecase.file.saveToStorage.ports.application.domain.SaveToStorage;
|
||||
import app.module.core.usecase.file.url.application.port.in.FileUrlPortIn;
|
||||
import java.io.IOException;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@Controller
|
||||
@RequiredArgsConstructor
|
||||
public class EditorImageUploadController {
|
||||
|
||||
private final SaveToStoragePortIn saveToStoragePortIn;
|
||||
private final FileUrlPortIn fileUrlPortIn;
|
||||
|
||||
@PostMapping(path = "/api/front/editorImage/upload")
|
||||
ResponseEntity<?> editorImageUpload(MultipartFile editorImage) throws IOException {
|
||||
SaveToStorage saveToStorage =
|
||||
saveToStoragePortIn.operate(FileUploadType.EDITOR_IMAGE, editorImage).orElseThrow();
|
||||
|
||||
return ResponseEntity.status(HttpStatus.OK)
|
||||
.body(
|
||||
fileUrlPortIn.getInline(
|
||||
saveToStorage.getType().getFileStorageType(),
|
||||
saveToStorage.getPath(),
|
||||
saveToStorage.getName()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package app.module.front.usecase.home.index.adapter.web;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
@Controller
|
||||
@RequiredArgsConstructor
|
||||
public class HomeController {
|
||||
|
||||
@GetMapping(path = "/")
|
||||
public String home() {
|
||||
return "home";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package app.module.front.usecase.security.login.adapter.web;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
@Controller
|
||||
public class LoginController {
|
||||
|
||||
@GetMapping("/login")
|
||||
public String login() {
|
||||
return "security/login";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package app.module.front.usecase.user.createUser.adapters.web;
|
||||
|
||||
import app.module.core.config.application.enums.SignUpType;
|
||||
import app.module.core.config.application.util.CoreUtil;
|
||||
import app.module.core.usecase.user.createUser.ports.CreateUserPortIn;
|
||||
import app.module.core.usecase.user.createUser.ports.application.domain.CreateUser;
|
||||
import app.module.core.usecase.user.createUser.ports.application.domain.CreateUserCmd;
|
||||
import app.module.front.usecase.user.createUser.adapters.web.model.CreateUserReqVO;
|
||||
import app.module.front.usecase.user.createUser.adapters.web.validator.CreateUserValidator;
|
||||
import jakarta.validation.Valid;
|
||||
import java.util.Set;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
class CreateUserController {
|
||||
|
||||
private final CreateUserPortIn createUserPortIn;
|
||||
private final CreateUserValidator createUserValidator;
|
||||
private final CoreUtil coreUtil;
|
||||
|
||||
@PostMapping(path = "/api/public/user/create")
|
||||
ResponseEntity<?> operate(@Valid CreateUserReqVO reqVO, BindingResult bindingResult) {
|
||||
|
||||
createUserValidator.validate(reqVO, bindingResult);
|
||||
if (bindingResult.hasErrors()) {
|
||||
return coreUtil.getErrorInfo(bindingResult);
|
||||
}
|
||||
|
||||
CreateUser user =
|
||||
createUserPortIn
|
||||
.operate(
|
||||
new CreateUserCmd(
|
||||
reqVO.getId(),
|
||||
reqVO.getPassword(),
|
||||
reqVO.getEmail(),
|
||||
reqVO.getNickname(),
|
||||
SignUpType.NORMAL,
|
||||
false,
|
||||
0,
|
||||
false,
|
||||
Set.of("ROLE_GENERAL")))
|
||||
.orElseThrow();
|
||||
|
||||
return ResponseEntity.status(HttpStatus.OK).body(user);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package app.module.front.usecase.user.createUser.adapters.web.model;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.Pattern;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode
|
||||
public class CreateUserReqVO {
|
||||
|
||||
@NotBlank(message = "{valid.common.required}")
|
||||
private String id;
|
||||
|
||||
@NotBlank(message = "{valid.common.required}")
|
||||
private String password;
|
||||
|
||||
@NotBlank(message = "{valid.common.required}")
|
||||
private String passwordRe;
|
||||
|
||||
@NotBlank(message = "{valid.common.required}")
|
||||
private String email;
|
||||
|
||||
@NotBlank(message = "{valid.common.required}")
|
||||
@Pattern(regexp = "^[가-힣a-zA-Z0-9_-]{2,10}$", message = "{valid.common.nickname.wrong}")
|
||||
private String nickname;
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package app.module.front.usecase.user.createUser.adapters.web.validator;
|
||||
|
||||
import app.module.front.usecase.user.createUser.adapters.web.model.CreateUserReqVO;
|
||||
import java.util.Optional;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.validation.Errors;
|
||||
import org.springframework.validation.Validator;
|
||||
|
||||
@Component
|
||||
public class CreateUserValidator implements Validator {
|
||||
|
||||
private final String ID_REGEX = "^[a-zA-Z0-9_-]{6,12}$";
|
||||
private final String PASSWORD_REGEX = "^((?=.*[a-z])(?=.*[A-Z])(?=.*[!@#$%_\\-])\\S{6,15})$";
|
||||
private final String EMAIL_REGEX = "^[\\w!#$%&’*+/=?`{|}~^-]+(?:\\.[\\w!#$%&’*+/=?`{|}~^-]+)*@(?:[a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,6}$";
|
||||
|
||||
@Override
|
||||
public boolean supports(Class<?> clazz) {
|
||||
return CreateUserReqVO.class.equals(clazz);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate(Object target, Errors errors) {
|
||||
CreateUserReqVO vo = (CreateUserReqVO) target;
|
||||
|
||||
// 아이디
|
||||
Optional.ofNullable(vo.getId())
|
||||
.filter(id -> !id.isEmpty() && !id.matches(ID_REGEX))
|
||||
.ifPresent(id -> errors.rejectValue("id", "valid.common.id.wrong"));
|
||||
|
||||
// 비밀번호
|
||||
Optional.ofNullable(vo.getPassword())
|
||||
.filter(password -> !password.isEmpty() && !password.matches(PASSWORD_REGEX))
|
||||
.ifPresent(password -> errors.rejectValue("password", "valid.common.password.wrong"));
|
||||
|
||||
// 비밀번호 재확인
|
||||
Optional.ofNullable(vo.getPasswordRe())
|
||||
.filter(passwordRe -> !passwordRe.isEmpty() && !passwordRe.equals(vo.getPassword()))
|
||||
.ifPresent(
|
||||
passwordRe -> errors.rejectValue("passwordRe", "valid.common.re.password.wrong"));
|
||||
|
||||
// 이메일
|
||||
Optional.ofNullable(vo.getEmail())
|
||||
.filter(email -> !email.isEmpty() && !email.matches(EMAIL_REGEX))
|
||||
.ifPresent(email -> errors.rejectValue("email", "valid.common.email.wrong"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package app.module.front.usecase.user.createUserUI.adapters.web;
|
||||
|
||||
import app.module.front.usecase.user.createUserUI.adapters.web.model.CreateUserUIReqVO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
|
||||
@Controller
|
||||
@RequiredArgsConstructor
|
||||
class CreateUserUIController {
|
||||
|
||||
@GetMapping(path = "/user/register")
|
||||
String operate(Model model, @ModelAttribute("reqVO") CreateUserUIReqVO reqVO) {
|
||||
|
||||
return "user/register";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package app.module.front.usecase.user.createUserUI.adapters.web.model;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode
|
||||
public class CreateUserUIReqVO {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package app.module.front.usecase.user.social.parseSocialUser.ports;
|
||||
|
||||
import app.module.front.usecase.user.social.parseSocialUser.ports.application.domain.ParseSocialUserCmd;
|
||||
import app.module.front.usecase.user.social.parseSocialUser.ports.application.domain.ParsedUserInfo;
|
||||
import java.util.Optional;
|
||||
|
||||
public interface ParseSocialUserPortIn {
|
||||
|
||||
Optional<ParsedUserInfo> operate(ParseSocialUserCmd cmd);
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package app.module.front.usecase.user.social.parseSocialUser.ports.application;
|
||||
|
||||
import app.module.front.usecase.user.social.parseSocialUser.ports.ParseSocialUserPortIn;
|
||||
import app.module.front.usecase.user.social.parseSocialUser.ports.application.domain.KakaoUserInfo;
|
||||
import app.module.front.usecase.user.social.parseSocialUser.ports.application.domain.NaverUserInfo;
|
||||
import app.module.front.usecase.user.social.parseSocialUser.ports.application.domain.ParseSocialUserCmd;
|
||||
import app.module.front.usecase.user.social.parseSocialUser.ports.application.domain.ParsedUserInfo;
|
||||
import java.util.Optional;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
class ParseSocialUserService implements ParseSocialUserPortIn {
|
||||
|
||||
@Override
|
||||
public Optional<ParsedUserInfo> operate(ParseSocialUserCmd cmd) {
|
||||
ParsedUserInfo parsedUserInfo = null;
|
||||
|
||||
switch (cmd.getSocialType()) {
|
||||
case KAKAO -> {
|
||||
parsedUserInfo = new KakaoUserInfo(cmd.getUserNameAttributeName(),
|
||||
cmd.getAttributes());
|
||||
}
|
||||
case NAVER -> {
|
||||
parsedUserInfo = new NaverUserInfo(cmd.getUserNameAttributeName(),
|
||||
cmd.getAttributes());
|
||||
}
|
||||
}
|
||||
|
||||
if (parsedUserInfo != null) {
|
||||
log.info("socialId: {}", parsedUserInfo.getSocialId());
|
||||
log.info("nickname: {}", parsedUserInfo.getNickName());
|
||||
log.info("name: {}", parsedUserInfo.getName());
|
||||
log.info("ci: {}", parsedUserInfo.getCi());
|
||||
log.info("birthday: {}", parsedUserInfo.getBirthday());
|
||||
log.info("email: {}", parsedUserInfo.getEmail());
|
||||
log.info("phone: {}", parsedUserInfo.getPhone());
|
||||
}
|
||||
|
||||
return Optional.ofNullable(parsedUserInfo);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
package app.module.front.usecase.user.social.parseSocialUser.ports.application.domain;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
public class KakaoUserInfo implements ParsedUserInfo {
|
||||
|
||||
private final String userNameAttribute;
|
||||
private final Map<String, Object> attributes;
|
||||
|
||||
public KakaoUserInfo(String userNameAttribute, Map<String, Object> attributes) {
|
||||
this.userNameAttribute = userNameAttribute;
|
||||
this.attributes = attributes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSocialId() {
|
||||
return String.valueOf(attributes.get(userNameAttribute));
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public String getNickName() {
|
||||
Map<String, Object> account = (Map<String, Object>) attributes.get("kakao_account");
|
||||
Map<String, Object> profile = (Map<String, Object>) account.get("profile");
|
||||
|
||||
return (String) profile.get("nickname");
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public String getName() {
|
||||
Map<String, Object> account = (Map<String, Object>) attributes.get("kakao_account");
|
||||
|
||||
if (account == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 카카오 로그인 서비스 인증 전에 이름 정보는 전달되지 않는다.
|
||||
if (account.get("name") == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (String) account.get("name");
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public String getEmail() {
|
||||
Map<String, Object> account = (Map<String, Object>) attributes.get("kakao_account");
|
||||
|
||||
if (account == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String email = (String) account.get("email");
|
||||
|
||||
// 카카오 로그인 서비스 인증 전에 이메일 정보는 전달되지 않는다.
|
||||
return Objects.requireNonNullElse(email, "NO-KAKAO-EMAIL@noemail.com");
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public String getPhone() {
|
||||
Map<String, Object> account = (Map<String, Object>) attributes.get("kakao_account");
|
||||
|
||||
if (account == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 카카오 로그인 서비스 인증 전에 phone 정보는 전달되지 않는다.
|
||||
if (account.get("phone_number") == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// "0" + s.replaceAll("^\\+\\d{1,3}-?|-", "").trim();
|
||||
return (String) account.get("phone_number");
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public String getBirthday() {
|
||||
Map<String, Object> account = (Map<String, Object>) attributes.get("kakao_account");
|
||||
|
||||
if (account == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String birthyear = (String) account.get("birthyear");
|
||||
String birthday = (String) account.get("birthday");
|
||||
|
||||
// 카카오 로그인 서비스 인증 전에 생년월일 정보는 전달되지 않는다.
|
||||
if (birthyear == null || birthday == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return birthyear + birthday;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public String getCi() {
|
||||
Map<String, Object> account = (Map<String, Object>) attributes.get("kakao_account");
|
||||
|
||||
if (account == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 카카오 로그인 서비스 인증 전에 CI 정보는 전달되지 않는다.
|
||||
if (account.get("ci") == null || ((String) account.get("ci")).equals("")) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (String) account.get("ci");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package app.module.front.usecase.user.social.parseSocialUser.ports.application.domain;
|
||||
|
||||
import java.util.Map;
|
||||
import lombok.ToString;
|
||||
|
||||
@ToString
|
||||
public class NaverUserInfo implements ParsedUserInfo {
|
||||
|
||||
private final String userNameAttribute;
|
||||
private final Map<String, Object> attributes;
|
||||
|
||||
public NaverUserInfo(String userNameAttribute, Map<String, Object> attributes) {
|
||||
this.userNameAttribute = userNameAttribute;
|
||||
this.attributes = attributes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSocialId() {
|
||||
return (String) getAttrs().get("id");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNickName() {
|
||||
return (String) getAttrs().get("nickname");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return (String) getAttrs().get("name");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEmail() {
|
||||
return (String) getAttrs().get("email");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPhone() {
|
||||
String phone = (String) getAttrs().get("mobile");
|
||||
return phone != null ? phone.replaceAll("-", "") : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBirthday() {
|
||||
String birthYear = (String) getAttrs().get("birthyear");
|
||||
String birthday = (String) getAttrs().get("birthday");
|
||||
return (birthYear + birthday).replaceAll("-", "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCi() {
|
||||
// 네이버 로그인 서비스 인증 전에 CI 정보는 전달되지 않는다.
|
||||
return (String) getAttrs().get("ci");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Map<String, Object> getAttrs() {
|
||||
return (Map<String, Object>) attributes.get(userNameAttribute);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package app.module.front.usecase.user.social.parseSocialUser.ports.application.domain;
|
||||
|
||||
import app.module.core.config.application.enums.SocialType;
|
||||
import java.util.Map;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode
|
||||
public class ParseSocialUserCmd {
|
||||
|
||||
private SocialType socialType;
|
||||
private String userNameAttributeName;
|
||||
private Map<String, Object> attributes;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package app.module.front.usecase.user.social.parseSocialUser.ports.application.domain;
|
||||
|
||||
public interface ParsedUserInfo {
|
||||
|
||||
String getSocialId();
|
||||
|
||||
String getNickName();
|
||||
|
||||
String getName();
|
||||
|
||||
String getEmail();
|
||||
|
||||
String getPhone();
|
||||
|
||||
String getBirthday();
|
||||
|
||||
String getCi();
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package app.module.front.usecase.user.social.processSocialLogin.adapters.persistence;
|
||||
|
||||
import app.module.core.config.adapters.persistence.entity.FrontUserSocial;
|
||||
import app.module.core.config.application.enums.SocialType;
|
||||
import java.util.Optional;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface FrontUserSocialRepo {
|
||||
|
||||
Optional<FrontUserSocial> findBySocialTypeAndSocialId(SocialType socialType, String socialId);
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package app.module.front.usecase.user.social.processSocialLogin.adapters.persistence;
|
||||
|
||||
import app.module.core.config.adapters.persistence.entity.FrontUserSocial;
|
||||
import app.module.front.usecase.user.social.processSocialLogin.ports.ProcessSocialLoginPortOut;
|
||||
import app.module.front.usecase.user.social.processSocialLogin.ports.application.domain.CreateUserSocialCmd;
|
||||
import app.module.front.usecase.user.social.processSocialLogin.ports.application.domain.GetUserSocial;
|
||||
import app.module.front.usecase.user.social.processSocialLogin.ports.application.domain.GetUserSocialCmd;
|
||||
import app.module.front.usecase.user.social.processSocialLogin.ports.application.domain.ProcessSocialLogin;
|
||||
import app.module.front.usecase.user.social.processSocialLogin.ports.application.domain.ProcessSocialLoginCmd;
|
||||
import java.util.Optional;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
@RequiredArgsConstructor
|
||||
class ProcessSocialLoginDao implements ProcessSocialLoginPortOut {
|
||||
|
||||
private final FrontUserSocialRepo frontUserSocialRepo;
|
||||
|
||||
@Override
|
||||
public Optional<ProcessSocialLogin> operate(ProcessSocialLoginCmd cmd) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<GetUserSocial> findUserSocial(GetUserSocialCmd cmd) {
|
||||
return frontUserSocialRepo
|
||||
.findBySocialTypeAndSocialId(cmd.getSocialType(), cmd.getSocialId())
|
||||
.flatMap(
|
||||
frontSocialUser ->
|
||||
Optional.of(
|
||||
new GetUserSocial(
|
||||
frontSocialUser.getSeq(),
|
||||
frontSocialUser.getUserId(),
|
||||
frontSocialUser.getSocialType(),
|
||||
frontSocialUser.getSocialId(),
|
||||
frontSocialUser.getEmail(),
|
||||
frontSocialUser.getName(),
|
||||
frontSocialUser.getCi())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<GetUserSocial> createUserSocial(CreateUserSocialCmd cmd) {
|
||||
// FrontUserSocial createUserSocial =
|
||||
// frontUserSocialRepo.save(
|
||||
// new FrontUserSocial(
|
||||
// null,
|
||||
// cmd.getUserId(),
|
||||
// cmd.getSocialType(),
|
||||
// cmd.getSocialId(),
|
||||
// cmd.getEmail(),
|
||||
// cmd.getName(),
|
||||
// cmd.getCi()));
|
||||
//
|
||||
// return Optional.of(
|
||||
// new GetUserSocial(
|
||||
// createUserSocial.getSeq(),
|
||||
// createUserSocial.getUserId(),
|
||||
// createUserSocial.getSocialType(),
|
||||
// createUserSocial.getSocialId(),
|
||||
// createUserSocial.getEmail(),
|
||||
// createUserSocial.getName(),
|
||||
// createUserSocial.getCi()));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package app.module.front.usecase.user.social.processSocialLogin.ports;
|
||||
|
||||
import app.module.core.config.adapters.web.security.domain.SocialUser;
|
||||
import app.module.front.usecase.user.social.processSocialLogin.ports.application.domain.ProcessSocialLoginCmd;
|
||||
import java.util.Optional;
|
||||
|
||||
public interface ProcessSocialLoginPortIn {
|
||||
|
||||
Optional<SocialUser> operate(ProcessSocialLoginCmd cmd);
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package app.module.front.usecase.user.social.processSocialLogin.ports;
|
||||
|
||||
import app.module.front.usecase.user.social.processSocialLogin.ports.application.domain.CreateUserSocialCmd;
|
||||
import app.module.front.usecase.user.social.processSocialLogin.ports.application.domain.GetUserSocial;
|
||||
import app.module.front.usecase.user.social.processSocialLogin.ports.application.domain.GetUserSocialCmd;
|
||||
import app.module.front.usecase.user.social.processSocialLogin.ports.application.domain.ProcessSocialLogin;
|
||||
import app.module.front.usecase.user.social.processSocialLogin.ports.application.domain.ProcessSocialLoginCmd;
|
||||
import java.util.Optional;
|
||||
|
||||
public interface ProcessSocialLoginPortOut {
|
||||
|
||||
Optional<ProcessSocialLogin> operate(ProcessSocialLoginCmd cmd);
|
||||
|
||||
Optional<GetUserSocial> findUserSocial(GetUserSocialCmd cmd);
|
||||
|
||||
Optional<GetUserSocial> createUserSocial(CreateUserSocialCmd cmd);
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
package app.module.front.usecase.user.social.processSocialLogin.ports.application;
|
||||
|
||||
import app.module.core.config.adapters.web.security.domain.CorePrivilege;
|
||||
import app.module.core.config.adapters.web.security.domain.CoreRole;
|
||||
import app.module.core.config.adapters.web.security.domain.SocialUser;
|
||||
import app.module.core.config.application.enums.SignUpType;
|
||||
import app.module.core.usecase.user.createUser.ports.CreateUserPortIn;
|
||||
import app.module.core.usecase.user.createUser.ports.application.domain.CreateUserCmd;
|
||||
import app.module.core.usecase.user.findUser.ports.FindUserPortIn;
|
||||
import app.module.core.usecase.user.findUser.ports.application.domain.FindUser;
|
||||
import app.module.core.usecase.user.findUser.ports.application.domain.FindUserCmd;
|
||||
import app.module.front.usecase.user.social.parseSocialUser.ports.ParseSocialUserPortIn;
|
||||
import app.module.front.usecase.user.social.parseSocialUser.ports.application.domain.ParseSocialUserCmd;
|
||||
import app.module.front.usecase.user.social.parseSocialUser.ports.application.domain.ParsedUserInfo;
|
||||
import app.module.front.usecase.user.social.processSocialLogin.ports.ProcessSocialLoginPortIn;
|
||||
import app.module.front.usecase.user.social.processSocialLogin.ports.ProcessSocialLoginPortOut;
|
||||
import app.module.front.usecase.user.social.processSocialLogin.ports.application.domain.CreateUserSocialCmd;
|
||||
import app.module.front.usecase.user.social.processSocialLogin.ports.application.domain.GetUserSocialCmd;
|
||||
import app.module.front.usecase.user.social.processSocialLogin.ports.application.domain.ProcessSocialLoginCmd;
|
||||
import java.util.Collection;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
class ProcessSocialLoginService implements ProcessSocialLoginPortIn {
|
||||
|
||||
private final ProcessSocialLoginPortOut portOut;
|
||||
private final ParseSocialUserPortIn parseSocialUserPortIn;
|
||||
private final FindUserPortIn findUserPortIn;
|
||||
private final CreateUserPortIn createUserPortIn;
|
||||
|
||||
@Override
|
||||
public Optional<SocialUser> operate(ProcessSocialLoginCmd cmd) {
|
||||
|
||||
// SNS Login Provider 가 제공하는 사용자 정보 파싱
|
||||
Optional<ParsedUserInfo> parsedUserInfo =
|
||||
parseSocialUserPortIn.operate(
|
||||
new ParseSocialUserCmd(
|
||||
cmd.getSocialType(), cmd.getUserNameAttributeName(), cmd.getAttributes()));
|
||||
|
||||
if (parsedUserInfo.isPresent()) {
|
||||
ParsedUserInfo parsedUser = parsedUserInfo.get();
|
||||
|
||||
return portOut
|
||||
.findUserSocial(new GetUserSocialCmd(cmd.getSocialType(), parsedUser.getSocialId()))
|
||||
.flatMap(
|
||||
getUserSocial ->
|
||||
findUserPortIn
|
||||
.operate(new FindUserCmd(getUserSocial.getUserId()))
|
||||
.flatMap(findUser -> getSocialUserOpt(findUser, cmd)))
|
||||
.or(
|
||||
() -> {
|
||||
// 신규 회원인 경우,
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
|
||||
return createUserPortIn
|
||||
.operate(
|
||||
new CreateUserCmd(
|
||||
uuid,
|
||||
"NO_PASSWD",
|
||||
parsedUser.getEmail(),
|
||||
parsedUser.getNickName(),
|
||||
SignUpType.SOCIAL,
|
||||
false,
|
||||
0,
|
||||
false,
|
||||
Set.of("ROLE_GENERAL")))
|
||||
.flatMap(
|
||||
createUser ->
|
||||
portOut.createUserSocial(
|
||||
new CreateUserSocialCmd(
|
||||
createUser.getId(),
|
||||
cmd.getSocialType(),
|
||||
parsedUser.getSocialId(),
|
||||
createUser.getEmail(),
|
||||
parsedUser.getName(),
|
||||
parsedUser.getCi())))
|
||||
.flatMap(
|
||||
getUserSocial ->
|
||||
findUserPortIn
|
||||
.operate(new FindUserCmd(getUserSocial.getUserId()))
|
||||
.flatMap(findUser -> getSocialUserOpt(findUser, cmd)));
|
||||
});
|
||||
}
|
||||
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
private Optional<SocialUser> getSocialUserOpt(FindUser findUser, ProcessSocialLoginCmd cmd) {
|
||||
boolean accountLocked = Optional.ofNullable(findUser.getAccountLocked()).orElse(false);
|
||||
boolean accountDisabled = Optional.ofNullable(findUser.getAccountDisabled()).orElse(false);
|
||||
|
||||
return Optional.of(
|
||||
new SocialUser(
|
||||
getAuthorities(findUser.getRoles()),
|
||||
cmd.getAttributes(),
|
||||
cmd.getUserNameAttributeName(),
|
||||
findUser.getId(),
|
||||
findUser.getPassword(),
|
||||
!accountDisabled,
|
||||
true,
|
||||
true,
|
||||
!accountLocked,
|
||||
findUser.getNickname(),
|
||||
0L));
|
||||
}
|
||||
|
||||
private Collection<? extends GrantedAuthority> getAuthorities(Collection<CoreRole> roles) {
|
||||
return Stream.concat(getRoles(roles), getPrivileges(roles))
|
||||
.map(SimpleGrantedAuthority::new)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private Stream<String> getRoles(Collection<CoreRole> roles) {
|
||||
return roles.stream().map(CoreRole::getId);
|
||||
}
|
||||
|
||||
private Stream<String> getPrivileges(Collection<CoreRole> roles) {
|
||||
return roles.stream()
|
||||
.flatMap(roleOutput -> roleOutput.getPrivileges().stream())
|
||||
.map(CorePrivilege::getId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package app.module.front.usecase.user.social.processSocialLogin.ports.application.domain;
|
||||
|
||||
import app.module.core.config.application.enums.SocialType;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode
|
||||
public class CreateUserSocialCmd {
|
||||
|
||||
private String userId;
|
||||
|
||||
private SocialType socialType;
|
||||
|
||||
private String socialId;
|
||||
|
||||
private String email;
|
||||
|
||||
private String name;
|
||||
|
||||
private String ci;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package app.module.front.usecase.user.social.processSocialLogin.ports.application.domain;
|
||||
|
||||
import app.module.core.config.application.enums.SocialType;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode
|
||||
public class GetUserSocial {
|
||||
|
||||
private Integer seq;
|
||||
|
||||
private String userId;
|
||||
|
||||
private SocialType socialType;
|
||||
|
||||
private String socialId;
|
||||
|
||||
private String email;
|
||||
|
||||
private String name;
|
||||
|
||||
private String ci;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package app.module.front.usecase.user.social.processSocialLogin.ports.application.domain;
|
||||
|
||||
import app.module.core.config.application.enums.SocialType;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode
|
||||
public class GetUserSocialCmd {
|
||||
|
||||
private SocialType socialType;
|
||||
private String socialId;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package app.module.front.usecase.user.social.processSocialLogin.ports.application.domain;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode
|
||||
public class ProcessSocialLogin {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package app.module.front.usecase.user.social.processSocialLogin.ports.application.domain;
|
||||
|
||||
import app.module.core.config.application.enums.SocialType;
|
||||
import java.util.Map;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode
|
||||
public class ProcessSocialLoginCmd {
|
||||
|
||||
private SocialType socialType;
|
||||
private String userNameAttributeName;
|
||||
private Map<String, Object> attributes;
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package app.module.front.usecase.user.updateUser.adapters.web;
|
||||
|
||||
import app.module.core.config.application.util.CoreUtil;
|
||||
import app.module.core.usecase.user.updateFrontUser.ports.UpdateFrontUserPortIn;
|
||||
import app.module.core.usecase.user.updateFrontUser.ports.application.domain.UpdateFrontUserInCmd;
|
||||
import app.module.front.usecase.user.updateUser.adapters.web.model.UpdateUserReqVO;
|
||||
import app.module.front.usecase.user.updateUser.adapters.web.validator.UpdateUserValidator;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.annotation.PatchMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
class UpdateUserController {
|
||||
|
||||
private final UpdateFrontUserPortIn updateFrontUserPortIn;
|
||||
private final UpdateUserValidator updateUserValidator;
|
||||
private final CoreUtil coreUtil;
|
||||
|
||||
@PatchMapping(path = "/api/front/user/update")
|
||||
ResponseEntity<?> operate(@Valid UpdateUserReqVO reqVO, BindingResult bindingResult) {
|
||||
|
||||
updateUserValidator.validate(reqVO, bindingResult);
|
||||
if (bindingResult.hasErrors()) {
|
||||
return coreUtil.getErrorInfo(bindingResult);
|
||||
}
|
||||
|
||||
updateFrontUserPortIn.operate(
|
||||
new UpdateFrontUserInCmd(
|
||||
reqVO.getPassword(), reqVO.getEmail(), reqVO.getNickname(),
|
||||
reqVO.getFileMappingId()));
|
||||
|
||||
return ResponseEntity.status(HttpStatus.OK).body(reqVO);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package app.module.front.usecase.user.updateUser.adapters.web.model;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.Pattern;
|
||||
import java.util.List;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode
|
||||
public class UpdateUserReqVO {
|
||||
|
||||
@NotBlank(message = "{valid.common.required}")
|
||||
private String id;
|
||||
|
||||
private String password;
|
||||
private String passwordRe;
|
||||
|
||||
@NotBlank(message = "{valid.common.required}")
|
||||
private String email;
|
||||
|
||||
@NotBlank(message = "{valid.common.required}")
|
||||
@Pattern(regexp = "^[가-힣a-zA-Z0-9_-]{1,15}$", message = "{valid.common.nickname.wrong}")
|
||||
private String nickname;
|
||||
|
||||
private List<String> fileMappingId;
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package app.module.front.usecase.user.updateUser.adapters.web.validator;
|
||||
|
||||
import app.module.front.usecase.user.updateUser.adapters.web.model.UpdateUserReqVO;
|
||||
import java.util.Optional;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.validation.Errors;
|
||||
import org.springframework.validation.Validator;
|
||||
|
||||
@Component
|
||||
public class UpdateUserValidator implements Validator {
|
||||
|
||||
private final String PASSWORD_REGEX = "^((?=.*[a-z])(?=.*[A-Z])(?=.*[!@#$%_\\-])\\S{6,15})$";
|
||||
private final String EMAIL_REGEX = "^[\\w!#$%&’*+/=?`{|}~^-]+(?:\\.[\\w!#$%&’*+/=?`{|}~^-]+)*@(?:[a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,6}$";
|
||||
|
||||
@Override
|
||||
public boolean supports(Class<?> clazz) {
|
||||
return UpdateUserReqVO.class.equals(clazz);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate(Object target, Errors errors) {
|
||||
UpdateUserReqVO vo = (UpdateUserReqVO) target;
|
||||
|
||||
// 비밀번호
|
||||
Optional.ofNullable(vo.getPassword())
|
||||
.filter(password -> !password.isEmpty() && !password.matches(PASSWORD_REGEX))
|
||||
.ifPresent(password -> errors.rejectValue("password", "valid.common.password.wrong"));
|
||||
|
||||
// 비밀번호 재확인
|
||||
Optional.ofNullable(vo.getPasswordRe())
|
||||
.filter(passwordRe -> !passwordRe.isEmpty() && !passwordRe.equals(vo.getPassword()))
|
||||
.ifPresent(
|
||||
passwordRe -> errors.rejectValue("passwordRe", "valid.common.re.password.wrong"));
|
||||
|
||||
// 이메일
|
||||
Optional.ofNullable(vo.getEmail())
|
||||
.filter(email -> !email.isEmpty() && !email.matches(EMAIL_REGEX))
|
||||
.ifPresent(email -> errors.rejectValue("email", "valid.common.email.wrong"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package app.module.front.usecase.user.updateUserUI.adapters.web;
|
||||
|
||||
import app.module.core.config.application.util.CommonUtil;
|
||||
import app.module.core.usecase.user.findUser.ports.FindUserPortIn;
|
||||
import app.module.core.usecase.user.findUser.ports.application.domain.FindUserCmd;
|
||||
import app.module.front.usecase.user.updateUserUI.adapters.web.model.UpdateUserUIReqVO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
|
||||
@Controller
|
||||
@RequiredArgsConstructor
|
||||
class UpdateUserUIController {
|
||||
|
||||
private final FindUserPortIn findUserPortIn;
|
||||
|
||||
@GetMapping(path = "/user/info")
|
||||
String operate(Model model, @ModelAttribute("reqVO") UpdateUserUIReqVO reqVO) {
|
||||
|
||||
model.addAttribute("userInfo",
|
||||
findUserPortIn.operate(new FindUserCmd(CommonUtil.getLoginUsername())).orElseThrow());
|
||||
|
||||
return "user/info";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package app.module.front.usecase.user.updateUserUI.adapters.web.model;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode
|
||||
public class UpdateUserUIReqVO {
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user