최초 커밋!
This commit is contained in:
30
admin/src/main/java/app/module/admin/AdminApplication.java
Normal file
30
admin/src/main/java/app/module/admin/AdminApplication.java
Normal file
@@ -0,0 +1,30 @@
|
||||
package app.module.admin;
|
||||
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
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 AdminApplication extends SpringBootServletInitializer {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(AdminApplication.class, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* maven jar 배포시 필요없지만, war 배포를 선택한 경우 configure 오버라이드가 필요하기에 선언.
|
||||
*
|
||||
* @param builder
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
|
||||
return builder.sources(AdminApplication.class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
package app.module.admin.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.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class AdminURIInterceptor implements HandlerInterceptor {
|
||||
|
||||
private final URICurrentMatchingPortIn uriCurrentMatchingPortIn;
|
||||
private final URIAncestryPortIn uriAncestryPortIn;
|
||||
private final URITopTierPortIn topTierPortIn;
|
||||
|
||||
@Value("${app.aws.s3.domain:null}")
|
||||
private String cloudFrontDomain;
|
||||
|
||||
@Value("${app.aws.s3.bucketFolder:null}")
|
||||
private String bucketFolder;
|
||||
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
|
||||
Object handler)
|
||||
throws Exception {
|
||||
String requestURI = request.getRequestURI();
|
||||
|
||||
URICurrentMatching currentURI = uriCurrentMatchingPortIn.connect(AppType.ADMIN, 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.ADMIN);
|
||||
modelAndView.addObject("topNode", recursiveMapping(topTierOutput));
|
||||
|
||||
if (modelAndView.getModelMap().getAttribute("currentURI") == null) {
|
||||
modelAndView.addObject("currentURI", request.getAttribute("currentURI"));
|
||||
}
|
||||
|
||||
modelAndView.addObject(
|
||||
"menuHierarchy", uriAncestryPortIn.connect(AppType.ADMIN, request.getRequestURI()));
|
||||
|
||||
if (cloudFrontDomain != null && bucketFolder != null) {
|
||||
modelAndView.addObject("S3URL", "https://" + cloudFrontDomain + bucketFolder);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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,82 @@
|
||||
package app.module.admin.config.adapters.web.mvc;
|
||||
|
||||
import app.module.admin.config.adapters.web.interceptor.AdminURIInterceptor;
|
||||
import app.module.core.config.adapters.web.interceptor.URIAuthorizeInterceptor;
|
||||
import app.module.core.config.application.enums.PublicAccess;
|
||||
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 AdminWebMvcConfig implements WebMvcConfigurer {
|
||||
|
||||
private final AdminURIInterceptor adminURIInterceptor;
|
||||
private final URIAuthorizeInterceptor uriAuthorizeInterceptor;
|
||||
@Value("${path.upload.public}")
|
||||
private String publicPath;
|
||||
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
registry
|
||||
.addInterceptor(adminURIInterceptor)
|
||||
.addPathPatterns("/**")
|
||||
.excludePathPatterns(
|
||||
Arrays.stream(PublicAccess.values())
|
||||
.map(PublicAccess::getPath)
|
||||
.collect(Collectors.toList()))
|
||||
.excludePathPatterns("/api/**"); // api 는 menu 정보가 없기에 skip
|
||||
|
||||
registry
|
||||
.addInterceptor(uriAuthorizeInterceptor)
|
||||
.addPathPatterns("/**")
|
||||
.excludePathPatterns(
|
||||
Arrays.stream(PublicAccess.values())
|
||||
.map(PublicAccess::getPath)
|
||||
.collect(Collectors.toList()))
|
||||
.excludePathPatterns("/api/**"); // api 는 menu 정보가 없기에 skip
|
||||
|
||||
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,38 @@
|
||||
package app.module.admin.config.application.aop;
|
||||
|
||||
import app.module.core.config.application.enums.AppType;
|
||||
import app.module.core.config.application.enums.OperationLogType;
|
||||
import app.module.core.config.application.util.CommonUtil;
|
||||
import app.module.core.config.application.util.MessageUtil;
|
||||
import app.module.core.usecase.operationlog.save.application.domain.OperationLogSaveCommand;
|
||||
import app.module.core.usecase.operationlog.save.application.port.in.OperationLogSavePortIn;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
import org.aspectj.lang.annotation.After;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Aspect
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class LoginFailAspect {
|
||||
|
||||
private final OperationLogSavePortIn operationLogSavePortIn;
|
||||
private final MessageUtil messageUtil;
|
||||
|
||||
@After("@annotation(app.module.admin.config.application.aop.LoginFailOperateLog)")
|
||||
public void operate(JoinPoint joinPoint) throws Throwable {
|
||||
Object[] args = joinPoint.getArgs();
|
||||
HttpServletRequest request = (HttpServletRequest) args[0];
|
||||
String targetId = request.getParameter("username");
|
||||
|
||||
operationLogSavePortIn.connect(
|
||||
new OperationLogSaveCommand(
|
||||
AppType.ADMIN,
|
||||
OperationLogType.LOGIN_FAIL,
|
||||
targetId,
|
||||
CommonUtil.getClientIP(request),
|
||||
messageUtil.getMessage("operate.login.fail", targetId)));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package app.module.admin.config.application.aop;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Target(ElementType.METHOD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface LoginFailOperateLog {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package app.module.admin.config.application.aop;
|
||||
|
||||
import app.module.core.config.application.enums.AppType;
|
||||
import app.module.core.config.application.enums.OperationLogType;
|
||||
import app.module.core.config.application.util.CommonUtil;
|
||||
import app.module.core.config.application.util.MessageUtil;
|
||||
import app.module.core.usecase.operationlog.save.application.domain.OperationLogSaveCommand;
|
||||
import app.module.core.usecase.operationlog.save.application.port.in.OperationLogSavePortIn;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
import org.aspectj.lang.annotation.After;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Aspect
|
||||
@Component
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public class LoginSuccessAspect {
|
||||
|
||||
private final OperationLogSavePortIn operationLogSavePortIn;
|
||||
private final MessageUtil messageUtil;
|
||||
|
||||
@After("@annotation(app.module.admin.config.application.aop.LoginSuccessOperateLog)")
|
||||
public void operate(JoinPoint joinPoint) throws Throwable {
|
||||
Object[] args = joinPoint.getArgs();
|
||||
|
||||
HttpServletRequest request = (HttpServletRequest) args[0];
|
||||
Authentication authentication = (Authentication) args[2];
|
||||
|
||||
operationLogSavePortIn.connect(
|
||||
new OperationLogSaveCommand(
|
||||
AppType.ADMIN,
|
||||
OperationLogType.LOGIN_SUCCESS,
|
||||
null,
|
||||
CommonUtil.getClientIP(request),
|
||||
messageUtil.getMessage("operate.login.success", authentication.getName())));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package app.module.admin.config.application.aop;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Target(ElementType.METHOD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface LoginSuccessOperateLog {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
package app.module.admin.config.application.aop;
|
||||
|
||||
import app.module.core.config.adapters.web.security.domain.CoreRole;
|
||||
import app.module.core.config.application.enums.AppType;
|
||||
import app.module.core.config.application.enums.OperationLogType;
|
||||
import app.module.core.config.application.util.CommonUtil;
|
||||
import app.module.core.usecase.admin.view.ports.AdminViewPortIn;
|
||||
import app.module.core.usecase.admin.view.ports.application.domain.AdminView;
|
||||
import app.module.core.usecase.operationlog.save.application.domain.OperationLogSaveCommand;
|
||||
import app.module.core.usecase.operationlog.save.application.port.in.OperationLogSavePortIn;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.reflect.MethodSignature;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.thymeleaf.util.StringUtils;
|
||||
|
||||
@Aspect
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class RoleUpdateAspect {
|
||||
|
||||
private final AdminViewPortIn adminViewPortIn;
|
||||
private final OperationLogSavePortIn operationLogSavePortIn;
|
||||
|
||||
@Around(
|
||||
"execution(* app.module.core.usecase.admin.saveAdmin.ports.application.SaveAdminService.connect(..))")
|
||||
public Object operate(ProceedingJoinPoint joinPoint) throws Throwable {
|
||||
Object[] args = joinPoint.getArgs();
|
||||
|
||||
String adminId = (String) args[0];
|
||||
List<String> currentRoles = Collections.emptyList();
|
||||
|
||||
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
|
||||
Method method = signature.getMethod();
|
||||
|
||||
for (int i = 0; i < method.getParameters().length; i++) {
|
||||
String parameterName = method.getParameters()[i].getName();
|
||||
if (parameterName.equals("roleIds") && args[i] instanceof List) {
|
||||
currentRoles = (List<String>) args[i];
|
||||
}
|
||||
}
|
||||
|
||||
Optional<AdminView> beforeAdmin = adminViewPortIn.connect(adminId);
|
||||
|
||||
// List<String> currentRoles =
|
||||
// adminId.getWithRoles().stream()
|
||||
// .map(adminUserWithRole -> adminUserWithRole.getRole().getId())
|
||||
// .collect(Collectors.toList());
|
||||
|
||||
boolean createLog = false;
|
||||
|
||||
if (beforeAdmin.isPresent()) {
|
||||
List<String> beforeRoles =
|
||||
beforeAdmin.get().getRoles().stream().map(CoreRole::getId).toList();
|
||||
if (beforeRoles.size() != currentRoles.size()
|
||||
|| currentRoles.stream().anyMatch(item -> !beforeRoles.contains(item))) {
|
||||
createLog = true;
|
||||
}
|
||||
} else if (currentRoles.size() > 0) {
|
||||
createLog = true;
|
||||
}
|
||||
|
||||
if (createLog) {
|
||||
String operatorId = Optional.ofNullable(CommonUtil.getLoginUsername())
|
||||
.orElse("init data");
|
||||
HttpServletRequest request = CommonUtil.getRequest();
|
||||
|
||||
operationLogSavePortIn.connect(
|
||||
new OperationLogSaveCommand(
|
||||
AppType.ADMIN,
|
||||
OperationLogType.ROLE_UPDATE,
|
||||
adminId,
|
||||
request != null ? CommonUtil.getClientIP(request) : null,
|
||||
String.format(
|
||||
"`%s` grants [%s] permissions to `%s`",
|
||||
operatorId, StringUtils.join(currentRoles, ", "), adminId)));
|
||||
}
|
||||
|
||||
return joinPoint.proceed();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package app.module.admin.config.application.aop;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Target(ElementType.METHOD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface RoleUpdateOperateLog {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package app.module.admin.config.application.listener;
|
||||
|
||||
import jakarta.servlet.http.HttpSessionEvent;
|
||||
import jakarta.servlet.http.HttpSessionListener;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* Spring Boot 을 이용하지만 내장 Tomcat 이 아닌 외부 WAS 를 이용하는 경우 HttpSessionListener 를 이용해 Session 유효기간을 지정해야
|
||||
* 한다.
|
||||
*/
|
||||
@Component
|
||||
public class SessionListener implements HttpSessionListener {
|
||||
|
||||
@Value("${app.admin.session.validity.period.seconds}")
|
||||
Integer sessionValiditySeconds;
|
||||
|
||||
@Override
|
||||
public void sessionCreated(HttpSessionEvent se) {
|
||||
se.getSession().setMaxInactiveInterval(sessionValiditySeconds);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
package app.module.admin.config.application.security;
|
||||
|
||||
import app.module.core.config.application.enums.AppType;
|
||||
import app.module.core.config.application.enums.OperationLogType;
|
||||
import app.module.core.config.application.util.CommonUtil;
|
||||
import app.module.core.config.application.util.MessageUtil;
|
||||
import app.module.core.usecase.admin.status.ports.AdminUpdateAccountLockPortIn;
|
||||
import app.module.core.usecase.admin.status.ports.AdminUpdateLoginFailPortIn;
|
||||
import app.module.core.usecase.admin.view.ports.AdminViewPortIn;
|
||||
import app.module.core.usecase.operationlog.save.application.domain.OperationLogSaveCommand;
|
||||
import app.module.core.usecase.operationlog.save.application.port.in.OperationLogSavePortIn;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import java.util.Optional;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.event.EventListener;
|
||||
import org.springframework.security.authentication.BadCredentialsException;
|
||||
import org.springframework.security.authentication.event.AbstractAuthenticationFailureEvent;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class AdminAuthFailEvent {
|
||||
|
||||
private final AdminViewPortIn adminViewPortIn;
|
||||
private final AdminUpdateLoginFailPortIn updateLoginFailPortIn;
|
||||
private final AdminUpdateAccountLockPortIn updateAccountLockPortIn;
|
||||
private final OperationLogSavePortIn operationLogSavePortIn;
|
||||
private final MessageUtil messageUtil;
|
||||
@Value("${app.admin.auth.fail.permit}")
|
||||
private int failPermit;
|
||||
|
||||
@EventListener
|
||||
public void handleAuthenticationFailureEvent(AbstractAuthenticationFailureEvent event) {
|
||||
HttpServletRequest request =
|
||||
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
|
||||
|
||||
if (event.getException() instanceof BadCredentialsException) {
|
||||
adminViewPortIn
|
||||
.connect(request.getParameter("username"))
|
||||
.filter(admin -> admin.getAccountLocked() == null || !admin.getAccountLocked())
|
||||
.ifPresent(
|
||||
adminUserViewInfo -> {
|
||||
String adminUserId = adminUserViewInfo.getId();
|
||||
int failCnt =
|
||||
Optional.ofNullable(adminUserViewInfo.getLoginFailCnt()).orElse(0) + 1;
|
||||
updateLoginFailPortIn.connect(adminUserId, failCnt);
|
||||
|
||||
if (failCnt >= failPermit) {
|
||||
// 계정 잠금 처리
|
||||
updateAccountLockPortIn.connect(adminUserId, true);
|
||||
|
||||
// 계정 잠금 메세지 전달
|
||||
CommonUtil.addFlashAlertMessages(
|
||||
request.getSession(),
|
||||
messageUtil.getMessage("security.auth.fail.exceed", failPermit));
|
||||
|
||||
// 계정 잠금 로그 기록
|
||||
operationLogSavePortIn.connect(
|
||||
new OperationLogSaveCommand(
|
||||
AppType.ADMIN,
|
||||
OperationLogType.ACCOUNT_LOCKED,
|
||||
adminUserViewInfo.getId(),
|
||||
CommonUtil.getClientIP(request),
|
||||
messageUtil.getMessage(
|
||||
"operate.account.locked", adminUserViewInfo.getId())));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
package app.module.admin.config.application.security;
|
||||
|
||||
import app.module.admin.usecase.loggedinuser.save.ports.LoggedInUserSavePortIn;
|
||||
import app.module.admin.usecase.loggedinuser.save.ports.application.domain.LoggedInUserIdSaveCmd;
|
||||
import app.module.admin.usecase.loggedinuser.save.ports.application.domain.LoggedInUserSaveCmd;
|
||||
import app.module.admin.usecase.loggedinuser.view.ports.LoggedInUserViewPortIn;
|
||||
import app.module.admin.usecase.loggedinuser.view.ports.application.domain.LoggedInUserIdCmd;
|
||||
import app.module.admin.usecase.loggedinuser.view.ports.application.domain.LoggedInUserView;
|
||||
import app.module.core.config.application.enums.AppType;
|
||||
import app.module.core.config.application.util.CommonUtil;
|
||||
import app.module.core.config.application.util.MessageUtil;
|
||||
import app.module.core.usecase.admin.status.ports.AdminUpdateLoginFailPortIn;
|
||||
import app.module.core.usecase.admin.view.ports.AdminViewPortIn;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import java.time.LocalDateTime;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.event.EventListener;
|
||||
import org.springframework.security.authentication.event.AbstractAuthenticationFailureEvent;
|
||||
import org.springframework.security.authentication.event.AuthenticationSuccessEvent;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class AdminAuthSuccessEvent {
|
||||
|
||||
private final MessageUtil messageUtil;
|
||||
private final AdminViewPortIn adminViewPortIn;
|
||||
private final AdminUpdateLoginFailPortIn updateLoginFailPortIn;
|
||||
private final LoggedInUserViewPortIn loggedInUserViewPortIn;
|
||||
private final LoggedInUserSavePortIn loggedInUserSavePortIn;
|
||||
@Value("${app.admin.password.validity.period.days}")
|
||||
private long passwordValidPeriodDays;
|
||||
@Value("${app.admin.password.change.notice.period.days}")
|
||||
private long passwordChangeNoticeDays;
|
||||
@Value("${app.admin.session.validity.period.seconds}")
|
||||
private long sessionValidPeriodSeconds;
|
||||
@Value("${app.admin.session.maximum.num}")
|
||||
private Integer maxSessionNum;
|
||||
|
||||
@EventListener
|
||||
public void handleAuthenticationSuccessEvent(AuthenticationSuccessEvent event) {
|
||||
Authentication authentication = event.getAuthentication();
|
||||
AdminUser adminUser = (AdminUser) authentication.getPrincipal();
|
||||
|
||||
HttpServletRequest request =
|
||||
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
|
||||
|
||||
// 로그인 실패 회수 초기화
|
||||
adminViewPortIn
|
||||
.connect(authentication.getName())
|
||||
.ifPresent(admin -> updateLoginFailPortIn.connect(admin.getId(), 0));
|
||||
|
||||
// 패스워드 변경일 공지
|
||||
if (passwordValidPeriodDays != -1
|
||||
&& adminUser.getRemainPasswordDays() <= passwordChangeNoticeDays) {
|
||||
CommonUtil.addFlashAlertMessages(
|
||||
request.getSession(),
|
||||
messageUtil.getMessage(
|
||||
"security.password.change.notify", adminUser.getRemainPasswordDays()));
|
||||
}
|
||||
|
||||
if (maxSessionNum == 1) {
|
||||
// 동시 접속 (중복 로그인) 여부 판단 후 사용자에게 메세지 보이기
|
||||
if (isAlreadyLoggedInSomewhere(authentication.getName(),
|
||||
CommonUtil.getClientIP(request))) {
|
||||
CommonUtil.addFlashAlertMessages(
|
||||
request.getSession(), messageUtil.getMessage("security.auth.duplicate.login"));
|
||||
}
|
||||
|
||||
// 로그인 활성화 기록 생성
|
||||
loggedInUserSavePortIn.connect(
|
||||
LoggedInUserSaveCmd.builder()
|
||||
.loggedInUserId(
|
||||
LoggedInUserIdSaveCmd.builder()
|
||||
.appType(AppType.ADMIN)
|
||||
.id(authentication.getName())
|
||||
.build())
|
||||
.clientIP(CommonUtil.getClientIP(request))
|
||||
.lastLoggedInAt(LocalDateTime.now())
|
||||
.build());
|
||||
}
|
||||
}
|
||||
|
||||
@EventListener
|
||||
public void handleAuthenticationFailureEvent(AbstractAuthenticationFailureEvent event) {
|
||||
Exception e = event.getException();
|
||||
Authentication authentication = event.getAuthentication();
|
||||
log.warn("Unsuccessful authentication result: {}", authentication, e);
|
||||
}
|
||||
|
||||
/**
|
||||
* 사용자 로그인 여부 확인
|
||||
*/
|
||||
private boolean isAlreadyLoggedInSomewhere(String username, String currentIP) {
|
||||
LoggedInUserView loggedInUser =
|
||||
loggedInUserViewPortIn.connect(new LoggedInUserIdCmd(AppType.ADMIN, username));
|
||||
if (loggedInUser == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
LocalDateTime lastLoggedInAt = loggedInUser.getLastLoggedInAt();
|
||||
|
||||
return lastLoggedInAt.plusSeconds(sessionValidPeriodSeconds).isAfter(LocalDateTime.now())
|
||||
&& !currentIP.equals(loggedInUser.getClientIP());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
package app.module.admin.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.admin.view.ports.AdminViewPortIn;
|
||||
import app.module.core.usecase.admin.view.ports.application.domain.AdminView;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
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 AdminDetailsService implements UserDetailsService {
|
||||
|
||||
private final AdminViewPortIn adminViewPortIn;
|
||||
|
||||
@Value("${app.admin.password.validity.period.days}")
|
||||
private long passwordValidPeriodDays;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
|
||||
AdminView adminUser =
|
||||
adminViewPortIn
|
||||
.connect(username)
|
||||
.orElseThrow(() -> new UsernameNotFoundException("Invalid username or password."));
|
||||
|
||||
boolean accountLocked = Optional.ofNullable(adminUser.getAccountLocked()).orElse(false);
|
||||
boolean accountDisabled = Optional.ofNullable(adminUser.getAccountDisabled()).orElse(false);
|
||||
|
||||
return new AdminUser(
|
||||
adminUser.getId(),
|
||||
adminUser.getPassword(),
|
||||
!accountDisabled,
|
||||
true,
|
||||
isCredentialsNonExpired(adminUser.getPasswordUpdatedAt()),
|
||||
!accountLocked,
|
||||
getAuthorities(adminUser.getRoles()),
|
||||
passwordValidPeriodDays - getDaysPassedFrom(adminUser.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,11 @@
|
||||
package app.module.admin.config.application.security;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
|
||||
import org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration;
|
||||
|
||||
@Configuration
|
||||
@EnableGlobalMethodSecurity(jsr250Enabled = true)
|
||||
public class AdminMethodSecurityConfig extends GlobalMethodSecurityConfiguration {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
package app.module.admin.config.application.security;
|
||||
|
||||
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.ApplicationEventPublisher;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.security.authentication.AuthenticationEventPublisher;
|
||||
import org.springframework.security.authentication.DefaultAuthenticationEventPublisher;
|
||||
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 AdminSecurityConfig {
|
||||
|
||||
private final AdminDetailsService adminDetailsService;
|
||||
private final DataSource dataSource;
|
||||
private final BCryptPasswordEncoder passwordEncoder;
|
||||
@Value("${app.admin.session.maximum.num}")
|
||||
private Integer maxSessionNum;
|
||||
|
||||
@Bean
|
||||
public DaoAuthenticationProvider authenticationProvider() {
|
||||
DaoAuthenticationProvider auth = new DaoAuthenticationProvider();
|
||||
auth.setUserDetailsService(adminDetailsService);
|
||||
auth.setPasswordEncoder(passwordEncoder);
|
||||
return auth;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public PersistentTokenRepository persistentTokenRepository() {
|
||||
JdbcTokenRepositoryImpl jdbcTokenRepository = new JdbcTokenRepositoryImpl();
|
||||
jdbcTokenRepository.setDataSource(dataSource);
|
||||
return jdbcTokenRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* 중복 로그인 방지를 위해 선언
|
||||
*/
|
||||
@Bean
|
||||
public SessionRegistry sessionRegistry() {
|
||||
return new SessionRegistryImpl();
|
||||
}
|
||||
|
||||
/**
|
||||
* 중복 로그인 방지를 위해 선언
|
||||
*/
|
||||
@Bean
|
||||
public ServletListenerRegistrationBean httpSessionEventPublisher() {
|
||||
return new ServletListenerRegistrationBean(new HttpSessionEventPublisher());
|
||||
}
|
||||
|
||||
/**
|
||||
* 인증 성공/실패 이벤트 수신을 위해 선언
|
||||
*/
|
||||
@Bean
|
||||
public AuthenticationEventPublisher authenticationEventPublisher(
|
||||
ApplicationEventPublisher applicationEventPublisher) {
|
||||
return new DefaultAuthenticationEventPublisher(applicationEventPublisher);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
|
||||
List<String> permitPaths =
|
||||
Arrays.stream(PublicAccess.values())
|
||||
.map(PublicAccess::getPath)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
http.authorizeHttpRequests(
|
||||
(auth) ->
|
||||
auth.requestMatchers(permitPaths.toArray(String[]::new))
|
||||
.permitAll()
|
||||
.anyRequest().hasAuthority("ADMIN_ACCESS"))
|
||||
.formLogin(formLogin -> formLogin.loginPage("/login"))
|
||||
.rememberMe(
|
||||
remMe ->
|
||||
remMe
|
||||
.tokenValiditySeconds(1209600)
|
||||
.userDetailsService(adminDetailsService)
|
||||
.tokenRepository(persistentTokenRepository()))
|
||||
.logout(
|
||||
logout ->
|
||||
logout
|
||||
.invalidateHttpSession(true)
|
||||
.clearAuthentication(true)
|
||||
.logoutRequestMatcher(new AntPathRequestMatcher("/logout")))
|
||||
.sessionManagement(
|
||||
session -> session.maximumSessions(maxSessionNum).maxSessionsPreventsLogin(false));
|
||||
|
||||
return http.build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package app.module.admin.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 AdminUser extends User {
|
||||
|
||||
private long remainPasswordDays;
|
||||
|
||||
public AdminUser(
|
||||
String username,
|
||||
String password,
|
||||
boolean enabled,
|
||||
boolean accountNonExpired,
|
||||
boolean credentialsNonExpired,
|
||||
boolean accountNonLocked,
|
||||
Collection<? extends GrantedAuthority> authorities,
|
||||
long remainPasswordDays) {
|
||||
super(
|
||||
username,
|
||||
password,
|
||||
enabled,
|
||||
accountNonExpired,
|
||||
credentialsNonExpired,
|
||||
accountNonLocked,
|
||||
authorities);
|
||||
this.remainPasswordDays = remainPasswordDays;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package app.module.admin.config.application.util;
|
||||
|
||||
import app.module.core.config.adapters.web.interceptor.model.URITopTierVO;
|
||||
import java.util.List;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class AdminUtil {
|
||||
|
||||
public boolean shouldDisplaySubNodes(List<URITopTierVO> uriList) {
|
||||
boolean result = false;
|
||||
if (uriList != null && !uriList.isEmpty()) {
|
||||
for (URITopTierVO uri : uriList) {
|
||||
if (uri.getShowOnNavi()) {
|
||||
result = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package app.module.admin.usecase.admin.getAdmins.adapters.web;
|
||||
|
||||
import app.module.admin.usecase.admin.getAdmins.adapters.web.model.AdminListFilterVO;
|
||||
import app.module.core.config.application.util.ExcelUtil;
|
||||
import app.module.core.usecase.admin.getAdmins.ports.GetAdminsPortIn;
|
||||
import app.module.core.usecase.admin.getAdmins.ports.application.domain.GetAdmins;
|
||||
import app.module.core.usecase.admin.getAdmins.ports.application.domain.GetAdminsCmd;
|
||||
import app.module.core.usecase.admin.getAdmins.ports.application.domain.GetAdminsRole;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.web.PageableDefault;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
|
||||
@Controller
|
||||
@RequiredArgsConstructor
|
||||
class AdminExcelController {
|
||||
|
||||
private final GetAdminsPortIn getAdminsPortIn;
|
||||
private final ExcelUtil excelUtil;
|
||||
|
||||
@PostMapping(path = "/settings/admins/excel")
|
||||
void excelDownload(
|
||||
HttpServletResponse response,
|
||||
@PageableDefault(sort = "createdAt") Pageable pageable,
|
||||
@ModelAttribute("paramDto") AdminListFilterVO adminListFilterVO) {
|
||||
|
||||
Workbook wb = new XSSFWorkbook();
|
||||
Sheet sheet = wb.createSheet("예제 관리자 목록");
|
||||
|
||||
Page<GetAdmins> listOutput =
|
||||
getAdminsPortIn.connect(
|
||||
pageable,
|
||||
new GetAdminsCmd(
|
||||
adminListFilterVO.getSearchField(),
|
||||
adminListFilterVO.getSearchValue(),
|
||||
adminListFilterVO.getSearchRole()));
|
||||
|
||||
if (CollectionUtils.isNotEmpty(listOutput.getContent())) {
|
||||
// Header
|
||||
Row headerRow = sheet.createRow(sheet.getPhysicalNumberOfRows());
|
||||
excelUtil.createCells(headerRow, "번호", "이메일", "권한", "등록일", "최근 수정일");
|
||||
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
|
||||
|
||||
listOutput
|
||||
.getContent()
|
||||
.forEach(
|
||||
item -> {
|
||||
Row row = sheet.createRow(sheet.getPhysicalNumberOfRows());
|
||||
excelUtil.createCells(
|
||||
row,
|
||||
item.getId(),
|
||||
item.getEmail(),
|
||||
item.getRoles().stream()
|
||||
.map(GetAdminsRole::getId)
|
||||
.collect(Collectors.joining(", ")),
|
||||
Optional.ofNullable(item.getCreatedAt())
|
||||
.map(localDateTime -> localDateTime.format(formatter))
|
||||
.orElse(""),
|
||||
Optional.ofNullable(item.getUpdatedAt())
|
||||
.map(localDateTime -> localDateTime.format(formatter))
|
||||
.orElse(""));
|
||||
});
|
||||
}
|
||||
|
||||
excelUtil.generateWithPassword(response, wb, "admin-list");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package app.module.admin.usecase.admin.getAdmins.adapters.web;
|
||||
|
||||
import app.module.admin.usecase.admin.getAdmins.adapters.web.model.AdminListFilterVO;
|
||||
import app.module.core.config.application.enums.AppType;
|
||||
import app.module.core.usecase.admin.getAdmins.ports.GetAdminsPortIn;
|
||||
import app.module.core.usecase.admin.getAdmins.ports.application.domain.GetAdmins;
|
||||
import app.module.core.usecase.admin.getAdmins.ports.application.domain.GetAdminsCmd;
|
||||
import app.module.core.usecase.role.list.ports.RoleListPortIn;
|
||||
import app.module.core.usecase.role.list.ports.application.domain.RoleElement;
|
||||
import app.module.core.usecase.uicode.list.ports.UICodeListPortIn;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.web.PageableDefault;
|
||||
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 AdminListController {
|
||||
|
||||
private final GetAdminsPortIn getAdminsPortIn;
|
||||
private final RoleListPortIn<RoleElement> roleListPortIn;
|
||||
private final UICodeListPortIn uiCodeListPortIn;
|
||||
|
||||
@GetMapping(path = "/settings/admins")
|
||||
String operate(
|
||||
Model model,
|
||||
@PageableDefault(sort = "createdAt") Pageable pageable,
|
||||
@ModelAttribute("listStatus") AdminListFilterVO adminListFilterVO) {
|
||||
|
||||
Page<GetAdmins> listOutput =
|
||||
getAdminsPortIn.connect(
|
||||
pageable,
|
||||
new GetAdminsCmd(
|
||||
adminListFilterVO.getSearchField(),
|
||||
adminListFilterVO.getSearchValue(),
|
||||
adminListFilterVO.getSearchRole()));
|
||||
|
||||
model.addAttribute("listOutput", listOutput);
|
||||
model.addAttribute("roles", roleListPortIn.connect(AppType.ADMIN));
|
||||
model.addAttribute("pageRows", uiCodeListPortIn.connect("code.pageable.rows"));
|
||||
|
||||
return "admin/adminList";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package app.module.admin.usecase.admin.getAdmins.adapters.web.model;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
public class AdminListFilterVO {
|
||||
|
||||
private String searchField;
|
||||
private String searchValue;
|
||||
private String searchRole;
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package app.module.admin.usecase.admin.removeAdmins.adapters.web;
|
||||
|
||||
import app.module.core.config.application.util.MessageUtil;
|
||||
import app.module.core.usecase.admin.removeAdmin.ports.RemoveAdminPortIn;
|
||||
import java.util.List;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
||||
|
||||
@Controller
|
||||
@RequiredArgsConstructor
|
||||
class AdminRemoveController {
|
||||
|
||||
private final MessageUtil messageUtil;
|
||||
private final RemoveAdminPortIn removeAdminPortIn;
|
||||
|
||||
@PostMapping(path = "/settings/admins/delete")
|
||||
String operate(RedirectAttributes redirectAttributes, @RequestParam List<String> checkedIds) {
|
||||
|
||||
if (CollectionUtils.isNotEmpty(checkedIds)) {
|
||||
removeAdminPortIn.connect(checkedIds);
|
||||
redirectAttributes.addFlashAttribute(
|
||||
"operationMessage", messageUtil.getMessage("operation.settings.admin.removed"));
|
||||
}
|
||||
|
||||
return "redirect:/settings/admins";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package app.module.admin.usecase.admin.removeAdmins.adapters.web;
|
||||
|
||||
import app.module.admin.usecase.admin.removeAdmins.adapters.web.model.RemoveAdminsReqVO;
|
||||
import app.module.core.config.application.util.MessageUtil;
|
||||
import app.module.core.usecase.admin.removeAdmin.ports.RemoveAdminPortIn;
|
||||
import jakarta.validation.Valid;
|
||||
import java.util.List;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
||||
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
class RemoveAdminsController {
|
||||
|
||||
private final RemoveAdminPortIn removeAdminPortIn;
|
||||
|
||||
@DeleteMapping(path = "/api/settings/admin/remove")
|
||||
ResponseEntity<?> operate(@Valid RemoveAdminsReqVO reqVO, BindingResult bindingResult) {
|
||||
if (bindingResult.hasErrors()) {
|
||||
return ResponseEntity.status(HttpStatus.UNPROCESSABLE_ENTITY)
|
||||
.body(bindingResult.getFieldErrors());
|
||||
}
|
||||
|
||||
if (CollectionUtils.isNotEmpty(reqVO.getCheckedIds())) {
|
||||
removeAdminPortIn.connect(reqVO.getCheckedIds());
|
||||
}
|
||||
|
||||
return ResponseEntity.status(HttpStatus.OK).body(reqVO);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package app.module.admin.usecase.admin.removeAdmins.adapters.web.model;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode
|
||||
public class RemoveAdminsReqVO {
|
||||
List<String> checkedIds;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package app.module.admin.usecase.admin.saveAdmin.adapters.web;
|
||||
|
||||
import app.module.admin.usecase.admin.saveAdmin.adapters.web.model.AdminCreateBindingVO;
|
||||
import app.module.core.config.application.enums.AppType;
|
||||
import app.module.core.usecase.role.list.ports.RoleListPortIn;
|
||||
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
|
||||
public class AdminCreateGetController {
|
||||
|
||||
private final RoleListPortIn roleListPortIn;
|
||||
|
||||
@GetMapping(path = "/settings/admins/create")
|
||||
String operate(Model model, @ModelAttribute("bindingVO") AdminCreateBindingVO bindingVO) {
|
||||
model.addAttribute("roles", roleListPortIn.connect(AppType.ADMIN));
|
||||
return "admin/adminCreateForm";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package app.module.admin.usecase.admin.saveAdmin.adapters.web;
|
||||
|
||||
import app.module.admin.usecase.admin.saveAdmin.adapters.web.model.AdminCreateBindingVO;
|
||||
import app.module.admin.usecase.admin.saveAdmin.adapters.web.validator.AdminCreateValidator;
|
||||
import app.module.core.config.application.enums.AppType;
|
||||
import app.module.core.config.application.util.MessageUtil;
|
||||
import app.module.core.usecase.admin.saveAdmin.ports.SaveAdminPortIn;
|
||||
import app.module.core.usecase.role.list.ports.RoleListPortIn;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
||||
|
||||
@Controller
|
||||
@RequiredArgsConstructor
|
||||
public class AdminCreatePostController {
|
||||
|
||||
private final RoleListPortIn roleListPortIn;
|
||||
private final MessageUtil messageUtil;
|
||||
private final SaveAdminPortIn savePortIn;
|
||||
private final AdminCreateValidator adminCreateValidator;
|
||||
|
||||
@PostMapping(path = "/settings/admins/create")
|
||||
String operate(
|
||||
RedirectAttributes redirectAttributes,
|
||||
Model model,
|
||||
@Valid @ModelAttribute("bindingVO") AdminCreateBindingVO bindingVO,
|
||||
BindingResult bindingResult) {
|
||||
|
||||
adminCreateValidator.validate(bindingVO, bindingResult);
|
||||
if (bindingResult.hasErrors()) {
|
||||
model.addAttribute("roles", roleListPortIn.connect(AppType.ADMIN));
|
||||
return "admin/adminCreateForm";
|
||||
}
|
||||
|
||||
savePortIn.connect(
|
||||
bindingVO.getId(),
|
||||
bindingVO.getPassword(),
|
||||
bindingVO.getEmail(),
|
||||
bindingVO.getAccountDisabled(),
|
||||
bindingVO.getAccountLocked(),
|
||||
bindingVO.getRoleIds());
|
||||
|
||||
redirectAttributes.addFlashAttribute(
|
||||
"operationMessage",
|
||||
messageUtil.getMessage("operation.settings.admin.created", bindingVO.getId()));
|
||||
|
||||
return "redirect:/settings/admins";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package app.module.admin.usecase.admin.saveAdmin.adapters.web;
|
||||
|
||||
import app.module.admin.usecase.admin.getAdmins.adapters.web.model.AdminListFilterVO;
|
||||
import app.module.admin.usecase.admin.saveAdmin.adapters.web.model.AdminUpdateBindingVO;
|
||||
import app.module.core.config.adapters.web.security.domain.CoreRole;
|
||||
import app.module.core.config.application.component.ListPageableInfo;
|
||||
import app.module.core.config.application.enums.AppType;
|
||||
import app.module.core.config.application.util.MessageUtil;
|
||||
import app.module.core.usecase.admin.view.ports.AdminViewPortIn;
|
||||
import app.module.core.usecase.admin.view.ports.application.domain.AdminView;
|
||||
import app.module.core.usecase.role.list.ports.RoleListPortIn;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.stream.Collectors;
|
||||
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 AdminUpdateGetController {
|
||||
|
||||
private final AdminViewPortIn adminViewPortIn;
|
||||
private final RoleListPortIn roleListPortIn;
|
||||
private final MessageUtil messageUtil;
|
||||
|
||||
@GetMapping(path = "/settings/admins/update/{adminId}")
|
||||
String operate(
|
||||
Model model,
|
||||
@PathVariable String adminId,
|
||||
@ModelAttribute("pageable") final ListPageableInfo pageable,
|
||||
@ModelAttribute("listStatus") AdminListFilterVO listStatus) {
|
||||
|
||||
AdminView output =
|
||||
adminViewPortIn
|
||||
.connect(adminId)
|
||||
.orElseThrow(
|
||||
() ->
|
||||
new NoSuchElementException(
|
||||
messageUtil.getMessage("exception.noSuchElement", adminId,
|
||||
"Admin ID")));
|
||||
|
||||
AdminUpdateBindingVO bindingVO =
|
||||
new AdminUpdateBindingVO(
|
||||
output.getCreatedBy(),
|
||||
output.getCreatedAt(),
|
||||
output.getUpdatedBy(),
|
||||
output.getUpdatedAt(),
|
||||
output.getId(),
|
||||
null,
|
||||
output.getEmail(),
|
||||
output.getPasswordUpdatedAt(),
|
||||
output.getAccountDisabled(),
|
||||
output.getLoginFailCnt(),
|
||||
output.getAccountLocked(),
|
||||
output.getRoles().stream().map(CoreRole::getId).collect(Collectors.toList()));
|
||||
|
||||
model.addAttribute("bindingVO", bindingVO);
|
||||
model.addAttribute("roles", roleListPortIn.connect(AppType.ADMIN));
|
||||
|
||||
return "admin/adminUpdateForm";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package app.module.admin.usecase.admin.saveAdmin.adapters.web;
|
||||
|
||||
import app.module.admin.usecase.admin.saveAdmin.adapters.web.model.AdminUpdateBindingVO;
|
||||
import app.module.admin.usecase.admin.saveAdmin.adapters.web.validator.AdminUpdateValidator;
|
||||
import app.module.core.config.application.enums.AppType;
|
||||
import app.module.core.config.application.util.MessageUtil;
|
||||
import app.module.core.usecase.admin.saveAdmin.ports.SaveAdminPortIn;
|
||||
import app.module.core.usecase.role.list.ports.RoleListPortIn;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
||||
|
||||
@Controller
|
||||
@RequiredArgsConstructor
|
||||
class AdminUpdatePostController {
|
||||
|
||||
private final AdminUpdateValidator adminUpdateValidator;
|
||||
private final RoleListPortIn roleListPortIn;
|
||||
private final SaveAdminPortIn saveAdminPortIn;
|
||||
private final MessageUtil messageUtil;
|
||||
|
||||
@PostMapping(path = "/settings/admins/update/{id}")
|
||||
String operate(
|
||||
Model model,
|
||||
RedirectAttributes redirectAttributes,
|
||||
@Valid @ModelAttribute("bindingVO") AdminUpdateBindingVO bindingVO,
|
||||
BindingResult bindingResult) {
|
||||
|
||||
adminUpdateValidator.validate(bindingVO, bindingResult);
|
||||
if (bindingResult.hasErrors()) {
|
||||
model.addAttribute("roles", roleListPortIn.connect(AppType.ADMIN));
|
||||
return "admin/adminUpdateForm";
|
||||
}
|
||||
|
||||
saveAdminPortIn.connect(
|
||||
bindingVO.getId(),
|
||||
bindingVO.getUpdatePassword(),
|
||||
bindingVO.getEmail(),
|
||||
bindingVO.getAccountDisabled(),
|
||||
bindingVO.getAccountLocked(),
|
||||
bindingVO.getRoleIds());
|
||||
|
||||
redirectAttributes.addFlashAttribute(
|
||||
"operationMessage",
|
||||
messageUtil.getMessage("operation.settings.admin.updated", bindingVO.getId()));
|
||||
|
||||
return "redirect:/settings/admins";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package app.module.admin.usecase.admin.saveAdmin.adapters.web.model;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.Pattern;
|
||||
import java.util.List;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
public class AdminCreateBindingVO {
|
||||
|
||||
private String id;
|
||||
private String password;
|
||||
|
||||
@NotBlank(message = "{valid.common.required}")
|
||||
@Pattern(
|
||||
regexp =
|
||||
"^[\\w!#$%&’*+/=?`{|}~^-]+(?:\\.[\\w!#$%&’*+/=?`{|}~^-]+)*@(?:[a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,6}$",
|
||||
message = "{valid.common.email.wrong}")
|
||||
private String email;
|
||||
|
||||
private Boolean accountDisabled;
|
||||
private Boolean accountLocked;
|
||||
private List<String> roleIds;
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package app.module.admin.usecase.admin.saveAdmin.adapters.web.model;
|
||||
|
||||
import app.module.core.config.application.component.AuditOutput;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.Pattern;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
public class AdminUpdateBindingVO implements AuditOutput {
|
||||
|
||||
private final String createdBy;
|
||||
|
||||
private final LocalDateTime createdAt;
|
||||
|
||||
private final String updatedBy;
|
||||
|
||||
private final LocalDateTime updatedAt;
|
||||
|
||||
private String id;
|
||||
private String updatePassword;
|
||||
|
||||
@NotBlank(message = "{valid.common.required}")
|
||||
@Pattern(
|
||||
regexp =
|
||||
"^[\\w!#$%&’*+/=?`{|}~^-]+(?:\\.[\\w!#$%&’*+/=?`{|}~^-]+)*@(?:[a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,6}$",
|
||||
message = "{valid.common.email.wrong}")
|
||||
private String email;
|
||||
|
||||
private LocalDateTime passwordUpdatedAt;
|
||||
private Boolean accountDisabled;
|
||||
private Integer loginFailCnt;
|
||||
private Boolean accountLocked;
|
||||
private List<String> roleIds;
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package app.module.admin.usecase.admin.saveAdmin.adapters.web.validator;
|
||||
|
||||
import app.module.admin.usecase.admin.saveAdmin.adapters.web.model.AdminCreateBindingVO;
|
||||
import java.util.Optional;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.validation.Errors;
|
||||
import org.springframework.validation.ValidationUtils;
|
||||
import org.springframework.validation.Validator;
|
||||
|
||||
@Component
|
||||
public class AdminCreateValidator implements Validator {
|
||||
|
||||
private final String PASSWORD_REGEX = "^((?=.*[a-z])(?=.*[A-Z])(?=.*[!@#$%_\\-])\\S{6,15})$";
|
||||
|
||||
@Override
|
||||
public boolean supports(Class<?> clazz) {
|
||||
return AdminCreateBindingVO.class.equals(clazz);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate(Object target, Errors errors) {
|
||||
AdminCreateBindingVO vo = (AdminCreateBindingVO) target;
|
||||
|
||||
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "password", "valid.common.required");
|
||||
|
||||
Optional.ofNullable(vo.getPassword())
|
||||
.filter(password -> !password.matches(PASSWORD_REGEX))
|
||||
.ifPresent(password -> errors.rejectValue("password", "valid.common.password.wrong"));
|
||||
|
||||
Optional.ofNullable(vo.getRoleIds())
|
||||
.filter(ids -> ids.size() < 1)
|
||||
.ifPresent(
|
||||
ids ->
|
||||
errors.rejectValue(
|
||||
"roleIds", "valid.common.required.size.min", new Object[]{1}, ""));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package app.module.admin.usecase.admin.saveAdmin.adapters.web.validator;
|
||||
|
||||
import app.module.admin.usecase.admin.saveAdmin.adapters.web.model.AdminUpdateBindingVO;
|
||||
import java.util.Optional;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.validation.Errors;
|
||||
import org.springframework.validation.Validator;
|
||||
|
||||
@Component
|
||||
public class AdminUpdateValidator implements Validator {
|
||||
|
||||
private final String PASSWORD_REGEX = "^((?=.*[a-z])(?=.*[A-Z])(?=.*[!@#$%_\\-])\\S{6,15})$";
|
||||
|
||||
@Override
|
||||
public boolean supports(Class<?> clazz) {
|
||||
return AdminUpdateBindingVO.class.equals(clazz);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate(Object target, Errors errors) {
|
||||
AdminUpdateBindingVO vo = (AdminUpdateBindingVO) target;
|
||||
|
||||
Optional.ofNullable(vo.getRoleIds())
|
||||
.filter(ids -> ids.size() < 1)
|
||||
.ifPresent(
|
||||
ids ->
|
||||
errors.rejectValue(
|
||||
"roleIds", "valid.common.required.size.min", new Object[]{1}, ""));
|
||||
|
||||
Optional.ofNullable(vo.getUpdatePassword())
|
||||
.filter(s -> !s.trim().isEmpty() && !s.matches(PASSWORD_REGEX))
|
||||
.ifPresent(s -> errors.rejectValue("updatePassword", "valid.common.password.wrong"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package app.module.admin.usecase.article.createArticle.adapters.web;
|
||||
|
||||
import app.module.admin.usecase.article.createArticle.adapters.web.model.CreateArticleReqVO;
|
||||
import app.module.admin.usecase.article.createArticle.adapters.web.validator.CreateArticleValidator;
|
||||
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 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/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.admin.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.admin.usecase.article.createArticle.adapters.web.validator;
|
||||
|
||||
import app.module.admin.usecase.article.createArticle.adapters.web.model.CreateArticleReqVO;
|
||||
import app.module.core.config.application.util.MessageUtil;
|
||||
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,23 @@
|
||||
package app.module.admin.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/board/articles/{id}")
|
||||
ResponseEntity<?> operate(@PathVariable Long id) {
|
||||
return ResponseEntity.status(HttpStatus.OK)
|
||||
.body(getArticlePortIn.operate(new GetArticleCmd(id)).orElseThrow());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package app.module.admin.usecase.article.getArticleCreateUI.adapters.web;
|
||||
|
||||
import app.module.admin.usecase.article.getArticleCreateUI.adapters.web.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.admin.usecase.article.getArticleCreateUI.adapters.web.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.admin.usecase.article.getArticleUpdateUI.adapters.web;
|
||||
|
||||
import app.module.admin.usecase.article.getArticleUpdateUI.adapters.web.model.GetArticleUpdateUIReqVO;
|
||||
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 GetArticleUpdateUIController {
|
||||
|
||||
@GetMapping(path = "/board/articles/{id}")
|
||||
String operate(
|
||||
Model model,
|
||||
@PathVariable @ModelAttribute("id") Long id,
|
||||
@ModelAttribute("reqVO") GetArticleUpdateUIReqVO reqVO) {
|
||||
|
||||
return "board/articles/{id}";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package app.module.admin.usecase.article.getArticleUpdateUI.adapters.web.model;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode
|
||||
public class GetArticleUpdateUIReqVO {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package app.module.admin.usecase.article.getArticles.adapters.web;
|
||||
|
||||
import app.module.admin.usecase.article.getArticles.adapters.web.model.GetArticlesReqVO;
|
||||
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 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.admin.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,210 @@
|
||||
package app.module.admin.usecase.article.getArticlesExcel.adapters.web;
|
||||
|
||||
import app.module.admin.usecase.article.getArticlesExcel.adapters.web.model.GetArticlesExcelReqVO;
|
||||
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.core.usecase.excel.createCell.ports.CreateCellPortIn;
|
||||
import app.module.core.usecase.excel.createCell.ports.application.model.CellConfig;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.poi.ss.usermodel.CellType;
|
||||
import org.apache.poi.ss.usermodel.HorizontalAlignment;
|
||||
import org.apache.poi.ss.util.CellRangeAddress;
|
||||
import org.apache.poi.xssf.streaming.SXSSFSheet;
|
||||
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.web.PageableDefault;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
class GetArticlesExcelController {
|
||||
|
||||
private final GetArticlesPortIn getArticlesPortIn;
|
||||
private final CreateCellPortIn createCellPortIn;
|
||||
|
||||
@GetMapping(path = "/api/board/articles/excel")
|
||||
void operate(
|
||||
@PageableDefault(size = Integer.MAX_VALUE) Pageable pageable,
|
||||
GetArticlesExcelReqVO reqVO,
|
||||
HttpServletResponse response)
|
||||
throws IOException {
|
||||
|
||||
String title = "예제 게시판 목록";
|
||||
|
||||
Page<GetArticles> output =
|
||||
getArticlesPortIn.operate(
|
||||
pageable,
|
||||
new GetArticlesCmd(
|
||||
reqVO.getSearchField(), reqVO.getSearchValue(), reqVO.getSearchOpen()));
|
||||
|
||||
if (!output.getContent().isEmpty()) {
|
||||
|
||||
// 1000 개 로우가 넘으면 디스크에 기록한다.
|
||||
try (SXSSFWorkbook wb = new SXSSFWorkbook(1000)) {
|
||||
SXSSFSheet sheet = wb.createSheet(title);
|
||||
sheet.trackAllColumnsForAutoSizing();
|
||||
|
||||
AtomicInteger colNo = new AtomicInteger(0);
|
||||
|
||||
// 상단 Header 생성 및 필터 적용
|
||||
createCellPortIn.operate(
|
||||
// 상단 Header 의 Row 목록 - 2개 이상이면 병합이 가능해진다.
|
||||
List.of(sheet.createRow(sheet.getPhysicalNumberOfRows())),
|
||||
// 상단 Header Row 를 구성하는 col 목록
|
||||
List.of(
|
||||
new CellConfig(
|
||||
0,
|
||||
colNo.getAndIncrement(),
|
||||
null,
|
||||
CellType.STRING,
|
||||
"제목",
|
||||
createCellPortIn.getDefaultHeaderStyle(wb, HorizontalAlignment.CENTER),
|
||||
null),
|
||||
new CellConfig(
|
||||
0,
|
||||
colNo.getAndIncrement(),
|
||||
null,
|
||||
CellType.STRING,
|
||||
"공개여부",
|
||||
createCellPortIn.getDefaultHeaderStyle(wb, HorizontalAlignment.CENTER),
|
||||
null),
|
||||
new CellConfig(
|
||||
0,
|
||||
colNo.getAndIncrement(),
|
||||
null,
|
||||
CellType.STRING,
|
||||
"게시일",
|
||||
createCellPortIn.getDefaultHeaderStyle(wb, HorizontalAlignment.CENTER),
|
||||
null),
|
||||
new CellConfig(
|
||||
0,
|
||||
colNo.getAndIncrement(),
|
||||
null,
|
||||
CellType.STRING,
|
||||
"종료일",
|
||||
createCellPortIn.getDefaultHeaderStyle(wb, HorizontalAlignment.CENTER),
|
||||
null),
|
||||
new CellConfig(
|
||||
0,
|
||||
colNo.getAndIncrement(),
|
||||
null,
|
||||
CellType.STRING,
|
||||
"최근 수정자",
|
||||
createCellPortIn.getDefaultHeaderStyle(wb, HorizontalAlignment.CENTER),
|
||||
null),
|
||||
new CellConfig(
|
||||
0,
|
||||
colNo.getAndIncrement(),
|
||||
null,
|
||||
CellType.STRING,
|
||||
"최근 수정일",
|
||||
createCellPortIn.getDefaultHeaderStyle(wb, HorizontalAlignment.CENTER),
|
||||
null)));
|
||||
sheet.setAutoFilter(new CellRangeAddress(0, 0, 0, colNo.get() - 1));
|
||||
|
||||
// 본문 데이터
|
||||
output
|
||||
.getContent()
|
||||
.forEach(
|
||||
item -> {
|
||||
colNo.set(0);
|
||||
createCellPortIn.operate(
|
||||
List.of(sheet.createRow(sheet.getPhysicalNumberOfRows())),
|
||||
List.of(
|
||||
new CellConfig(
|
||||
0,
|
||||
colNo.getAndIncrement(),
|
||||
null,
|
||||
CellType.STRING,
|
||||
item.getTitle(),
|
||||
createCellPortIn.getDefaultDataStyle(wb,
|
||||
HorizontalAlignment.CENTER),
|
||||
null),
|
||||
new CellConfig(
|
||||
0,
|
||||
colNo.getAndIncrement(),
|
||||
null,
|
||||
CellType.STRING,
|
||||
item.getVisible() ? "Y" : "N",
|
||||
createCellPortIn.getDefaultDataStyle(wb,
|
||||
HorizontalAlignment.CENTER),
|
||||
null),
|
||||
new CellConfig(
|
||||
0,
|
||||
colNo.getAndIncrement(),
|
||||
null,
|
||||
CellType.STRING,
|
||||
item.getStartDate()
|
||||
.format(
|
||||
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")),
|
||||
createCellPortIn.getDefaultDataStyle(wb,
|
||||
HorizontalAlignment.CENTER),
|
||||
null),
|
||||
new CellConfig(
|
||||
0,
|
||||
colNo.getAndIncrement(),
|
||||
null,
|
||||
CellType.STRING,
|
||||
item.getEndDate()
|
||||
.format(
|
||||
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")),
|
||||
createCellPortIn.getDefaultDataStyle(wb,
|
||||
HorizontalAlignment.CENTER),
|
||||
null),
|
||||
new CellConfig(
|
||||
0,
|
||||
colNo.getAndIncrement(),
|
||||
null,
|
||||
CellType.STRING,
|
||||
item.getUpdatedBy(),
|
||||
createCellPortIn.getDefaultDataStyle(wb,
|
||||
HorizontalAlignment.CENTER),
|
||||
null),
|
||||
new CellConfig(
|
||||
0,
|
||||
colNo.getAndIncrement(),
|
||||
null,
|
||||
CellType.STRING,
|
||||
item.getUpdatedAt()
|
||||
.format(
|
||||
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")),
|
||||
createCellPortIn.getDefaultDataStyle(wb,
|
||||
HorizontalAlignment.CENTER),
|
||||
null)));
|
||||
});
|
||||
|
||||
// 한글 파일명 처리를 위해 URLEncoder 필요
|
||||
String filename =
|
||||
URLEncoder.encode(
|
||||
String.format(
|
||||
"%s-%s.xlsx",
|
||||
title,
|
||||
new SimpleDateFormat("yyyyMMdd").format(
|
||||
Calendar.getInstance().getTime())),
|
||||
StandardCharsets.UTF_8);
|
||||
|
||||
response.setHeader(
|
||||
HttpHeaders.CONTENT_DISPOSITION,
|
||||
String.format("attachment; filename=\"%s\"", filename));
|
||||
|
||||
wb.write(response.getOutputStream());
|
||||
|
||||
// 디스크에 기록한 임시 파일 제거
|
||||
wb.dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package app.module.admin.usecase.article.getArticlesExcel.adapters.web.model;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode
|
||||
public class GetArticlesExcelReqVO {
|
||||
|
||||
private String searchField;
|
||||
private String searchValue;
|
||||
private String searchOpen;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package app.module.admin.usecase.article.getArticlesUI.adapters.web;
|
||||
|
||||
import app.module.admin.usecase.article.getArticlesUI.adapters.web.model.GetArticlesUIReqVO;
|
||||
import app.module.core.usecase.uicode.list.ports.UICodeListPortIn;
|
||||
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(@ModelAttribute("reqVO") GetArticlesUIReqVO reqVO, Model model) {
|
||||
|
||||
model.addAttribute("pageRows", uiCodeListPortIn.connect("code.pageable.rows"));
|
||||
|
||||
return "board/articles";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package app.module.admin.usecase.article.getArticlesUI.adapters.web.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.admin.usecase.article.removeArticles.adapters.web;
|
||||
|
||||
import app.module.admin.usecase.article.removeArticles.adapters.web.model.RemoveArticlesReqVO;
|
||||
import app.module.core.usecase.article.removeArticles.ports.RemoveArticlesPortIn;
|
||||
import app.module.core.usecase.article.removeArticles.ports.application.domain.RemoveArticlesCmd;
|
||||
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/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.admin.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,40 @@
|
||||
package app.module.admin.usecase.article.sortArticles.adapters.web;
|
||||
|
||||
import app.module.admin.usecase.article.sortArticles.adapters.web.model.SortArticlesReqVO;
|
||||
import app.module.core.usecase.article.sortArticles.ports.SortArticlesPortIn;
|
||||
import app.module.core.usecase.article.sortArticles.ports.application.domain.SortArticlesCmd;
|
||||
import jakarta.validation.Valid;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
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.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
class SortArticlesController {
|
||||
|
||||
private final SortArticlesPortIn sortArticlesPortIn;
|
||||
|
||||
@PatchMapping(path = "/api/board/articles/sort")
|
||||
ResponseEntity<?> operate(
|
||||
@Valid @RequestBody List<SortArticlesReqVO> reqVO, BindingResult bindingResult) {
|
||||
if (bindingResult.hasErrors()) {
|
||||
return ResponseEntity.status(HttpStatus.UNPROCESSABLE_ENTITY).body(bindingResult);
|
||||
}
|
||||
|
||||
sortArticlesPortIn.operate(
|
||||
reqVO.stream()
|
||||
.map(
|
||||
sortArticlesReqVO ->
|
||||
new SortArticlesCmd(sortArticlesReqVO.getId(),
|
||||
sortArticlesReqVO.getOrderNo()))
|
||||
.collect(Collectors.toList()));
|
||||
|
||||
return ResponseEntity.status(HttpStatus.OK).body(reqVO);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package app.module.admin.usecase.article.sortArticles.adapters.web.model;
|
||||
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode
|
||||
public class SortArticlesReqVO {
|
||||
|
||||
@NotNull(message = "{valid.common.required}")
|
||||
private Long id;
|
||||
|
||||
@NotNull(message = "{valid.common.required}")
|
||||
private Integer orderNo;
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package app.module.admin.usecase.article.updateArticle.adapters.web;
|
||||
|
||||
import app.module.admin.usecase.article.updateArticle.adapters.web.model.UpdateArticleReqVO;
|
||||
import app.module.admin.usecase.article.updateArticle.adapters.web.validator.UpdateArticleValidator;
|
||||
import app.module.core.usecase.article.updateArticle.ports.UpdateArticlePortIn;
|
||||
import app.module.core.usecase.article.updateArticle.ports.application.domain.UpdateArticleCmd;
|
||||
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 UpdateArticleController {
|
||||
|
||||
private final UpdateArticlePortIn updateArticlePortIn;
|
||||
private final UpdateArticleValidator updateArticleValidator;
|
||||
|
||||
@PutMapping(path = "/api/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,51 @@
|
||||
package app.module.admin.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.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import org.apache.commons.text.StringEscapeUtils;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@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.admin.usecase.article.updateArticle.adapters.web.validator;
|
||||
|
||||
import app.module.admin.usecase.article.updateArticle.adapters.web.model.UpdateArticleReqVO;
|
||||
import app.module.core.config.application.util.MessageUtil;
|
||||
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,34 @@
|
||||
package app.module.admin.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/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,17 @@
|
||||
package app.module.admin.usecase.email.send.adapters.web;
|
||||
|
||||
import app.module.admin.usecase.email.send.adapters.web.model.EmailVO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
|
||||
@Controller
|
||||
@RequiredArgsConstructor
|
||||
public class EmailController {
|
||||
|
||||
@GetMapping(path = "/addons/email/form")
|
||||
public String emailForm(@ModelAttribute("formDto") EmailVO emailVO) {
|
||||
return "email/emailForm";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package app.module.admin.usecase.email.send.adapters.web;
|
||||
|
||||
import app.module.admin.usecase.email.send.adapters.web.model.EmailVO;
|
||||
import app.module.admin.usecase.email.send.ports.EmailSendPortIn;
|
||||
import app.module.admin.usecase.email.send.ports.application.domain.Email;
|
||||
import app.module.core.config.application.util.MessageUtil;
|
||||
import jakarta.mail.MessagingException;
|
||||
import jakarta.validation.Valid;
|
||||
import java.io.IOException;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
||||
|
||||
@Controller
|
||||
@RequiredArgsConstructor
|
||||
public class EmailSendController {
|
||||
|
||||
private final EmailSendPortIn emailSendPortIn;
|
||||
private final MessageUtil messageUtil;
|
||||
|
||||
@PostMapping(path = "/addons/email/form")
|
||||
public String sendEmail(
|
||||
RedirectAttributes redirectAttributes,
|
||||
@Valid @ModelAttribute("formDto") EmailVO emailVO,
|
||||
BindingResult bindingResult)
|
||||
throws IOException, MessagingException {
|
||||
|
||||
if (bindingResult.hasErrors()) {
|
||||
return "email/emailForm";
|
||||
}
|
||||
|
||||
emailSendPortIn.connect(
|
||||
new Email(
|
||||
emailVO.getTo(),
|
||||
null,
|
||||
emailVO.getSubject(),
|
||||
emailVO.getMsgType(),
|
||||
emailVO.getMessage(),
|
||||
emailVO.getMultipartFiles()));
|
||||
|
||||
redirectAttributes.addFlashAttribute(
|
||||
"operationMessage",
|
||||
messageUtil.getMessage("operation.common.email.to", emailVO.getTo()));
|
||||
|
||||
return "redirect:/addons/email/form";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package app.module.admin.usecase.email.send.adapters.web.model;
|
||||
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import java.util.List;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
public class EmailVO {
|
||||
|
||||
@NotEmpty(message = "{valid.common.required}")
|
||||
private String to;
|
||||
|
||||
@NotEmpty(message = "{valid.common.required}")
|
||||
private String subject;
|
||||
|
||||
private String msgType;
|
||||
|
||||
@NotEmpty(message = "{valid.common.required}")
|
||||
private String message;
|
||||
|
||||
private List<MultipartFile> multipartFiles;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package app.module.admin.usecase.email.send.ports;
|
||||
|
||||
import app.module.admin.usecase.email.send.ports.application.domain.Email;
|
||||
import jakarta.mail.MessagingException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
public interface EmailSendPortIn {
|
||||
|
||||
void connect(Email email) throws MessagingException, UnsupportedEncodingException;
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package app.module.admin.usecase.email.send.ports.application;
|
||||
|
||||
import app.module.admin.usecase.email.send.ports.EmailSendPortIn;
|
||||
import app.module.admin.usecase.email.send.ports.application.domain.Email;
|
||||
import jakarta.mail.MessagingException;
|
||||
import jakarta.mail.internet.MimeMessage;
|
||||
import jakarta.mail.internet.MimeUtility;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Objects;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.mail.javamail.JavaMailSender;
|
||||
import org.springframework.mail.javamail.MimeMessageHelper;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
class EmailSendService implements EmailSendPortIn {
|
||||
|
||||
private final JavaMailSender mailSender;
|
||||
|
||||
@Value("${spring.mail.username}")
|
||||
private String mailUsername;
|
||||
|
||||
@Override
|
||||
public void connect(Email email) throws MessagingException, UnsupportedEncodingException {
|
||||
MimeMessage mimeMessage = mailSender.createMimeMessage();
|
||||
MimeMessageHelper mimeMessageHelper = new MimeMessageHelper(mimeMessage, true, "UTF-8");
|
||||
mimeMessageHelper.setTo(email.getTo());
|
||||
mimeMessageHelper.setFrom(email.getFrom() != null ? email.getFrom() : mailUsername);
|
||||
mimeMessageHelper.setSubject(MimeUtility.encodeText(email.getSubject(), "UTF-8", "B"));
|
||||
mimeMessageHelper.setText(email.getMessage(), "HTML".equals(email.getMsgType()));
|
||||
|
||||
if (email.getMultipartFiles() != null) {
|
||||
for (MultipartFile multipartFile : email.getMultipartFiles()) {
|
||||
if (!multipartFile.isEmpty()) {
|
||||
mimeMessageHelper.addAttachment(
|
||||
Objects.requireNonNull(multipartFile.getOriginalFilename()), multipartFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mailSender.send(mimeMessage);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package app.module.admin.usecase.email.send.ports.application.domain;
|
||||
|
||||
import java.util.List;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class Email {
|
||||
|
||||
private String to;
|
||||
private String from;
|
||||
private String subject;
|
||||
private String msgType;
|
||||
private String message;
|
||||
private List<MultipartFile> multipartFiles;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package app.module.admin.usecase.home.adapters.web;
|
||||
|
||||
import app.module.core.usecase.admin.view.ports.AdminViewPortIn;
|
||||
import java.security.Principal;
|
||||
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.RequestMapping;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/")
|
||||
@RequiredArgsConstructor
|
||||
public class HomeController {
|
||||
|
||||
private final AdminViewPortIn adminViewPortIn;
|
||||
|
||||
@GetMapping
|
||||
public String home(Principal principal, Model model) {
|
||||
adminViewPortIn
|
||||
.connect(principal.getName())
|
||||
.ifPresent(
|
||||
loginUser -> {
|
||||
model.addAttribute("loginUser", loginUser);
|
||||
model.addAttribute("loginUserRoles", loginUser.getRoles());
|
||||
});
|
||||
|
||||
return "home";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package app.module.admin.usecase.loggedinuser.remove.adapters.persistence;
|
||||
|
||||
import app.module.admin.usecase.loggedinuser.remove.adapters.persistence.model.LoggedInUserRemoveParam;
|
||||
import app.module.admin.usecase.loggedinuser.remove.ports.LoggedInUserRemovePortOut;
|
||||
import app.module.admin.usecase.loggedinuser.remove.ports.application.domain.LoggedInUserRemoveCmd;
|
||||
import app.module.core.config.application.util.CommonUtil;
|
||||
import java.time.LocalDateTime;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
@RequiredArgsConstructor
|
||||
public class LoggedInUserRemoveDao implements LoggedInUserRemovePortOut {
|
||||
|
||||
private final LoggedInUserRemoveMapper mapper;
|
||||
|
||||
@Override
|
||||
public void connect(LoggedInUserRemoveCmd removeCommand) {
|
||||
mapper.deleteByCompositeId(new LoggedInUserRemoveParam(
|
||||
removeCommand.getAppType(),
|
||||
removeCommand.getId(),
|
||||
LocalDateTime.now(),
|
||||
CommonUtil.getLoginUsername(),
|
||||
LocalDateTime.now(),
|
||||
CommonUtil.getLoginUsername(),
|
||||
false
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package app.module.admin.usecase.loggedinuser.remove.adapters.persistence;
|
||||
|
||||
|
||||
import app.module.admin.usecase.loggedinuser.remove.adapters.persistence.model.LoggedInUserRemoveParam;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface LoggedInUserRemoveMapper {
|
||||
void deleteByCompositeId(LoggedInUserRemoveParam param);
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package app.module.admin.usecase.loggedinuser.remove.adapters.persistence.model;
|
||||
|
||||
import app.module.core.config.application.enums.AppType;
|
||||
import java.time.LocalDateTime;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
public class LoggedInUserRemoveParam {
|
||||
private AppType appType;
|
||||
private String id;
|
||||
private LocalDateTime updatedAt;
|
||||
private String updatedBy;
|
||||
private LocalDateTime deletedAt;
|
||||
private String deletedBy;
|
||||
private Boolean isDeleted;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package app.module.admin.usecase.loggedinuser.remove.ports;
|
||||
|
||||
import app.module.admin.usecase.loggedinuser.remove.ports.application.domain.LoggedInUserRemoveCmd;
|
||||
|
||||
public interface LoggedInUserRemovePortIn {
|
||||
|
||||
void connect(LoggedInUserRemoveCmd loggedInUserId);
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package app.module.admin.usecase.loggedinuser.remove.ports;
|
||||
|
||||
import app.module.admin.usecase.loggedinuser.remove.ports.application.domain.LoggedInUserRemoveCmd;
|
||||
|
||||
public interface LoggedInUserRemovePortOut {
|
||||
|
||||
void connect(LoggedInUserRemoveCmd removeCommand);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package app.module.admin.usecase.loggedinuser.remove.ports.application;
|
||||
|
||||
import app.module.admin.usecase.loggedinuser.remove.ports.LoggedInUserRemovePortIn;
|
||||
import app.module.admin.usecase.loggedinuser.remove.ports.LoggedInUserRemovePortOut;
|
||||
import app.module.admin.usecase.loggedinuser.remove.ports.application.domain.LoggedInUserRemoveCmd;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class LoggedInUserRemoveService implements LoggedInUserRemovePortIn {
|
||||
|
||||
private final LoggedInUserRemovePortOut portOut;
|
||||
|
||||
@Override
|
||||
public void connect(LoggedInUserRemoveCmd removeCommand) {
|
||||
portOut.connect(removeCommand);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package app.module.admin.usecase.loggedinuser.remove.ports.application.domain;
|
||||
|
||||
import app.module.core.config.application.enums.AppType;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class LoggedInUserRemoveCmd {
|
||||
private AppType appType;
|
||||
private String id;
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package app.module.admin.usecase.loggedinuser.save.adapter.persistence;
|
||||
|
||||
import app.module.admin.usecase.loggedinuser.save.ports.LoggedInUserSavePortOut;
|
||||
import app.module.admin.usecase.loggedinuser.save.ports.application.domain.LoggedInUserSaveCmd;
|
||||
import app.module.admin.usecase.loggedinuser.view.adapters.persistence.LoggedInUserViewMapper;
|
||||
import app.module.admin.usecase.loggedinuser.view.adapters.persistence.model.LoggedInUserDto;
|
||||
import app.module.core.config.adapters.persistence.entity.LoggedInUser;
|
||||
import java.util.Optional;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
@RequiredArgsConstructor
|
||||
public class LoggedInUserSaveDao implements LoggedInUserSavePortOut {
|
||||
|
||||
private final LoggedInUserSaveMapper mapper;
|
||||
private final LoggedInUserViewMapper viewMapper;
|
||||
|
||||
@Override
|
||||
public void connect(LoggedInUserSaveCmd saveCommand) {
|
||||
|
||||
Optional<LoggedInUserDto> existedLoggedInUser =
|
||||
viewMapper.findByCompositeKey(
|
||||
saveCommand.getLoggedInUserId().getAppType(),
|
||||
saveCommand.getLoggedInUserId().getId());
|
||||
|
||||
LoggedInUser loggedInUser = new LoggedInUser(
|
||||
saveCommand.getLoggedInUserId().getAppType(),
|
||||
saveCommand.getLoggedInUserId().getId(),
|
||||
saveCommand.getClientIP(),
|
||||
saveCommand.getLastLoggedInAt()
|
||||
);
|
||||
|
||||
if (existedLoggedInUser.isPresent()) {
|
||||
mapper.update(loggedInUser);
|
||||
} else {
|
||||
mapper.insert(loggedInUser);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package app.module.admin.usecase.loggedinuser.save.adapter.persistence;
|
||||
|
||||
import app.module.core.config.adapters.persistence.entity.LoggedInUser;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface LoggedInUserSaveMapper {
|
||||
void insert(LoggedInUser loggedInUser);
|
||||
void update(LoggedInUser loggedInUser);
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package app.module.admin.usecase.loggedinuser.save.ports;
|
||||
|
||||
import app.module.admin.usecase.loggedinuser.save.ports.application.domain.LoggedInUserSaveCmd;
|
||||
|
||||
public interface LoggedInUserSavePortIn {
|
||||
|
||||
void connect(LoggedInUserSaveCmd loggedInUserSaveCmd);
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package app.module.admin.usecase.loggedinuser.save.ports;
|
||||
|
||||
import app.module.admin.usecase.loggedinuser.save.ports.application.domain.LoggedInUserSaveCmd;
|
||||
|
||||
public interface LoggedInUserSavePortOut {
|
||||
|
||||
void connect(LoggedInUserSaveCmd loggedInUser);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package app.module.admin.usecase.loggedinuser.save.ports.application;
|
||||
|
||||
import app.module.admin.usecase.loggedinuser.save.ports.LoggedInUserSavePortIn;
|
||||
import app.module.admin.usecase.loggedinuser.save.ports.LoggedInUserSavePortOut;
|
||||
import app.module.admin.usecase.loggedinuser.save.ports.application.domain.LoggedInUserSaveCmd;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class LoggedInUserSaveService implements LoggedInUserSavePortIn {
|
||||
|
||||
private final LoggedInUserSavePortOut portOut;
|
||||
|
||||
@Override
|
||||
public void connect(LoggedInUserSaveCmd loggedInUserSaveCmd) {
|
||||
portOut.connect(loggedInUserSaveCmd);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package app.module.admin.usecase.loggedinuser.save.ports.application.domain;
|
||||
|
||||
import app.module.core.config.application.enums.AppType;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class LoggedInUserIdSaveCmd {
|
||||
private AppType appType;
|
||||
private String id;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package app.module.admin.usecase.loggedinuser.save.ports.application.domain;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@Builder
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class LoggedInUserSaveCmd {
|
||||
private LoggedInUserIdSaveCmd loggedInUserId;
|
||||
private String clientIP;
|
||||
private LocalDateTime lastLoggedInAt;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package app.module.admin.usecase.loggedinuser.view.adapters.persistence;
|
||||
|
||||
import app.module.admin.usecase.loggedinuser.view.adapters.persistence.model.LoggedInUserDto;
|
||||
import app.module.admin.usecase.loggedinuser.view.ports.LoggedInUserViewPortOut;
|
||||
import app.module.admin.usecase.loggedinuser.view.ports.application.domain.LoggedInUserIdCmd;
|
||||
import app.module.admin.usecase.loggedinuser.view.ports.application.domain.LoggedInUserView;
|
||||
import java.util.Optional;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
@RequiredArgsConstructor
|
||||
public class LoggedInUserViewDao implements LoggedInUserViewPortOut {
|
||||
|
||||
private final LoggedInUserViewMapper mapper;
|
||||
|
||||
@Override
|
||||
public LoggedInUserView connect(LoggedInUserIdCmd userCommand) {
|
||||
return mapper.findByCompositeKey(userCommand.getAppType(), userCommand.getId())
|
||||
.map(d -> new LoggedInUserView(
|
||||
new LoggedInUserIdCmd(d.getAppType(), d.getId()),
|
||||
d.getClientIP(),
|
||||
d.getLastLoggedInAt()
|
||||
)).orElse(null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package app.module.admin.usecase.loggedinuser.view.adapters.persistence;
|
||||
|
||||
import app.module.admin.usecase.loggedinuser.view.adapters.persistence.model.LoggedInUserDto;
|
||||
import app.module.core.config.application.enums.AppType;
|
||||
import java.util.Optional;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface LoggedInUserViewMapper {
|
||||
Optional<LoggedInUserDto> findByCompositeKey(AppType appType, String id);
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package app.module.admin.usecase.loggedinuser.view.adapters.persistence.model;
|
||||
|
||||
import app.module.core.config.application.enums.AppType;
|
||||
import java.time.LocalDateTime;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
public class LoggedInUserDto {
|
||||
private AppType appType;
|
||||
private String id;
|
||||
private String clientIP;
|
||||
private LocalDateTime lastLoggedInAt;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package app.module.admin.usecase.loggedinuser.view.ports;
|
||||
|
||||
import app.module.admin.usecase.loggedinuser.view.ports.application.domain.LoggedInUserIdCmd;
|
||||
import app.module.admin.usecase.loggedinuser.view.ports.application.domain.LoggedInUserView;
|
||||
|
||||
public interface LoggedInUserViewPortIn {
|
||||
|
||||
LoggedInUserView connect(LoggedInUserIdCmd userCommand);
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package app.module.admin.usecase.loggedinuser.view.ports;
|
||||
|
||||
import app.module.admin.usecase.loggedinuser.view.ports.application.domain.LoggedInUserIdCmd;
|
||||
import app.module.admin.usecase.loggedinuser.view.ports.application.domain.LoggedInUserView;
|
||||
|
||||
public interface LoggedInUserViewPortOut {
|
||||
|
||||
LoggedInUserView connect(LoggedInUserIdCmd userCommand);
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package app.module.admin.usecase.loggedinuser.view.ports.application;
|
||||
|
||||
import app.module.admin.usecase.loggedinuser.view.ports.LoggedInUserViewPortIn;
|
||||
import app.module.admin.usecase.loggedinuser.view.ports.LoggedInUserViewPortOut;
|
||||
import app.module.admin.usecase.loggedinuser.view.ports.application.domain.LoggedInUserIdCmd;
|
||||
import app.module.admin.usecase.loggedinuser.view.ports.application.domain.LoggedInUserView;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class LoggedInUserViewService implements LoggedInUserViewPortIn {
|
||||
|
||||
private final LoggedInUserViewPortOut portOut;
|
||||
|
||||
@Override
|
||||
public LoggedInUserView connect(LoggedInUserIdCmd userCommand) {
|
||||
return portOut.connect(userCommand);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package app.module.admin.usecase.loggedinuser.view.ports.application.domain;
|
||||
|
||||
import app.module.core.config.application.enums.AppType;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
public class LoggedInUserIdCmd {
|
||||
private AppType appType;
|
||||
private String id;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package app.module.admin.usecase.loggedinuser.view.ports.application.domain;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
public class LoggedInUserView {
|
||||
private LoggedInUserIdCmd loggedInUserId;
|
||||
private String clientIP;
|
||||
private LocalDateTime lastLoggedInAt;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package app.module.admin.usecase.login.adapters.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,45 @@
|
||||
package app.module.admin.usecase.operationlog.list.adapters.web;
|
||||
|
||||
import app.module.admin.usecase.operationlog.list.adapters.web.model.OperationLogListFilterVO;
|
||||
import app.module.core.usecase.operationlog.list.application.domain.OperationLogElement;
|
||||
import app.module.core.usecase.operationlog.list.application.domain.OperationLogListFilterCommand;
|
||||
import app.module.core.usecase.operationlog.list.application.port.in.OperationLogListPortIn;
|
||||
import app.module.core.usecase.uicode.list.ports.UICodeListPortIn;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort.Direction;
|
||||
import org.springframework.data.web.PageableDefault;
|
||||
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
|
||||
public class OperationLogListController {
|
||||
|
||||
private final OperationLogListPortIn operationLogListPortIn;
|
||||
private final UICodeListPortIn uiCodeListPortIn;
|
||||
|
||||
@GetMapping("/analysis/operationlog")
|
||||
String operate(
|
||||
Model model,
|
||||
@PageableDefault(sort = "createdAt", direction = Direction.DESC) Pageable pageable,
|
||||
@ModelAttribute("paramDto") OperationLogListFilterVO statusVO) {
|
||||
|
||||
Page<OperationLogElement> listOutput =
|
||||
operationLogListPortIn.connect(
|
||||
pageable,
|
||||
new OperationLogListFilterCommand(
|
||||
statusVO.getSearchField(),
|
||||
statusVO.getSearchValue(),
|
||||
statusVO.getSearchAppType(),
|
||||
statusVO.getSearchOperationType()));
|
||||
|
||||
model.addAttribute("listOutput", listOutput);
|
||||
model.addAttribute("pageRows", uiCodeListPortIn.connect("code.pageable.rows"));
|
||||
|
||||
return "operationLog/operationLogList";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package app.module.admin.usecase.operationlog.list.adapters.web;
|
||||
|
||||
import app.module.admin.usecase.operationlog.list.adapters.web.model.OperationLogListFilterVO;
|
||||
import app.module.core.config.application.util.ExcelUtil;
|
||||
import app.module.core.usecase.operationlog.list.application.domain.OperationLogElement;
|
||||
import app.module.core.usecase.operationlog.list.application.domain.OperationLogListFilterCommand;
|
||||
import app.module.core.usecase.operationlog.list.application.port.in.OperationLogListPortIn;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Optional;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort.Direction;
|
||||
import org.springframework.data.web.PageableDefault;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
|
||||
@Controller
|
||||
@RequiredArgsConstructor
|
||||
public class OperationLogListExcelController {
|
||||
|
||||
private final ExcelUtil excelUtil;
|
||||
private final OperationLogListPortIn operationLogListPortIn;
|
||||
|
||||
@GetMapping("/analysis/operationlog/excel")
|
||||
public void operate(
|
||||
HttpServletResponse response,
|
||||
@PageableDefault(sort = "createdAt", direction = Direction.DESC) Pageable pageable,
|
||||
@ModelAttribute("paramDto") OperationLogListFilterVO statusVO) {
|
||||
Workbook wb = new XSSFWorkbook();
|
||||
Sheet sheet = wb.createSheet("수행로그 목록");
|
||||
|
||||
Page<OperationLogElement> listOutput =
|
||||
operationLogListPortIn.connect(
|
||||
pageable,
|
||||
new OperationLogListFilterCommand(
|
||||
statusVO.getSearchField(),
|
||||
statusVO.getSearchValue(),
|
||||
statusVO.getSearchAppType(),
|
||||
statusVO.getSearchOperationType()));
|
||||
|
||||
if (CollectionUtils.isNotEmpty(listOutput.getContent())) {
|
||||
// Header
|
||||
Row headerRow = sheet.createRow(sheet.getPhysicalNumberOfRows());
|
||||
excelUtil.createCells(
|
||||
headerRow, "로그 ID", "App Type", "Operation Type", "IP", "수행일", "수행자", "피수행자",
|
||||
"수행 내용");
|
||||
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
|
||||
|
||||
listOutput
|
||||
.getContent()
|
||||
.forEach(
|
||||
item -> {
|
||||
Row row = sheet.createRow(sheet.getPhysicalNumberOfRows());
|
||||
|
||||
excelUtil.createCells(
|
||||
row,
|
||||
item.getId(),
|
||||
item.getAppType().name(),
|
||||
item.getOperationLogType().name(),
|
||||
item.getIp(),
|
||||
Optional.ofNullable(item.getCreatedAt())
|
||||
.map(localDateTime -> localDateTime.format(formatter))
|
||||
.orElse(""),
|
||||
item.getCreatedBy(),
|
||||
item.getTargetId(),
|
||||
item.getTaskDesc());
|
||||
});
|
||||
}
|
||||
|
||||
excelUtil.generateWithPassword(response, wb, "operation-logs");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package app.module.admin.usecase.operationlog.list.adapters.web.model;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
public class OperationLogListFilterVO {
|
||||
|
||||
private String searchField;
|
||||
private String searchValue;
|
||||
private String searchAppType;
|
||||
private String searchOperationType;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package app.module.admin.usecase.privileges.index.adapters.web;
|
||||
|
||||
import app.module.core.config.application.enums.AppType;
|
||||
import groovy.util.logging.Slf4j;
|
||||
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.RequestMapping;
|
||||
|
||||
@Controller
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/settings/adminPrivilege")
|
||||
@Slf4j
|
||||
class PrivilegeIndexController {
|
||||
|
||||
@GetMapping
|
||||
String intro(Model model) {
|
||||
model.addAttribute("appType", AppType.ADMIN);
|
||||
return "privilege/privilegeList";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package app.module.admin.usecase.privileges.list.adapters.web;
|
||||
|
||||
import app.module.admin.usecase.privileges.list.adapters.web.model.PrivilegeElementVO;
|
||||
import app.module.core.config.adapters.web.rest.response.RestResponse;
|
||||
import app.module.core.config.application.enums.AppType;
|
||||
import app.module.core.usecase.privilege.list.ports.PrivilegeListPortIn;
|
||||
import app.module.core.usecase.privilege.list.ports.application.domain.PrivilegeElement;
|
||||
import java.util.stream.Collectors;
|
||||
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.RestController;
|
||||
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
class PrivilegeListRestController {
|
||||
|
||||
private final PrivilegeListPortIn<PrivilegeElement> listPortIn;
|
||||
|
||||
@GetMapping("/api/adminPrivilege/get/recursiveItems")
|
||||
ResponseEntity<?> operate() {
|
||||
return ResponseEntity.status(HttpStatus.OK)
|
||||
.body(
|
||||
RestResponse.<PrivilegeElementVO>builder()
|
||||
.items(
|
||||
listPortIn.connect(AppType.ADMIN).stream()
|
||||
.map(
|
||||
p ->
|
||||
new PrivilegeElementVO(
|
||||
p.getCreatedBy(),
|
||||
p.getCreatedAt(),
|
||||
p.getUpdatedBy(),
|
||||
p.getUpdatedAt(),
|
||||
p.getId(),
|
||||
p.getDescription(),
|
||||
p.getOrderNo()))
|
||||
.collect(Collectors.toList()))
|
||||
.build());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package app.module.admin.usecase.privileges.list.adapters.web.model;
|
||||
|
||||
import app.module.core.config.application.converter.CustomLocalDateTimeSerializer;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
|
||||
import java.time.LocalDateTime;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
public class PrivilegeElementVO {
|
||||
|
||||
private final String createdBy;
|
||||
|
||||
@JsonSerialize(using = CustomLocalDateTimeSerializer.class)
|
||||
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
|
||||
private final LocalDateTime createdAt;
|
||||
|
||||
private final String updatedBy;
|
||||
|
||||
@JsonSerialize(using = CustomLocalDateTimeSerializer.class)
|
||||
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
|
||||
private final LocalDateTime updatedAt;
|
||||
|
||||
private final String id;
|
||||
private final String description;
|
||||
private final Integer orderNo;
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package app.module.admin.usecase.privileges.remove.adapters.web;
|
||||
|
||||
import app.module.admin.usecase.privileges.remove.adapters.web.model.RoleRemoveVO;
|
||||
import app.module.core.config.adapters.web.rest.response.RestResponse;
|
||||
import app.module.core.config.application.util.MessageUtil;
|
||||
import app.module.core.usecase.privilege.remove.ports.PrivilegeRemovePortIn;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
class PrivilegeRemoveRestController {
|
||||
|
||||
private final PrivilegeRemovePortIn removePortIn;
|
||||
private final MessageUtil messageUtil;
|
||||
|
||||
@PostMapping("/api/adminPrivilege/remove")
|
||||
ResponseEntity<?> remove(RoleRemoveVO formDto) {
|
||||
removePortIn.connect(formDto.getId());
|
||||
return ResponseEntity.status(HttpStatus.OK)
|
||||
.body(
|
||||
RestResponse.builder()
|
||||
.message(messageUtil.getMessage("operation.common.remove.done"))
|
||||
.build());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package app.module.admin.usecase.privileges.remove.adapters.web.model;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class RoleRemoveVO {
|
||||
|
||||
private String id;
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package app.module.admin.usecase.privileges.save.adapters.web;
|
||||
|
||||
import app.module.admin.usecase.privileges.save.adapters.web.model.PrivilegeSaveBindingVO;
|
||||
import app.module.core.config.adapters.web.rest.response.RestResponse;
|
||||
import app.module.core.config.application.enums.AppType;
|
||||
import app.module.core.config.application.exception.AlreadyExistsRoleException;
|
||||
import app.module.core.config.application.util.CoreUtil;
|
||||
import app.module.core.config.application.util.MessageUtil;
|
||||
import app.module.core.usecase.privilege.save.ports.PrivilegeSavePortIn;
|
||||
import app.module.core.usecase.privilege.save.ports.application.domain.PrivilegeSaveCommand;
|
||||
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 PrivilegeSaveRestController {
|
||||
|
||||
private final CoreUtil coreUtil;
|
||||
private final MessageUtil messageUtil;
|
||||
private final PrivilegeSavePortIn savePortIn;
|
||||
|
||||
@PostMapping("/api/adminPrivilege/save")
|
||||
ResponseEntity<?> operate(@Valid PrivilegeSaveBindingVO bindingVO,
|
||||
BindingResult bindingResult) {
|
||||
if (bindingResult.hasErrors()) {
|
||||
return coreUtil.getErrorInfo(bindingResult);
|
||||
}
|
||||
|
||||
PrivilegeSaveCommand saveInput =
|
||||
new PrivilegeSaveCommand(
|
||||
AppType.ADMIN, bindingVO.getId(), bindingVO.getDescription(), bindingVO.getOrderNo());
|
||||
|
||||
try {
|
||||
savePortIn.connect(saveInput);
|
||||
|
||||
// `create` 인 경우 save 과정에서 orderNo 가 생성된다.
|
||||
bindingVO.setOrderNo(saveInput.getOrderNo());
|
||||
|
||||
} catch (AlreadyExistsRoleException e) {
|
||||
bindingResult.rejectValue("id", "", e.getMessage());
|
||||
return coreUtil.getErrorInfo(bindingResult);
|
||||
}
|
||||
|
||||
return ResponseEntity.status(HttpStatus.OK)
|
||||
.body(
|
||||
RestResponse.builder()
|
||||
.item(bindingVO)
|
||||
.message(messageUtil.getMessage("operation.common.save.done"))
|
||||
.build());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package app.module.admin.usecase.privileges.save.adapters.web.model;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
public class PrivilegeSaveBindingVO {
|
||||
|
||||
private final String id;
|
||||
private final String description;
|
||||
private Integer orderNo;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package app.module.admin.usecase.privileges.sort.adapters.web;
|
||||
|
||||
import app.module.admin.usecase.privileges.sort.adapters.web.model.PrivilegeSortVO;
|
||||
import app.module.core.usecase.privilege.sort.ports.PrivilegeSortPortIn;
|
||||
import app.module.core.usecase.privilege.sort.ports.application.domain.PrivilegeSortCmd;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
class PrivilegeSortRestController {
|
||||
|
||||
private final PrivilegeSortPortIn sortPortIn;
|
||||
|
||||
@PostMapping("/api/adminPrivilege/switchOrderNo")
|
||||
ResponseEntity<?> switchOrderNo(@RequestBody List<PrivilegeSortVO> sortVOs) {
|
||||
sortPortIn.connect(
|
||||
sortVOs.stream()
|
||||
.map(s -> new PrivilegeSortCmd(s.getId(), s.getOrderNo()))
|
||||
.collect(Collectors.toList()));
|
||||
|
||||
return ResponseEntity.status(HttpStatus.OK).body(null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package app.module.admin.usecase.privileges.sort.adapters.web.model;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class PrivilegeSortVO {
|
||||
|
||||
private String id;
|
||||
private Integer orderNo;
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package app.module.admin.usecase.privileges.view.adapters.web;
|
||||
|
||||
import app.module.admin.usecase.privileges.view.adapters.web.model.PrivilegeViewVO;
|
||||
import app.module.core.config.adapters.web.rest.response.RestResponse;
|
||||
import app.module.core.config.application.util.MessageUtil;
|
||||
import app.module.core.usecase.privilege.view.ports.PrivilegeViewPortIn;
|
||||
import app.module.core.usecase.privilege.view.ports.application.domain.PrivilegeView;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Optional;
|
||||
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 PrivilegeViewRestController {
|
||||
|
||||
private final MessageUtil messageUtil;
|
||||
private final PrivilegeViewPortIn privilegeViewPortIn;
|
||||
|
||||
@GetMapping("/api/adminPrivilege/get/{id}")
|
||||
ResponseEntity<?> view(@PathVariable String id) {
|
||||
PrivilegeView item =
|
||||
Optional.ofNullable(privilegeViewPortIn.connect(id))
|
||||
.orElseThrow(
|
||||
() ->
|
||||
new NoSuchElementException(
|
||||
messageUtil.getMessage("exception.noSuchElement", id, "ROLE ID")));
|
||||
|
||||
return ResponseEntity.status(HttpStatus.OK)
|
||||
.body(
|
||||
RestResponse.builder()
|
||||
.item(
|
||||
new PrivilegeViewVO(
|
||||
item.getCreatedBy(),
|
||||
item.getCreatedAt(),
|
||||
item.getUpdatedBy(),
|
||||
item.getUpdatedAt(),
|
||||
item.getId(),
|
||||
item.getDescription(),
|
||||
item.getOrderNo()))
|
||||
.build());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package app.module.admin.usecase.privileges.view.adapters.web.model;
|
||||
|
||||
import app.module.core.config.application.converter.CustomLocalDateTimeSerializer;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
|
||||
import java.time.LocalDateTime;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
public class PrivilegeViewVO {
|
||||
|
||||
private final String createdBy;
|
||||
|
||||
@JsonSerialize(using = CustomLocalDateTimeSerializer.class)
|
||||
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
|
||||
private final LocalDateTime createdAt;
|
||||
|
||||
private final String updatedBy;
|
||||
|
||||
@JsonSerialize(using = CustomLocalDateTimeSerializer.class)
|
||||
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
|
||||
private final LocalDateTime updatedAt;
|
||||
|
||||
private final String id;
|
||||
private final String description;
|
||||
private final Integer orderNo;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package app.module.admin.usecase.role.index.adapters.web;
|
||||
|
||||
import app.module.core.config.application.enums.AppType;
|
||||
import app.module.core.usecase.privilege.list.ports.PrivilegeListPortIn;
|
||||
import app.module.core.usecase.privilege.list.ports.application.domain.PrivilegeElement;
|
||||
import groovy.util.logging.Slf4j;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
@Controller
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
class RoleIndexUIController {
|
||||
|
||||
private final PrivilegeListPortIn<PrivilegeElement> privilegeListPortIn;
|
||||
|
||||
@GetMapping("/settings/adminRoles")
|
||||
String intro(Model model) {
|
||||
model.addAttribute("privileges", privilegeListPortIn.connect(AppType.ADMIN));
|
||||
return "adminRole/adminRoleList";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package app.module.admin.usecase.role.list.adapters.web;
|
||||
|
||||
import app.module.admin.usecase.role.view.adapters.web.model.RoleBindingVO;
|
||||
import app.module.core.config.adapters.web.rest.response.RestResponse;
|
||||
import app.module.core.config.application.enums.AppType;
|
||||
import app.module.core.usecase.role.list.ports.RoleListPortIn;
|
||||
import app.module.core.usecase.role.list.ports.application.domain.PrivilegeElement;
|
||||
import app.module.core.usecase.role.list.ports.application.domain.RoleElement;
|
||||
import java.util.stream.Collectors;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
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 RoleListRestController {
|
||||
|
||||
private final RoleListPortIn<RoleElement> roleListPortIn;
|
||||
|
||||
@GetMapping("/api/adminRole/get/recursiveItems")
|
||||
ResponseEntity<?> operate() {
|
||||
|
||||
return ResponseEntity.status(HttpStatus.OK)
|
||||
.body(
|
||||
RestResponse.<RoleBindingVO>builder()
|
||||
.items(
|
||||
roleListPortIn.connect(AppType.ADMIN).stream()
|
||||
.map(
|
||||
item ->
|
||||
new RoleBindingVO(
|
||||
item.getCreatedBy(),
|
||||
item.getCreatedAt(),
|
||||
item.getUpdatedBy(),
|
||||
item.getUpdatedAt(),
|
||||
item.getId(),
|
||||
item.getDescription(),
|
||||
item.getOrderNo(),
|
||||
CollectionUtils.emptyIfNull(item.getPrivileges()).stream()
|
||||
.map(PrivilegeElement::getId)
|
||||
.collect(Collectors.toList())))
|
||||
.collect(Collectors.toList()))
|
||||
.build());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package app.module.admin.usecase.role.list.adapters.web.model;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
public class PrivilegeBindingVO {
|
||||
|
||||
private final String id;
|
||||
private final String description;
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user