From 7342ad4bf5a237dc3fb1500f47018b17b3a0444b Mon Sep 17 00:00:00 2001 From: KimDoubleB Date: Sat, 24 Dec 2022 13:51:17 +0900 Subject: [PATCH 01/46] refactor: JWT expired date logic to method --- .../config/security/token/jwt/JwtTokenProvider.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/archive-web/src/main/java/site/archive/web/config/security/token/jwt/JwtTokenProvider.java b/archive-web/src/main/java/site/archive/web/config/security/token/jwt/JwtTokenProvider.java index 17df2ef..fc6cc4b 100644 --- a/archive-web/src/main/java/site/archive/web/config/security/token/jwt/JwtTokenProvider.java +++ b/archive-web/src/main/java/site/archive/web/config/security/token/jwt/JwtTokenProvider.java @@ -15,6 +15,7 @@ @Slf4j public class JwtTokenProvider implements TokenProvider { + private static final long DAY_30 = 1000L * 60 * 60 * 24 * 30; private final String secretKey; private final ObjectMapper mapper; @@ -24,8 +25,6 @@ public JwtTokenProvider(String key, ObjectMapper mapper) { } public String createToken(UserInfo info) { - Date date = new Date(); - date.setTime(date.getTime() + 1000L * 60 * 60 * 24 * 30); return Jwts .builder() .setSubject("user") @@ -33,11 +32,17 @@ public String createToken(UserInfo info) { .setHeaderParam("typ", "JWT") .setHeaderParam("alg", "ES56") .setHeaderParam("kid", "default") - .setExpiration(date) + .setExpiration(getTokenExpiredDate()) .signWith(SignatureAlgorithm.HS256, secretKey.getBytes()) .compact(); } + private Date getTokenExpiredDate() { + Date date = new Date(); + date.setTime(date.getTime() + DAY_30); + return date; + } + public UserInfo parseUserInfoFromToken(String token) { try { var jwtClaims = Jwts.parser() From d694a6f6093d27a86e9305dcd31206eb864e9d9b Mon Sep 17 00:00:00 2001 From: KimDoubleB Date: Sat, 24 Dec 2022 14:36:01 +0900 Subject: [PATCH 02/46] feat(#48): migration to spring boot 3.0 --- .editorconfig | 4 +- .../archive/config/AsyncConfiguration.java | 2 - .../dto/v1/auth/BasicRegisterCommandV1.java | 4 +- .../v1/auth/PasswordRegisterCommandV1.java | 4 +- .../v1/user/OAuthRegisterRequestDtoV1.java | 2 +- .../dto/v1/user/UserEmailRequestDtoV1.java | 6 +- .../user/UserPasswordResetRequestDtoV1.java | 10 +- .../archive/dto/v2/OAuthLoginRequestDto.java | 2 +- .../dto/v2/OAuthUserInfoRequestDto.java | 2 +- .../dto/v2/PasswordRegisterRequestDto.java | 6 +- .../site/archive/infra/mail/MailService.java | 7 +- .../user/oauth/provider/AppleClient.java | 2 - .../archive/service/report/ReportService.java | 2 +- archive-domain/build.gradle | 9 +- .../site/archive/domain/archive/Archive.java | 28 ++-- .../archive/domain/archive/ArchiveImage.java | 18 +-- .../converter/CompanionsConverter.java | 4 +- .../site/archive/domain/banner/Banner.java | 16 +- .../archive/domain/common/BaseTimeEntity.java | 6 +- .../site/archive/domain/config/JpaConfig.java | 4 +- .../java/site/archive/domain/like/Like.java | 18 +-- .../site/archive/domain/report/Report.java | 18 +-- .../site/archive/domain/user/BaseUser.java | 22 +-- .../site/archive/domain/user/OAuthUser.java | 12 +- .../archive/domain/user/PasswordUser.java | 8 +- .../archive/domain/user/UserRepository.java | 2 +- .../site/archive/domain/JpaTestConfig.java | 4 +- .../src/test/resources/application-test.yml | 2 +- archive-web/build.gradle | 11 +- .../interceptor/InjectTokenInterceptor.java | 4 +- .../ArchivePageableArgumentResolver.java | 2 +- .../archive/web/config/SwaggerConfig.java | 145 +++--------------- .../web/config/security/SecurityConfig.java | 30 ++-- .../authn/AdminLoginAuthenticationFilter.java | 4 +- .../BodyCredentialAuthenticationFilter.java | 2 +- .../authn/CustomAuthenticationEntryPoint.java | 4 +- .../authn/LoginAuthenticationFilter.java | 4 +- .../authz/CustomAccessDeniedHandler.java | 4 +- .../common/handler/LoginFailureHandler.java | 6 +- .../common/handler/LoginSuccessHandler.java | 4 +- .../security/token/HttpAuthTokenSupport.java | 4 +- .../token/jwt/JwtTokenPersistFilter.java | 8 +- .../security/token/jwt/JwtTokenProvider.java | 30 ++-- .../security/token/jwt/JwtTokenSupport.java | 4 +- .../src/main/resources/application-dev.yml | 2 +- .../src/main/resources/application-prd.yml | 2 +- build.gradle | 4 +- 47 files changed, 202 insertions(+), 296 deletions(-) diff --git a/.editorconfig b/.editorconfig index f821b32..3d76f34 100644 --- a/.editorconfig +++ b/.editorconfig @@ -95,7 +95,7 @@ ij_java_for_statement_wrap = on_every_item ij_java_generate_final_locals = false ij_java_generate_final_parameters = false ij_java_if_brace_force = always -ij_java_imports_layout = *,|,javax.**,|,java.**,|,$* +ij_java_imports_layout = *,|,jakarta.**,|,java.**,|,$* ij_java_indent_case_from_switch = true ij_java_insert_inner_class_imports = false ij_java_insert_override_annotation = true @@ -130,7 +130,7 @@ ij_java_method_parameters_wrap = on_every_item ij_java_modifier_list_wrap = false ij_java_names_count_to_use_import_on_demand = 9999 ij_java_new_line_after_lparen_in_record_header = false -ij_java_packages_to_use_import_on_demand = java.awt.*,javax.swing.* +ij_java_packages_to_use_import_on_demand = java.awt.*,jakarta.swing.* ij_java_parameter_annotation_wrap = on_every_item ij_java_parentheses_expression_new_line_after_left_paren = false ij_java_parentheses_expression_right_paren_on_new_line = false diff --git a/archive-application/src/main/java/site/archive/config/AsyncConfiguration.java b/archive-application/src/main/java/site/archive/config/AsyncConfiguration.java index 2df15f0..e17c8d3 100644 --- a/archive-application/src/main/java/site/archive/config/AsyncConfiguration.java +++ b/archive-application/src/main/java/site/archive/config/AsyncConfiguration.java @@ -7,7 +7,6 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler; import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.boot.context.properties.ConstructorBinding; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -48,7 +47,6 @@ public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() { } @ConfigurationProperties(prefix = "spring.mail.executor") - @ConstructorBinding @AllArgsConstructor @Getter @ToString diff --git a/archive-application/src/main/java/site/archive/dto/v1/auth/BasicRegisterCommandV1.java b/archive-application/src/main/java/site/archive/dto/v1/auth/BasicRegisterCommandV1.java index 2a1957e..a79f0a1 100644 --- a/archive-application/src/main/java/site/archive/dto/v1/auth/BasicRegisterCommandV1.java +++ b/archive-application/src/main/java/site/archive/dto/v1/auth/BasicRegisterCommandV1.java @@ -6,8 +6,8 @@ import lombok.Setter; import site.archive.domain.user.BaseUser; -import javax.validation.constraints.Email; -import javax.validation.constraints.NotEmpty; +import jakarta.validation.constraints.Email; +import jakarta.validation.constraints.NotEmpty; @Getter @Setter diff --git a/archive-application/src/main/java/site/archive/dto/v1/auth/PasswordRegisterCommandV1.java b/archive-application/src/main/java/site/archive/dto/v1/auth/PasswordRegisterCommandV1.java index e95aa03..373d594 100644 --- a/archive-application/src/main/java/site/archive/dto/v1/auth/PasswordRegisterCommandV1.java +++ b/archive-application/src/main/java/site/archive/dto/v1/auth/PasswordRegisterCommandV1.java @@ -9,8 +9,8 @@ import site.archive.domain.user.PasswordUser; import site.archive.domain.user.UserRole; -import javax.validation.constraints.NotEmpty; -import javax.validation.constraints.Pattern; +import jakarta.validation.constraints.NotEmpty; +import jakarta.validation.constraints.Pattern; @EqualsAndHashCode(callSuper = true) @Getter diff --git a/archive-application/src/main/java/site/archive/dto/v1/user/OAuthRegisterRequestDtoV1.java b/archive-application/src/main/java/site/archive/dto/v1/user/OAuthRegisterRequestDtoV1.java index 59136df..6884b8f 100644 --- a/archive-application/src/main/java/site/archive/dto/v1/user/OAuthRegisterRequestDtoV1.java +++ b/archive-application/src/main/java/site/archive/dto/v1/user/OAuthRegisterRequestDtoV1.java @@ -6,7 +6,7 @@ import lombok.NoArgsConstructor; import lombok.ToString; -import javax.validation.constraints.NotNull; +import jakarta.validation.constraints.NotNull; @Getter @ToString diff --git a/archive-application/src/main/java/site/archive/dto/v1/user/UserEmailRequestDtoV1.java b/archive-application/src/main/java/site/archive/dto/v1/user/UserEmailRequestDtoV1.java index a1d9ce0..03a811a 100644 --- a/archive-application/src/main/java/site/archive/dto/v1/user/UserEmailRequestDtoV1.java +++ b/archive-application/src/main/java/site/archive/dto/v1/user/UserEmailRequestDtoV1.java @@ -4,9 +4,9 @@ import lombok.Getter; import lombok.NoArgsConstructor; -import javax.validation.constraints.Email; -import javax.validation.constraints.NotBlank; -import javax.validation.constraints.NotNull; +import jakarta.validation.constraints.Email; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; @Getter @NoArgsConstructor diff --git a/archive-application/src/main/java/site/archive/dto/v1/user/UserPasswordResetRequestDtoV1.java b/archive-application/src/main/java/site/archive/dto/v1/user/UserPasswordResetRequestDtoV1.java index f32799d..f2735f9 100644 --- a/archive-application/src/main/java/site/archive/dto/v1/user/UserPasswordResetRequestDtoV1.java +++ b/archive-application/src/main/java/site/archive/dto/v1/user/UserPasswordResetRequestDtoV1.java @@ -4,11 +4,11 @@ import lombok.Getter; import lombok.NoArgsConstructor; -import javax.validation.constraints.Email; -import javax.validation.constraints.NotBlank; -import javax.validation.constraints.NotEmpty; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Pattern; +import jakarta.validation.constraints.Email; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotEmpty; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Pattern; @Getter @NoArgsConstructor diff --git a/archive-application/src/main/java/site/archive/dto/v2/OAuthLoginRequestDto.java b/archive-application/src/main/java/site/archive/dto/v2/OAuthLoginRequestDto.java index 2c9e39b..554801c 100644 --- a/archive-application/src/main/java/site/archive/dto/v2/OAuthLoginRequestDto.java +++ b/archive-application/src/main/java/site/archive/dto/v2/OAuthLoginRequestDto.java @@ -5,7 +5,7 @@ import lombok.Getter; import lombok.NoArgsConstructor; -import javax.validation.constraints.NotEmpty; +import jakarta.validation.constraints.NotEmpty; @Getter @NoArgsConstructor diff --git a/archive-application/src/main/java/site/archive/dto/v2/OAuthUserInfoRequestDto.java b/archive-application/src/main/java/site/archive/dto/v2/OAuthUserInfoRequestDto.java index 5ff0cd3..b4c521a 100644 --- a/archive-application/src/main/java/site/archive/dto/v2/OAuthUserInfoRequestDto.java +++ b/archive-application/src/main/java/site/archive/dto/v2/OAuthUserInfoRequestDto.java @@ -6,7 +6,7 @@ import lombok.NoArgsConstructor; import lombok.ToString; -import javax.validation.constraints.NotEmpty; +import jakarta.validation.constraints.NotEmpty; @Getter @ToString diff --git a/archive-application/src/main/java/site/archive/dto/v2/PasswordRegisterRequestDto.java b/archive-application/src/main/java/site/archive/dto/v2/PasswordRegisterRequestDto.java index e9987df..2917795 100644 --- a/archive-application/src/main/java/site/archive/dto/v2/PasswordRegisterRequestDto.java +++ b/archive-application/src/main/java/site/archive/dto/v2/PasswordRegisterRequestDto.java @@ -7,9 +7,9 @@ import site.archive.domain.user.PasswordUser; import site.archive.domain.user.UserRole; -import javax.validation.constraints.Email; -import javax.validation.constraints.NotEmpty; -import javax.validation.constraints.Pattern; +import jakarta.validation.constraints.Email; +import jakarta.validation.constraints.NotEmpty; +import jakarta.validation.constraints.Pattern; @Getter @NoArgsConstructor diff --git a/archive-application/src/main/java/site/archive/infra/mail/MailService.java b/archive-application/src/main/java/site/archive/infra/mail/MailService.java index 399c41e..515e2e7 100644 --- a/archive-application/src/main/java/site/archive/infra/mail/MailService.java +++ b/archive-application/src/main/java/site/archive/infra/mail/MailService.java @@ -9,10 +9,11 @@ import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import org.thymeleaf.context.Context; -import org.thymeleaf.spring5.SpringTemplateEngine; -import javax.mail.MessagingException; -import javax.mail.internet.MimeMessage; +import jakarta.mail.MessagingException; +import jakarta.mail.internet.MimeMessage; + +import org.thymeleaf.spring6.SpringTemplateEngine; import java.util.Map; diff --git a/archive-application/src/main/java/site/archive/infra/user/oauth/provider/AppleClient.java b/archive-application/src/main/java/site/archive/infra/user/oauth/provider/AppleClient.java index 432f3bd..21f5759 100644 --- a/archive-application/src/main/java/site/archive/infra/user/oauth/provider/AppleClient.java +++ b/archive-application/src/main/java/site/archive/infra/user/oauth/provider/AppleClient.java @@ -9,7 +9,6 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.boot.context.properties.ConstructorBinding; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.stereotype.Component; import org.springframework.web.client.RestTemplate; @@ -151,7 +150,6 @@ private static boolean isJwtVerifiedByKeys(SignedJWT jwtToken, List> allEndpoints = new ArrayList(); - var webEndpoints = webEndpointsSupplier.getEndpoints(); - allEndpoints.addAll(webEndpoints); - allEndpoints.addAll(servletEndpointsSupplier.getEndpoints()); - allEndpoints.addAll(controllerEndpointsSupplier.getEndpoints()); - var basePath = webEndpointProperties.getBasePath(); - var endpointMapping = new EndpointMapping(basePath); - boolean shouldRegisterLinksMapping = this.shouldRegisterLinksMapping(webEndpointProperties, environment, basePath); - return new WebMvcEndpointHandlerMapping(endpointMapping, - webEndpoints, - endpointMediaTypes, - corsProperties.toCorsConfiguration(), - new EndpointLinksResolver(allEndpoints, basePath), - shouldRegisterLinksMapping, - null); - } - - private boolean shouldRegisterLinksMapping(WebEndpointProperties webEndpointProperties, Environment environment, String basePath) { - return webEndpointProperties.getDiscovery().isEnabled() - && (StringUtils.hasText(basePath) || ManagementPortType.get(environment).equals(ManagementPortType.DIFFERENT)); - } - - @Override - public OpenAPI transform(OpenApiTransformationContext context) { - OpenAPI openApi = context.getSpecification(); - Server server = new Server(); - server.setDescription("Archive server"); - server.setUrl(baseUrl); - openApi.setServers(List.of(server)); - return openApi; - } - - @Override - public boolean supports(DocumentationType documentationType) { - return documentationType.equals(DocumentationType.OAS_30); - } - - private ApiInfo apiInfo() { - return new ApiInfoBuilder() - .title("Archive Swagger") - .version("2.0") - .build(); - } - - private ApiKey apiKey() { - return new ApiKey(AUTHORIZATION_HEADER, AUTHORIZATION_HEADER, "header"); - } - - private SecurityContext securityContext() { - return SecurityContext.builder() - .securityReferences(defaultAuth()) - .build(); - } - - private List defaultAuth() { - var authorizationScope = new AuthorizationScope("global", "accessEverything"); - var authorizationScopes = new AuthorizationScope[1]; - authorizationScopes[0] = authorizationScope; - return List.of(new SecurityReference(AUTHORIZATION_HEADER, authorizationScopes)); + public OpenAPI openAPI() { + final String securitySchemeName = "bearerAuth"; + return new OpenAPI() + .info(new Info().title("Archive API") + .description("Archive API 입니다") + .version("2.0")) + .addSecurityItem(new SecurityRequirement() + .addList(securitySchemeName)) + .components(new Components() + .addSecuritySchemes(securitySchemeName, new SecurityScheme() + .name(securitySchemeName) + .type(SecurityScheme.Type.HTTP) + .scheme("Bearer") + .bearerFormat("JWT"))); } } \ No newline at end of file diff --git a/archive-web/src/main/java/site/archive/web/config/security/SecurityConfig.java b/archive-web/src/main/java/site/archive/web/config/security/SecurityConfig.java index 4f41c52..0001f2a 100644 --- a/archive-web/src/main/java/site/archive/web/config/security/SecurityConfig.java +++ b/archive-web/src/main/java/site/archive/web/config/security/SecurityConfig.java @@ -58,15 +58,15 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http, .httpBasic().disable() .logout().disable() .headers().frameOptions().sameOrigin().and() - .authorizeRequests() - .antMatchers("/actuator/**").permitAll() - .antMatchers("/api/v1/**").permitAll() - .antMatchers("/api/v2/user/duplicate/**").permitAll() - .antMatchers("/api/v2/auth/register/**").permitAll() - .antMatchers("/api/v2/auth/login/social").permitAll() - .antMatchers("/login/**").permitAll() - .antMatchers(HttpMethod.GET, "/exception/**").permitAll() - .anyRequest().authenticated().and() + .authorizeHttpRequests(auth -> auth + .requestMatchers("/actuator/**").permitAll() + .requestMatchers("/api/v1/**").permitAll() + .requestMatchers("/api/v2/user/duplicate/**").permitAll() + .requestMatchers("/api/v2/auth/register/**").permitAll() + .requestMatchers("/api/v2/auth/login/social").permitAll() + .requestMatchers("/login/**").permitAll() + .requestMatchers(HttpMethod.GET, "/exception/**").permitAll() + .anyRequest().authenticated()) .exceptionHandling() .authenticationEntryPoint(customAuthenticationEntryPoint) .accessDeniedHandler(customAccessDeniedHandler).and() @@ -86,12 +86,12 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http, @Bean public WebSecurityCustomizer webSecurityCustomizer() { - return web -> web.ignoring().antMatchers("/h2-console/**", - "/favicon.ico", - "/error", - "/swagger-ui/**", - "/swagger-resources/**", - "/v3/api-docs"); + return web -> web.ignoring().requestMatchers("/h2-console/**", + "/favicon.ico", + "/error", + "/swagger-ui/**", + "/swagger-resources/**", + "/v3/api-docs/**"); } @Bean diff --git a/archive-web/src/main/java/site/archive/web/config/security/authn/AdminLoginAuthenticationFilter.java b/archive-web/src/main/java/site/archive/web/config/security/authn/AdminLoginAuthenticationFilter.java index 35b50f6..526d5db 100644 --- a/archive-web/src/main/java/site/archive/web/config/security/authn/AdminLoginAuthenticationFilter.java +++ b/archive-web/src/main/java/site/archive/web/config/security/authn/AdminLoginAuthenticationFilter.java @@ -10,8 +10,8 @@ import site.archive.domain.user.UserRole; import site.archive.web.config.security.common.UserPrincipal; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; diff --git a/archive-web/src/main/java/site/archive/web/config/security/authn/BodyCredentialAuthenticationFilter.java b/archive-web/src/main/java/site/archive/web/config/security/authn/BodyCredentialAuthenticationFilter.java index 309fabf..bc25d90 100644 --- a/archive-web/src/main/java/site/archive/web/config/security/authn/BodyCredentialAuthenticationFilter.java +++ b/archive-web/src/main/java/site/archive/web/config/security/authn/BodyCredentialAuthenticationFilter.java @@ -5,7 +5,7 @@ import org.springframework.security.core.Authentication; import site.archive.dto.v1.auth.LoginCommandV1; -import javax.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletRequest; import java.io.IOException; diff --git a/archive-web/src/main/java/site/archive/web/config/security/authn/CustomAuthenticationEntryPoint.java b/archive-web/src/main/java/site/archive/web/config/security/authn/CustomAuthenticationEntryPoint.java index 69cfe78..28881bb 100644 --- a/archive-web/src/main/java/site/archive/web/config/security/authn/CustomAuthenticationEntryPoint.java +++ b/archive-web/src/main/java/site/archive/web/config/security/authn/CustomAuthenticationEntryPoint.java @@ -6,8 +6,8 @@ import org.springframework.security.web.AuthenticationEntryPoint; import org.springframework.stereotype.Component; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; diff --git a/archive-web/src/main/java/site/archive/web/config/security/authn/LoginAuthenticationFilter.java b/archive-web/src/main/java/site/archive/web/config/security/authn/LoginAuthenticationFilter.java index 4bac70f..732fdfb 100644 --- a/archive-web/src/main/java/site/archive/web/config/security/authn/LoginAuthenticationFilter.java +++ b/archive-web/src/main/java/site/archive/web/config/security/authn/LoginAuthenticationFilter.java @@ -6,8 +6,8 @@ import org.springframework.security.core.AuthenticationException; import org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; diff --git a/archive-web/src/main/java/site/archive/web/config/security/authz/CustomAccessDeniedHandler.java b/archive-web/src/main/java/site/archive/web/config/security/authz/CustomAccessDeniedHandler.java index 89534a8..fdd2145 100644 --- a/archive-web/src/main/java/site/archive/web/config/security/authz/CustomAccessDeniedHandler.java +++ b/archive-web/src/main/java/site/archive/web/config/security/authz/CustomAccessDeniedHandler.java @@ -6,8 +6,8 @@ import org.springframework.security.web.access.AccessDeniedHandler; import org.springframework.stereotype.Component; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; diff --git a/archive-web/src/main/java/site/archive/web/config/security/common/handler/LoginFailureHandler.java b/archive-web/src/main/java/site/archive/web/config/security/common/handler/LoginFailureHandler.java index e7225a5..acf51c4 100644 --- a/archive-web/src/main/java/site/archive/web/config/security/common/handler/LoginFailureHandler.java +++ b/archive-web/src/main/java/site/archive/web/config/security/common/handler/LoginFailureHandler.java @@ -5,9 +5,9 @@ import org.springframework.security.core.AuthenticationException; import org.springframework.security.web.authentication.AuthenticationFailureHandler; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; diff --git a/archive-web/src/main/java/site/archive/web/config/security/common/handler/LoginSuccessHandler.java b/archive-web/src/main/java/site/archive/web/config/security/common/handler/LoginSuccessHandler.java index 9259fa7..8470871 100644 --- a/archive-web/src/main/java/site/archive/web/config/security/common/handler/LoginSuccessHandler.java +++ b/archive-web/src/main/java/site/archive/web/config/security/common/handler/LoginSuccessHandler.java @@ -11,8 +11,8 @@ import site.archive.web.config.security.token.HttpAuthTokenSupport; import site.archive.web.config.security.token.TokenProvider; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; @RequiredArgsConstructor @Slf4j diff --git a/archive-web/src/main/java/site/archive/web/config/security/token/HttpAuthTokenSupport.java b/archive-web/src/main/java/site/archive/web/config/security/token/HttpAuthTokenSupport.java index b103c48..b84a299 100644 --- a/archive-web/src/main/java/site/archive/web/config/security/token/HttpAuthTokenSupport.java +++ b/archive-web/src/main/java/site/archive/web/config/security/token/HttpAuthTokenSupport.java @@ -1,8 +1,8 @@ package site.archive.web.config.security.token; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; public interface HttpAuthTokenSupport { diff --git a/archive-web/src/main/java/site/archive/web/config/security/token/jwt/JwtTokenPersistFilter.java b/archive-web/src/main/java/site/archive/web/config/security/token/jwt/JwtTokenPersistFilter.java index 27e8d90..114c259 100644 --- a/archive-web/src/main/java/site/archive/web/config/security/token/jwt/JwtTokenPersistFilter.java +++ b/archive-web/src/main/java/site/archive/web/config/security/token/jwt/JwtTokenPersistFilter.java @@ -7,10 +7,10 @@ import site.archive.web.config.security.token.HttpAuthTokenSupport; import site.archive.web.config.security.token.TokenProvider; -import javax.servlet.FilterChain; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.FilterChain; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; diff --git a/archive-web/src/main/java/site/archive/web/config/security/token/jwt/JwtTokenProvider.java b/archive-web/src/main/java/site/archive/web/config/security/token/jwt/JwtTokenProvider.java index fc6cc4b..4c36596 100644 --- a/archive-web/src/main/java/site/archive/web/config/security/token/jwt/JwtTokenProvider.java +++ b/archive-web/src/main/java/site/archive/web/config/security/token/jwt/JwtTokenProvider.java @@ -2,25 +2,28 @@ import com.fasterxml.jackson.databind.ObjectMapper; import io.jsonwebtoken.Jwts; -import io.jsonwebtoken.SignatureAlgorithm; +import io.jsonwebtoken.security.Keys; import lombok.extern.slf4j.Slf4j; import site.archive.common.exception.security.TokenNotFoundException; import site.archive.domain.user.UserInfo; import site.archive.web.config.security.token.TokenProvider; +import java.security.Key; import java.util.Base64; import java.util.Date; -import java.util.HashMap; @Slf4j public class JwtTokenProvider implements TokenProvider { private static final long DAY_30 = 1000L * 60 * 60 * 24 * 30; - private final String secretKey; + private static final String CLAIM_INFO_KEY = "info"; + + private final Key secretKey; private final ObjectMapper mapper; public JwtTokenProvider(String key, ObjectMapper mapper) { - secretKey = Base64.getEncoder().encodeToString(key.getBytes()); + var encodedKey = Base64.getEncoder().encodeToString(key.getBytes()); + this.secretKey = Keys.hmacShaKeyFor(encodedKey.getBytes()); this.mapper = mapper; } @@ -28,12 +31,12 @@ public String createToken(UserInfo info) { return Jwts .builder() .setSubject("user") - .claim("info", info) + .claim(CLAIM_INFO_KEY, info) .setHeaderParam("typ", "JWT") .setHeaderParam("alg", "ES56") .setHeaderParam("kid", "default") .setExpiration(getTokenExpiredDate()) - .signWith(SignatureAlgorithm.HS256, secretKey.getBytes()) + .signWith(secretKey) .compact(); } @@ -44,15 +47,14 @@ private Date getTokenExpiredDate() { } public UserInfo parseUserInfoFromToken(String token) { + var jwtParser = Jwts.parserBuilder() + .setSigningKey(secretKey) + .build(); + var tokenClaim = jwtParser.parseClaimsJws(token).getBody(); try { - var jwtClaims = Jwts.parser() - .setSigningKey(secretKey.getBytes()) - .parseClaimsJws(token) - .getBody(); - var map = (HashMap) jwtClaims.get("info"); - var info = mapper.convertValue(map, UserInfo.class); - log.debug("토큰 파싱 결과; id: {}, email: {}, role: {}", info.getUserId(), info.getMailAddress(), info.getUserRole()); - return info; + var userInfo = mapper.convertValue(tokenClaim.get(CLAIM_INFO_KEY), UserInfo.class); + log.debug("토큰 파싱 결과; id: {}, email: {}, role: {}", userInfo.getUserId(), userInfo.getMailAddress(), userInfo.getUserRole()); + return userInfo; } catch (Exception e) { throw new TokenNotFoundException(); } diff --git a/archive-web/src/main/java/site/archive/web/config/security/token/jwt/JwtTokenSupport.java b/archive-web/src/main/java/site/archive/web/config/security/token/jwt/JwtTokenSupport.java index bc255da..de55756 100644 --- a/archive-web/src/main/java/site/archive/web/config/security/token/jwt/JwtTokenSupport.java +++ b/archive-web/src/main/java/site/archive/web/config/security/token/jwt/JwtTokenSupport.java @@ -5,8 +5,8 @@ import site.archive.common.exception.security.TokenNotFoundException; import site.archive.web.config.security.token.HttpAuthTokenSupport; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; @Slf4j public class JwtTokenSupport implements HttpAuthTokenSupport { diff --git a/archive-web/src/main/resources/application-dev.yml b/archive-web/src/main/resources/application-dev.yml index 0baff99..31ee7c7 100644 --- a/archive-web/src/main/resources/application-dev.yml +++ b/archive-web/src/main/resources/application-dev.yml @@ -30,7 +30,7 @@ spring: username: ${DB_USER} password: ${DB_PASSWORD} jpa: - database-platform: org.hibernate.dialect.MySQL5InnoDBDialect + database-platform: org.hibernate.dialect.MySQL5Dialect hibernate: ddl-auto: none naming: diff --git a/archive-web/src/main/resources/application-prd.yml b/archive-web/src/main/resources/application-prd.yml index e96b7bf..fff9f3a 100644 --- a/archive-web/src/main/resources/application-prd.yml +++ b/archive-web/src/main/resources/application-prd.yml @@ -30,7 +30,7 @@ spring: username: ${DB_USER} password: ${DB_PASSWORD} jpa: - database-platform: org.hibernate.dialect.MySQL5InnoDBDialect + database-platform: org.hibernate.dialect.MySQL5Dialect show-sql: false hibernate: ddl-auto: none diff --git a/build.gradle b/build.gradle index ef2d493..52a2987 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ plugins { - id 'org.springframework.boot' version '2.7.0' - id 'io.spring.dependency-management' version '1.0.11.RELEASE' + id 'org.springframework.boot' version '3.0.0' + id 'io.spring.dependency-management' version '1.1.0' id 'java' } From 5ae5f0f0e157be43a392aadef109b31d4ddbf655 Mon Sep 17 00:00:00 2001 From: KimDoubleB Date: Wed, 28 Dec 2022 01:17:23 +0900 Subject: [PATCH 03/46] feat(#48): use ScriptUtils.runInitScript instead of Sql annotation --- .../site/archive/domain/JpaTestSupport.java | 4 - .../archive/domain/MySQLTestContainer.java | 8 ++ .../src/test/resources/application-test.yml | 2 +- .../src/test/resources/sql/default/ddl.sql | 98 +++++++++++++++++++ 4 files changed, 107 insertions(+), 5 deletions(-) create mode 100644 archive-domain/src/test/resources/sql/default/ddl.sql diff --git a/archive-domain/src/test/java/site/archive/domain/JpaTestSupport.java b/archive-domain/src/test/java/site/archive/domain/JpaTestSupport.java index 1a61f8a..323c8a6 100644 --- a/archive-domain/src/test/java/site/archive/domain/JpaTestSupport.java +++ b/archive-domain/src/test/java/site/archive/domain/JpaTestSupport.java @@ -1,9 +1,5 @@ package site.archive.domain; -import org.springframework.test.context.jdbc.Sql; - @JpaTest -@Sql({"classpath:sql/default/user.sql", - "classpath:sql/default/archive.sql"}) public abstract class JpaTestSupport extends MySQLTestContainer { } diff --git a/archive-domain/src/test/java/site/archive/domain/MySQLTestContainer.java b/archive-domain/src/test/java/site/archive/domain/MySQLTestContainer.java index 708761c..6f93439 100644 --- a/archive-domain/src/test/java/site/archive/domain/MySQLTestContainer.java +++ b/archive-domain/src/test/java/site/archive/domain/MySQLTestContainer.java @@ -3,6 +3,8 @@ import org.springframework.test.context.DynamicPropertyRegistry; import org.springframework.test.context.DynamicPropertySource; import org.testcontainers.containers.MySQLContainer; +import org.testcontainers.ext.ScriptUtils; +import org.testcontainers.jdbc.JdbcDatabaseDelegate; import org.testcontainers.junit.jupiter.Testcontainers; @Testcontainers @@ -17,6 +19,12 @@ public abstract class MySQLTestContainer { .withUsername("test") .withPassword("test-archive"); MY_SQL_CONTAINER.start(); + + var jdbcDatabaseDelegate = new JdbcDatabaseDelegate(MY_SQL_CONTAINER, ""); + ScriptUtils.runInitScript(jdbcDatabaseDelegate, "sql/default/ddl.sql"); + ScriptUtils.runInitScript(jdbcDatabaseDelegate, "sql/default/user.sql"); + ScriptUtils.runInitScript(jdbcDatabaseDelegate, "sql/default/like.sql"); + ScriptUtils.runInitScript(jdbcDatabaseDelegate, "sql/default/archive.sql"); } @DynamicPropertySource diff --git a/archive-domain/src/test/resources/application-test.yml b/archive-domain/src/test/resources/application-test.yml index 2f01b89..ca1d48c 100644 --- a/archive-domain/src/test/resources/application-test.yml +++ b/archive-domain/src/test/resources/application-test.yml @@ -3,7 +3,7 @@ spring: database-platform: org.hibernate.dialect.MySQL5Dialect show-sql: true hibernate: - ddl-auto: create-drop + ddl-auto: none properties: hibernate: format_sql: true diff --git a/archive-domain/src/test/resources/sql/default/ddl.sql b/archive-domain/src/test/resources/sql/default/ddl.sql new file mode 100644 index 0000000..6b14d94 --- /dev/null +++ b/archive-domain/src/test/resources/sql/default/ddl.sql @@ -0,0 +1,98 @@ +-- Test table ddl +create table if not exists archive +( + archive_id bigint auto_increment primary key, + created_at timestamp default CURRENT_TIMESTAMP null, + is_deleted tinyint(1) default 0 null, + updated_at timestamp default CURRENT_TIMESTAMP null on update CURRENT_TIMESTAMP, + companions varchar(255) null, + emotion varchar(255) null, + main_image varchar(255) null, + name varchar(100) not null, + watched_on timestamp null, + author_id bigint not null, + is_public tinyint(1) default 0 null +); + +create table if not exists archive_image +( + archive_image_id bigint auto_increment primary key, + created_at timestamp default CURRENT_TIMESTAMP null, + is_deleted tinyint(1) default 0 null, + updated_at timestamp default CURRENT_TIMESTAMP null on update CURRENT_TIMESTAMP, + image varchar(255) null, + review varchar(255) null, + archive_id bigint null, + background_color varchar(45) null +); + +create table if not exists banner +( + banner_id bigint auto_increment primary key, + summary_image varchar(255) null, + main_content varchar(500) null, + is_deleted tinyint(1) default 0 null, + created_at timestamp default CURRENT_TIMESTAMP null, + updated_at timestamp default CURRENT_TIMESTAMP null, + type varchar(10) null +); + +create table if not exists user +( + user_type varchar(31) not null, + user_id bigint auto_increment primary key, + created_at timestamp null, + is_deleted tinyint(1) null, + updated_at timestamp null, + mail_address varchar(255) null, + user_role varchar(255) null, + profile_image varchar(255) null, + nickname varchar(255) null +); + +create table if not exists archive_like +( + archive_like_id bigint auto_increment primary key, + created_at timestamp default CURRENT_TIMESTAMP null, + is_deleted tinyint(1) default 0 null, + updated_at timestamp default CURRENT_TIMESTAMP null on update CURRENT_TIMESTAMP, + user_id bigint not null, + archive_id bigint not null +); + +create table if not exists archive_report +( + archive_report_id bigint auto_increment comment 'report_id' primary key, + user_id bigint null, + archive_id bigint null, + reason varchar(100) null, + created_at timestamp default CURRENT_TIMESTAMP null, + updated_at timestamp default CURRENT_TIMESTAMP null, + is_deleted tinyint(1) default 0 null +); + +create table if not exists oauth_user +( + oauth_provider varchar(255) null, + user_id bigint not null primary key +); + +create table if not exists password_user +( + password varchar(255) null, + user_id bigint not null primary key, + is_temporary_password tinyint(1) default 0 null +); + +create table if not exists user_deleted +( + user_type varchar(31) not null, + user_id bigint auto_increment primary key, + created_at timestamp null, + is_deleted tinyint(1) null, + updated_at timestamp null, + mail_address varchar(255) null, + user_role varchar(255) null, + profile_image varchar(255) null, + nickname varchar(255) null +); From d690bd8232f1d3a122c63b03b5b69537e8e42c11 Mon Sep 17 00:00:00 2001 From: KimDoubleB Date: Sun, 8 Jan 2023 00:05:04 +0900 Subject: [PATCH 04/46] refactor: remove JWT Filter log MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - JWT가 필요없는 모든 경우에 로깅되고 있어, 이를 제외 --- .../web/config/security/token/jwt/JwtTokenPersistFilter.java | 1 - 1 file changed, 1 deletion(-) diff --git a/archive-web/src/main/java/site/archive/web/config/security/token/jwt/JwtTokenPersistFilter.java b/archive-web/src/main/java/site/archive/web/config/security/token/jwt/JwtTokenPersistFilter.java index 114c259..03fec1c 100644 --- a/archive-web/src/main/java/site/archive/web/config/security/token/jwt/JwtTokenPersistFilter.java +++ b/archive-web/src/main/java/site/archive/web/config/security/token/jwt/JwtTokenPersistFilter.java @@ -29,7 +29,6 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse var authToken = tokenProvider.parseUserInfoFromToken(tokenStr); SecurityContextHolder.getContext().setAuthentication(new JwtAuthenticationToken(authToken)); } catch (Exception e) { - log.debug("JwtTokenPersistFilter error [토큰 오류]: {}", e.getMessage()); SecurityContextHolder.clearContext(); } filterChain.doFilter(request, response); From fd300631140c71cc6ca35bea216623b741d48a16 Mon Sep 17 00:00:00 2001 From: KimDoubleB Date: Sun, 8 Jan 2023 00:37:16 +0900 Subject: [PATCH 05/46] fix(#48): use environment variable for Jwt secret key --- archive-web/src/main/resources/application-dev.yml | 2 +- archive-web/src/main/resources/application-local.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/archive-web/src/main/resources/application-dev.yml b/archive-web/src/main/resources/application-dev.yml index 31ee7c7..1a99f01 100644 --- a/archive-web/src/main/resources/application-dev.yml +++ b/archive-web/src/main/resources/application-dev.yml @@ -57,7 +57,7 @@ spring: await_termination_seconds: 120 jwt: - secret-key: testKey + secret-key: ${JWT_SECRET_KEY} # s3 configuration cloud: diff --git a/archive-web/src/main/resources/application-local.yml b/archive-web/src/main/resources/application-local.yml index 785792b..03febdb 100644 --- a/archive-web/src/main/resources/application-local.yml +++ b/archive-web/src/main/resources/application-local.yml @@ -61,7 +61,7 @@ spring: await_termination_seconds: 120 jwt: - secret-key: testKey + secret-key: ${JWT_SECRET_KEY} # s3 configuration cloud: aws: From 7e831a9f5f43388dfe30a045f42e164c2a66c44c Mon Sep 17 00:00:00 2001 From: KimDoubleB Date: Sun, 8 Jan 2023 00:37:50 +0900 Subject: [PATCH 06/46] refactor(#48): set springdoc annotations --- .../site/archive/web/api/resolver/annotation/RequestUser.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/archive-web/src/main/java/site/archive/web/api/resolver/annotation/RequestUser.java b/archive-web/src/main/java/site/archive/web/api/resolver/annotation/RequestUser.java index b9cbbb9..1d0ce1d 100644 --- a/archive-web/src/main/java/site/archive/web/api/resolver/annotation/RequestUser.java +++ b/archive-web/src/main/java/site/archive/web/api/resolver/annotation/RequestUser.java @@ -1,5 +1,7 @@ package site.archive.web.api.resolver.annotation; +import io.swagger.v3.oas.annotations.media.Schema; + import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -7,5 +9,6 @@ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.PARAMETER) +@Schema(hidden = true) public @interface RequestUser { } From 66e8128c2abb3fef2791adb21cd3f922a2457977 Mon Sep 17 00:00:00 2001 From: KimDoubleB Date: Sun, 8 Jan 2023 01:07:26 +0900 Subject: [PATCH 07/46] feat(#48): ArchiveCommunityTimeSortType request parameter allow upper case --- .../domain/archive/custom/ArchiveCommunityTimeSortType.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/archive-domain/src/main/java/site/archive/domain/archive/custom/ArchiveCommunityTimeSortType.java b/archive-domain/src/main/java/site/archive/domain/archive/custom/ArchiveCommunityTimeSortType.java index 83a7baf..aa97ecd 100644 --- a/archive-domain/src/main/java/site/archive/domain/archive/custom/ArchiveCommunityTimeSortType.java +++ b/archive-domain/src/main/java/site/archive/domain/archive/custom/ArchiveCommunityTimeSortType.java @@ -65,7 +65,10 @@ public long convertToMillis(Archive archive) { static { Arrays.stream(values()) - .forEach(sortType -> sortTypeMap.put(sortType.getFieldName(), sortType)); + .forEach(sortType -> { + sortTypeMap.put(sortType.getFieldName(), sortType); + sortTypeMap.put(sortType.name(), sortType); + }); } private final String fieldName; From 4c2358802beacaa1be17a4967c1ee4d4f7b49bc6 Mon Sep 17 00:00:00 2001 From: KimDoubleB Date: Sun, 8 Jan 2023 01:08:04 +0900 Subject: [PATCH 08/46] fix(#48): ArchiveCommunityTimeSortType of method null check log message --- .../domain/archive/custom/ArchiveCommunityTimeSortType.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/archive-domain/src/main/java/site/archive/domain/archive/custom/ArchiveCommunityTimeSortType.java b/archive-domain/src/main/java/site/archive/domain/archive/custom/ArchiveCommunityTimeSortType.java index aa97ecd..085541b 100644 --- a/archive-domain/src/main/java/site/archive/domain/archive/custom/ArchiveCommunityTimeSortType.java +++ b/archive-domain/src/main/java/site/archive/domain/archive/custom/ArchiveCommunityTimeSortType.java @@ -80,7 +80,7 @@ public long convertToMillis(Archive archive) { public static ArchiveCommunityTimeSortType of(String fieldName) { var sortType = sortTypeMap.get(fieldName); if (sortType == null) { - throw new IllegalArgumentException("SortType 값이 올바르지 않습니다"); + throw new IllegalArgumentException("SortType 값이 존재하지 않습니다."); } return sortType; } From 66c230c4f29536bd850b0d88a7e774fbc9073261 Mon Sep 17 00:00:00 2001 From: KimDoubleB Date: Sun, 8 Jan 2023 01:12:28 +0900 Subject: [PATCH 09/46] feat(#48): use ParameterObject to ArchivePageable request parameter - for get all each fields by request parameter at swagger using ParameterObject annotation --- .../site/archive/web/api/v2/ArchiveCommunityControllerV2.java | 3 ++- .../main/java/site/archive/web/api/v2/ArchiveControllerV2.java | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/archive-web/src/main/java/site/archive/web/api/v2/ArchiveCommunityControllerV2.java b/archive-web/src/main/java/site/archive/web/api/v2/ArchiveCommunityControllerV2.java index e5054bd..17dccd6 100644 --- a/archive-web/src/main/java/site/archive/web/api/v2/ArchiveCommunityControllerV2.java +++ b/archive-web/src/main/java/site/archive/web/api/v2/ArchiveCommunityControllerV2.java @@ -2,6 +2,7 @@ import io.swagger.v3.oas.annotations.Operation; import lombok.RequiredArgsConstructor; +import org.springdoc.core.annotations.ParameterObject; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; @@ -24,7 +25,7 @@ public class ArchiveCommunityControllerV2 { @Operation(summary = "아카이브 전시소통 리스트 조회") @GetMapping public ResponseEntity> archiveCommunityView(@RequestUser UserInfo user, - ArchivePageable pageable) { + @ParameterObject ArchivePageable pageable) { if (pageable.isRequestFirstPage()) { return ResponseEntity.ok(archiveCommunityService.getCommunityFirstPage(user.getUserId(), pageable)); } diff --git a/archive-web/src/main/java/site/archive/web/api/v2/ArchiveControllerV2.java b/archive-web/src/main/java/site/archive/web/api/v2/ArchiveControllerV2.java index 44e28ac..601c404 100644 --- a/archive-web/src/main/java/site/archive/web/api/v2/ArchiveControllerV2.java +++ b/archive-web/src/main/java/site/archive/web/api/v2/ArchiveControllerV2.java @@ -2,6 +2,7 @@ import io.swagger.v3.oas.annotations.Operation; import lombok.RequiredArgsConstructor; +import org.springdoc.core.annotations.ParameterObject; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -28,7 +29,7 @@ public class ArchiveControllerV2 { @Operation(summary = "나의 관람 뷰 (아카이브 리스트)", description = "홈 뷰 - 아카이브 리스트 조회") @GetMapping public ResponseEntity archiveListView(@RequestUser UserInfo userInfo, - ArchivePageable pageable) { + @ParameterObject ArchivePageable pageable) { var archiveCount = archiveService.countArchive(userInfo); var myArchives = pageable.isRequestFirstPage() ? archiveService.getAllArchiveFirstPage(userInfo, pageable) From 02e6f8cf5a61b8255e0065884e84364031d71586 Mon Sep 17 00:00:00 2001 From: KimDoubleB Date: Sun, 15 Jan 2023 01:16:17 +0900 Subject: [PATCH 10/46] feat(#48): added exception endpoints cors configurations --- .../java/site/archive/web/config/security/SecurityConfig.java | 1 + 1 file changed, 1 insertion(+) diff --git a/archive-web/src/main/java/site/archive/web/config/security/SecurityConfig.java b/archive-web/src/main/java/site/archive/web/config/security/SecurityConfig.java index 0001f2a..ad0c87b 100644 --- a/archive-web/src/main/java/site/archive/web/config/security/SecurityConfig.java +++ b/archive-web/src/main/java/site/archive/web/config/security/SecurityConfig.java @@ -115,6 +115,7 @@ public CorsConfigurationSource corsConfigurationSource() { var source = new UrlBasedCorsConfigurationSource(); source.registerCorsConfiguration("/api/**", configuration); + source.registerCorsConfiguration("/exception/**", configuration); return source; } From 0e11fce5ff06cb7332163663fa8d38b120e5285e Mon Sep 17 00:00:00 2001 From: KimDoubleB Date: Sun, 15 Jan 2023 01:16:55 +0900 Subject: [PATCH 11/46] feat(#48): permit X-Forwarded header prefix - for reverse proxy nginx --- archive-web/src/main/resources/application.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/archive-web/src/main/resources/application.yml b/archive-web/src/main/resources/application.yml index 2b0b45d..0d2530f 100644 --- a/archive-web/src/main/resources/application.yml +++ b/archive-web/src/main/resources/application.yml @@ -9,6 +9,7 @@ spring: max-request-size: 20MB server: port: 8080 + forward-headers-strategy: FRAMEWORK tomcat: basedir: . accesslog: From c6ee7ee910a7efefad4a5dd21404c27829130849 Mon Sep 17 00:00:00 2001 From: KimDoubleB Date: Sun, 15 Jan 2023 02:40:50 +0900 Subject: [PATCH 12/46] refactor: extract v2 api docs to Docs interface based on Swagger --- .../ArchiveCommunityControllerV2Docs.java | 20 +++++++++++ .../docs/swagger/ArchiveControllerV2Docs.java | 36 +++++++++++++++++++ .../swagger/ArchiveImageControllerV2Docs.java | 18 ++++++++++ .../swagger/ArchiveLikeControllerV2Docs.java | 13 +++++++ .../docs/swagger/BannerControllerV2Docs.java | 29 +++++++++++++++ .../docs/swagger/LikeControllerV2Docs.java | 30 ++++++++++++++++ .../docs/swagger/ReportControllerV2Docs.java | 25 +++++++++++++ .../swagger/UserAuthControllerV2Docs.java | 26 ++++++++++++++ .../docs/swagger/UserControllerV2Docs.java | 24 +++++++++++++ .../swagger/UserProfileControllerV2Docs.java | 22 ++++++++++++ .../api/v2/ArchiveCommunityControllerV2.java | 8 ++--- .../web/api/v2/ArchiveControllerV2.java | 12 ++----- .../web/api/v2/ArchiveImageControllerV2.java | 8 ++--- .../web/api/v2/ArchiveLikeControllerV2.java | 5 ++- .../web/api/v2/BannerControllerV2.java | 8 ++--- .../archive/web/api/v2/LikeControllerV2.java | 8 ++--- .../web/api/v2/ReportControllerV2.java | 19 +++++----- .../web/api/v2/UserAuthControllerV2.java | 8 ++--- .../archive/web/api/v2/UserControllerV2.java | 4 --- .../web/api/v2/UserProfileControllerV2.java | 9 ++--- 20 files changed, 271 insertions(+), 61 deletions(-) create mode 100644 archive-web/src/main/java/site/archive/web/api/docs/swagger/ArchiveCommunityControllerV2Docs.java create mode 100644 archive-web/src/main/java/site/archive/web/api/docs/swagger/ArchiveControllerV2Docs.java create mode 100644 archive-web/src/main/java/site/archive/web/api/docs/swagger/ArchiveImageControllerV2Docs.java create mode 100644 archive-web/src/main/java/site/archive/web/api/docs/swagger/ArchiveLikeControllerV2Docs.java create mode 100644 archive-web/src/main/java/site/archive/web/api/docs/swagger/BannerControllerV2Docs.java create mode 100644 archive-web/src/main/java/site/archive/web/api/docs/swagger/LikeControllerV2Docs.java create mode 100644 archive-web/src/main/java/site/archive/web/api/docs/swagger/ReportControllerV2Docs.java create mode 100644 archive-web/src/main/java/site/archive/web/api/docs/swagger/UserAuthControllerV2Docs.java create mode 100644 archive-web/src/main/java/site/archive/web/api/docs/swagger/UserControllerV2Docs.java create mode 100644 archive-web/src/main/java/site/archive/web/api/docs/swagger/UserProfileControllerV2Docs.java diff --git a/archive-web/src/main/java/site/archive/web/api/docs/swagger/ArchiveCommunityControllerV2Docs.java b/archive-web/src/main/java/site/archive/web/api/docs/swagger/ArchiveCommunityControllerV2Docs.java new file mode 100644 index 0000000..0b93152 --- /dev/null +++ b/archive-web/src/main/java/site/archive/web/api/docs/swagger/ArchiveCommunityControllerV2Docs.java @@ -0,0 +1,20 @@ +package site.archive.web.api.docs.swagger; + +import io.swagger.v3.oas.annotations.Operation; +import org.springdoc.core.annotations.ParameterObject; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import site.archive.domain.archive.custom.ArchivePageable; +import site.archive.domain.user.UserInfo; +import site.archive.dto.v2.ArchiveCommunityResponseDto; + +import java.util.List; + +public interface ArchiveCommunityControllerV2Docs { + + @Operation(summary = "아카이브 전시소통 리스트 조회") + @GetMapping + ResponseEntity> archiveCommunityView(UserInfo user, + @ParameterObject ArchivePageable pageable); + +} diff --git a/archive-web/src/main/java/site/archive/web/api/docs/swagger/ArchiveControllerV2Docs.java b/archive-web/src/main/java/site/archive/web/api/docs/swagger/ArchiveControllerV2Docs.java new file mode 100644 index 0000000..751ed33 --- /dev/null +++ b/archive-web/src/main/java/site/archive/web/api/docs/swagger/ArchiveControllerV2Docs.java @@ -0,0 +1,36 @@ +package site.archive.web.api.docs.swagger; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import org.springdoc.core.annotations.ParameterObject; +import org.springframework.http.ResponseEntity; +import site.archive.domain.archive.custom.ArchivePageable; +import site.archive.domain.user.UserInfo; +import site.archive.dto.v1.archive.ArchiveListResponseDtoV1; +import site.archive.dto.v2.ArchiveCountResponseDto; +import site.archive.dto.v2.ArchiveDtoV2; +import site.archive.dto.v2.MyArchiveListResponseDto; + +public interface ArchiveControllerV2Docs { + + @Operation(summary = "나의 관람 뷰 (아카이브 리스트)", description = "홈 뷰 - 아카이브 리스트 조회") + ResponseEntity archiveListView(UserInfo userInfo, + @ParameterObject ArchivePageable pageable); + + @Operation(summary = "특정 유저 아카이브 리스트 조회") + ResponseEntity archiveListView(UserInfo userInfo, + @Parameter(name = "userId", description = "조회하고자 하는 유저 Index") Long userId); + + @Operation(summary = "아카이브 상세 조회") + ResponseEntity archiveSpecificView(UserInfo userInfo, + @Parameter(name = "archiveId", description = "archive Index (Id)") Long archiveId); + + @Operation(summary = "이번 달 아카이브 개수 조회") + ResponseEntity countArchiveOfCurrentMonth(UserInfo userInfo); + + @Operation(summary = "아카이브 공개여부 설정/수정") + ResponseEntity archivePublicPrivate(UserInfo userInfo, + @Parameter(name = "archiveId", description = "archive Index (Id)") Long archiveId, + Boolean isPublic); + +} diff --git a/archive-web/src/main/java/site/archive/web/api/docs/swagger/ArchiveImageControllerV2Docs.java b/archive-web/src/main/java/site/archive/web/api/docs/swagger/ArchiveImageControllerV2Docs.java new file mode 100644 index 0000000..ecc317e --- /dev/null +++ b/archive-web/src/main/java/site/archive/web/api/docs/swagger/ArchiveImageControllerV2Docs.java @@ -0,0 +1,18 @@ +package site.archive.web.api.docs.swagger; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import org.springframework.http.ResponseEntity; +import org.springframework.web.multipart.MultipartFile; +import site.archive.dto.v1.archive.ArchiveImageUrlResponseDtoV1; + +public interface ArchiveImageControllerV2Docs { + + @Operation(summary = "이미지 업로드") + ResponseEntity uploadImage( + @Parameter(name = "imageFile", description = "업로드 할 이미지 파일") MultipartFile imageFile); + + @Operation(summary = "이미지 제거") + ResponseEntity removeImage(@Parameter(name = "fileUri", description = "제거할 이미지 파일 주소") String fileUri); + +} diff --git a/archive-web/src/main/java/site/archive/web/api/docs/swagger/ArchiveLikeControllerV2Docs.java b/archive-web/src/main/java/site/archive/web/api/docs/swagger/ArchiveLikeControllerV2Docs.java new file mode 100644 index 0000000..361c140 --- /dev/null +++ b/archive-web/src/main/java/site/archive/web/api/docs/swagger/ArchiveLikeControllerV2Docs.java @@ -0,0 +1,13 @@ +package site.archive.web.api.docs.swagger; + +import io.swagger.v3.oas.annotations.Operation; +import org.springframework.http.ResponseEntity; +import site.archive.domain.user.UserInfo; +import site.archive.dto.v2.ArchiveLikeListResponseDto; + +public interface ArchiveLikeControllerV2Docs { + + @Operation(summary = "좋아요 한 Archive 조회") + ResponseEntity archiveLikeListView(UserInfo userInfo); + +} diff --git a/archive-web/src/main/java/site/archive/web/api/docs/swagger/BannerControllerV2Docs.java b/archive-web/src/main/java/site/archive/web/api/docs/swagger/BannerControllerV2Docs.java new file mode 100644 index 0000000..4274350 --- /dev/null +++ b/archive-web/src/main/java/site/archive/web/api/docs/swagger/BannerControllerV2Docs.java @@ -0,0 +1,29 @@ +package site.archive.web.api.docs.swagger; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import org.springframework.http.ResponseEntity; +import org.springframework.web.multipart.MultipartFile; +import site.archive.dto.v2.BannerListResponseDto; + +public interface BannerControllerV2Docs { + + @Operation(summary = "배너 조회 [캐싱 - 1시간]") + ResponseEntity archiveCommunityBannerView(); + + @Operation(summary = "배너 생성 (업로드) - 이미지 타입") + ResponseEntity createArchiveCommunityBanner( + @Parameter(name = "summaryImage", description = "전시소통 배너칸 노출 이미지") MultipartFile summaryImage, + @Parameter(name = "mainImage", description = "배너 메인 이미지") MultipartFile mainImage); + + @Operation(summary = "배너 생성 (업로드) - URL 타입") + ResponseEntity createArchiveCommunityBanner( + @Parameter(name = "summaryImage", description = "전시소통 배너칸 노출 이미지") MultipartFile summaryImage, + @Parameter(name = "mainContentUrl", description = "배너 연결 URL") String mainContentUrl); + + @Operation(summary = "배너 제거") + ResponseEntity deleteArchiveCommunityBanner(@Parameter(name = "bannerId", description = "제거할 배너 Index") Long bannerId); + +} + + diff --git a/archive-web/src/main/java/site/archive/web/api/docs/swagger/LikeControllerV2Docs.java b/archive-web/src/main/java/site/archive/web/api/docs/swagger/LikeControllerV2Docs.java new file mode 100644 index 0000000..63ea369 --- /dev/null +++ b/archive-web/src/main/java/site/archive/web/api/docs/swagger/LikeControllerV2Docs.java @@ -0,0 +1,30 @@ +package site.archive.web.api.docs.swagger; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import org.springframework.http.ResponseEntity; +import site.archive.domain.user.UserInfo; +import site.archive.dto.v2.LikesRequestDto; +import site.archive.dto.v2.UnlikesRequestDto; + +public interface LikeControllerV2Docs { + + @Operation(summary = "좋아요 추가") + ResponseEntity like(UserInfo user, + @Parameter(name = "archiveId", description = "좋아요 할 아카이브 Index (Id)") Long archiveId); + + @Operation(summary = "좋아요 추가 (Bulk)") + ResponseEntity likeBulk(UserInfo user, + @Parameter(name = "likesRequest", description = "좋아요 할 아카이브 Index list") LikesRequestDto likesRequest); + + @Operation(summary = "좋아요 삭제") + ResponseEntity unlike(UserInfo user, + @Parameter(name = "archiveId", description = "좋아요 취소할 아카이브 Index (Id)") Long archiveId); + + + @Operation(summary = "좋아요 삭제 (Bulk)") + ResponseEntity unlikeBulk(UserInfo user, + @Parameter(name = "unlikesRequest", description = "좋아요 취소할 아카이브 Index list") + UnlikesRequestDto unlikesRequest); + +} diff --git a/archive-web/src/main/java/site/archive/web/api/docs/swagger/ReportControllerV2Docs.java b/archive-web/src/main/java/site/archive/web/api/docs/swagger/ReportControllerV2Docs.java new file mode 100644 index 0000000..c4e7e97 --- /dev/null +++ b/archive-web/src/main/java/site/archive/web/api/docs/swagger/ReportControllerV2Docs.java @@ -0,0 +1,25 @@ +package site.archive.web.api.docs.swagger; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import org.springframework.http.ResponseEntity; +import site.archive.domain.user.UserInfo; +import site.archive.dto.v2.ReportCheckResponse; +import site.archive.dto.v2.ReportRequestDto; + +public interface ReportControllerV2Docs { + + @Operation(summary = "신고 여부 확인") + ResponseEntity isReport(UserInfo userInfo, + @Parameter(name = "archiveId", description = "신고여부 확인할 archive Index") Long archiveId); + + @Operation(summary = "신고하기") + ResponseEntity report(UserInfo userInfo, + @Parameter(name = "archiveId", description = "신고할 archive Index") Long archiveId, + ReportRequestDto reportRequestDto); + + @Operation(summary = "신고 취소하기") + ResponseEntity reportCancel(UserInfo userInfo, + @Parameter(name = "archiveId", description = "신고 취소할 archive Index") Long archiveId); + +} diff --git a/archive-web/src/main/java/site/archive/web/api/docs/swagger/UserAuthControllerV2Docs.java b/archive-web/src/main/java/site/archive/web/api/docs/swagger/UserAuthControllerV2Docs.java new file mode 100644 index 0000000..191fc8a --- /dev/null +++ b/archive-web/src/main/java/site/archive/web/api/docs/swagger/UserAuthControllerV2Docs.java @@ -0,0 +1,26 @@ +package site.archive.web.api.docs.swagger; + +import io.swagger.v3.oas.annotations.Operation; +import org.springframework.http.ResponseEntity; +import site.archive.domain.user.UserInfo; +import site.archive.dto.v1.user.UserPasswordResetRequestDtoV1; +import site.archive.dto.v2.OAuthLoginRequestDto; +import site.archive.dto.v2.OAuthUserInfoRequestDto; +import site.archive.dto.v2.PasswordRegisterRequestDto; + +public interface UserAuthControllerV2Docs { + + @Operation(summary = "비밀번호 초기화 - 새로운 비밀번호 설정") + ResponseEntity resetPassword(UserInfo userInfo, + UserPasswordResetRequestDtoV1 userPasswordResetRequestDtoV1); + + @Operation(summary = "[NoAuth] 패스워드 유저 회원가입") + ResponseEntity registerPasswordUser(PasswordRegisterRequestDto passwordRegisterRequest); + + @Operation(summary = "[NoAuth] 소셜 유저 회원가입") + ResponseEntity registerSocialUser(OAuthUserInfoRequestDto oAuthUserInfoRequest); + + @Operation(summary = "[NoAuth] 소셜 유저 로그인") + ResponseEntity loginSocialUser(OAuthLoginRequestDto oAuthLoginRequestDto); + +} diff --git a/archive-web/src/main/java/site/archive/web/api/docs/swagger/UserControllerV2Docs.java b/archive-web/src/main/java/site/archive/web/api/docs/swagger/UserControllerV2Docs.java new file mode 100644 index 0000000..b834cea --- /dev/null +++ b/archive-web/src/main/java/site/archive/web/api/docs/swagger/UserControllerV2Docs.java @@ -0,0 +1,24 @@ +package site.archive.web.api.docs.swagger; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import org.springframework.http.ResponseEntity; +import site.archive.domain.user.UserInfo; +import site.archive.dto.v1.archive.EmailDuplicateResponseDtoV1; +import site.archive.dto.v2.NicknameDuplicateResponseDto; +import site.archive.dto.v2.UserNicknameUpdateRequest; + +public interface UserControllerV2Docs { + + @Operation(summary = "[NoAuth] 이메일 중복 검사") + ResponseEntity checkDuplicatedEmail( + @Parameter(name = "value", description = "중복검사 할 이메일 주소") String email); + + @Operation(summary = "[NoAuth] 닉네임 중복 검사") + ResponseEntity checkDuplicatedNickname( + @Parameter(name = "value", description = "중복검사 할 닉네임") String nickname); + + @Operation(summary = "프로필 닉네임 수정 (업데이트)") + ResponseEntity updateProfileNickname(UserInfo user, UserNicknameUpdateRequest request); + +} diff --git a/archive-web/src/main/java/site/archive/web/api/docs/swagger/UserProfileControllerV2Docs.java b/archive-web/src/main/java/site/archive/web/api/docs/swagger/UserProfileControllerV2Docs.java new file mode 100644 index 0000000..634672a --- /dev/null +++ b/archive-web/src/main/java/site/archive/web/api/docs/swagger/UserProfileControllerV2Docs.java @@ -0,0 +1,22 @@ +package site.archive.web.api.docs.swagger; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import org.springframework.http.ResponseEntity; +import org.springframework.web.multipart.MultipartFile; +import site.archive.domain.user.UserInfo; +import site.archive.dto.v1.user.SpecificUserDtoV1; + +public interface UserProfileControllerV2Docs { + + @Operation(summary = "프로필 정보 조회") + ResponseEntity getUserProfileInfo(UserInfo user); + + @Operation(summary = "프로필 이미지 업로드 및 업데이트") + ResponseEntity uploadProfileImage(UserInfo user, + @Parameter(name = "image", description = "프로필 이미지 파일") MultipartFile imageFile); + + @Operation(summary = "프로필 이미지 제거") + ResponseEntity removeProfileImage(UserInfo user); + +} diff --git a/archive-web/src/main/java/site/archive/web/api/v2/ArchiveCommunityControllerV2.java b/archive-web/src/main/java/site/archive/web/api/v2/ArchiveCommunityControllerV2.java index 17dccd6..ebc4876 100644 --- a/archive-web/src/main/java/site/archive/web/api/v2/ArchiveCommunityControllerV2.java +++ b/archive-web/src/main/java/site/archive/web/api/v2/ArchiveCommunityControllerV2.java @@ -1,8 +1,6 @@ package site.archive.web.api.v2; -import io.swagger.v3.oas.annotations.Operation; import lombok.RequiredArgsConstructor; -import org.springdoc.core.annotations.ParameterObject; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; @@ -12,20 +10,20 @@ import site.archive.dto.v2.ArchiveCommunityResponseDto; import site.archive.service.archive.ArchiveCommunityService; import site.archive.web.api.resolver.annotation.RequestUser; +import site.archive.web.api.docs.swagger.ArchiveCommunityControllerV2Docs; import java.util.List; @RestController @RequestMapping("/api/v2/archive/community") @RequiredArgsConstructor -public class ArchiveCommunityControllerV2 { +public class ArchiveCommunityControllerV2 implements ArchiveCommunityControllerV2Docs { private final ArchiveCommunityService archiveCommunityService; - @Operation(summary = "아카이브 전시소통 리스트 조회") @GetMapping public ResponseEntity> archiveCommunityView(@RequestUser UserInfo user, - @ParameterObject ArchivePageable pageable) { + ArchivePageable pageable) { if (pageable.isRequestFirstPage()) { return ResponseEntity.ok(archiveCommunityService.getCommunityFirstPage(user.getUserId(), pageable)); } diff --git a/archive-web/src/main/java/site/archive/web/api/v2/ArchiveControllerV2.java b/archive-web/src/main/java/site/archive/web/api/v2/ArchiveControllerV2.java index 601c404..c2bffbb 100644 --- a/archive-web/src/main/java/site/archive/web/api/v2/ArchiveControllerV2.java +++ b/archive-web/src/main/java/site/archive/web/api/v2/ArchiveControllerV2.java @@ -1,8 +1,6 @@ package site.archive.web.api.v2; -import io.swagger.v3.oas.annotations.Operation; import lombok.RequiredArgsConstructor; -import org.springdoc.core.annotations.ParameterObject; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -18,18 +16,18 @@ import site.archive.dto.v2.MyArchiveListResponseDto; import site.archive.service.archive.ArchiveService; import site.archive.web.api.resolver.annotation.RequestUser; +import site.archive.web.api.docs.swagger.ArchiveControllerV2Docs; @RestController @RequestMapping("/api/v2/archive") @RequiredArgsConstructor -public class ArchiveControllerV2 { +public class ArchiveControllerV2 implements ArchiveControllerV2Docs { private final ArchiveService archiveService; - @Operation(summary = "나의 관람 뷰 (아카이브 리스트)", description = "홈 뷰 - 아카이브 리스트 조회") @GetMapping public ResponseEntity archiveListView(@RequestUser UserInfo userInfo, - @ParameterObject ArchivePageable pageable) { + ArchivePageable pageable) { var archiveCount = archiveService.countArchive(userInfo); var myArchives = pageable.isRequestFirstPage() ? archiveService.getAllArchiveFirstPage(userInfo, pageable) @@ -37,28 +35,24 @@ public ResponseEntity archiveListView(@RequestUser Use return ResponseEntity.ok(MyArchiveListResponseDto.from(archiveCount, myArchives)); } - @Operation(summary = "특정 유저 아카이브 리스트 조회") @GetMapping("/other") public ResponseEntity archiveListView(@RequestUser UserInfo userInfo, @RequestParam Long userId) { return ResponseEntity.ok(archiveService.getAllArchive(userInfo, userId)); } - @Operation(summary = "아카이브 상세 조회") @GetMapping("/{archiveId}") public ResponseEntity archiveSpecificView(@RequestUser UserInfo userInfo, @PathVariable Long archiveId) { return ResponseEntity.ok(archiveService.getOneArchiveById(userInfo, archiveId)); } - @Operation(summary = "이번 달 아카이브 개수 조회") @GetMapping("/count/month") public ResponseEntity countArchiveOfCurrentMonth(@RequestUser UserInfo userInfo) { var count = archiveService.countArchiveOfCurrentMonth(userInfo); return ResponseEntity.ok(new ArchiveCountResponseDto(count)); } - @Operation(summary = "아카이브 공개여부 설정/수정") @PutMapping("/{archiveId}") public ResponseEntity archivePublicPrivate(@RequestUser UserInfo userInfo, @PathVariable Long archiveId, diff --git a/archive-web/src/main/java/site/archive/web/api/v2/ArchiveImageControllerV2.java b/archive-web/src/main/java/site/archive/web/api/v2/ArchiveImageControllerV2.java index 9607c6f..1006fe2 100644 --- a/archive-web/src/main/java/site/archive/web/api/v2/ArchiveImageControllerV2.java +++ b/archive-web/src/main/java/site/archive/web/api/v2/ArchiveImageControllerV2.java @@ -1,6 +1,5 @@ package site.archive.web.api.v2; -import io.swagger.v3.oas.annotations.Operation; import lombok.RequiredArgsConstructor; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; @@ -10,20 +9,20 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; +import site.archive.common.FileUtils; import site.archive.dto.v1.archive.ArchiveImageUrlResponseDtoV1; import site.archive.service.archive.ArchiveImageService; -import site.archive.common.FileUtils; +import site.archive.web.api.docs.swagger.ArchiveImageControllerV2Docs; import static site.archive.service.archive.ArchiveImageService.ARCHIVE_IMAGE_DIRECTORY; @RestController @RequestMapping("/api/v2/archive") @RequiredArgsConstructor -public class ArchiveImageControllerV2 { +public class ArchiveImageControllerV2 implements ArchiveImageControllerV2Docs { private final ArchiveImageService imageService; - @Operation(summary = "이미지 업로드") @PostMapping(path = "/image/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) @@ -33,7 +32,6 @@ public ResponseEntity uploadImage(@RequestParam("i return ResponseEntity.ok(new ArchiveImageUrlResponseDtoV1(imageUri)); } - @Operation(summary = "이미지 제거") @DeleteMapping("/image/remove") public ResponseEntity removeImage(@RequestParam String fileUri) { imageService.remove(fileUri); diff --git a/archive-web/src/main/java/site/archive/web/api/v2/ArchiveLikeControllerV2.java b/archive-web/src/main/java/site/archive/web/api/v2/ArchiveLikeControllerV2.java index 3a1ab57..b072e87 100644 --- a/archive-web/src/main/java/site/archive/web/api/v2/ArchiveLikeControllerV2.java +++ b/archive-web/src/main/java/site/archive/web/api/v2/ArchiveLikeControllerV2.java @@ -1,6 +1,5 @@ package site.archive.web.api.v2; -import io.swagger.v3.oas.annotations.Operation; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; @@ -11,16 +10,16 @@ import site.archive.service.archive.ArchiveService; import site.archive.service.like.LikeService; import site.archive.web.api.resolver.annotation.RequestUser; +import site.archive.web.api.docs.swagger.ArchiveLikeControllerV2Docs; @RestController @RequestMapping("/api/v2/archive/like") @RequiredArgsConstructor -public class ArchiveLikeControllerV2 { +public class ArchiveLikeControllerV2 implements ArchiveLikeControllerV2Docs { private final ArchiveService archiveService; private final LikeService likeService; - @Operation(summary = "좋아요 한 Archive 조회") @GetMapping public ResponseEntity archiveLikeListView(@RequestUser UserInfo userInfo) { var archiveIds = likeService.likeArchiveIds(userInfo.getUserId()); diff --git a/archive-web/src/main/java/site/archive/web/api/v2/BannerControllerV2.java b/archive-web/src/main/java/site/archive/web/api/v2/BannerControllerV2.java index accceb3..37d5127 100644 --- a/archive-web/src/main/java/site/archive/web/api/v2/BannerControllerV2.java +++ b/archive-web/src/main/java/site/archive/web/api/v2/BannerControllerV2.java @@ -1,6 +1,5 @@ package site.archive.web.api.v2; -import io.swagger.v3.oas.annotations.Operation; import lombok.RequiredArgsConstructor; import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.Cacheable; @@ -20,6 +19,7 @@ import site.archive.dto.v2.BannerListResponseDto; import site.archive.service.archive.ArchiveImageService; import site.archive.service.banner.BannerService; +import site.archive.web.api.docs.swagger.BannerControllerV2Docs; import site.archive.web.config.security.authz.AdminChecker; import site.archive.web.config.security.authz.annotation.RequirePermission; @@ -29,19 +29,17 @@ @RestController @RequestMapping("/api/v2/banner") @RequiredArgsConstructor -public class BannerControllerV2 { +public class BannerControllerV2 implements BannerControllerV2Docs { private final BannerService bannerService; private final ArchiveImageService imageService; - @Operation(summary = "배너 조회") @Cacheable(CacheInfo.BANNERS) @GetMapping public ResponseEntity archiveCommunityBannerView() { return ResponseEntity.ok(bannerService.getAllBanner()); } - @Operation(summary = "배너 생성 (업로드) - 이미지 타입") @CacheEvict(CacheInfo.BANNERS) @RequirePermission(handler = AdminChecker.class) @PostMapping(path = "/type/image", @@ -55,7 +53,6 @@ public ResponseEntity createArchiveCommunityBanner(@RequestParam Multipart return ResponseEntity.noContent().build(); } - @Operation(summary = "배너 생성 (업로드) - URL 타입") @CacheEvict(CacheInfo.BANNERS) @RequirePermission(handler = AdminChecker.class) @PostMapping(path = "/type/url", @@ -68,7 +65,6 @@ public ResponseEntity createArchiveCommunityBanner(@RequestParam Multipart return ResponseEntity.noContent().build(); } - @Operation(summary = "배너 제거") @CacheEvict(CacheInfo.BANNERS) @RequirePermission(handler = AdminChecker.class) @DeleteMapping("/{bannerId}") diff --git a/archive-web/src/main/java/site/archive/web/api/v2/LikeControllerV2.java b/archive-web/src/main/java/site/archive/web/api/v2/LikeControllerV2.java index 55daf2a..546bcf6 100644 --- a/archive-web/src/main/java/site/archive/web/api/v2/LikeControllerV2.java +++ b/archive-web/src/main/java/site/archive/web/api/v2/LikeControllerV2.java @@ -1,6 +1,5 @@ package site.archive.web.api.v2; -import io.swagger.v3.oas.annotations.Operation; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.DeleteMapping; @@ -14,36 +13,33 @@ import site.archive.dto.v2.UnlikesRequestDto; import site.archive.service.like.LikeService; import site.archive.web.api.resolver.annotation.RequestUser; +import site.archive.web.api.docs.swagger.LikeControllerV2Docs; @RestController @RequestMapping("/api/v2/archive/like") @RequiredArgsConstructor -public class LikeControllerV2 { +public class LikeControllerV2 implements LikeControllerV2Docs { private final LikeService likeService; - @Operation(summary = "좋아요 추가") @PostMapping("/{archiveId}") public ResponseEntity like(@RequestUser UserInfo user, @PathVariable Long archiveId) { likeService.save(user.getUserId(), archiveId); return ResponseEntity.ok().build(); } - @Operation(summary = "좋아요 추가 (Bulk)") @PostMapping public ResponseEntity likeBulk(@RequestUser UserInfo user, @RequestBody LikesRequestDto likesRequest) { likeService.save(user.getUserId(), likesRequest.getArchiveIds()); return ResponseEntity.ok().build(); } - @Operation(summary = "좋아요 삭제") @DeleteMapping("/{archiveId}") public ResponseEntity unlike(@RequestUser UserInfo user, @PathVariable Long archiveId) { likeService.delete(user.getUserId(), archiveId); return ResponseEntity.ok().build(); } - @Operation(summary = "좋아요 삭제 (Bulk)") @DeleteMapping public ResponseEntity unlikeBulk(@RequestUser UserInfo user, @RequestBody UnlikesRequestDto unlikesRequest) { likeService.delete(user.getUserId(), unlikesRequest.getArchiveIds()); diff --git a/archive-web/src/main/java/site/archive/web/api/v2/ReportControllerV2.java b/archive-web/src/main/java/site/archive/web/api/v2/ReportControllerV2.java index 7cf98fb..0fb81a5 100644 --- a/archive-web/src/main/java/site/archive/web/api/v2/ReportControllerV2.java +++ b/archive-web/src/main/java/site/archive/web/api/v2/ReportControllerV2.java @@ -1,6 +1,5 @@ package site.archive.web.api.v2; -import io.swagger.v3.oas.annotations.Operation; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.DeleteMapping; @@ -15,35 +14,33 @@ import site.archive.dto.v2.ReportRequestDto; import site.archive.service.report.ReportService; import site.archive.web.api.resolver.annotation.RequestUser; +import site.archive.web.api.docs.swagger.ReportControllerV2Docs; @RestController @RequestMapping("/api/v2/report") @RequiredArgsConstructor -public class ReportControllerV2 { +public class ReportControllerV2 implements ReportControllerV2Docs { private final ReportService reportService; - @Operation(summary = "신고 여부 확인") @GetMapping("/{archiveId}") - public ResponseEntity isReport(@PathVariable Long archiveId, - @RequestUser UserInfo userInfo) { + public ResponseEntity isReport(@RequestUser UserInfo userInfo, + @PathVariable Long archiveId) { var isReported = reportService.isReportedBy(archiveId, userInfo.getUserId()); return ResponseEntity.ok(new ReportCheckResponse(isReported)); } - @Operation(summary = "신고하기") @PostMapping("/{archiveId}") - public ResponseEntity report(@PathVariable Long archiveId, - @RequestUser UserInfo userInfo, + public ResponseEntity report(@RequestUser UserInfo userInfo, + @PathVariable Long archiveId, @RequestBody ReportRequestDto reportRequestDto) { reportService.reportArchive(archiveId, userInfo.getUserId(), reportRequestDto.getReason()); return ResponseEntity.noContent().build(); } - @Operation(summary = "신고 취소하기") @DeleteMapping("/{archiveId}") - public ResponseEntity reportCancel(@PathVariable Long archiveId, - @RequestUser UserInfo userInfo) { + public ResponseEntity reportCancel(@RequestUser UserInfo userInfo, + @PathVariable Long archiveId) { reportService.cancelReportArchive(archiveId, userInfo.getUserId()); return ResponseEntity.noContent().build(); } diff --git a/archive-web/src/main/java/site/archive/web/api/v2/UserAuthControllerV2.java b/archive-web/src/main/java/site/archive/web/api/v2/UserAuthControllerV2.java index 77be057..c5f63d7 100644 --- a/archive-web/src/main/java/site/archive/web/api/v2/UserAuthControllerV2.java +++ b/archive-web/src/main/java/site/archive/web/api/v2/UserAuthControllerV2.java @@ -1,6 +1,5 @@ package site.archive.web.api.v2; -import io.swagger.v3.oas.annotations.Operation; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.security.core.context.SecurityContextHolder; @@ -20,12 +19,13 @@ import site.archive.service.user.UserRegisterServiceV2; import site.archive.service.user.UserService; import site.archive.web.api.resolver.annotation.RequestUser; +import site.archive.web.api.docs.swagger.UserAuthControllerV2Docs; import site.archive.web.config.security.token.jwt.JwtAuthenticationToken; @RestController @RequestMapping("/api/v2/auth") @RequiredArgsConstructor -public class UserAuthControllerV2 { +public class UserAuthControllerV2 implements UserAuthControllerV2Docs { private final UserService userService; private final UserAuthService userAuthService; @@ -33,7 +33,6 @@ public class UserAuthControllerV2 { private final OAuthUserService oAuthUserService; private final PasswordEncoder encoder; - @Operation(summary = "비밀번호 초기화 - 새로운 비밀번호 설정") @PostMapping("/password/reset") public ResponseEntity resetPassword(@RequestUser UserInfo userInfo, @Validated @RequestBody UserPasswordResetRequestDtoV1 userPasswordResetRequestDtoV1) { @@ -41,7 +40,6 @@ public ResponseEntity resetPassword(@RequestUser UserInfo userInfo, return ResponseEntity.ok().build(); } - @Operation(summary = "[NoAuth] 패스워드 유저 회원가입") @PostMapping("/register") public ResponseEntity registerPasswordUser(@Validated @RequestBody PasswordRegisterRequestDto passwordRegisterRequest) { passwordRegisterRequest.updatePasswordToEncrypt(encoder.encode(passwordRegisterRequest.getPassword())); @@ -50,7 +48,6 @@ public ResponseEntity registerPasswordUser(@Validated @RequestBody Passwor return ResponseEntity.ok().build(); } - @Operation(summary = "[NoAuth] 소셜 유저 회원가입") @PostMapping("/register/social") public ResponseEntity registerSocialUser(@Validated @RequestBody OAuthUserInfoRequestDto oAuthUserInfoRequest) { var oAuthRegisterRequest = oAuthUserService.getOAuthRegisterInfo(oAuthUserInfoRequest); @@ -59,7 +56,6 @@ public ResponseEntity registerSocialUser(@Validated @RequestBody OAuthUser return ResponseEntity.ok().build(); } - @Operation(summary = "[NoAuth] 소셜 유저 로그인") @PostMapping("/login/social") public ResponseEntity loginSocialUser(@Validated @RequestBody OAuthLoginRequestDto oAuthLoginRequestDto) { var oAuthEmail = oAuthUserService.getOAuthEmail(oAuthLoginRequestDto); diff --git a/archive-web/src/main/java/site/archive/web/api/v2/UserControllerV2.java b/archive-web/src/main/java/site/archive/web/api/v2/UserControllerV2.java index 7ada24e..f7d17ed 100644 --- a/archive-web/src/main/java/site/archive/web/api/v2/UserControllerV2.java +++ b/archive-web/src/main/java/site/archive/web/api/v2/UserControllerV2.java @@ -1,6 +1,5 @@ package site.archive.web.api.v2; -import io.swagger.v3.oas.annotations.Operation; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; @@ -23,21 +22,18 @@ public class UserControllerV2 { private final UserService userService; - @Operation(summary = "[NoAuth] 이메일 중복 검사") @GetMapping("/duplicate/email") public ResponseEntity checkDuplicatedEmail(@RequestParam(value = "value") String email) { var emailDuplicateResponseDto = new EmailDuplicateResponseDtoV1(userService.existsEmail(email)); return ResponseEntity.ok(emailDuplicateResponseDto); } - @Operation(summary = "[NoAuth] 닉네임 중복 검사") @GetMapping("/duplicate/nickname") public ResponseEntity checkDuplicatedNickname(@RequestParam(value = "value") String nickname) { var nicknameDuplicateResponseDto = new NicknameDuplicateResponseDto(userService.existsNickname(nickname)); return ResponseEntity.ok(nicknameDuplicateResponseDto); } - @Operation(summary = "프로필 닉네임 수정 (업데이트)") @PutMapping("/nickname") public ResponseEntity updateProfileNickname(@RequestUser UserInfo user, @RequestBody UserNicknameUpdateRequest request) { diff --git a/archive-web/src/main/java/site/archive/web/api/v2/UserProfileControllerV2.java b/archive-web/src/main/java/site/archive/web/api/v2/UserProfileControllerV2.java index d114291..95948e9 100644 --- a/archive-web/src/main/java/site/archive/web/api/v2/UserProfileControllerV2.java +++ b/archive-web/src/main/java/site/archive/web/api/v2/UserProfileControllerV2.java @@ -1,6 +1,5 @@ package site.archive.web.api.v2; -import io.swagger.v3.oas.annotations.Operation; import lombok.RequiredArgsConstructor; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; @@ -11,32 +10,31 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; +import site.archive.common.FileUtils; import site.archive.domain.user.UserInfo; import site.archive.dto.v1.user.SpecificUserDtoV1; import site.archive.service.archive.ArchiveImageService; import site.archive.service.user.UserProfileImageService; import site.archive.service.user.UserService; import site.archive.web.api.resolver.annotation.RequestUser; -import site.archive.common.FileUtils; +import site.archive.web.api.docs.swagger.UserProfileControllerV2Docs; import static site.archive.service.archive.ArchiveImageService.USER_PROFILE_IMAGE_DIRECTORY; @RestController @RequestMapping("/api/v2/user/profile") @RequiredArgsConstructor -public class UserProfileControllerV2 { +public class UserProfileControllerV2 implements UserProfileControllerV2Docs { private final UserService userService; private final UserProfileImageService userProfileImageService; private final ArchiveImageService imageService; - @Operation(summary = "프로필 정보 조회") @GetMapping public ResponseEntity getUserProfileInfo(@RequestUser UserInfo user) { return ResponseEntity.ok(userService.findSpecificUserById(user.getUserId())); } - @Operation(summary = "프로필 이미지 업로드 및 업데이트") @PostMapping(path = "/image/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) @@ -51,7 +49,6 @@ public ResponseEntity uploadProfileImage(@RequestUser UserInfo user, return ResponseEntity.noContent().build(); } - @Operation(summary = "프로필 이미지 제거") @DeleteMapping(path = "/image/remove") public ResponseEntity removeProfileImage(@RequestUser UserInfo user) { var outdatedImageUri = userService.findUserById(user.getUserId()).getProfileImage(); From 94f98c044c6bd72693b3c31db3942554e604c7b4 Mon Sep 17 00:00:00 2001 From: KimDoubleB Date: Sun, 15 Jan 2023 12:38:01 +0900 Subject: [PATCH 13/46] refactor: extract v1 api docs to Docs interface based on Swagger --- .../docs/swagger/ArchiveControllerV1Docs.java | 34 +++++++++++++++++++ .../swagger/RegisterControllerV1Docs.java | 16 +++++++++ .../docs/swagger/UserControllerV1Docs.java | 33 ++++++++++++++++++ .../web/api/v1/ArchiveControllerV1.java | 12 ++----- .../web/api/v1/RegisterControllerV1.java | 6 ++-- .../archive/web/api/v1/UserControllerV1.java | 10 ++---- .../archive/web/api/v2/UserControllerV2.java | 3 +- 7 files changed, 92 insertions(+), 22 deletions(-) create mode 100644 archive-web/src/main/java/site/archive/web/api/docs/swagger/ArchiveControllerV1Docs.java create mode 100644 archive-web/src/main/java/site/archive/web/api/docs/swagger/RegisterControllerV1Docs.java create mode 100644 archive-web/src/main/java/site/archive/web/api/docs/swagger/UserControllerV1Docs.java diff --git a/archive-web/src/main/java/site/archive/web/api/docs/swagger/ArchiveControllerV1Docs.java b/archive-web/src/main/java/site/archive/web/api/docs/swagger/ArchiveControllerV1Docs.java new file mode 100644 index 0000000..217976a --- /dev/null +++ b/archive-web/src/main/java/site/archive/web/api/docs/swagger/ArchiveControllerV1Docs.java @@ -0,0 +1,34 @@ +package site.archive.web.api.docs.swagger; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import org.springframework.http.ResponseEntity; +import org.springframework.web.multipart.MultipartFile; +import site.archive.domain.user.UserInfo; +import site.archive.dto.v1.archive.ArchiveCountResponseDtoV1; +import site.archive.dto.v1.archive.ArchiveDtoV1; +import site.archive.dto.v1.archive.ArchiveImageUrlResponseDtoV1; +import site.archive.dto.v1.archive.ArchiveListResponseDtoV1; + +public interface ArchiveControllerV1Docs { + + @Operation(summary = "아카이브 리스트 조회", description = "홈 뷰 - 아카이브 리스트 조회") + ResponseEntity archiveListView(UserInfo user); + + @Operation(summary = "아카이브 상세 조회", description = "상세 뷰 - 아카이브 상세 조회") + ResponseEntity archiveSpecificView(@Parameter(name = "id", description = "상세 조회할 archive index (id)") Long id); + + @Operation(summary = "아카이브 삭제", description = "아카이브 제거 - 실제 제거 X") + void delete(@Parameter(name = "id", description = "제거할 archive index (id)") Long id); + + @Operation(summary = "[Deprecated -> /api/v2/user/profile/image/upload] 이미지 업로드") + ResponseEntity uploadImage( + @Parameter(name = "image", description = "업로드할 이미지 파일") MultipartFile imageFile); + + @Operation(summary = "아키이브 추가") + ResponseEntity addArchive(UserInfo user, ArchiveDtoV1 archiveDtoV1); + + @Operation(summary = "아카이브 개수 조회") + ResponseEntity countArchive(UserInfo user); + +} diff --git a/archive-web/src/main/java/site/archive/web/api/docs/swagger/RegisterControllerV1Docs.java b/archive-web/src/main/java/site/archive/web/api/docs/swagger/RegisterControllerV1Docs.java new file mode 100644 index 0000000..babb5a2 --- /dev/null +++ b/archive-web/src/main/java/site/archive/web/api/docs/swagger/RegisterControllerV1Docs.java @@ -0,0 +1,16 @@ +package site.archive.web.api.docs.swagger; + +import io.swagger.v3.oas.annotations.Operation; +import org.springframework.http.ResponseEntity; +import site.archive.dto.v1.auth.PasswordRegisterCommandV1; +import site.archive.dto.v1.user.OAuthRegisterRequestDtoV1; + +public interface RegisterControllerV1Docs { + + @Operation(summary = "[Deprecated -> /api/v2/auth/register] 패스워드 유저 회원가입") + ResponseEntity registerUser(PasswordRegisterCommandV1 command); + + @Operation(summary = "[Deprecated -> /api/v2/auth/register/social, login/social] 소셜 로그인 유저 회원가입 및 로그인") + ResponseEntity registerOrLoginSocialUser(OAuthRegisterRequestDtoV1 oAuthRegisterRequestDtoV1); + +} diff --git a/archive-web/src/main/java/site/archive/web/api/docs/swagger/UserControllerV1Docs.java b/archive-web/src/main/java/site/archive/web/api/docs/swagger/UserControllerV1Docs.java new file mode 100644 index 0000000..edd1170 --- /dev/null +++ b/archive-web/src/main/java/site/archive/web/api/docs/swagger/UserControllerV1Docs.java @@ -0,0 +1,33 @@ +package site.archive.web.api.docs.swagger; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import org.springframework.http.ResponseEntity; +import site.archive.domain.user.UserInfo; +import site.archive.dto.v1.archive.EmailDuplicateResponseDtoV1; +import site.archive.dto.v1.auth.LoginCommandV1; +import site.archive.dto.v1.user.UserEmailRequestDtoV1; +import site.archive.dto.v1.user.UserPasswordResetRequestDtoV1; + +public interface UserControllerV1Docs { + + @Operation(summary = "패스워드 유저 로그인") + void loginUser(LoginCommandV1 loginCommandV1); + + @Operation(summary = "회원 탈퇴") + ResponseEntity unregisterUser(UserInfo user); + + @Operation(summary = "[Deprecated -> /api/v2/user/profile] 자기 정보 조회") + ResponseEntity getUserInfo(UserInfo user); + + @Operation(summary = "[Deprecated -> /api/v2/user/duplicate/email] 이메일 중복 검사") + ResponseEntity checkDuplicatedEmail( + @Parameter(name = "email", description = "중복검사 하려는 이메일 주소") String email); + + @Operation(summary = "비밀번호 초기화 - 임시 비밀번호 발급") + ResponseEntity issueTemporaryPassword(UserEmailRequestDtoV1 userEmailRequestDtoV1); + + @Operation(summary = "[Deprecated -> /api/v2/auth/password/reset] 비밀번호 초기화 - 새로운 비밀번호 설정") + ResponseEntity resetPassword(UserPasswordResetRequestDtoV1 userPasswordResetRequestDtoV1); + +} diff --git a/archive-web/src/main/java/site/archive/web/api/v1/ArchiveControllerV1.java b/archive-web/src/main/java/site/archive/web/api/v1/ArchiveControllerV1.java index 6df6162..f8c999e 100644 --- a/archive-web/src/main/java/site/archive/web/api/v1/ArchiveControllerV1.java +++ b/archive-web/src/main/java/site/archive/web/api/v1/ArchiveControllerV1.java @@ -1,6 +1,5 @@ package site.archive.web.api.v1; -import io.swagger.v3.oas.annotations.Operation; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; @@ -14,6 +13,7 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; +import site.archive.common.FileUtils; import site.archive.domain.user.UserInfo; import site.archive.dto.v1.archive.ArchiveCountResponseDtoV1; import site.archive.dto.v1.archive.ArchiveDtoV1; @@ -21,43 +21,39 @@ import site.archive.dto.v1.archive.ArchiveListResponseDtoV1; import site.archive.service.archive.ArchiveImageService; import site.archive.service.archive.ArchiveService; +import site.archive.web.api.docs.swagger.ArchiveControllerV1Docs; import site.archive.web.api.resolver.annotation.RequestUser; import site.archive.web.config.security.authz.AdminOrAuthorChecker; import site.archive.web.config.security.authz.annotation.RequirePermission; -import site.archive.common.FileUtils; import static site.archive.service.archive.ArchiveImageService.ARCHIVE_IMAGE_DIRECTORY; @RestController @RequestMapping("/api/v1/archive") @RequiredArgsConstructor -public class ArchiveControllerV1 { +public class ArchiveControllerV1 implements ArchiveControllerV1Docs { private final ArchiveService archiveService; private final ArchiveImageService imageService; - @Operation(summary = "아카이브 리스트 조회", description = "홈 뷰 - 아카이브 리스트 조회") @GetMapping public ResponseEntity archiveListView(@RequestUser UserInfo user) { return ResponseEntity.ok(archiveService.getAllArchive(user)); } @RequirePermission(handler = AdminOrAuthorChecker.class, id = "id") - @Operation(summary = "아카이브 상세 조회", description = "상세 뷰 - 아카이브 상세 조회") @GetMapping("/{id}") public ResponseEntity archiveSpecificView(@PathVariable Long id) { return ResponseEntity.ok(archiveService.getOneArchiveById(id)); } @RequirePermission(handler = AdminOrAuthorChecker.class, id = "id") - @Operation(summary = "아카이브 삭제", description = "아카이브 제거 - 실제 제거 X") @DeleteMapping("/{id}") public void delete(@PathVariable Long id) { archiveService.delete(id); } @Deprecated - @Operation(summary = "[Deprecated -> /api/v2/user/profile/image/upload] 이미지 업로드") @PostMapping(path = "/image/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity uploadImage(@RequestParam("image") MultipartFile imageFile) { FileUtils.verifyImageFile(imageFile); @@ -65,14 +61,12 @@ public ResponseEntity uploadImage(@RequestParam("i return ResponseEntity.ok(new ArchiveImageUrlResponseDtoV1(imageUri)); } - @Operation(summary = "아키이브 추가") @PostMapping public ResponseEntity addArchive(@RequestUser UserInfo user, @RequestBody ArchiveDtoV1 archiveDtoV1) { archiveService.save(archiveDtoV1, user.getUserId()); return ResponseEntity.status(HttpStatus.CREATED).build(); } - @Operation(summary = "아카이브 개수 조회") @GetMapping("/count") public ResponseEntity countArchive(@RequestUser UserInfo user) { var archiveCountDto = new ArchiveCountResponseDtoV1(archiveService.countArchive(user)); diff --git a/archive-web/src/main/java/site/archive/web/api/v1/RegisterControllerV1.java b/archive-web/src/main/java/site/archive/web/api/v1/RegisterControllerV1.java index 0e9457c..dbdc3cb 100644 --- a/archive-web/src/main/java/site/archive/web/api/v1/RegisterControllerV1.java +++ b/archive-web/src/main/java/site/archive/web/api/v1/RegisterControllerV1.java @@ -1,6 +1,5 @@ package site.archive.web.api.v1; -import io.swagger.v3.oas.annotations.Operation; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.security.core.context.SecurityContextHolder; @@ -14,19 +13,19 @@ import site.archive.dto.v1.user.OAuthRegisterRequestDtoV1; import site.archive.infra.user.oauth.OAuthUserService; import site.archive.service.user.UserRegisterServiceV1; +import site.archive.web.api.docs.swagger.RegisterControllerV1Docs; import site.archive.web.config.security.token.jwt.JwtAuthenticationToken; @RestController @RequestMapping("/api/v1/auth") @RequiredArgsConstructor -public class RegisterControllerV1 { +public class RegisterControllerV1 implements RegisterControllerV1Docs { private final UserRegisterServiceV1 userRegisterServiceV1; private final OAuthUserService oAuthUserService; private final PasswordEncoder encoder; @Deprecated - @Operation(summary = "[Deprecated -> /api/v2/auth/register] 패스워드 유저 회원가입") @PostMapping("/register") public ResponseEntity registerUser(@Validated @RequestBody PasswordRegisterCommandV1 command) { command.setPassword(encoder.encode(command.getPassword())); @@ -36,7 +35,6 @@ public ResponseEntity registerUser(@Validated @RequestBody PasswordRegiste } @Deprecated - @Operation(summary = "[Deprecated -> /api/v2/auth/register/social, login/social] 소셜 로그인 유저 회원가입 및 로그인") @PostMapping("/social") public ResponseEntity registerOrLoginSocialUser(@Validated @RequestBody OAuthRegisterRequestDtoV1 oAuthRegisterRequestDtoV1) { var oAuthRegisterInfo = oAuthUserService.getOAuthRegisterInfo(oAuthRegisterRequestDtoV1); diff --git a/archive-web/src/main/java/site/archive/web/api/v1/UserControllerV1.java b/archive-web/src/main/java/site/archive/web/api/v1/UserControllerV1.java index eed5940..c970822 100644 --- a/archive-web/src/main/java/site/archive/web/api/v1/UserControllerV1.java +++ b/archive-web/src/main/java/site/archive/web/api/v1/UserControllerV1.java @@ -1,6 +1,5 @@ package site.archive.web.api.v1; -import io.swagger.v3.oas.annotations.Operation; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; @@ -18,20 +17,20 @@ import site.archive.dto.v1.user.UserPasswordResetRequestDtoV1; import site.archive.service.user.UserAuthService; import site.archive.service.user.UserService; +import site.archive.web.api.docs.swagger.UserControllerV1Docs; import site.archive.web.api.resolver.annotation.RequestUser; import site.archive.web.config.security.util.SecurityUtils; @RestController @RequestMapping("/api/v1/auth") @RequiredArgsConstructor -public class UserControllerV1 { +public class UserControllerV1 implements UserControllerV1Docs { private static final int TEMP_PASSWORD_LENGTH = 10; private final UserService userService; private final UserAuthService userAuthService; @SuppressWarnings(value = "all") - @Operation(summary = "패스워드 유저 로그인") @PostMapping("/login") public void loginUser(@RequestBody LoginCommandV1 loginCommandV1) { /* @@ -40,7 +39,6 @@ public void loginUser(@RequestBody LoginCommandV1 loginCommandV1) { */ } - @Operation(summary = "회원 탈퇴") @DeleteMapping("/unregister") public ResponseEntity unregisterUser(@RequestUser UserInfo user) { userService.deleteUser(user.getUserId()); @@ -48,21 +46,18 @@ public ResponseEntity unregisterUser(@RequestUser UserInfo user) { } @Deprecated - @Operation(summary = "[Deprecated -> /api/v2/user/profile] 자기 정보 조회") @GetMapping("/info") public ResponseEntity getUserInfo(@RequestUser UserInfo user) { return ResponseEntity.ok(user); } @Deprecated - @Operation(summary = "[Deprecated -> /api/v2/user/duplicate/email] 이메일 중복 검사") @GetMapping("/email/{email}") public ResponseEntity checkDuplicatedEmail(@PathVariable String email) { var emailDuplicateResponseDto = new EmailDuplicateResponseDtoV1(userService.existsEmail(email)); return ResponseEntity.ok(emailDuplicateResponseDto); } - @Operation(summary = "비밀번호 초기화 - 임시 비밀번호 발급") @PostMapping("/password/temporary") public ResponseEntity issueTemporaryPassword(@Validated @RequestBody UserEmailRequestDtoV1 userEmailRequestDtoV1) { var temporaryPassword = SecurityUtils.generateRandomString(TEMP_PASSWORD_LENGTH); @@ -71,7 +66,6 @@ public ResponseEntity issueTemporaryPassword(@Validated @RequestBody UserE } @Deprecated - @Operation(summary = "[Deprecated -> /api/v2/auth/password/reset] 비밀번호 초기화 - 새로운 비밀번호 설정") @PostMapping("/password/reset") public ResponseEntity resetPassword(@Validated @RequestBody UserPasswordResetRequestDtoV1 userPasswordResetRequestDtoV1) { userAuthService.resetPassword(userPasswordResetRequestDtoV1); diff --git a/archive-web/src/main/java/site/archive/web/api/v2/UserControllerV2.java b/archive-web/src/main/java/site/archive/web/api/v2/UserControllerV2.java index f7d17ed..fc39e3d 100644 --- a/archive-web/src/main/java/site/archive/web/api/v2/UserControllerV2.java +++ b/archive-web/src/main/java/site/archive/web/api/v2/UserControllerV2.java @@ -13,12 +13,13 @@ import site.archive.dto.v2.NicknameDuplicateResponseDto; import site.archive.dto.v2.UserNicknameUpdateRequest; import site.archive.service.user.UserService; +import site.archive.web.api.docs.swagger.UserControllerV2Docs; import site.archive.web.api.resolver.annotation.RequestUser; @RestController @RequestMapping("/api/v2/user") @RequiredArgsConstructor -public class UserControllerV2 { +public class UserControllerV2 implements UserControllerV2Docs { private final UserService userService; From 64fa1b411059f23ab5ff814111618373d67d73e8 Mon Sep 17 00:00:00 2001 From: KimDoubleB Date: Sun, 15 Jan 2023 13:06:52 +0900 Subject: [PATCH 14/46] fix: springdoc-openapi bugs - cannot read Request parameter name if not passed annotation value --- .../java/site/archive/web/api/v2/BannerControllerV2.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/archive-web/src/main/java/site/archive/web/api/v2/BannerControllerV2.java b/archive-web/src/main/java/site/archive/web/api/v2/BannerControllerV2.java index 37d5127..a3b0297 100644 --- a/archive-web/src/main/java/site/archive/web/api/v2/BannerControllerV2.java +++ b/archive-web/src/main/java/site/archive/web/api/v2/BannerControllerV2.java @@ -45,8 +45,8 @@ public ResponseEntity archiveCommunityBannerView() { @PostMapping(path = "/type/image", consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity createArchiveCommunityBanner(@RequestParam MultipartFile summaryImage, - @RequestParam MultipartFile mainImage) { + public ResponseEntity createArchiveCommunityBanner(@RequestParam(name = "summaryImage") MultipartFile summaryImage, + @RequestParam(name = "mainImage") MultipartFile mainImage) { var summaryImageUri = imageUploadAndGetUri(BANNER_SUMMARY_IMAGE_DIRECTORY, summaryImage); var mainImageUri = imageUploadAndGetUri(BANNER_MAIN_IMAGE_DIRECTORY, mainImage); bannerService.createBanner(summaryImageUri, mainImageUri, BannerType.IMAGE); @@ -58,7 +58,7 @@ public ResponseEntity createArchiveCommunityBanner(@RequestParam Multipart @PostMapping(path = "/type/url", consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity createArchiveCommunityBanner(@RequestParam MultipartFile summaryImage, + public ResponseEntity createArchiveCommunityBanner(@RequestParam(name = "summaryImage") MultipartFile summaryImage, @RequestParam String mainContentUrl) { var summaryImageUri = imageUploadAndGetUri(BANNER_SUMMARY_IMAGE_DIRECTORY, summaryImage); bannerService.createBanner(summaryImageUri, mainContentUrl, BannerType.URL); From 7f99ff2abc6128effb39c028c5c7c9043d69ae96 Mon Sep 17 00:00:00 2001 From: KimDoubleB Date: Sun, 15 Jan 2023 21:49:55 +0900 Subject: [PATCH 15/46] feat(#51): define CoverImageType at Archive Entity --- .../site/archive/domain/archive/Archive.java | 29 +++++++++++-------- .../domain/archive/CoverImageType.java | 8 +++++ 2 files changed, 25 insertions(+), 12 deletions(-) create mode 100644 archive-domain/src/main/java/site/archive/domain/archive/CoverImageType.java diff --git a/archive-domain/src/main/java/site/archive/domain/archive/Archive.java b/archive-domain/src/main/java/site/archive/domain/archive/Archive.java index 426fa6f..7fbbbce 100644 --- a/archive-domain/src/main/java/site/archive/domain/archive/Archive.java +++ b/archive-domain/src/main/java/site/archive/domain/archive/Archive.java @@ -1,16 +1,5 @@ package site.archive.domain.archive; -import lombok.AccessLevel; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; -import org.hibernate.annotations.SQLDelete; -import org.hibernate.annotations.Where; -import site.archive.domain.archive.converter.CompanionsConverter; -import site.archive.domain.common.BaseTimeEntity; -import site.archive.domain.like.Like; -import site.archive.domain.user.BaseUser; - import jakarta.persistence.CascadeType; import jakarta.persistence.Column; import jakarta.persistence.Convert; @@ -26,6 +15,17 @@ import jakarta.persistence.OneToMany; import jakarta.persistence.Table; +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.Where; +import site.archive.domain.archive.converter.CompanionsConverter; +import site.archive.domain.common.BaseTimeEntity; +import site.archive.domain.like.Like; +import site.archive.domain.user.BaseUser; + import java.time.LocalDate; import java.util.ArrayList; import java.util.List; @@ -59,6 +59,9 @@ public class Archive extends BaseTimeEntity { private String mainImage; @Column(name = "is_public") private Boolean isPublic; + @Enumerated(value = EnumType.STRING) + @Column(name = "cover_image_type") + private CoverImageType coverImageType; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "author_id", nullable = false) private BaseUser author; @@ -77,6 +80,7 @@ public Archive(Long id, Emotion emotion, String mainImage, Boolean isPublic, + CoverImageType coverImageType, List companions, BaseUser author) { this.id = id; @@ -84,8 +88,9 @@ public Archive(Long id, this.watchedOn = watchedOn; this.emotion = emotion; this.mainImage = mainImage; - this.companions = companions; this.isPublic = isPublic; + this.coverImageType = coverImageType; + this.companions = companions; this.author = author; } diff --git a/archive-domain/src/main/java/site/archive/domain/archive/CoverImageType.java b/archive-domain/src/main/java/site/archive/domain/archive/CoverImageType.java new file mode 100644 index 0000000..bc13411 --- /dev/null +++ b/archive-domain/src/main/java/site/archive/domain/archive/CoverImageType.java @@ -0,0 +1,8 @@ +package site.archive.domain.archive; + +public enum CoverImageType { + + EMOTION_COVER, + NO_COVER + +} From 495d7a2d274ca7b16b840ba241f364da54a239d8 Mon Sep 17 00:00:00 2001 From: KimDoubleB Date: Sun, 15 Jan 2023 21:50:13 +0900 Subject: [PATCH 16/46] feat(#51): added CoverImageType to DTOs --- .../site/archive/dto/v1/archive/ArchiveDtoV1.java | 12 +++++++++--- .../archive/dto/v2/ArchiveCommunityResponseDto.java | 3 +++ .../main/java/site/archive/dto/v2/ArchiveDtoV2.java | 7 ++++--- .../site/archive/dto/v2/ArchiveLikeResponseDto.java | 3 +++ .../site/archive/dto/v2/MyArchiveResponseDto.java | 3 +++ 5 files changed, 22 insertions(+), 6 deletions(-) diff --git a/archive-application/src/main/java/site/archive/dto/v1/archive/ArchiveDtoV1.java b/archive-application/src/main/java/site/archive/dto/v1/archive/ArchiveDtoV1.java index 16c756e..7473523 100644 --- a/archive-application/src/main/java/site/archive/dto/v1/archive/ArchiveDtoV1.java +++ b/archive-application/src/main/java/site/archive/dto/v1/archive/ArchiveDtoV1.java @@ -7,11 +7,13 @@ import lombok.Getter; import lombok.NoArgsConstructor; import site.archive.domain.archive.Archive; +import site.archive.domain.archive.CoverImageType; import site.archive.domain.archive.Emotion; import site.archive.domain.user.BaseUser; import java.time.LocalDate; import java.util.List; +import java.util.Objects; import static site.archive.common.DateTimeUtil.YY_MM_DD_FORMATTER; @@ -26,7 +28,8 @@ public class ArchiveDtoV1 { private String watchedOn; private Emotion emotion; private String mainImage; - private Boolean isPublic; // Default value is false + private Boolean isPublic; // Default value is false + private CoverImageType coverImageType; // Default value is EMOTION_COVER private long authorId; @@ -60,11 +63,13 @@ public static ArchiveDtoV1 simpleFrom(Archive archive) { .mainImage(archive.getMainImage()) .authorId(archive.getAuthor().getId()) .isPublic(archive.getIsPublic()) + .coverImageType(archive.getCoverImageType()) .build(); } public Archive toEntity(BaseUser user) { - var defaultIsPublic = this.isPublic != null && this.isPublic; + var archivePublic = this.isPublic != null && this.isPublic; + var archiveCoverImageType = Objects.requireNonNullElse(coverImageType, CoverImageType.EMOTION_COVER); return Archive.builder() .name(name) .watchedOn(LocalDate.parse(watchedOn, YY_MM_DD_FORMATTER)) @@ -72,7 +77,8 @@ public Archive toEntity(BaseUser user) { .mainImage(mainImage) .companions(companions) .author(user) - .isPublic(defaultIsPublic) + .isPublic(archivePublic) + .coverImageType(archiveCoverImageType) .build(); } diff --git a/archive-application/src/main/java/site/archive/dto/v2/ArchiveCommunityResponseDto.java b/archive-application/src/main/java/site/archive/dto/v2/ArchiveCommunityResponseDto.java index 9df4b49..02e820a 100644 --- a/archive-application/src/main/java/site/archive/dto/v2/ArchiveCommunityResponseDto.java +++ b/archive-application/src/main/java/site/archive/dto/v2/ArchiveCommunityResponseDto.java @@ -4,6 +4,7 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; import site.archive.domain.archive.Archive; +import site.archive.domain.archive.CoverImageType; import site.archive.domain.archive.Emotion; import static site.archive.common.DateTimeUtil.YY_MM_DD_FORMATTER; @@ -18,6 +19,7 @@ public class ArchiveCommunityResponseDto { private final String watchedOn; private final Emotion emotion; private final String mainImage; + private final CoverImageType coverImageType; private final Long authorId; private final String authorNickname; private final String authorProfileImage; @@ -37,6 +39,7 @@ public static ArchiveCommunityResponseDto from(Archive archive, Long currentUser .watchedOn(archive.getWatchedOn().format(YY_MM_DD_FORMATTER)) .emotion(archive.getEmotion()) .mainImage(archive.getMainImage()) + .coverImageType(archive.getCoverImageType()) .authorId(author.getId()) .authorNickname(author.getNickname()) .authorProfileImage(author.getProfileImage()) diff --git a/archive-application/src/main/java/site/archive/dto/v2/ArchiveDtoV2.java b/archive-application/src/main/java/site/archive/dto/v2/ArchiveDtoV2.java index 1b3cd8f..e5e2c15 100644 --- a/archive-application/src/main/java/site/archive/dto/v2/ArchiveDtoV2.java +++ b/archive-application/src/main/java/site/archive/dto/v2/ArchiveDtoV2.java @@ -6,11 +6,10 @@ import lombok.Getter; import lombok.NoArgsConstructor; import site.archive.domain.archive.Archive; +import site.archive.domain.archive.CoverImageType; import site.archive.domain.archive.Emotion; -import site.archive.domain.user.BaseUser; import site.archive.dto.v1.archive.ArchiveImageDtoV1; -import java.time.LocalDate; import java.util.List; import static site.archive.common.DateTimeUtil.YY_MM_DD_FORMATTER; @@ -27,7 +26,8 @@ public class ArchiveDtoV2 { private String watchedOn; private Emotion emotion; private String mainImage; - private Boolean isPublic; // Default value is false + private Boolean isPublic; // Default value is false + private CoverImageType coverImageType; // Default value is EMOTION_COVER private long authorId; private String nickname; @@ -53,6 +53,7 @@ public static ArchiveDtoV2 specificFrom(Archive archive) { .nickname(author.getNickname()) .profileImage(author.getProfileImage()) .isPublic(archive.getIsPublic()) + .coverImageType(archive.getCoverImageType()) .build(); } } diff --git a/archive-application/src/main/java/site/archive/dto/v2/ArchiveLikeResponseDto.java b/archive-application/src/main/java/site/archive/dto/v2/ArchiveLikeResponseDto.java index 0665b25..79c97ea 100644 --- a/archive-application/src/main/java/site/archive/dto/v2/ArchiveLikeResponseDto.java +++ b/archive-application/src/main/java/site/archive/dto/v2/ArchiveLikeResponseDto.java @@ -5,6 +5,7 @@ import lombok.RequiredArgsConstructor; import lombok.ToString; import site.archive.domain.archive.Archive; +import site.archive.domain.archive.CoverImageType; import site.archive.domain.archive.Emotion; import static site.archive.common.DateTimeUtil.YY_MM_DD_FORMATTER; @@ -20,6 +21,7 @@ public class ArchiveLikeResponseDto { private final String watchedOn; private final Emotion emotion; private final String mainImage; + private final CoverImageType coverImageType; private final Long authorId; private final String authorNickname; private final String authorProfileImage; @@ -38,6 +40,7 @@ public static ArchiveLikeResponseDto from(Archive archive, Long currentUserIdx) .watchedOn(archive.getWatchedOn().format(YY_MM_DD_FORMATTER)) .emotion(archive.getEmotion()) .mainImage(archive.getMainImage()) + .coverImageType(archive.getCoverImageType()) .authorId(author.getId()) .authorNickname(author.getNickname()) .authorProfileImage(author.getProfileImage()) diff --git a/archive-application/src/main/java/site/archive/dto/v2/MyArchiveResponseDto.java b/archive-application/src/main/java/site/archive/dto/v2/MyArchiveResponseDto.java index 9175373..12381e2 100644 --- a/archive-application/src/main/java/site/archive/dto/v2/MyArchiveResponseDto.java +++ b/archive-application/src/main/java/site/archive/dto/v2/MyArchiveResponseDto.java @@ -4,6 +4,7 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; import site.archive.domain.archive.Archive; +import site.archive.domain.archive.CoverImageType; import site.archive.domain.archive.Emotion; import static site.archive.common.DateTimeUtil.YY_MM_DD_FORMATTER; @@ -19,6 +20,7 @@ public class MyArchiveResponseDto { private final Emotion emotion; private final String mainImage; private final Boolean isPublic; + private final CoverImageType coverImageType; private final Long authorId; private final Long likeCount; private final Long dateMilli; @@ -34,6 +36,7 @@ public static MyArchiveResponseDto from(Archive archive, long dateMilli) { .emotion(archive.getEmotion()) .mainImage(archive.getMainImage()) .isPublic(archive.getIsPublic()) + .coverImageType(archive.getCoverImageType()) .authorId(author.getId()) .likeCount(likeCount) .dateMilli(dateMilli) From c4d9baf17a1f6f26f63e8536edd81d870b057cc4 Mon Sep 17 00:00:00 2001 From: KimDoubleB Date: Sun, 15 Jan 2023 22:01:44 +0900 Subject: [PATCH 17/46] docs(#51): added ArchiveDTO comments about simple/specific form meaning --- .../site/archive/dto/v1/archive/ArchiveDtoV1.java | 14 ++++++++++++++ .../java/site/archive/dto/v2/ArchiveDtoV2.java | 8 ++++++++ 2 files changed, 22 insertions(+) diff --git a/archive-application/src/main/java/site/archive/dto/v1/archive/ArchiveDtoV1.java b/archive-application/src/main/java/site/archive/dto/v1/archive/ArchiveDtoV1.java index 7473523..9038747 100644 --- a/archive-application/src/main/java/site/archive/dto/v1/archive/ArchiveDtoV1.java +++ b/archive-application/src/main/java/site/archive/dto/v1/archive/ArchiveDtoV1.java @@ -36,6 +36,13 @@ public class ArchiveDtoV1 { private List companions; private List images; + /** + * 아카이브 상세 조회 DTO V1 + * 아카이브 연결 이미지들을 다 포함 + * + * @param archive Archive Entity + * @return ArchiveDtoV1 archive specific DTO + */ public static ArchiveDtoV1 specificFrom(Archive archive) { var archiveImages = archive.getArchiveImages().stream() .map(ArchiveImageDtoV1::from) @@ -53,6 +60,13 @@ public static ArchiveDtoV1 specificFrom(Archive archive) { .build(); } + /** + * 아카이브 리스트 조회 DTO + * 아카이브 연결 이미지들을 포함하고 있지 않음 + * + * @param archive archive entity + * @return ArchiveDtoV1 archive simple DTO + */ public static ArchiveDtoV1 simpleFrom(Archive archive) { return ArchiveDtoV1.builder() .archiveId(archive.getId()) diff --git a/archive-application/src/main/java/site/archive/dto/v2/ArchiveDtoV2.java b/archive-application/src/main/java/site/archive/dto/v2/ArchiveDtoV2.java index e5e2c15..c9dac0d 100644 --- a/archive-application/src/main/java/site/archive/dto/v2/ArchiveDtoV2.java +++ b/archive-application/src/main/java/site/archive/dto/v2/ArchiveDtoV2.java @@ -36,6 +36,14 @@ public class ArchiveDtoV2 { private List companions; private List images; + /** + * 아카이브 상세 조회 DTO V2 + * 아카이브 작가의 닉네임, 프로필이미지 포함 + * 아카이브 연결 이미지들을 다 포함 + * + * @param archive Archive Entity + * @return ArchiveDtoV2 archive specific DTO + */ public static ArchiveDtoV2 specificFrom(Archive archive) { var archiveImages = archive.getArchiveImages().stream() .map(ArchiveImageDtoV1::from) From 7473eb942b7892bb30bd29902a55f063f8affd30 Mon Sep 17 00:00:00 2001 From: KimDoubleB Date: Sun, 15 Jan 2023 22:12:10 +0900 Subject: [PATCH 18/46] test(#51): added cover_image_type to test Init SQL script --- .../test/resources/sql/default/archive.sql | 30 +++++++++---------- .../src/test/resources/sql/default/ddl.sql | 23 +++++++------- 2 files changed, 27 insertions(+), 26 deletions(-) diff --git a/archive-domain/src/test/resources/sql/default/archive.sql b/archive-domain/src/test/resources/sql/default/archive.sql index 235a3cc..bd94167 100644 --- a/archive-domain/src/test/resources/sql/default/archive.sql +++ b/archive-domain/src/test/resources/sql/default/archive.sql @@ -1,20 +1,20 @@ -- archive INSERT INTO archive (archive_id, created_at, is_deleted, updated_at, companions, emotion, main_image, name, watched_on, author_id, - is_public) -VALUES (1, '2022-01-18 11:23:01', 0, '2022-01-11 11:23:07', '친구1', 'INTERESTING', '메인 이미지', '아카이브1', '2022-01-11 00:00:00', 1, 1), - (2, '2022-02-17 12:23:03', 0, '2022-12-03 12:23:07', '친구2,친구3', 'AMAZING', '메인 이미지', 'A 전시회', '2022-03-22 00:00:00', 1, 0), - (3, '2022-03-16 13:23:04', 1, '2022-02-09 13:23:07', '친구2,친구4', 'PLEASANT', '메인 이미지', '우와아아', '2022-02-09 00:00:00', 3, 1), - (4, '2022-04-15 14:23:06', 0, '2022-11-27 14:23:07', '어머니', 'PLEASANT', '메인 이미지', '탑건', '2022-11-27 00:00:00', 2, 1), - (5, '2022-05-14 15:23:17', 0, '2022-03-22 15:23:07', '아버지', 'INTERESTING', '메인 이미지', '김보배전시회', '2022-03-22 00:00:00', 4, 0), - (6, '2022-06-13 16:23:27', 1, '2022-10-13 16:23:07', 'A,B,C', 'INTERESTING2', '메인 이미지', '엄청난콘서트', '2022-03-22 00:00:00', 6, 1), - (7, '2022-07-12 17:23:37', 0, '2022-05-07 17:23:07', '여자친구,남자친구', 'SHAME', '메인 이미지', '사진전', '2022-05-07 00:00:00', 5, 1), - (8, '2022-08-11 18:23:42', 0, '2022-07-29 18:23:07', '누구,누구2,누구4', 'PLEASANT', '메인 이미지', '호그와트', '2022-07-29 00:00:00', 9, 1), - (9, '2022-08-12 18:23:42', 0, '2022-07-29 18:23:07', '누구,누구2,누구4', 'PLEASANT', '메인 이미지', '반지의제왕', '2022-01-29 00:00:00', 10, 1), - (10, '2022-08-13 18:23:42', 0, '2022-07-29 18:23:07', '누구,누구2,누구4', 'IMPRESSIVE', '메인 이미지', '호그와트', '2022-02-22 00:00:00', 4, 1), - (11, '2022-08-14 18:23:42', 0, '2022-07-29 18:23:07', '누구,누구2,누구4', 'PLEASANT', '메인 이미지', '전시전시회', '2022-03-29 00:00:00', 7, 1), - (12, '2022-08-15 18:23:42', 0, '2022-07-29 18:23:07', '누구,누구2,누구4', 'TOUCHING', '메인 이미지', '청와대', '2022-04-29 00:00:00', 8, 1), - (13, '2022-08-16 18:23:42', 1, '2022-07-29 18:23:07', '누구,누구2,누구4', 'PLEASANT', '메인 이미지', '창덕궁', '2022-05-29 00:00:00', 8, 0), - (14, '2022-08-17 18:23:42', 0, '2022-07-29 18:23:07', '누구,누구2,누구4', 'TOUCHING', '메인 이미지', '전쟁기념관', '2022-06-29 00:00:00', 5, 1); + is_public, cover_image_type) +VALUES (1, '2022-01-18 11:23:01', 0, '2022-01-11 11:23:07', '친구1', 'INTERESTING', '메인 이미지', '아카이브1', '2022-01-11 00:00:00', 1, 1, 'EMOTION_COVER'), + (2, '2022-02-17 12:23:03', 0, '2022-12-03 12:23:07', '친구2,친구3', 'AMAZING', '메인 이미지', 'A 전시회', '2022-03-22 00:00:00', 1, 0, 'EMOTION_COVER'), + (3, '2022-03-16 13:23:04', 1, '2022-02-09 13:23:07', '친구2,친구4', 'PLEASANT', '메인 이미지', '우와아아', '2022-02-09 00:00:00', 3, 1, 'NO_COVER'), + (4, '2022-04-15 14:23:06', 0, '2022-11-27 14:23:07', '어머니', 'PLEASANT', '메인 이미지', '탑건', '2022-11-27 00:00:00', 2, 1, 'EMOTION_COVER'), + (5, '2022-05-14 15:23:17', 0, '2022-03-22 15:23:07', '아버지', 'INTERESTING', '메인 이미지', '김보배전시회', '2022-03-22 00:00:00', 4, 0, 'EMOTION_COVER'), + (6, '2022-06-13 16:23:27', 1, '2022-10-13 16:23:07', 'A,B,C', 'INTERESTING2', '메인 이미지', '엄청난콘서트', '2022-03-22 00:00:00', 6, 1, 'NO_COVER'), + (7, '2022-07-12 17:23:37', 0, '2022-05-07 17:23:07', '여자친구,남자친구', 'SHAME', '메인 이미지', '사진전', '2022-05-07 00:00:00', 5, 1, 'EMOTION_COVER'), + (8, '2022-08-11 18:23:42', 0, '2022-07-29 18:23:07', '누구,누구2,누구4', 'PLEASANT', '메인 이미지', '호그와트', '2022-07-29 00:00:00', 9, 1, 'NO_COVER'), + (9, '2022-08-12 18:23:42', 0, '2022-07-29 18:23:07', '누구,누구2,누구4', 'PLEASANT', '메인 이미지', '반지의제왕', '2022-01-29 00:00:00', 10, 1, 'EMOTION_COVER'), + (10, '2022-08-13 18:23:42', 0, '2022-07-29 18:23:07', '누구,누구2,누구4', 'IMPRESSIVE', '메인 이미지', '호그와트', '2022-02-22 00:00:00', 4, 1, 'EMOTION_COVER'), + (11, '2022-08-14 18:23:42', 0, '2022-07-29 18:23:07', '누구,누구2,누구4', 'PLEASANT', '메인 이미지', '전시전시회', '2022-03-29 00:00:00', 7, 1, 'NO_COVER'), + (12, '2022-08-15 18:23:42', 0, '2022-07-29 18:23:07', '누구,누구2,누구4', 'TOUCHING', '메인 이미지', '청와대', '2022-04-29 00:00:00', 8, 1, 'EMOTION_COVER'), + (13, '2022-08-16 18:23:42', 1, '2022-07-29 18:23:07', '누구,누구2,누구4', 'PLEASANT', '메인 이미지', '창덕궁', '2022-05-29 00:00:00', 8, 0, 'NO_COVER'), + (14, '2022-08-17 18:23:42', 0, '2022-07-29 18:23:07', '누구,누구2,누구4', 'TOUCHING', '메인 이미지', '전쟁기념관', '2022-06-29 00:00:00', 5, 1, 'EMOTION_COVER'); -- archive-image INSERT INTO archive_image (archive_image_id, created_at, is_deleted, updated_at, image, review, archive_id, background_color) diff --git a/archive-domain/src/test/resources/sql/default/ddl.sql b/archive-domain/src/test/resources/sql/default/ddl.sql index 6b14d94..7a87f56 100644 --- a/archive-domain/src/test/resources/sql/default/ddl.sql +++ b/archive-domain/src/test/resources/sql/default/ddl.sql @@ -1,17 +1,18 @@ -- Test table ddl create table if not exists archive ( - archive_id bigint auto_increment primary key, - created_at timestamp default CURRENT_TIMESTAMP null, - is_deleted tinyint(1) default 0 null, - updated_at timestamp default CURRENT_TIMESTAMP null on update CURRENT_TIMESTAMP, - companions varchar(255) null, - emotion varchar(255) null, - main_image varchar(255) null, - name varchar(100) not null, - watched_on timestamp null, - author_id bigint not null, - is_public tinyint(1) default 0 null + archive_id bigint auto_increment primary key, + created_at timestamp default CURRENT_TIMESTAMP null, + is_deleted tinyint(1) default 0 null, + updated_at timestamp default CURRENT_TIMESTAMP null on update CURRENT_TIMESTAMP, + companions varchar(255) null, + emotion varchar(255) null, + main_image varchar(255) null, + name varchar(100) not null, + watched_on timestamp null, + author_id bigint not null, + is_public tinyint(1) default 0 null, + cover_image_type varchar(20) default 'EMOTION_COVER' not null ); create table if not exists archive_image From 6c14f8dc9d02c6671835be1bc7da1eeed28c5863 Mon Sep 17 00:00:00 2001 From: KimDoubleB Date: Mon, 16 Jan 2023 01:48:31 +0900 Subject: [PATCH 19/46] refactor: remove unused comment --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 52a2987..071d707 100644 --- a/build.gradle +++ b/build.gradle @@ -15,7 +15,7 @@ ext { testContainerVersion = "1.17.2" } -subprojects { // 추후 root project 제거시 subproject 로 수정 +subprojects { apply { plugin 'java' plugin 'io.spring.dependency-management' From dc4836be99cf55478ea82902a56167463c103946 Mon Sep 17 00:00:00 2001 From: KimDoubleB Date: Mon, 16 Jan 2023 01:57:46 +0900 Subject: [PATCH 20/46] chore(#53): added kotlin configurations --- build.gradle | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/build.gradle b/build.gradle index 071d707..1fcafaa 100644 --- a/build.gradle +++ b/build.gradle @@ -2,9 +2,12 @@ plugins { id 'org.springframework.boot' version '3.0.0' id 'io.spring.dependency-management' version '1.1.0' id 'java' -} -version = '2.0.1' + // for kotlin + id 'org.jetbrains.kotlin.jvm' version '1.7.22' + id 'org.jetbrains.kotlin.plugin.spring' version '1.7.22' + id "org.jetbrains.kotlin.plugin.jpa" version '1.7.22' +} repositories { mavenCentral() @@ -17,12 +20,17 @@ ext { subprojects { apply { - plugin 'java' - plugin 'io.spring.dependency-management' plugin 'org.springframework.boot' + plugin 'io.spring.dependency-management' + plugin 'java' + plugin 'org.jetbrains.kotlin.jvm' + plugin 'org.jetbrains.kotlin.plugin.spring' + plugin 'org.jetbrains.kotlin.plugin.jpa' } group = 'site.archive' + version = '2.0.1' + sourceCompatibility = '17' java { sourceCompatibility = JavaVersion.VERSION_17 @@ -46,6 +54,11 @@ subprojects { testImplementation "org.testcontainers:testcontainers:${testContainerVersion}" testImplementation "org.testcontainers:junit-jupiter:${testContainerVersion}" testImplementation "org.testcontainers:mysql:${testContainerVersion}" + + // for kotlin + implementation 'com.fasterxml.jackson.module:jackson-module-kotlin' + implementation 'org.jetbrains.kotlin:kotlin-reflect' + implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8' } configurations { @@ -57,6 +70,22 @@ subprojects { tasks.named('test') { useJUnitPlatform() } + + // for kotlin + tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile) { + kotlinOptions { + jvmTarget = JavaVersion.VERSION_17 + freeCompilerArgs = ["-Xjsr305=strict"] + } + } + + // for kotlin + allOpen { + annotation("javax.persistence.Entity") + annotation("javax.persistence.MappedSuperclass") + annotation("javax.persistence.Embeddable") + } + } configure(allprojects.findAll { it.name != 'archive-common' }) { From c1dc0556d1fbc779571672aab9fc1e98f4f4232f Mon Sep 17 00:00:00 2001 From: KimDoubleB Date: Tue, 17 Jan 2023 01:49:33 +0900 Subject: [PATCH 21/46] feat(#53): converted Utils classes java to kotlin --- .../archive/dto/v1/archive/ArchiveDtoV1.java | 9 ++--- .../archive/dto/v1/user/BaseUserDtoV1.java | 4 +- .../dto/v1/user/SpecificUserDtoV1.java | 4 +- .../dto/v2/ArchiveCommunityResponseDto.java | 5 +-- .../site/archive/dto/v2/ArchiveDtoV2.java | 5 +-- .../dto/v2/ArchiveLikeResponseDto.java | 5 +-- .../archive/dto/v2/MyArchiveResponseDto.java | 5 +-- .../archive/common/ArchiveStringUtils.java | 14 ------- .../site/archive/common/ArchiveStringUtils.kt | 9 +++++ .../site/archive/common/DateTimeUtil.java | 40 ------------------- .../java/site/archive/common/DateTimeUtils.kt | 34 ++++++++++++++++ .../java/site/archive/common/FileUtils.java | 30 -------------- .../java/site/archive/common/FileUtils.kt | 22 ++++++++++ .../site/archive/common/DateTimeUtilTest.java | 12 +++--- .../custom/ArchiveCommunityTimeSortType.java | 14 +++---- .../custom/ArchiveCustomRepositoryImpl.java | 4 +- .../domain/archive/ArchiveRepositoryTest.java | 4 +- 17 files changed, 98 insertions(+), 122 deletions(-) delete mode 100644 archive-common/src/main/java/site/archive/common/ArchiveStringUtils.java create mode 100644 archive-common/src/main/java/site/archive/common/ArchiveStringUtils.kt delete mode 100644 archive-common/src/main/java/site/archive/common/DateTimeUtil.java create mode 100644 archive-common/src/main/java/site/archive/common/DateTimeUtils.kt delete mode 100644 archive-common/src/main/java/site/archive/common/FileUtils.java create mode 100644 archive-common/src/main/java/site/archive/common/FileUtils.kt diff --git a/archive-application/src/main/java/site/archive/dto/v1/archive/ArchiveDtoV1.java b/archive-application/src/main/java/site/archive/dto/v1/archive/ArchiveDtoV1.java index 9038747..f8878b0 100644 --- a/archive-application/src/main/java/site/archive/dto/v1/archive/ArchiveDtoV1.java +++ b/archive-application/src/main/java/site/archive/dto/v1/archive/ArchiveDtoV1.java @@ -6,6 +6,7 @@ import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import site.archive.common.DateTimeUtils; import site.archive.domain.archive.Archive; import site.archive.domain.archive.CoverImageType; import site.archive.domain.archive.Emotion; @@ -15,8 +16,6 @@ import java.util.List; import java.util.Objects; -import static site.archive.common.DateTimeUtil.YY_MM_DD_FORMATTER; - @NoArgsConstructor @AllArgsConstructor @Getter @@ -50,7 +49,7 @@ public static ArchiveDtoV1 specificFrom(Archive archive) { return ArchiveDtoV1.builder() .archiveId(archive.getId()) .name(archive.getName()) - .watchedOn(archive.getWatchedOn().format(YY_MM_DD_FORMATTER)) + .watchedOn(archive.getWatchedOn().format(DateTimeUtils.getYymmddFormatter())) .emotion(archive.getEmotion()) .mainImage(archive.getMainImage()) .companions(archive.getCompanions()) @@ -71,7 +70,7 @@ public static ArchiveDtoV1 simpleFrom(Archive archive) { return ArchiveDtoV1.builder() .archiveId(archive.getId()) .name(archive.getName()) - .watchedOn(archive.getWatchedOn().format(YY_MM_DD_FORMATTER)) + .watchedOn(archive.getWatchedOn().format(DateTimeUtils.getYymmddFormatter())) .emotion(archive.getEmotion()) .companions(archive.getCompanions()) .mainImage(archive.getMainImage()) @@ -86,7 +85,7 @@ public Archive toEntity(BaseUser user) { var archiveCoverImageType = Objects.requireNonNullElse(coverImageType, CoverImageType.EMOTION_COVER); return Archive.builder() .name(name) - .watchedOn(LocalDate.parse(watchedOn, YY_MM_DD_FORMATTER)) + .watchedOn(LocalDate.parse(watchedOn, DateTimeUtils.getYymmddFormatter())) .emotion(emotion) .mainImage(mainImage) .companions(companions) diff --git a/archive-application/src/main/java/site/archive/dto/v1/user/BaseUserDtoV1.java b/archive-application/src/main/java/site/archive/dto/v1/user/BaseUserDtoV1.java index 7edea58..05a8600 100644 --- a/archive-application/src/main/java/site/archive/dto/v1/user/BaseUserDtoV1.java +++ b/archive-application/src/main/java/site/archive/dto/v1/user/BaseUserDtoV1.java @@ -2,7 +2,7 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; -import site.archive.common.DateTimeUtil; +import site.archive.common.DateTimeUtils; import site.archive.domain.user.BaseUser; import site.archive.domain.user.UserRole; @@ -29,7 +29,7 @@ public static BaseUserDtoV1 from(BaseUser baseUser) { } public String getCreatedAt() { - return DateTimeUtil.DATE_TIME_FORMATTER.format(this.createdAt); + return DateTimeUtils.getDateTimeFormatter().format(this.createdAt); } } diff --git a/archive-application/src/main/java/site/archive/dto/v1/user/SpecificUserDtoV1.java b/archive-application/src/main/java/site/archive/dto/v1/user/SpecificUserDtoV1.java index 31161af..d92a9c5 100644 --- a/archive-application/src/main/java/site/archive/dto/v1/user/SpecificUserDtoV1.java +++ b/archive-application/src/main/java/site/archive/dto/v1/user/SpecificUserDtoV1.java @@ -2,7 +2,7 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; -import site.archive.common.DateTimeUtil; +import site.archive.common.DateTimeUtils; import site.archive.domain.user.BaseUser; import site.archive.domain.user.UserRole; @@ -19,7 +19,7 @@ public class SpecificUserDtoV1 { private final String userType; public static SpecificUserDtoV1 from(BaseUser baseUser) { - var createdAt = DateTimeUtil.DATE_TIME_FORMATTER.format(baseUser.getCreatedAt()); + var createdAt = DateTimeUtils.getDateTimeFormatter().format(baseUser.getCreatedAt()); return new SpecificUserDtoV1(baseUser.getId(), baseUser.getMailAddress(), baseUser.getRole(), diff --git a/archive-application/src/main/java/site/archive/dto/v2/ArchiveCommunityResponseDto.java b/archive-application/src/main/java/site/archive/dto/v2/ArchiveCommunityResponseDto.java index 02e820a..b5149d3 100644 --- a/archive-application/src/main/java/site/archive/dto/v2/ArchiveCommunityResponseDto.java +++ b/archive-application/src/main/java/site/archive/dto/v2/ArchiveCommunityResponseDto.java @@ -3,12 +3,11 @@ import lombok.Builder; import lombok.Getter; import lombok.RequiredArgsConstructor; +import site.archive.common.DateTimeUtils; import site.archive.domain.archive.Archive; import site.archive.domain.archive.CoverImageType; import site.archive.domain.archive.Emotion; -import static site.archive.common.DateTimeUtil.YY_MM_DD_FORMATTER; - @RequiredArgsConstructor @Builder @Getter @@ -36,7 +35,7 @@ public static ArchiveCommunityResponseDto from(Archive archive, Long currentUser return ArchiveCommunityResponseDto.builder() .archiveId(archive.getId()) .name(archive.getName()) - .watchedOn(archive.getWatchedOn().format(YY_MM_DD_FORMATTER)) + .watchedOn(archive.getWatchedOn().format(DateTimeUtils.getYymmddFormatter())) .emotion(archive.getEmotion()) .mainImage(archive.getMainImage()) .coverImageType(archive.getCoverImageType()) diff --git a/archive-application/src/main/java/site/archive/dto/v2/ArchiveDtoV2.java b/archive-application/src/main/java/site/archive/dto/v2/ArchiveDtoV2.java index c9dac0d..bbbb159 100644 --- a/archive-application/src/main/java/site/archive/dto/v2/ArchiveDtoV2.java +++ b/archive-application/src/main/java/site/archive/dto/v2/ArchiveDtoV2.java @@ -5,6 +5,7 @@ import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import site.archive.common.DateTimeUtils; import site.archive.domain.archive.Archive; import site.archive.domain.archive.CoverImageType; import site.archive.domain.archive.Emotion; @@ -12,8 +13,6 @@ import java.util.List; -import static site.archive.common.DateTimeUtil.YY_MM_DD_FORMATTER; - @NoArgsConstructor @AllArgsConstructor @Getter @@ -52,7 +51,7 @@ public static ArchiveDtoV2 specificFrom(Archive archive) { return ArchiveDtoV2.builder() .archiveId(archive.getId()) .name(archive.getName()) - .watchedOn(archive.getWatchedOn().format(YY_MM_DD_FORMATTER)) + .watchedOn(archive.getWatchedOn().format(DateTimeUtils.getYymmddFormatter())) .emotion(archive.getEmotion()) .mainImage(archive.getMainImage()) .companions(archive.getCompanions()) diff --git a/archive-application/src/main/java/site/archive/dto/v2/ArchiveLikeResponseDto.java b/archive-application/src/main/java/site/archive/dto/v2/ArchiveLikeResponseDto.java index 79c97ea..0406219 100644 --- a/archive-application/src/main/java/site/archive/dto/v2/ArchiveLikeResponseDto.java +++ b/archive-application/src/main/java/site/archive/dto/v2/ArchiveLikeResponseDto.java @@ -4,12 +4,11 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; import lombok.ToString; +import site.archive.common.DateTimeUtils; import site.archive.domain.archive.Archive; import site.archive.domain.archive.CoverImageType; import site.archive.domain.archive.Emotion; -import static site.archive.common.DateTimeUtil.YY_MM_DD_FORMATTER; - @RequiredArgsConstructor @Builder @Getter @@ -37,7 +36,7 @@ public static ArchiveLikeResponseDto from(Archive archive, Long currentUserIdx) return ArchiveLikeResponseDto.builder() .archiveId(archive.getId()) .name(archive.getName()) - .watchedOn(archive.getWatchedOn().format(YY_MM_DD_FORMATTER)) + .watchedOn(archive.getWatchedOn().format(DateTimeUtils.getYymmddFormatter())) .emotion(archive.getEmotion()) .mainImage(archive.getMainImage()) .coverImageType(archive.getCoverImageType()) diff --git a/archive-application/src/main/java/site/archive/dto/v2/MyArchiveResponseDto.java b/archive-application/src/main/java/site/archive/dto/v2/MyArchiveResponseDto.java index 12381e2..80149e7 100644 --- a/archive-application/src/main/java/site/archive/dto/v2/MyArchiveResponseDto.java +++ b/archive-application/src/main/java/site/archive/dto/v2/MyArchiveResponseDto.java @@ -3,12 +3,11 @@ import lombok.Builder; import lombok.Getter; import lombok.RequiredArgsConstructor; +import site.archive.common.DateTimeUtils; import site.archive.domain.archive.Archive; import site.archive.domain.archive.CoverImageType; import site.archive.domain.archive.Emotion; -import static site.archive.common.DateTimeUtil.YY_MM_DD_FORMATTER; - @RequiredArgsConstructor @Builder @Getter @@ -32,7 +31,7 @@ public static MyArchiveResponseDto from(Archive archive, long dateMilli) { return MyArchiveResponseDto.builder() .archiveId(archive.getId()) .name(archive.getName()) - .watchedOn(archive.getWatchedOn().format(YY_MM_DD_FORMATTER)) + .watchedOn(archive.getWatchedOn().format(DateTimeUtils.getYymmddFormatter())) .emotion(archive.getEmotion()) .mainImage(archive.getMainImage()) .isPublic(archive.getIsPublic()) diff --git a/archive-common/src/main/java/site/archive/common/ArchiveStringUtils.java b/archive-common/src/main/java/site/archive/common/ArchiveStringUtils.java deleted file mode 100644 index 64b5300..0000000 --- a/archive-common/src/main/java/site/archive/common/ArchiveStringUtils.java +++ /dev/null @@ -1,14 +0,0 @@ -package site.archive.common; - -public class ArchiveStringUtils { - - private static final Character MAIL_AT = '@'; - - private ArchiveStringUtils() { - } - - public static String extractIdFromMail(final String mailAddress) { - return mailAddress.substring(0, mailAddress.indexOf(MAIL_AT)); - } - -} diff --git a/archive-common/src/main/java/site/archive/common/ArchiveStringUtils.kt b/archive-common/src/main/java/site/archive/common/ArchiveStringUtils.kt new file mode 100644 index 0000000..b1cd64a --- /dev/null +++ b/archive-common/src/main/java/site/archive/common/ArchiveStringUtils.kt @@ -0,0 +1,9 @@ +@file:JvmName("ArchiveStringUtils") + +package site.archive.common + +private const val MAIL_AT = '@' + +fun extractIdFromMail(mailAddress: String): String { + return mailAddress.substring(0, mailAddress.indexOf(MAIL_AT)) +} \ No newline at end of file diff --git a/archive-common/src/main/java/site/archive/common/DateTimeUtil.java b/archive-common/src/main/java/site/archive/common/DateTimeUtil.java deleted file mode 100644 index 4cd23a9..0000000 --- a/archive-common/src/main/java/site/archive/common/DateTimeUtil.java +++ /dev/null @@ -1,40 +0,0 @@ -package site.archive.common; - -import java.time.Clock; -import java.time.Instant; -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.time.YearMonth; -import java.time.ZoneId; -import java.time.ZonedDateTime; -import java.time.format.DateTimeFormatter; - -public class DateTimeUtil { - - public static final DateTimeFormatter YY_MM_DD_FORMATTER = DateTimeFormatter.ofPattern("yy/MM/dd"); - public static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); - - public static final ZoneId ASIA_SEOUL_ZONE = ZoneId.of("Asia/Seoul"); - - private static Clock clock = Clock.system(ASIA_SEOUL_ZONE); - - private DateTimeUtil() {} - - public static void changeClock(LocalDate date) { - // log.warn("Change clock of DateTimeUtil. It may effect now() methods of DateTimeUtil."); - var dateTime = date.atStartOfDay(); - var zoneOffset = ASIA_SEOUL_ZONE.getRules().getOffset(dateTime); - clock = Clock.fixed(dateTime.atOffset(zoneOffset).toInstant(), zoneOffset); - } - - public static ZonedDateTime fromMilli(long milli) { - return Instant.ofEpochMilli(milli).atZone(ASIA_SEOUL_ZONE); - } - - public static LocalDateTime firstDateTimeOfMonth() { - return YearMonth.now(clock) - .atDay(1) - .atTime(0, 0); - } - -} diff --git a/archive-common/src/main/java/site/archive/common/DateTimeUtils.kt b/archive-common/src/main/java/site/archive/common/DateTimeUtils.kt new file mode 100644 index 0000000..3f230af --- /dev/null +++ b/archive-common/src/main/java/site/archive/common/DateTimeUtils.kt @@ -0,0 +1,34 @@ +@file:JvmName("DateTimeUtils") +package site.archive.common + +import java.time.Clock +import java.time.Instant +import java.time.LocalDate +import java.time.LocalDateTime +import java.time.YearMonth +import java.time.ZoneId +import java.time.ZonedDateTime +import java.time.format.DateTimeFormatter + +const val ASIA_SEOUL_ZONE_ID = "Asia/Seoul" +val yymmddFormatter: DateTimeFormatter = DateTimeFormatter.ofPattern("yy/MM/dd") +val dateTimeFormatter: DateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss") +val asiaSeoulZone: ZoneId = ZoneId.of(ASIA_SEOUL_ZONE_ID) + +var clock: Clock = Clock.system(asiaSeoulZone) + +fun changeClock(date: LocalDate) { + val dateTime = date.atStartOfDay() + val zoneOffset = asiaSeoulZone.rules.getOffset(dateTime) + clock = Clock.fixed(dateTime.atOffset(zoneOffset).toInstant(), zoneOffset) +} + +fun fromMilli(milli: Long): ZonedDateTime { + return Instant.ofEpochMilli(milli).atZone(asiaSeoulZone) +} + +fun firstDateTimeOfMonth(): LocalDateTime { + return YearMonth.now(clock) + .atDay(1) + .atTime(0, 0) +} \ No newline at end of file diff --git a/archive-common/src/main/java/site/archive/common/FileUtils.java b/archive-common/src/main/java/site/archive/common/FileUtils.java deleted file mode 100644 index fe23011..0000000 --- a/archive-common/src/main/java/site/archive/common/FileUtils.java +++ /dev/null @@ -1,30 +0,0 @@ -package site.archive.common; - -import org.springframework.web.multipart.MultipartFile; - -import java.util.Arrays; - -import static org.springframework.http.MediaType.IMAGE_GIF_VALUE; -import static org.springframework.http.MediaType.IMAGE_JPEG_VALUE; -import static org.springframework.http.MediaType.IMAGE_PNG_VALUE; - -public class FileUtils { - - private static final String HTTP = "http://"; - private static final String HTTPS = "https://"; - - private FileUtils() { - } - - public static void verifyImageFile(final MultipartFile imageFile) { - if (!Arrays.asList(IMAGE_PNG_VALUE, IMAGE_GIF_VALUE, IMAGE_JPEG_VALUE) - .contains(imageFile.getContentType())) { - throw new IllegalStateException("FIle uploaded is not an image"); - } - } - - public static boolean isFileUrl(final String file) { - return file != null && (file.startsWith(HTTP) || file.startsWith(HTTPS)); - } - -} diff --git a/archive-common/src/main/java/site/archive/common/FileUtils.kt b/archive-common/src/main/java/site/archive/common/FileUtils.kt new file mode 100644 index 0000000..ba14e92 --- /dev/null +++ b/archive-common/src/main/java/site/archive/common/FileUtils.kt @@ -0,0 +1,22 @@ +@file:JvmName("FileUtils") + +package site.archive.common + +import org.springframework.http.MediaType.IMAGE_GIF_VALUE +import org.springframework.http.MediaType.IMAGE_JPEG_VALUE +import org.springframework.http.MediaType.IMAGE_PNG_VALUE +import org.springframework.web.multipart.MultipartFile + +private const val HTTP = "http://" +private const val HTTPS = "https://" + +fun verifyImageFile(imageFile: MultipartFile) { + if (!listOf(IMAGE_PNG_VALUE, IMAGE_GIF_VALUE, IMAGE_JPEG_VALUE) + .contains(imageFile.contentType)) { + throw IllegalStateException("FIle uploaded is not an image") + } +} + +fun isFileUrl(file: String?) : Boolean{ + return file != null && (file.startsWith(HTTP) || file.startsWith(HTTPS)) +} \ No newline at end of file diff --git a/archive-common/src/test/java/site/archive/common/DateTimeUtilTest.java b/archive-common/src/test/java/site/archive/common/DateTimeUtilTest.java index 9f3eeff..591a51d 100644 --- a/archive-common/src/test/java/site/archive/common/DateTimeUtilTest.java +++ b/archive-common/src/test/java/site/archive/common/DateTimeUtilTest.java @@ -16,25 +16,25 @@ class DateTimeUtilTest { @Test void YY_MM_DD_formatterTest() { - var convertedDate = dummyDate.format(DateTimeUtil.YY_MM_DD_FORMATTER); + var convertedDate = dummyDate.format(DateTimeUtils.getYymmddFormatter()); assertThat(convertedDate).isEqualTo("95/09/25"); } @Test void DATE_TIME_formatterTest() { - var convertedDateTime = dummyDateTime.format(DateTimeUtil.DATE_TIME_FORMATTER); + var convertedDateTime = dummyDateTime.format(DateTimeUtils.getDateTimeFormatter()); assertThat(convertedDateTime).isEqualTo("1995-09-25 11:11:11"); } @Test void dateOfMonthTest() { - DateTimeUtil.changeClock(LocalDate.of(2022, 7, 2)); - var julFirstDate = DateTimeUtil.firstDateTimeOfMonth(); + DateTimeUtils.changeClock(LocalDate.of(2022, 7, 2)); + var julFirstDate = DateTimeUtils.firstDateTimeOfMonth(); assertThat(julFirstDate).isEqualTo(LocalDateTime.of(2022, 7, 1, 0, 0)); var augFirstDate = julFirstDate.plusMonths(1); - DateTimeUtil.changeClock(LocalDate.of(2022, 8, 22)); - assertThat(augFirstDate).isEqualTo(DateTimeUtil.firstDateTimeOfMonth()); + DateTimeUtils.changeClock(LocalDate.of(2022, 8, 22)); + assertThat(augFirstDate).isEqualTo(DateTimeUtils.firstDateTimeOfMonth()); } } \ No newline at end of file diff --git a/archive-domain/src/main/java/site/archive/domain/archive/custom/ArchiveCommunityTimeSortType.java b/archive-domain/src/main/java/site/archive/domain/archive/custom/ArchiveCommunityTimeSortType.java index 085541b..7b085a9 100644 --- a/archive-domain/src/main/java/site/archive/domain/archive/custom/ArchiveCommunityTimeSortType.java +++ b/archive-domain/src/main/java/site/archive/domain/archive/custom/ArchiveCommunityTimeSortType.java @@ -3,7 +3,7 @@ import com.querydsl.core.types.OrderSpecifier; import com.querydsl.core.types.dsl.BooleanExpression; import lombok.Getter; -import site.archive.common.DateTimeUtil; +import site.archive.common.DateTimeUtils; import site.archive.domain.archive.Archive; import site.archive.domain.archive.QArchive; @@ -17,13 +17,13 @@ public enum ArchiveCommunityTimeSortType { CREATED_AT("createdAt") { @Override public BooleanExpression getLtWhere(QArchive archive, final long milli) { - var lastCreatedAtOfPage = DateTimeUtil.fromMilli(milli).toLocalDateTime(); + var lastCreatedAtOfPage = DateTimeUtils.fromMilli(milli).toLocalDateTime(); return archive.createdAt.lt(lastCreatedAtOfPage); } @Override public BooleanExpression getEqWhere(QArchive archive, long milli) { - var lastCreatedAtOfPage = DateTimeUtil.fromMilli(milli).toLocalDateTime(); + var lastCreatedAtOfPage = DateTimeUtils.fromMilli(milli).toLocalDateTime(); return archive.createdAt.eq(lastCreatedAtOfPage); } @@ -34,19 +34,19 @@ public OrderSpecifier getOrderBy(QArchive archive) { @Override public long convertToMillis(Archive archive) { - return archive.getCreatedAt().atZone(DateTimeUtil.ASIA_SEOUL_ZONE).toInstant().toEpochMilli(); + return archive.getCreatedAt().atZone(DateTimeUtils.getAsiaSeoulZone()).toInstant().toEpochMilli(); } }, WATCHED_ON("watchedOn") { @Override public BooleanExpression getLtWhere(QArchive archive, final long milli) { - var lastWatchedOnOfPage = DateTimeUtil.fromMilli(milli).toLocalDate(); + var lastWatchedOnOfPage = DateTimeUtils.fromMilli(milli).toLocalDate(); return archive.watchedOn.lt(lastWatchedOnOfPage); } @Override public BooleanExpression getEqWhere(QArchive archive, long milli) { - var lastWatchedOnOfPage = DateTimeUtil.fromMilli(milli).toLocalDate(); + var lastWatchedOnOfPage = DateTimeUtils.fromMilli(milli).toLocalDate(); return archive.watchedOn.eq(lastWatchedOnOfPage); } @@ -57,7 +57,7 @@ public OrderSpecifier getOrderBy(QArchive archive) { @Override public long convertToMillis(Archive archive) { - return archive.getWatchedOn().atStartOfDay(DateTimeUtil.ASIA_SEOUL_ZONE).toInstant().toEpochMilli(); + return archive.getWatchedOn().atStartOfDay(DateTimeUtils.getAsiaSeoulZone()).toInstant().toEpochMilli(); } }; diff --git a/archive-domain/src/main/java/site/archive/domain/archive/custom/ArchiveCustomRepositoryImpl.java b/archive-domain/src/main/java/site/archive/domain/archive/custom/ArchiveCustomRepositoryImpl.java index b0721c7..53ee1ae 100644 --- a/archive-domain/src/main/java/site/archive/domain/archive/custom/ArchiveCustomRepositoryImpl.java +++ b/archive-domain/src/main/java/site/archive/domain/archive/custom/ArchiveCustomRepositoryImpl.java @@ -6,7 +6,7 @@ import lombok.RequiredArgsConstructor; import org.springframework.cache.annotation.Cacheable; import org.springframework.stereotype.Repository; -import site.archive.common.DateTimeUtil; +import site.archive.common.DateTimeUtils; import site.archive.common.cache.CacheType; import site.archive.domain.archive.Archive; import site.archive.domain.archive.Emotion; @@ -77,7 +77,7 @@ public List findByIdInWithLike(List archiveIds, ArchivePageable p @Override public long countArchiveOfCurrentMonthByAuthorId(Long authorId) { - var firstDateOfCurrentMonth = DateTimeUtil.firstDateTimeOfMonth(); + var firstDateOfCurrentMonth = DateTimeUtils.firstDateTimeOfMonth(); var firstDateOfNextMonth = firstDateOfCurrentMonth.plusMonths(1); var currentMonthWhere = QArchive.archive.createdAt.goe(firstDateOfCurrentMonth) .and(QArchive.archive.createdAt.lt(firstDateOfNextMonth)); diff --git a/archive-domain/src/test/java/site/archive/domain/archive/ArchiveRepositoryTest.java b/archive-domain/src/test/java/site/archive/domain/archive/ArchiveRepositoryTest.java index a1b3ea2..040607a 100644 --- a/archive-domain/src/test/java/site/archive/domain/archive/ArchiveRepositoryTest.java +++ b/archive-domain/src/test/java/site/archive/domain/archive/ArchiveRepositoryTest.java @@ -4,7 +4,7 @@ import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import site.archive.common.DateTimeUtil; +import site.archive.common.DateTimeUtils; import site.archive.domain.JpaTestSupport; import java.time.LocalDate; @@ -26,7 +26,7 @@ void currentMonthCountOfArchiveTest() { var eightAuthorId = 8L; // and - set current month to 2022.08 - DateTimeUtil.changeClock(LocalDate.of(2022, 8, 11)); + DateTimeUtils.changeClock(LocalDate.of(2022, 8, 11)); // when var oneAuthorArchiveCount = archiveRepository.countArchiveOfCurrentMonthByAuthorId(oneAuthorId); From e03631dc9f14dc51f66fb80a5ccc666ccddefd9e Mon Sep 17 00:00:00 2001 From: KimDoubleB Date: Wed, 18 Jan 2023 01:02:33 +0900 Subject: [PATCH 22/46] feat(#53): converted common Exception classes java to kotlin --- .../archive/infra/messaging/SlackService.java | 2 +- .../common/exception/BaseException.java | 29 ---------------- .../archive/common/exception/BaseException.kt | 23 +++++++++++++ .../{ExceptionCode.java => ExceptionCode.kt} | 33 ++++--------------- .../common/DuplicateFieldValueException.java | 15 --------- .../common/DuplicateFieldValueException.kt | 10 ++++++ .../common/DuplicateResourceException.java | 12 ------- .../common/DuplicateResourceException.kt | 6 ++++ .../common/ResourceNotFoundException.java | 17 ---------- .../common/ResourceNotFoundException.kt | 6 ++++ .../common/UnauthorizedResourceException.java | 17 ---------- .../common/UnauthorizedResourceException.kt | 6 ++++ .../exception/infra/FileInvalidException.java | 12 ------- .../exception/infra/FileInvalidException.kt | 6 ++++ .../exception/infra/SlackException.java | 9 ----- .../common/exception/infra/SlackException.kt | 6 ++++ .../security/InvalidTokenException.java | 12 ------- .../security/InvalidTokenException.kt | 6 ++++ .../security/TokenNotFoundException.java | 11 ------- .../security/TokenNotFoundException.kt | 6 ++++ .../exception/user/LoginFailException.java | 12 ------- .../exception/user/LoginFailException.kt | 6 ++++ .../user/OAuthRegisterFailException.java | 13 -------- .../user/OAuthRegisterFailException.kt | 7 ++++ .../OAuthUserHasNotPasswordException.java | 12 ------- .../user/OAuthUserHasNotPasswordException.kt | 7 ++++ .../api/exception/GlobalExceptionHandler.java | 2 +- 27 files changed, 104 insertions(+), 199 deletions(-) delete mode 100644 archive-common/src/main/java/site/archive/common/exception/BaseException.java create mode 100644 archive-common/src/main/java/site/archive/common/exception/BaseException.kt rename archive-common/src/main/java/site/archive/common/exception/{ExceptionCode.java => ExceptionCode.kt} (75%) delete mode 100644 archive-common/src/main/java/site/archive/common/exception/common/DuplicateFieldValueException.java create mode 100644 archive-common/src/main/java/site/archive/common/exception/common/DuplicateFieldValueException.kt delete mode 100644 archive-common/src/main/java/site/archive/common/exception/common/DuplicateResourceException.java create mode 100644 archive-common/src/main/java/site/archive/common/exception/common/DuplicateResourceException.kt delete mode 100644 archive-common/src/main/java/site/archive/common/exception/common/ResourceNotFoundException.java create mode 100644 archive-common/src/main/java/site/archive/common/exception/common/ResourceNotFoundException.kt delete mode 100644 archive-common/src/main/java/site/archive/common/exception/common/UnauthorizedResourceException.java create mode 100644 archive-common/src/main/java/site/archive/common/exception/common/UnauthorizedResourceException.kt delete mode 100644 archive-common/src/main/java/site/archive/common/exception/infra/FileInvalidException.java create mode 100644 archive-common/src/main/java/site/archive/common/exception/infra/FileInvalidException.kt delete mode 100644 archive-common/src/main/java/site/archive/common/exception/infra/SlackException.java create mode 100644 archive-common/src/main/java/site/archive/common/exception/infra/SlackException.kt delete mode 100644 archive-common/src/main/java/site/archive/common/exception/security/InvalidTokenException.java create mode 100644 archive-common/src/main/java/site/archive/common/exception/security/InvalidTokenException.kt delete mode 100644 archive-common/src/main/java/site/archive/common/exception/security/TokenNotFoundException.java create mode 100644 archive-common/src/main/java/site/archive/common/exception/security/TokenNotFoundException.kt delete mode 100644 archive-common/src/main/java/site/archive/common/exception/user/LoginFailException.java create mode 100644 archive-common/src/main/java/site/archive/common/exception/user/LoginFailException.kt delete mode 100644 archive-common/src/main/java/site/archive/common/exception/user/OAuthRegisterFailException.java create mode 100644 archive-common/src/main/java/site/archive/common/exception/user/OAuthRegisterFailException.kt delete mode 100644 archive-common/src/main/java/site/archive/common/exception/user/OAuthUserHasNotPasswordException.java create mode 100644 archive-common/src/main/java/site/archive/common/exception/user/OAuthUserHasNotPasswordException.kt diff --git a/archive-application/src/main/java/site/archive/infra/messaging/SlackService.java b/archive-application/src/main/java/site/archive/infra/messaging/SlackService.java index 1432091..62ac123 100644 --- a/archive-application/src/main/java/site/archive/infra/messaging/SlackService.java +++ b/archive-application/src/main/java/site/archive/infra/messaging/SlackService.java @@ -60,7 +60,7 @@ public void sendUserRegisterMessage(final BaseUserDtoV1 baseUser, final String r baseUser.getCreatedAt())))) ))); } catch (IOException | SlackApiException e) { - throw new SlackException(e.getMessage()); + throw new SlackException(); } } diff --git a/archive-common/src/main/java/site/archive/common/exception/BaseException.java b/archive-common/src/main/java/site/archive/common/exception/BaseException.java deleted file mode 100644 index 2ced88b..0000000 --- a/archive-common/src/main/java/site/archive/common/exception/BaseException.java +++ /dev/null @@ -1,29 +0,0 @@ -package site.archive.common.exception; - -import java.util.Optional; - -public class BaseException extends RuntimeException { - - private final ExceptionCode exceptionCode; - private String additionalMessage; - - public BaseException(ExceptionCode exceptionCode) { - super(exceptionCode.getMessage()); - this.exceptionCode = exceptionCode; - } - - public BaseException(String additionalMessage, ExceptionCode exceptionCode) { - super(String.format("%s : %s", exceptionCode.getMessage(), additionalMessage)); - this.exceptionCode = exceptionCode; - this.additionalMessage = additionalMessage; - } - - public ExceptionCode getErrorCode() { - return exceptionCode; - } - - public Optional getAdditionalMessage() { - return Optional.ofNullable(additionalMessage); - } - -} diff --git a/archive-common/src/main/java/site/archive/common/exception/BaseException.kt b/archive-common/src/main/java/site/archive/common/exception/BaseException.kt new file mode 100644 index 0000000..1b545df --- /dev/null +++ b/archive-common/src/main/java/site/archive/common/exception/BaseException.kt @@ -0,0 +1,23 @@ +package site.archive.common.exception + +import java.util.Optional + +open class BaseException : RuntimeException { + + val exceptionCode: ExceptionCode + private var additionalMessage: String? = null + + constructor(exceptionCode: ExceptionCode) : super(exceptionCode.message) { + this.exceptionCode = exceptionCode + } + + constructor(additionalMessage: String?, exceptionCode: ExceptionCode) : super("${exceptionCode.message} : $additionalMessage") { + this.exceptionCode = exceptionCode + this.additionalMessage = additionalMessage + } + + fun getAdditionalMessage(): Optional { + return Optional.ofNullable(additionalMessage) + } + +} \ No newline at end of file diff --git a/archive-common/src/main/java/site/archive/common/exception/ExceptionCode.java b/archive-common/src/main/java/site/archive/common/exception/ExceptionCode.kt similarity index 75% rename from archive-common/src/main/java/site/archive/common/exception/ExceptionCode.java rename to archive-common/src/main/java/site/archive/common/exception/ExceptionCode.kt index a129a5c..d140464 100644 --- a/archive-common/src/main/java/site/archive/common/exception/ExceptionCode.java +++ b/archive-common/src/main/java/site/archive/common/exception/ExceptionCode.kt @@ -1,10 +1,12 @@ -package site.archive.common.exception; +package site.archive.common.exception -import com.fasterxml.jackson.annotation.JsonFormat; -import org.springframework.http.HttpStatus; +import com.fasterxml.jackson.annotation.JsonFormat +import org.springframework.http.HttpStatus @JsonFormat(shape = JsonFormat.Shape.OBJECT) -public enum ExceptionCode { +enum class ExceptionCode(val status: HttpStatus, + val code: String, + val message: String) { // Global NO_VALUE(HttpStatus.BAD_REQUEST, "Global001", "필요한 값이 없거나 전달된 값에 문제가 있습니다."), @@ -16,6 +18,7 @@ public enum ExceptionCode { // Infra FAILED_FILE_UPLOAD(HttpStatus.INTERNAL_SERVER_ERROR, "Infra001", "(File IO) Failed to stream of upload file"), + SLACK_MESSAGE_FAILED(HttpStatus.INTERNAL_SERVER_ERROR, "Infra002", "Sending slack message failed"), // Common DUPLICATED_RESOURCE(HttpStatus.CONFLICT, "Common001", "이미 존재하는 리소스 입니다"), @@ -34,26 +37,4 @@ public enum ExceptionCode { AUTHENTICATION_FAILURE(HttpStatus.UNAUTHORIZED, "Security003", "인증에 실패하였습니다"), ; - private final HttpStatus status; - private final String code; - private final String message; - - ExceptionCode(final HttpStatus status, final String code, final String message) { - this.status = status; - this.message = message; - this.code = code; - } - - public String getMessage() { - return this.message; - } - - public String getCode() { - return code; - } - - public HttpStatus getStatus() { - return status; - } - } \ No newline at end of file diff --git a/archive-common/src/main/java/site/archive/common/exception/common/DuplicateFieldValueException.java b/archive-common/src/main/java/site/archive/common/exception/common/DuplicateFieldValueException.java deleted file mode 100644 index 85140d3..0000000 --- a/archive-common/src/main/java/site/archive/common/exception/common/DuplicateFieldValueException.java +++ /dev/null @@ -1,15 +0,0 @@ -package site.archive.common.exception.common; - -import site.archive.common.exception.BaseException; -import site.archive.common.exception.ExceptionCode; - -public class DuplicateFieldValueException extends BaseException { - - private static final String DUPLICATED_FILED_MESSAGE = "'%s'은 중복된 %s 입니다. 다른 %s을 사용해주세요."; - - public DuplicateFieldValueException(String duplicatedField, String duplicatedValue) { - super(DUPLICATED_FILED_MESSAGE.formatted(duplicatedValue, duplicatedField, duplicatedField), - ExceptionCode.DUPLICATED_FIELD_VALUE); - } - -} diff --git a/archive-common/src/main/java/site/archive/common/exception/common/DuplicateFieldValueException.kt b/archive-common/src/main/java/site/archive/common/exception/common/DuplicateFieldValueException.kt new file mode 100644 index 0000000..d9533b4 --- /dev/null +++ b/archive-common/src/main/java/site/archive/common/exception/common/DuplicateFieldValueException.kt @@ -0,0 +1,10 @@ +package site.archive.common.exception.common + +import site.archive.common.exception.BaseException +import site.archive.common.exception.ExceptionCode + +class DuplicateFieldValueException(duplicatedField: String, duplicatedValue: String) : + BaseException( + "'$duplicatedValue'은 중복된 $duplicatedField 입니다. 다른 $duplicatedField 을 사용해주세요", + ExceptionCode.DUPLICATED_FIELD_VALUE + ) \ No newline at end of file diff --git a/archive-common/src/main/java/site/archive/common/exception/common/DuplicateResourceException.java b/archive-common/src/main/java/site/archive/common/exception/common/DuplicateResourceException.java deleted file mode 100644 index 568a6fd..0000000 --- a/archive-common/src/main/java/site/archive/common/exception/common/DuplicateResourceException.java +++ /dev/null @@ -1,12 +0,0 @@ -package site.archive.common.exception.common; - -import site.archive.common.exception.BaseException; -import site.archive.common.exception.ExceptionCode; - -public class DuplicateResourceException extends BaseException { - - public DuplicateResourceException(String duplicatedResource) { - super(duplicatedResource, ExceptionCode.DUPLICATED_RESOURCE); - } - -} diff --git a/archive-common/src/main/java/site/archive/common/exception/common/DuplicateResourceException.kt b/archive-common/src/main/java/site/archive/common/exception/common/DuplicateResourceException.kt new file mode 100644 index 0000000..0c135a7 --- /dev/null +++ b/archive-common/src/main/java/site/archive/common/exception/common/DuplicateResourceException.kt @@ -0,0 +1,6 @@ +package site.archive.common.exception.common + +import site.archive.common.exception.BaseException +import site.archive.common.exception.ExceptionCode + +class DuplicateResourceException(duplicatedResource: String) : BaseException(duplicatedResource, ExceptionCode.DUPLICATED_RESOURCE) diff --git a/archive-common/src/main/java/site/archive/common/exception/common/ResourceNotFoundException.java b/archive-common/src/main/java/site/archive/common/exception/common/ResourceNotFoundException.java deleted file mode 100644 index 8f9e805..0000000 --- a/archive-common/src/main/java/site/archive/common/exception/common/ResourceNotFoundException.java +++ /dev/null @@ -1,17 +0,0 @@ -package site.archive.common.exception.common; - -import site.archive.common.exception.BaseException; -import site.archive.common.exception.ExceptionCode; - -public class ResourceNotFoundException extends BaseException { - - public ResourceNotFoundException(String notFoundMessage) { - super(notFoundMessage, ExceptionCode.NOT_FOUND_RESOURCE); - } - - public ResourceNotFoundException(String notFoundMessage, String notFoundResource) { - super(String.format("%s[%s]", notFoundMessage, notFoundResource), - ExceptionCode.NOT_FOUND_RESOURCE); - } - -} diff --git a/archive-common/src/main/java/site/archive/common/exception/common/ResourceNotFoundException.kt b/archive-common/src/main/java/site/archive/common/exception/common/ResourceNotFoundException.kt new file mode 100644 index 0000000..f265ee7 --- /dev/null +++ b/archive-common/src/main/java/site/archive/common/exception/common/ResourceNotFoundException.kt @@ -0,0 +1,6 @@ +package site.archive.common.exception.common + +import site.archive.common.exception.BaseException +import site.archive.common.exception.ExceptionCode + +class ResourceNotFoundException(notFoundMessage: String) : BaseException(notFoundMessage, ExceptionCode.NOT_FOUND_RESOURCE) diff --git a/archive-common/src/main/java/site/archive/common/exception/common/UnauthorizedResourceException.java b/archive-common/src/main/java/site/archive/common/exception/common/UnauthorizedResourceException.java deleted file mode 100644 index 69bbf00..0000000 --- a/archive-common/src/main/java/site/archive/common/exception/common/UnauthorizedResourceException.java +++ /dev/null @@ -1,17 +0,0 @@ -package site.archive.common.exception.common; - -import site.archive.common.exception.BaseException; -import site.archive.common.exception.ExceptionCode; - -public class UnauthorizedResourceException extends BaseException { - - public UnauthorizedResourceException(String message) { - super(message, ExceptionCode.UNAUTHORIZED_RESOURCE); - } - - public UnauthorizedResourceException(String message, String resource) { - super(String.format("%s[%s]", message, resource), - ExceptionCode.UNAUTHORIZED_RESOURCE); - } - -} diff --git a/archive-common/src/main/java/site/archive/common/exception/common/UnauthorizedResourceException.kt b/archive-common/src/main/java/site/archive/common/exception/common/UnauthorizedResourceException.kt new file mode 100644 index 0000000..469594d --- /dev/null +++ b/archive-common/src/main/java/site/archive/common/exception/common/UnauthorizedResourceException.kt @@ -0,0 +1,6 @@ +package site.archive.common.exception.common + +import site.archive.common.exception.BaseException +import site.archive.common.exception.ExceptionCode + +class UnauthorizedResourceException(message: String) : BaseException(message, ExceptionCode.UNAUTHORIZED_RESOURCE) diff --git a/archive-common/src/main/java/site/archive/common/exception/infra/FileInvalidException.java b/archive-common/src/main/java/site/archive/common/exception/infra/FileInvalidException.java deleted file mode 100644 index e45a292..0000000 --- a/archive-common/src/main/java/site/archive/common/exception/infra/FileInvalidException.java +++ /dev/null @@ -1,12 +0,0 @@ -package site.archive.common.exception.infra; - -import site.archive.common.exception.BaseException; -import site.archive.common.exception.ExceptionCode; - -public class FileInvalidException extends BaseException { - - public FileInvalidException() { - super(ExceptionCode.FAILED_FILE_UPLOAD); - } - -} diff --git a/archive-common/src/main/java/site/archive/common/exception/infra/FileInvalidException.kt b/archive-common/src/main/java/site/archive/common/exception/infra/FileInvalidException.kt new file mode 100644 index 0000000..8bf19ad --- /dev/null +++ b/archive-common/src/main/java/site/archive/common/exception/infra/FileInvalidException.kt @@ -0,0 +1,6 @@ +package site.archive.common.exception.infra + +import site.archive.common.exception.BaseException +import site.archive.common.exception.ExceptionCode + +class FileInvalidException : BaseException(ExceptionCode.FAILED_FILE_UPLOAD) diff --git a/archive-common/src/main/java/site/archive/common/exception/infra/SlackException.java b/archive-common/src/main/java/site/archive/common/exception/infra/SlackException.java deleted file mode 100644 index 745c9ab..0000000 --- a/archive-common/src/main/java/site/archive/common/exception/infra/SlackException.java +++ /dev/null @@ -1,9 +0,0 @@ -package site.archive.common.exception.infra; - -public class SlackException extends RuntimeException { - - public SlackException(String message) { - super(message); - } - -} diff --git a/archive-common/src/main/java/site/archive/common/exception/infra/SlackException.kt b/archive-common/src/main/java/site/archive/common/exception/infra/SlackException.kt new file mode 100644 index 0000000..af44262 --- /dev/null +++ b/archive-common/src/main/java/site/archive/common/exception/infra/SlackException.kt @@ -0,0 +1,6 @@ +package site.archive.common.exception.infra + +import site.archive.common.exception.BaseException +import site.archive.common.exception.ExceptionCode + +class SlackException : BaseException(ExceptionCode.SLACK_MESSAGE_FAILED) diff --git a/archive-common/src/main/java/site/archive/common/exception/security/InvalidTokenException.java b/archive-common/src/main/java/site/archive/common/exception/security/InvalidTokenException.java deleted file mode 100644 index 3380d14..0000000 --- a/archive-common/src/main/java/site/archive/common/exception/security/InvalidTokenException.java +++ /dev/null @@ -1,12 +0,0 @@ -package site.archive.common.exception.security; - -import site.archive.common.exception.BaseException; -import site.archive.common.exception.ExceptionCode; - -public class InvalidTokenException extends BaseException { - - public InvalidTokenException() { - super(ExceptionCode.INVALID_TOKEN); - } - -} diff --git a/archive-common/src/main/java/site/archive/common/exception/security/InvalidTokenException.kt b/archive-common/src/main/java/site/archive/common/exception/security/InvalidTokenException.kt new file mode 100644 index 0000000..daa7150 --- /dev/null +++ b/archive-common/src/main/java/site/archive/common/exception/security/InvalidTokenException.kt @@ -0,0 +1,6 @@ +package site.archive.common.exception.security + +import site.archive.common.exception.BaseException +import site.archive.common.exception.ExceptionCode + +class InvalidTokenException : BaseException(ExceptionCode.INVALID_TOKEN) \ No newline at end of file diff --git a/archive-common/src/main/java/site/archive/common/exception/security/TokenNotFoundException.java b/archive-common/src/main/java/site/archive/common/exception/security/TokenNotFoundException.java deleted file mode 100644 index fb37010..0000000 --- a/archive-common/src/main/java/site/archive/common/exception/security/TokenNotFoundException.java +++ /dev/null @@ -1,11 +0,0 @@ -package site.archive.common.exception.security; - -import site.archive.common.exception.ExceptionCode; - -public class TokenNotFoundException extends RuntimeException { - - public TokenNotFoundException() { - super(ExceptionCode.TOKEN_NOT_FOUND.getMessage()); - } - -} diff --git a/archive-common/src/main/java/site/archive/common/exception/security/TokenNotFoundException.kt b/archive-common/src/main/java/site/archive/common/exception/security/TokenNotFoundException.kt new file mode 100644 index 0000000..a268e2e --- /dev/null +++ b/archive-common/src/main/java/site/archive/common/exception/security/TokenNotFoundException.kt @@ -0,0 +1,6 @@ +package site.archive.common.exception.security + +import site.archive.common.exception.BaseException +import site.archive.common.exception.ExceptionCode + +class TokenNotFoundException : BaseException(ExceptionCode.TOKEN_NOT_FOUND) diff --git a/archive-common/src/main/java/site/archive/common/exception/user/LoginFailException.java b/archive-common/src/main/java/site/archive/common/exception/user/LoginFailException.java deleted file mode 100644 index bf3384c..0000000 --- a/archive-common/src/main/java/site/archive/common/exception/user/LoginFailException.java +++ /dev/null @@ -1,12 +0,0 @@ -package site.archive.common.exception.user; - -import site.archive.common.exception.BaseException; -import site.archive.common.exception.ExceptionCode; - -public class LoginFailException extends BaseException { - - public LoginFailException(String message) { - super(message, ExceptionCode.LOGIN_FAIL); - } - -} diff --git a/archive-common/src/main/java/site/archive/common/exception/user/LoginFailException.kt b/archive-common/src/main/java/site/archive/common/exception/user/LoginFailException.kt new file mode 100644 index 0000000..f863b19 --- /dev/null +++ b/archive-common/src/main/java/site/archive/common/exception/user/LoginFailException.kt @@ -0,0 +1,6 @@ +package site.archive.common.exception.user + +import site.archive.common.exception.BaseException +import site.archive.common.exception.ExceptionCode + +class LoginFailException(message: String) : BaseException(message, ExceptionCode.LOGIN_FAIL) diff --git a/archive-common/src/main/java/site/archive/common/exception/user/OAuthRegisterFailException.java b/archive-common/src/main/java/site/archive/common/exception/user/OAuthRegisterFailException.java deleted file mode 100644 index bac05b5..0000000 --- a/archive-common/src/main/java/site/archive/common/exception/user/OAuthRegisterFailException.java +++ /dev/null @@ -1,13 +0,0 @@ -package site.archive.common.exception.user; - -import site.archive.common.exception.BaseException; -import site.archive.common.exception.ExceptionCode; - -public class OAuthRegisterFailException extends BaseException { - - public OAuthRegisterFailException(String oAuthProviderRegistrationId, String message) { - super(String.format("%s : %s", oAuthProviderRegistrationId, message), - ExceptionCode.REGISTER_FAIL); - } - -} diff --git a/archive-common/src/main/java/site/archive/common/exception/user/OAuthRegisterFailException.kt b/archive-common/src/main/java/site/archive/common/exception/user/OAuthRegisterFailException.kt new file mode 100644 index 0000000..e4bfb3f --- /dev/null +++ b/archive-common/src/main/java/site/archive/common/exception/user/OAuthRegisterFailException.kt @@ -0,0 +1,7 @@ +package site.archive.common.exception.user + +import site.archive.common.exception.BaseException +import site.archive.common.exception.ExceptionCode + +class OAuthRegisterFailException(oAuthProviderRegistrationId: String, message: String) : + BaseException("$oAuthProviderRegistrationId : $message", ExceptionCode.REGISTER_FAIL) diff --git a/archive-common/src/main/java/site/archive/common/exception/user/OAuthUserHasNotPasswordException.java b/archive-common/src/main/java/site/archive/common/exception/user/OAuthUserHasNotPasswordException.java deleted file mode 100644 index 6f76324..0000000 --- a/archive-common/src/main/java/site/archive/common/exception/user/OAuthUserHasNotPasswordException.java +++ /dev/null @@ -1,12 +0,0 @@ -package site.archive.common.exception.user; - -import site.archive.common.exception.BaseException; -import site.archive.common.exception.ExceptionCode; - -public class OAuthUserHasNotPasswordException extends BaseException { - - public OAuthUserHasNotPasswordException() { - super(ExceptionCode.OAUTH_USER_NOT_HAS_PASSWORD); - } - -} diff --git a/archive-common/src/main/java/site/archive/common/exception/user/OAuthUserHasNotPasswordException.kt b/archive-common/src/main/java/site/archive/common/exception/user/OAuthUserHasNotPasswordException.kt new file mode 100644 index 0000000..81d7386 --- /dev/null +++ b/archive-common/src/main/java/site/archive/common/exception/user/OAuthUserHasNotPasswordException.kt @@ -0,0 +1,7 @@ +package site.archive.common.exception.user + +import site.archive.common.exception.BaseException +import site.archive.common.exception.ExceptionCode + +class OAuthUserHasNotPasswordException : BaseException(ExceptionCode.OAUTH_USER_NOT_HAS_PASSWORD) { +} \ No newline at end of file diff --git a/archive-web/src/main/java/site/archive/web/api/exception/GlobalExceptionHandler.java b/archive-web/src/main/java/site/archive/web/api/exception/GlobalExceptionHandler.java index e27366d..c385b53 100644 --- a/archive-web/src/main/java/site/archive/web/api/exception/GlobalExceptionHandler.java +++ b/archive-web/src/main/java/site/archive/web/api/exception/GlobalExceptionHandler.java @@ -95,7 +95,7 @@ protected ResponseEntity handleAuthenticationException(Authen @ExceptionHandler(BaseException.class) protected ResponseEntity handleBaseException(final BaseException e) { log.error("BaseException ", e); - final var errorCode = e.getErrorCode(); + final var errorCode = e.getExceptionCode(); final var response = e.getAdditionalMessage() .map(additionalMessage -> ExceptionResponse.of(errorCode, additionalMessage)) .orElse(ExceptionResponse.of(errorCode)); From 11ebfb9ae946cdad073cf3b9ae045d4d6f24a7fe Mon Sep 17 00:00:00 2001 From: KimDoubleB Date: Wed, 18 Jan 2023 01:24:53 +0900 Subject: [PATCH 23/46] feat(#53): converted common CacheType classes java to kotlin --- .../site/archive/common/cache/CacheType.java | 35 ------------------- .../site/archive/common/cache/CacheType.kt | 21 +++++++++++ .../archive/web/config/cache/CacheConfig.java | 2 +- 3 files changed, 22 insertions(+), 36 deletions(-) delete mode 100644 archive-common/src/main/java/site/archive/common/cache/CacheType.java create mode 100644 archive-common/src/main/java/site/archive/common/cache/CacheType.kt diff --git a/archive-common/src/main/java/site/archive/common/cache/CacheType.java b/archive-common/src/main/java/site/archive/common/cache/CacheType.java deleted file mode 100644 index 97168cf..0000000 --- a/archive-common/src/main/java/site/archive/common/cache/CacheType.java +++ /dev/null @@ -1,35 +0,0 @@ -package site.archive.common.cache; - -import lombok.Getter; - -@Getter -public enum CacheType { - - BANNERS(CacheInfo.BANNERS, CacheInfo.BANNERS_GET, 1), - ARCHIVE_COMMUNITIES(CacheInfo.ARCHIVE_COMMUNITIES, CacheInfo.ARCHIVE_COMMUNITIES_GET, 200) - ; - - private final String name; - private final int expireAfterWrite; // SECONDS TimeUnit - private final int maximumSize; - - CacheType(String name, int expireAfterWrite, int maximumSize) { - this.name = name; - this.expireAfterWrite = expireAfterWrite; - this.maximumSize = maximumSize; - } - - public static class CacheInfo { - - public static final String BANNERS = "banners"; - static final int BANNERS_GET = 3_600; // 1 hour - - public static final String ARCHIVE_COMMUNITIES = "archive-communities"; - static final int ARCHIVE_COMMUNITIES_GET = 30; - - private CacheInfo() { - } - - } - -} diff --git a/archive-common/src/main/java/site/archive/common/cache/CacheType.kt b/archive-common/src/main/java/site/archive/common/cache/CacheType.kt new file mode 100644 index 0000000..2cf83b1 --- /dev/null +++ b/archive-common/src/main/java/site/archive/common/cache/CacheType.kt @@ -0,0 +1,21 @@ +package site.archive.common.cache + +enum class CacheType(val key: String, val expireAfterWrite: Int, val maximumSize: Int) { + + BANNERS(CacheInfo.BANNERS, CacheInfo.BANNERS_GET_EXPIRE_TIME, CacheInfo.BANNERS_CACHE_SIZE), + ARCHIVE_COMMUNITIES(CacheInfo.ARCHIVE_COMMUNITIES, CacheInfo.ARCHIVE_COMMUNITIES_GET_EXPIRE_TIME, CacheInfo.ARCHIVE_COMMUNITIES_CACHE_SIZE) + ; + + class CacheInfo { + companion object { + const val BANNERS: String = "banners" + const val BANNERS_GET_EXPIRE_TIME: Int = 3_600 + const val BANNERS_CACHE_SIZE: Int = 1 + + const val ARCHIVE_COMMUNITIES: String = "archive-communities" + const val ARCHIVE_COMMUNITIES_GET_EXPIRE_TIME: Int = 30 + const val ARCHIVE_COMMUNITIES_CACHE_SIZE: Int = 200 + } + } + +} \ No newline at end of file diff --git a/archive-web/src/main/java/site/archive/web/config/cache/CacheConfig.java b/archive-web/src/main/java/site/archive/web/config/cache/CacheConfig.java index aed5f3f..92aa0a7 100644 --- a/archive-web/src/main/java/site/archive/web/config/cache/CacheConfig.java +++ b/archive-web/src/main/java/site/archive/web/config/cache/CacheConfig.java @@ -32,7 +32,7 @@ public KeyGenerator keyGenerator() { private List caches() { return Arrays.stream(CacheType.values()) - .map(cache -> new CaffeineCache(cache.getName(), + .map(cache -> new CaffeineCache(cache.getKey(), Caffeine.newBuilder() .expireAfterWrite(cache.getExpireAfterWrite(), TimeUnit.SECONDS) .maximumSize(cache.getMaximumSize()) From 73dafc2d407d9acc61f419aecd63a54e216368fb Mon Sep 17 00:00:00 2001 From: KimDoubleB Date: Wed, 18 Jan 2023 01:26:23 +0900 Subject: [PATCH 24/46] feat(#53): common module java directory to kotlin directory --- .../{java => kotlin}/site/archive/common/ArchiveStringUtils.kt | 0 .../main/{java => kotlin}/site/archive/common/DateTimeUtils.kt | 0 .../src/main/{java => kotlin}/site/archive/common/FileUtils.kt | 0 .../main/{java => kotlin}/site/archive/common/cache/CacheType.kt | 0 .../site/archive/common/exception/BaseException.kt | 0 .../site/archive/common/exception/ExceptionCode.kt | 0 .../common/exception/common/DuplicateFieldValueException.kt | 0 .../archive/common/exception/common/DuplicateResourceException.kt | 0 .../archive/common/exception/common/ResourceNotFoundException.kt | 0 .../common/exception/common/UnauthorizedResourceException.kt | 0 .../site/archive/common/exception/infra/FileInvalidException.kt | 0 .../site/archive/common/exception/infra/SlackException.kt | 0 .../archive/common/exception/security/InvalidTokenException.kt | 0 .../archive/common/exception/security/TokenNotFoundException.kt | 0 .../site/archive/common/exception/user/LoginFailException.kt | 0 .../archive/common/exception/user/OAuthRegisterFailException.kt | 0 .../common/exception/user/OAuthUserHasNotPasswordException.kt | 0 17 files changed, 0 insertions(+), 0 deletions(-) rename archive-common/src/main/{java => kotlin}/site/archive/common/ArchiveStringUtils.kt (100%) rename archive-common/src/main/{java => kotlin}/site/archive/common/DateTimeUtils.kt (100%) rename archive-common/src/main/{java => kotlin}/site/archive/common/FileUtils.kt (100%) rename archive-common/src/main/{java => kotlin}/site/archive/common/cache/CacheType.kt (100%) rename archive-common/src/main/{java => kotlin}/site/archive/common/exception/BaseException.kt (100%) rename archive-common/src/main/{java => kotlin}/site/archive/common/exception/ExceptionCode.kt (100%) rename archive-common/src/main/{java => kotlin}/site/archive/common/exception/common/DuplicateFieldValueException.kt (100%) rename archive-common/src/main/{java => kotlin}/site/archive/common/exception/common/DuplicateResourceException.kt (100%) rename archive-common/src/main/{java => kotlin}/site/archive/common/exception/common/ResourceNotFoundException.kt (100%) rename archive-common/src/main/{java => kotlin}/site/archive/common/exception/common/UnauthorizedResourceException.kt (100%) rename archive-common/src/main/{java => kotlin}/site/archive/common/exception/infra/FileInvalidException.kt (100%) rename archive-common/src/main/{java => kotlin}/site/archive/common/exception/infra/SlackException.kt (100%) rename archive-common/src/main/{java => kotlin}/site/archive/common/exception/security/InvalidTokenException.kt (100%) rename archive-common/src/main/{java => kotlin}/site/archive/common/exception/security/TokenNotFoundException.kt (100%) rename archive-common/src/main/{java => kotlin}/site/archive/common/exception/user/LoginFailException.kt (100%) rename archive-common/src/main/{java => kotlin}/site/archive/common/exception/user/OAuthRegisterFailException.kt (100%) rename archive-common/src/main/{java => kotlin}/site/archive/common/exception/user/OAuthUserHasNotPasswordException.kt (100%) diff --git a/archive-common/src/main/java/site/archive/common/ArchiveStringUtils.kt b/archive-common/src/main/kotlin/site/archive/common/ArchiveStringUtils.kt similarity index 100% rename from archive-common/src/main/java/site/archive/common/ArchiveStringUtils.kt rename to archive-common/src/main/kotlin/site/archive/common/ArchiveStringUtils.kt diff --git a/archive-common/src/main/java/site/archive/common/DateTimeUtils.kt b/archive-common/src/main/kotlin/site/archive/common/DateTimeUtils.kt similarity index 100% rename from archive-common/src/main/java/site/archive/common/DateTimeUtils.kt rename to archive-common/src/main/kotlin/site/archive/common/DateTimeUtils.kt diff --git a/archive-common/src/main/java/site/archive/common/FileUtils.kt b/archive-common/src/main/kotlin/site/archive/common/FileUtils.kt similarity index 100% rename from archive-common/src/main/java/site/archive/common/FileUtils.kt rename to archive-common/src/main/kotlin/site/archive/common/FileUtils.kt diff --git a/archive-common/src/main/java/site/archive/common/cache/CacheType.kt b/archive-common/src/main/kotlin/site/archive/common/cache/CacheType.kt similarity index 100% rename from archive-common/src/main/java/site/archive/common/cache/CacheType.kt rename to archive-common/src/main/kotlin/site/archive/common/cache/CacheType.kt diff --git a/archive-common/src/main/java/site/archive/common/exception/BaseException.kt b/archive-common/src/main/kotlin/site/archive/common/exception/BaseException.kt similarity index 100% rename from archive-common/src/main/java/site/archive/common/exception/BaseException.kt rename to archive-common/src/main/kotlin/site/archive/common/exception/BaseException.kt diff --git a/archive-common/src/main/java/site/archive/common/exception/ExceptionCode.kt b/archive-common/src/main/kotlin/site/archive/common/exception/ExceptionCode.kt similarity index 100% rename from archive-common/src/main/java/site/archive/common/exception/ExceptionCode.kt rename to archive-common/src/main/kotlin/site/archive/common/exception/ExceptionCode.kt diff --git a/archive-common/src/main/java/site/archive/common/exception/common/DuplicateFieldValueException.kt b/archive-common/src/main/kotlin/site/archive/common/exception/common/DuplicateFieldValueException.kt similarity index 100% rename from archive-common/src/main/java/site/archive/common/exception/common/DuplicateFieldValueException.kt rename to archive-common/src/main/kotlin/site/archive/common/exception/common/DuplicateFieldValueException.kt diff --git a/archive-common/src/main/java/site/archive/common/exception/common/DuplicateResourceException.kt b/archive-common/src/main/kotlin/site/archive/common/exception/common/DuplicateResourceException.kt similarity index 100% rename from archive-common/src/main/java/site/archive/common/exception/common/DuplicateResourceException.kt rename to archive-common/src/main/kotlin/site/archive/common/exception/common/DuplicateResourceException.kt diff --git a/archive-common/src/main/java/site/archive/common/exception/common/ResourceNotFoundException.kt b/archive-common/src/main/kotlin/site/archive/common/exception/common/ResourceNotFoundException.kt similarity index 100% rename from archive-common/src/main/java/site/archive/common/exception/common/ResourceNotFoundException.kt rename to archive-common/src/main/kotlin/site/archive/common/exception/common/ResourceNotFoundException.kt diff --git a/archive-common/src/main/java/site/archive/common/exception/common/UnauthorizedResourceException.kt b/archive-common/src/main/kotlin/site/archive/common/exception/common/UnauthorizedResourceException.kt similarity index 100% rename from archive-common/src/main/java/site/archive/common/exception/common/UnauthorizedResourceException.kt rename to archive-common/src/main/kotlin/site/archive/common/exception/common/UnauthorizedResourceException.kt diff --git a/archive-common/src/main/java/site/archive/common/exception/infra/FileInvalidException.kt b/archive-common/src/main/kotlin/site/archive/common/exception/infra/FileInvalidException.kt similarity index 100% rename from archive-common/src/main/java/site/archive/common/exception/infra/FileInvalidException.kt rename to archive-common/src/main/kotlin/site/archive/common/exception/infra/FileInvalidException.kt diff --git a/archive-common/src/main/java/site/archive/common/exception/infra/SlackException.kt b/archive-common/src/main/kotlin/site/archive/common/exception/infra/SlackException.kt similarity index 100% rename from archive-common/src/main/java/site/archive/common/exception/infra/SlackException.kt rename to archive-common/src/main/kotlin/site/archive/common/exception/infra/SlackException.kt diff --git a/archive-common/src/main/java/site/archive/common/exception/security/InvalidTokenException.kt b/archive-common/src/main/kotlin/site/archive/common/exception/security/InvalidTokenException.kt similarity index 100% rename from archive-common/src/main/java/site/archive/common/exception/security/InvalidTokenException.kt rename to archive-common/src/main/kotlin/site/archive/common/exception/security/InvalidTokenException.kt diff --git a/archive-common/src/main/java/site/archive/common/exception/security/TokenNotFoundException.kt b/archive-common/src/main/kotlin/site/archive/common/exception/security/TokenNotFoundException.kt similarity index 100% rename from archive-common/src/main/java/site/archive/common/exception/security/TokenNotFoundException.kt rename to archive-common/src/main/kotlin/site/archive/common/exception/security/TokenNotFoundException.kt diff --git a/archive-common/src/main/java/site/archive/common/exception/user/LoginFailException.kt b/archive-common/src/main/kotlin/site/archive/common/exception/user/LoginFailException.kt similarity index 100% rename from archive-common/src/main/java/site/archive/common/exception/user/LoginFailException.kt rename to archive-common/src/main/kotlin/site/archive/common/exception/user/LoginFailException.kt diff --git a/archive-common/src/main/java/site/archive/common/exception/user/OAuthRegisterFailException.kt b/archive-common/src/main/kotlin/site/archive/common/exception/user/OAuthRegisterFailException.kt similarity index 100% rename from archive-common/src/main/java/site/archive/common/exception/user/OAuthRegisterFailException.kt rename to archive-common/src/main/kotlin/site/archive/common/exception/user/OAuthRegisterFailException.kt diff --git a/archive-common/src/main/java/site/archive/common/exception/user/OAuthUserHasNotPasswordException.kt b/archive-common/src/main/kotlin/site/archive/common/exception/user/OAuthUserHasNotPasswordException.kt similarity index 100% rename from archive-common/src/main/java/site/archive/common/exception/user/OAuthUserHasNotPasswordException.kt rename to archive-common/src/main/kotlin/site/archive/common/exception/user/OAuthUserHasNotPasswordException.kt From be8d521cc869d8bbdf83f174e749ffaea5a55c2f Mon Sep 17 00:00:00 2001 From: KimDoubleB Date: Thu, 19 Jan 2023 01:41:23 +0900 Subject: [PATCH 25/46] feat(#53): converted archive dto v1 classes java to kotlin --- .../v1/archive/ArchiveCountResponseDtoV1.java | 13 --- .../v1/archive/ArchiveCountResponseDtoV1.kt | 3 + .../archive/dto/v1/archive/ArchiveDtoV1.java | 98 ------------------- .../archive/dto/v1/archive/ArchiveDtoV1.kt | 87 ++++++++++++++++ .../dto/v1/archive/ArchiveImageDtoV1.java | 34 ------- .../dto/v1/archive/ArchiveImageDtoV1.kt | 29 ++++++ .../archive/ArchiveImageUrlResponseDtoV1.java | 12 --- .../archive/ArchiveImageUrlResponseDtoV1.kt | 3 + .../v1/archive/ArchiveListResponseDtoV1.java | 22 ----- .../v1/archive/ArchiveListResponseDtoV1.kt | 17 ++++ .../archive/EmailDuplicateResponseDtoV1.java | 12 --- .../v1/archive/EmailDuplicateResponseDtoV1.kt | 3 + .../service/archive/ArchiveService.java | 13 +-- 13 files changed, 149 insertions(+), 197 deletions(-) delete mode 100644 archive-application/src/main/java/site/archive/dto/v1/archive/ArchiveCountResponseDtoV1.java create mode 100644 archive-application/src/main/java/site/archive/dto/v1/archive/ArchiveCountResponseDtoV1.kt delete mode 100644 archive-application/src/main/java/site/archive/dto/v1/archive/ArchiveDtoV1.java create mode 100644 archive-application/src/main/java/site/archive/dto/v1/archive/ArchiveDtoV1.kt delete mode 100644 archive-application/src/main/java/site/archive/dto/v1/archive/ArchiveImageDtoV1.java create mode 100644 archive-application/src/main/java/site/archive/dto/v1/archive/ArchiveImageDtoV1.kt delete mode 100644 archive-application/src/main/java/site/archive/dto/v1/archive/ArchiveImageUrlResponseDtoV1.java create mode 100644 archive-application/src/main/java/site/archive/dto/v1/archive/ArchiveImageUrlResponseDtoV1.kt delete mode 100644 archive-application/src/main/java/site/archive/dto/v1/archive/ArchiveListResponseDtoV1.java create mode 100644 archive-application/src/main/java/site/archive/dto/v1/archive/ArchiveListResponseDtoV1.kt delete mode 100644 archive-application/src/main/java/site/archive/dto/v1/archive/EmailDuplicateResponseDtoV1.java create mode 100644 archive-application/src/main/java/site/archive/dto/v1/archive/EmailDuplicateResponseDtoV1.kt diff --git a/archive-application/src/main/java/site/archive/dto/v1/archive/ArchiveCountResponseDtoV1.java b/archive-application/src/main/java/site/archive/dto/v1/archive/ArchiveCountResponseDtoV1.java deleted file mode 100644 index 7b2b68b..0000000 --- a/archive-application/src/main/java/site/archive/dto/v1/archive/ArchiveCountResponseDtoV1.java +++ /dev/null @@ -1,13 +0,0 @@ -package site.archive.dto.v1.archive; - -import lombok.AllArgsConstructor; -import lombok.Getter; - - -@Getter -@AllArgsConstructor -public class ArchiveCountResponseDtoV1 { - - private final long count; - -} diff --git a/archive-application/src/main/java/site/archive/dto/v1/archive/ArchiveCountResponseDtoV1.kt b/archive-application/src/main/java/site/archive/dto/v1/archive/ArchiveCountResponseDtoV1.kt new file mode 100644 index 0000000..867f701 --- /dev/null +++ b/archive-application/src/main/java/site/archive/dto/v1/archive/ArchiveCountResponseDtoV1.kt @@ -0,0 +1,3 @@ +package site.archive.dto.v1.archive + +data class ArchiveCountResponseDtoV1(val count: Long) \ No newline at end of file diff --git a/archive-application/src/main/java/site/archive/dto/v1/archive/ArchiveDtoV1.java b/archive-application/src/main/java/site/archive/dto/v1/archive/ArchiveDtoV1.java deleted file mode 100644 index f8878b0..0000000 --- a/archive-application/src/main/java/site/archive/dto/v1/archive/ArchiveDtoV1.java +++ /dev/null @@ -1,98 +0,0 @@ -package site.archive.dto.v1.archive; - -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonInclude.Include; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; -import site.archive.common.DateTimeUtils; -import site.archive.domain.archive.Archive; -import site.archive.domain.archive.CoverImageType; -import site.archive.domain.archive.Emotion; -import site.archive.domain.user.BaseUser; - -import java.time.LocalDate; -import java.util.List; -import java.util.Objects; - -@NoArgsConstructor -@AllArgsConstructor -@Getter -@Builder -@JsonInclude(Include.NON_NULL) -public class ArchiveDtoV1 { - private Long archiveId; - private String name; - private String watchedOn; - private Emotion emotion; - private String mainImage; - private Boolean isPublic; // Default value is false - private CoverImageType coverImageType; // Default value is EMOTION_COVER - - private long authorId; - - private List companions; - private List images; - - /** - * 아카이브 상세 조회 DTO V1 - * 아카이브 연결 이미지들을 다 포함 - * - * @param archive Archive Entity - * @return ArchiveDtoV1 archive specific DTO - */ - public static ArchiveDtoV1 specificFrom(Archive archive) { - var archiveImages = archive.getArchiveImages().stream() - .map(ArchiveImageDtoV1::from) - .toList(); - return ArchiveDtoV1.builder() - .archiveId(archive.getId()) - .name(archive.getName()) - .watchedOn(archive.getWatchedOn().format(DateTimeUtils.getYymmddFormatter())) - .emotion(archive.getEmotion()) - .mainImage(archive.getMainImage()) - .companions(archive.getCompanions()) - .images(archiveImages) - .authorId(archive.getAuthor().getId()) - .isPublic(archive.getIsPublic()) - .build(); - } - - /** - * 아카이브 리스트 조회 DTO - * 아카이브 연결 이미지들을 포함하고 있지 않음 - * - * @param archive archive entity - * @return ArchiveDtoV1 archive simple DTO - */ - public static ArchiveDtoV1 simpleFrom(Archive archive) { - return ArchiveDtoV1.builder() - .archiveId(archive.getId()) - .name(archive.getName()) - .watchedOn(archive.getWatchedOn().format(DateTimeUtils.getYymmddFormatter())) - .emotion(archive.getEmotion()) - .companions(archive.getCompanions()) - .mainImage(archive.getMainImage()) - .authorId(archive.getAuthor().getId()) - .isPublic(archive.getIsPublic()) - .coverImageType(archive.getCoverImageType()) - .build(); - } - - public Archive toEntity(BaseUser user) { - var archivePublic = this.isPublic != null && this.isPublic; - var archiveCoverImageType = Objects.requireNonNullElse(coverImageType, CoverImageType.EMOTION_COVER); - return Archive.builder() - .name(name) - .watchedOn(LocalDate.parse(watchedOn, DateTimeUtils.getYymmddFormatter())) - .emotion(emotion) - .mainImage(mainImage) - .companions(companions) - .author(user) - .isPublic(archivePublic) - .coverImageType(archiveCoverImageType) - .build(); - } - -} diff --git a/archive-application/src/main/java/site/archive/dto/v1/archive/ArchiveDtoV1.kt b/archive-application/src/main/java/site/archive/dto/v1/archive/ArchiveDtoV1.kt new file mode 100644 index 0000000..1362c19 --- /dev/null +++ b/archive-application/src/main/java/site/archive/dto/v1/archive/ArchiveDtoV1.kt @@ -0,0 +1,87 @@ +package site.archive.dto.v1.archive + +import com.fasterxml.jackson.annotation.JsonInclude +import site.archive.common.yymmddFormatter +import site.archive.domain.archive.Archive +import site.archive.domain.archive.CoverImageType +import site.archive.domain.archive.Emotion +import site.archive.domain.user.BaseUser +import java.time.LocalDate + +@JsonInclude(JsonInclude.Include.NON_NULL) +data class ArchiveDtoV1( + val archiveId: Long, + val name: String, + val watchedOn: String, + val emotion: Emotion, + val mainImage: String, + val authorId: Long, + val isPublic: Boolean? = null, + val coverImageType: CoverImageType? = null, + var companions: List? = null, + var images: List? = null +) { + + fun toEntity(user: BaseUser): Archive { + val archivePublic = isPublic ?: false + val archiveCoverImageType = coverImageType ?: CoverImageType.EMOTION_COVER + return Archive.builder() + .name(name) + .watchedOn(LocalDate.parse(watchedOn, yymmddFormatter)) + .emotion(emotion) + .mainImage(mainImage) + .companions(companions) + .author(user) + .isPublic(archivePublic) + .coverImageType(archiveCoverImageType) + .build() + } + + companion object { + /** + * 아카이브 상세 조회 DTO V1 + * 아카이브 연결 이미지들을 다 포함 + * + * @param archive Archive Entity + * @return ArchiveDtoV1 archive specific DTO + */ + @JvmStatic + fun specificForm(archive: Archive): ArchiveDtoV1 { + val archiveImages = archive.archiveImages.map(ArchiveImageDtoV1::from).toList() + return ArchiveDtoV1( + archiveId = archive.id, + name = archive.name, + watchedOn = archive.watchedOn.format(yymmddFormatter), + emotion = archive.emotion, + mainImage = archive.mainImage, + companions = archive.companions, + images = archiveImages, + authorId = archive.author.id, + isPublic = archive.isPublic + ) + } + + /** + * 아카이브 리스트 조회 DTO + * 아카이브 연결 이미지들을 포함하고 있지 않음 + * + * @param archive archive entity + * @return ArchiveDtoV1 archive simple DTO + */ + @JvmStatic + fun simpleForm(archive: Archive): ArchiveDtoV1 { + return ArchiveDtoV1( + archiveId = archive.id, + name = archive.name, + watchedOn = archive.watchedOn.format(yymmddFormatter), + emotion = archive.emotion, + companions = archive.companions, + mainImage = archive.mainImage, + authorId = archive.author.id, + isPublic = archive.isPublic, + coverImageType = archive.coverImageType + ) + } + } + +} \ No newline at end of file diff --git a/archive-application/src/main/java/site/archive/dto/v1/archive/ArchiveImageDtoV1.java b/archive-application/src/main/java/site/archive/dto/v1/archive/ArchiveImageDtoV1.java deleted file mode 100644 index 0fed022..0000000 --- a/archive-application/src/main/java/site/archive/dto/v1/archive/ArchiveImageDtoV1.java +++ /dev/null @@ -1,34 +0,0 @@ -package site.archive.dto.v1.archive; - -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; -import site.archive.domain.archive.Archive; -import site.archive.domain.archive.ArchiveImage; - -@NoArgsConstructor -@AllArgsConstructor -@Getter -@Builder -public class ArchiveImageDtoV1 { - - private Long archiveImageId; - private String image; - private String review; - private String backgroundColor; - - public static ArchiveImageDtoV1 from(ArchiveImage archiveImage) { - return ArchiveImageDtoV1.builder() - .archiveImageId(archiveImage.getId()) - .image(archiveImage.getImage()) - .review(archiveImage.getReview()) - .backgroundColor(archiveImage.getBackgroundColor()) - .build(); - } - - public ArchiveImage toEntity(Archive archive) { - return new ArchiveImage(image, review, backgroundColor, archive); - } - -} \ No newline at end of file diff --git a/archive-application/src/main/java/site/archive/dto/v1/archive/ArchiveImageDtoV1.kt b/archive-application/src/main/java/site/archive/dto/v1/archive/ArchiveImageDtoV1.kt new file mode 100644 index 0000000..51c51f8 --- /dev/null +++ b/archive-application/src/main/java/site/archive/dto/v1/archive/ArchiveImageDtoV1.kt @@ -0,0 +1,29 @@ +package site.archive.dto.v1.archive + +import site.archive.domain.archive.Archive +import site.archive.domain.archive.ArchiveImage + +data class ArchiveImageDtoV1( + val archiveImageId: Long, + val image: String, + val review: String, + val backgroundColor: String +) { + + fun toEntity(archive: Archive): ArchiveImage { + return ArchiveImage(image, review, backgroundColor, archive) + } + + companion object { + @JvmStatic + fun from(archiveImage: ArchiveImage): ArchiveImageDtoV1 { + return ArchiveImageDtoV1( + archiveImageId = archiveImage.id, + image = archiveImage.image, + review = archiveImage.review, + backgroundColor = archiveImage.backgroundColor + ) + } + } + +} \ No newline at end of file diff --git a/archive-application/src/main/java/site/archive/dto/v1/archive/ArchiveImageUrlResponseDtoV1.java b/archive-application/src/main/java/site/archive/dto/v1/archive/ArchiveImageUrlResponseDtoV1.java deleted file mode 100644 index 876a0df..0000000 --- a/archive-application/src/main/java/site/archive/dto/v1/archive/ArchiveImageUrlResponseDtoV1.java +++ /dev/null @@ -1,12 +0,0 @@ -package site.archive.dto.v1.archive; - -import lombok.Getter; -import lombok.RequiredArgsConstructor; - -@Getter -@RequiredArgsConstructor -public class ArchiveImageUrlResponseDtoV1 { - - private final String imageUrl; - -} diff --git a/archive-application/src/main/java/site/archive/dto/v1/archive/ArchiveImageUrlResponseDtoV1.kt b/archive-application/src/main/java/site/archive/dto/v1/archive/ArchiveImageUrlResponseDtoV1.kt new file mode 100644 index 0000000..d0fd740 --- /dev/null +++ b/archive-application/src/main/java/site/archive/dto/v1/archive/ArchiveImageUrlResponseDtoV1.kt @@ -0,0 +1,3 @@ +package site.archive.dto.v1.archive + +data class ArchiveImageUrlResponseDtoV1(val imageUrl: String) \ No newline at end of file diff --git a/archive-application/src/main/java/site/archive/dto/v1/archive/ArchiveListResponseDtoV1.java b/archive-application/src/main/java/site/archive/dto/v1/archive/ArchiveListResponseDtoV1.java deleted file mode 100644 index 386652a..0000000 --- a/archive-application/src/main/java/site/archive/dto/v1/archive/ArchiveListResponseDtoV1.java +++ /dev/null @@ -1,22 +0,0 @@ -package site.archive.dto.v1.archive; - -import lombok.Getter; - -import java.util.List; - -@Getter -public class ArchiveListResponseDtoV1 { - - private final int archiveCount; - private final List archives; - - private ArchiveListResponseDtoV1(List archives) { - this.archiveCount = archives.size(); - this.archives = archives; - } - - public static ArchiveListResponseDtoV1 from(List archiveDtoV1s) { - return new ArchiveListResponseDtoV1(archiveDtoV1s); - } - -} \ No newline at end of file diff --git a/archive-application/src/main/java/site/archive/dto/v1/archive/ArchiveListResponseDtoV1.kt b/archive-application/src/main/java/site/archive/dto/v1/archive/ArchiveListResponseDtoV1.kt new file mode 100644 index 0000000..2bd782c --- /dev/null +++ b/archive-application/src/main/java/site/archive/dto/v1/archive/ArchiveListResponseDtoV1.kt @@ -0,0 +1,17 @@ +package site.archive.dto.v1.archive + +data class ArchiveListResponseDtoV1( + val archiveCount: Int, + val archives: List +) { + + private constructor(archives: List) : this(archives.size, archives) + + companion object { + @JvmStatic + fun from(archiveDtoV1s: List): ArchiveListResponseDtoV1 { + return ArchiveListResponseDtoV1(archiveDtoV1s) + } + } + +} \ No newline at end of file diff --git a/archive-application/src/main/java/site/archive/dto/v1/archive/EmailDuplicateResponseDtoV1.java b/archive-application/src/main/java/site/archive/dto/v1/archive/EmailDuplicateResponseDtoV1.java deleted file mode 100644 index 8073587..0000000 --- a/archive-application/src/main/java/site/archive/dto/v1/archive/EmailDuplicateResponseDtoV1.java +++ /dev/null @@ -1,12 +0,0 @@ -package site.archive.dto.v1.archive; - -import lombok.AllArgsConstructor; -import lombok.Getter; - -@Getter -@AllArgsConstructor -public class EmailDuplicateResponseDtoV1 { - - private boolean isDuplicatedEmail; - -} diff --git a/archive-application/src/main/java/site/archive/dto/v1/archive/EmailDuplicateResponseDtoV1.kt b/archive-application/src/main/java/site/archive/dto/v1/archive/EmailDuplicateResponseDtoV1.kt new file mode 100644 index 0000000..839b2dd --- /dev/null +++ b/archive-application/src/main/java/site/archive/dto/v1/archive/EmailDuplicateResponseDtoV1.kt @@ -0,0 +1,3 @@ +package site.archive.dto.v1.archive + +data class EmailDuplicateResponseDtoV1(val isDuplicatedEmail: Boolean) \ No newline at end of file diff --git a/archive-application/src/main/java/site/archive/service/archive/ArchiveService.java b/archive-application/src/main/java/site/archive/service/archive/ArchiveService.java index 3be6b9c..1ac4873 100644 --- a/archive-application/src/main/java/site/archive/service/archive/ArchiveService.java +++ b/archive-application/src/main/java/site/archive/service/archive/ArchiveService.java @@ -19,6 +19,7 @@ import java.util.Comparator; import java.util.List; +import java.util.Objects; import java.util.Optional; import java.util.function.Predicate; @@ -43,7 +44,7 @@ public class ArchiveService { public ArchiveListResponseDtoV1 getAllArchive(UserInfo userInfo) { var authorId = userInfo.getUserId(); var archiveDtos = archiveRepository.findAllByAuthorId(authorId).stream() - .map(ArchiveDtoV1::simpleFrom) + .map(ArchiveDtoV1::simpleForm) .toList(); return ArchiveListResponseDtoV1.from(archiveDtos); } @@ -60,7 +61,7 @@ public ArchiveListResponseDtoV1 getAllArchive(UserInfo userInfo) { public ArchiveListResponseDtoV1 getAllArchive(UserInfo userInfo, Long authorId) { var archiveDtos = archiveRepository.findAllByAuthorId(authorId).stream() .filter(hasViewAuthority(userInfo.getUserId())) - .map(ArchiveDtoV1::simpleFrom) + .map(ArchiveDtoV1::simpleForm) .toList(); return ArchiveListResponseDtoV1.from(archiveDtos); } @@ -106,7 +107,7 @@ public List getAllArchiveNextPage(UserInfo userInfo, Archi public ArchiveDtoV1 getOneArchiveById(Long archiveId) { var archive = archiveRepository.findById(archiveId) .orElseThrow(() -> new ResourceNotFoundException("조회하려는 아카이브가 존재하지 않습니다")); - return ArchiveDtoV1.specificFrom(archive); + return ArchiveDtoV1.specificForm(archive); } /** @@ -136,9 +137,9 @@ public void save(ArchiveDtoV1 archiveDtoV1, Long authorId) { var user = userRepository.findById(authorId) .orElseThrow(() -> new ResourceNotFoundException("아이디에 해당하는 유저가 존재하지 않습니다.")); var archive = archiveRepository.save(archiveDtoV1.toEntity(user)); - archiveDtoV1.getImages().stream() - .map(archiveImageDto -> archiveImageDto.toEntity(archive)) - .forEach(archive::addImage); + Objects.requireNonNull(archiveDtoV1.getImages()).stream() + .map(archiveImageDto -> archiveImageDto.toEntity(archive)) + .forEach(archive::addImage); } public long countArchive(UserInfo userInfo) { From 5f8c0fc5e86ca5f6480195b31fc573e7183f3687 Mon Sep 17 00:00:00 2001 From: KimDoubleB Date: Thu, 19 Jan 2023 02:00:50 +0900 Subject: [PATCH 26/46] feat(#53): converted auth dto v1 classes java to kotlin --- .../dto/v1/auth/BasicRegisterCommandV1.java | 23 ----------- .../dto/v1/auth/BasicRegisterCommandV1.kt | 13 +++++++ .../archive/dto/v1/auth/LoginCommandV1.java | 17 -------- .../archive/dto/v1/auth/LoginCommandV1.kt | 3 ++ .../dto/v1/auth/OAuthRegisterCommandV1.java | 30 -------------- .../dto/v1/auth/OAuthRegisterCommandV1.kt | 20 ++++++++++ .../v1/auth/PasswordRegisterCommandV1.java | 39 ------------------- .../dto/v1/auth/PasswordRegisterCommandV1.kt | 29 ++++++++++++++ 8 files changed, 65 insertions(+), 109 deletions(-) delete mode 100644 archive-application/src/main/java/site/archive/dto/v1/auth/BasicRegisterCommandV1.java create mode 100644 archive-application/src/main/java/site/archive/dto/v1/auth/BasicRegisterCommandV1.kt delete mode 100644 archive-application/src/main/java/site/archive/dto/v1/auth/LoginCommandV1.java create mode 100644 archive-application/src/main/java/site/archive/dto/v1/auth/LoginCommandV1.kt delete mode 100644 archive-application/src/main/java/site/archive/dto/v1/auth/OAuthRegisterCommandV1.java create mode 100644 archive-application/src/main/java/site/archive/dto/v1/auth/OAuthRegisterCommandV1.kt delete mode 100644 archive-application/src/main/java/site/archive/dto/v1/auth/PasswordRegisterCommandV1.java create mode 100644 archive-application/src/main/java/site/archive/dto/v1/auth/PasswordRegisterCommandV1.kt diff --git a/archive-application/src/main/java/site/archive/dto/v1/auth/BasicRegisterCommandV1.java b/archive-application/src/main/java/site/archive/dto/v1/auth/BasicRegisterCommandV1.java deleted file mode 100644 index a79f0a1..0000000 --- a/archive-application/src/main/java/site/archive/dto/v1/auth/BasicRegisterCommandV1.java +++ /dev/null @@ -1,23 +0,0 @@ -package site.archive.dto.v1.auth; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; -import site.archive.domain.user.BaseUser; - -import jakarta.validation.constraints.Email; -import jakarta.validation.constraints.NotEmpty; - -@Getter -@Setter -@NoArgsConstructor -@AllArgsConstructor -public abstract class BasicRegisterCommandV1 { - - @NotEmpty(message = "필수 입력 항목입니다.") - @Email(message = "올바른 이메일을 입력해 주세요.") - private String email; - - public abstract BaseUser toUserEntity(); -} diff --git a/archive-application/src/main/java/site/archive/dto/v1/auth/BasicRegisterCommandV1.kt b/archive-application/src/main/java/site/archive/dto/v1/auth/BasicRegisterCommandV1.kt new file mode 100644 index 0000000..e15c488 --- /dev/null +++ b/archive-application/src/main/java/site/archive/dto/v1/auth/BasicRegisterCommandV1.kt @@ -0,0 +1,13 @@ +package site.archive.dto.v1.auth + +import jakarta.validation.constraints.Email +import jakarta.validation.constraints.NotBlank +import site.archive.domain.user.BaseUser + +abstract class BasicRegisterCommandV1( + @field: NotBlank(message = "이메일은 필수 입력 항목입니다.") + @field: Email(message = "올바른 이메일을 입력해 주세요.") + val email: String, +) { + abstract fun toUserEntity(): BaseUser +} \ No newline at end of file diff --git a/archive-application/src/main/java/site/archive/dto/v1/auth/LoginCommandV1.java b/archive-application/src/main/java/site/archive/dto/v1/auth/LoginCommandV1.java deleted file mode 100644 index 6abeda9..0000000 --- a/archive-application/src/main/java/site/archive/dto/v1/auth/LoginCommandV1.java +++ /dev/null @@ -1,17 +0,0 @@ -package site.archive.dto.v1.auth; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; - -@Getter -@Setter -@NoArgsConstructor -@AllArgsConstructor -public class LoginCommandV1 { - - private String email; - private String password; - -} diff --git a/archive-application/src/main/java/site/archive/dto/v1/auth/LoginCommandV1.kt b/archive-application/src/main/java/site/archive/dto/v1/auth/LoginCommandV1.kt new file mode 100644 index 0000000..331be0e --- /dev/null +++ b/archive-application/src/main/java/site/archive/dto/v1/auth/LoginCommandV1.kt @@ -0,0 +1,3 @@ +package site.archive.dto.v1.auth + +data class LoginCommandV1(val email: String, val password: String) \ No newline at end of file diff --git a/archive-application/src/main/java/site/archive/dto/v1/auth/OAuthRegisterCommandV1.java b/archive-application/src/main/java/site/archive/dto/v1/auth/OAuthRegisterCommandV1.java deleted file mode 100644 index 165b2ca..0000000 --- a/archive-application/src/main/java/site/archive/dto/v1/auth/OAuthRegisterCommandV1.java +++ /dev/null @@ -1,30 +0,0 @@ -package site.archive.dto.v1.auth; - -import lombok.Getter; -import lombok.NoArgsConstructor; -import site.archive.common.ArchiveStringUtils; -import site.archive.domain.user.BaseUser; -import site.archive.domain.user.OAuthProvider; -import site.archive.domain.user.OAuthUser; -import site.archive.domain.user.UserRole; - -@NoArgsConstructor -@Getter -public class OAuthRegisterCommandV1 extends BasicRegisterCommandV1 { - - private OAuthProvider provider; - - public OAuthRegisterCommandV1(String mailAddress, OAuthProvider provider) { - super(mailAddress); - this.provider = provider; - } - - @Override - public BaseUser toUserEntity() { - return new OAuthUser(getEmail(), - UserRole.GENERAL, - provider, - ArchiveStringUtils.extractIdFromMail(getEmail())); - } - -} diff --git a/archive-application/src/main/java/site/archive/dto/v1/auth/OAuthRegisterCommandV1.kt b/archive-application/src/main/java/site/archive/dto/v1/auth/OAuthRegisterCommandV1.kt new file mode 100644 index 0000000..247a5c5 --- /dev/null +++ b/archive-application/src/main/java/site/archive/dto/v1/auth/OAuthRegisterCommandV1.kt @@ -0,0 +1,20 @@ +package site.archive.dto.v1.auth + +import site.archive.common.extractIdFromMail +import site.archive.domain.user.BaseUser +import site.archive.domain.user.OAuthProvider +import site.archive.domain.user.OAuthUser +import site.archive.domain.user.UserRole + +class OAuthRegisterCommandV1(email: String, val provider: OAuthProvider) : BasicRegisterCommandV1(email) { + + override fun toUserEntity(): BaseUser { + return OAuthUser( + email, + UserRole.GENERAL, + provider, + extractIdFromMail(email) + ) + } + +} diff --git a/archive-application/src/main/java/site/archive/dto/v1/auth/PasswordRegisterCommandV1.java b/archive-application/src/main/java/site/archive/dto/v1/auth/PasswordRegisterCommandV1.java deleted file mode 100644 index 373d594..0000000 --- a/archive-application/src/main/java/site/archive/dto/v1/auth/PasswordRegisterCommandV1.java +++ /dev/null @@ -1,39 +0,0 @@ -package site.archive.dto.v1.auth; - -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; -import site.archive.common.ArchiveStringUtils; -import site.archive.domain.user.BaseUser; -import site.archive.domain.user.PasswordUser; -import site.archive.domain.user.UserRole; - -import jakarta.validation.constraints.NotEmpty; -import jakarta.validation.constraints.Pattern; - -@EqualsAndHashCode(callSuper = true) -@Getter -@Setter -@NoArgsConstructor -public class PasswordRegisterCommandV1 extends BasicRegisterCommandV1 { - - @NotEmpty(message = "필수 입력 항목입니다.") - @Pattern(regexp = "(?=.*[a-zA-Z])(?=.*[0-9])[a-zA-Z0-9@$!%*#?&]{8,20}$", - message = "비밀번호는 영문/숫자 를 꼭 포함하여 8~20자리로 입력해 주세요.") - private String password; - - public PasswordRegisterCommandV1(String userMail, String password) { - super(userMail); - this.password = password; - } - - @Override - public BaseUser toUserEntity() { - return new PasswordUser(getEmail(), - UserRole.GENERAL, - getPassword(), - ArchiveStringUtils.extractIdFromMail(getEmail())); - } - -} diff --git a/archive-application/src/main/java/site/archive/dto/v1/auth/PasswordRegisterCommandV1.kt b/archive-application/src/main/java/site/archive/dto/v1/auth/PasswordRegisterCommandV1.kt new file mode 100644 index 0000000..7fde82f --- /dev/null +++ b/archive-application/src/main/java/site/archive/dto/v1/auth/PasswordRegisterCommandV1.kt @@ -0,0 +1,29 @@ +package site.archive.dto.v1.auth + +import jakarta.validation.constraints.NotBlank +import jakarta.validation.constraints.Pattern +import site.archive.common.extractIdFromMail +import site.archive.domain.user.BaseUser +import site.archive.domain.user.PasswordUser +import site.archive.domain.user.UserRole + +class PasswordRegisterCommandV1( + email: String, + @field: NotBlank(message = "비밀번호는 필수 입력 항목입니다.") + @field: Pattern( + regexp = "(?=.*[a-zA-Z])(?=.*[0-9])[a-zA-Z0-9@$!%*#?&]{8,20}$", + message = "비밀번호는 영문/숫자 를 꼭 포함하여 8~20자리로 입력해 주세요." + ) + var password: String +) : BasicRegisterCommandV1(email) { + + override fun toUserEntity(): BaseUser { + return PasswordUser( + email, + UserRole.GENERAL, + password, + extractIdFromMail(email) + ) + } + +} \ No newline at end of file From 19b594bca74a5a1c67ae80a20201834e9437f9e4 Mon Sep 17 00:00:00 2001 From: KimDoubleB Date: Thu, 19 Jan 2023 02:21:39 +0900 Subject: [PATCH 27/46] feat(#53): converted user dto v1 classes java to kotlin --- .../archive/dto/v1/user/BaseUserDtoV1.java | 35 ------------------- .../site/archive/dto/v1/user/BaseUserDtoV1.kt | 35 +++++++++++++++++++ .../v1/user/OAuthRegisterRequestDtoV1.java | 23 ------------ .../dto/v1/user/OAuthRegisterRequestDtoV1.kt | 8 +++++ .../dto/v1/user/SpecificUserDtoV1.java | 32 ----------------- .../archive/dto/v1/user/SpecificUserDtoV1.kt | 33 +++++++++++++++++ .../dto/v1/user/UserEmailRequestDtoV1.java | 21 ----------- .../dto/v1/user/UserEmailRequestDtoV1.kt | 10 ++++++ .../user/UserPasswordResetRequestDtoV1.java | 33 ----------------- .../v1/user/UserPasswordResetRequestDtoV1.kt | 21 +++++++++++ 10 files changed, 107 insertions(+), 144 deletions(-) delete mode 100644 archive-application/src/main/java/site/archive/dto/v1/user/BaseUserDtoV1.java create mode 100644 archive-application/src/main/java/site/archive/dto/v1/user/BaseUserDtoV1.kt delete mode 100644 archive-application/src/main/java/site/archive/dto/v1/user/OAuthRegisterRequestDtoV1.java create mode 100644 archive-application/src/main/java/site/archive/dto/v1/user/OAuthRegisterRequestDtoV1.kt delete mode 100644 archive-application/src/main/java/site/archive/dto/v1/user/SpecificUserDtoV1.java create mode 100644 archive-application/src/main/java/site/archive/dto/v1/user/SpecificUserDtoV1.kt delete mode 100644 archive-application/src/main/java/site/archive/dto/v1/user/UserEmailRequestDtoV1.java create mode 100644 archive-application/src/main/java/site/archive/dto/v1/user/UserEmailRequestDtoV1.kt delete mode 100644 archive-application/src/main/java/site/archive/dto/v1/user/UserPasswordResetRequestDtoV1.java create mode 100644 archive-application/src/main/java/site/archive/dto/v1/user/UserPasswordResetRequestDtoV1.kt diff --git a/archive-application/src/main/java/site/archive/dto/v1/user/BaseUserDtoV1.java b/archive-application/src/main/java/site/archive/dto/v1/user/BaseUserDtoV1.java deleted file mode 100644 index 05a8600..0000000 --- a/archive-application/src/main/java/site/archive/dto/v1/user/BaseUserDtoV1.java +++ /dev/null @@ -1,35 +0,0 @@ -package site.archive.dto.v1.user; - -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import site.archive.common.DateTimeUtils; -import site.archive.domain.user.BaseUser; -import site.archive.domain.user.UserRole; - -import java.time.LocalDateTime; - -@RequiredArgsConstructor -@Getter -public class BaseUserDtoV1 { - - private final Long userId; - private final String mailAddress; - private final UserRole userRole; - private final LocalDateTime createdAt; - private final String profileImage; - private final String nickname; - - public static BaseUserDtoV1 from(BaseUser baseUser) { - return new BaseUserDtoV1(baseUser.getId(), - baseUser.getMailAddress(), - baseUser.getRole(), - baseUser.getCreatedAt(), - baseUser.getProfileImage(), - baseUser.getNickname()); - } - - public String getCreatedAt() { - return DateTimeUtils.getDateTimeFormatter().format(this.createdAt); - } - -} diff --git a/archive-application/src/main/java/site/archive/dto/v1/user/BaseUserDtoV1.kt b/archive-application/src/main/java/site/archive/dto/v1/user/BaseUserDtoV1.kt new file mode 100644 index 0000000..cd889d1 --- /dev/null +++ b/archive-application/src/main/java/site/archive/dto/v1/user/BaseUserDtoV1.kt @@ -0,0 +1,35 @@ +package site.archive.dto.v1.user + +import site.archive.common.dateTimeFormatter +import site.archive.domain.user.BaseUser +import site.archive.domain.user.UserRole +import java.time.LocalDateTime + +data class BaseUserDtoV1( + val userId: Long, + val mailAddress: String, + val userRole: UserRole, + val profileImage: String, + val nickname: String, + private val createdAt: LocalDateTime +) { + + fun getCreatedAt(): String { + return dateTimeFormatter.format(createdAt) + } + + companion object { + @JvmStatic + fun from(baseUser: BaseUser): BaseUserDtoV1 { + return BaseUserDtoV1( + userId = baseUser.id, + mailAddress = baseUser.mailAddress, + userRole = baseUser.role, + createdAt = baseUser.createdAt, + profileImage = baseUser.profileImage, + nickname = baseUser.nickname + ) + } + } + +} \ No newline at end of file diff --git a/archive-application/src/main/java/site/archive/dto/v1/user/OAuthRegisterRequestDtoV1.java b/archive-application/src/main/java/site/archive/dto/v1/user/OAuthRegisterRequestDtoV1.java deleted file mode 100644 index 6884b8f..0000000 --- a/archive-application/src/main/java/site/archive/dto/v1/user/OAuthRegisterRequestDtoV1.java +++ /dev/null @@ -1,23 +0,0 @@ -package site.archive.dto.v1.user; - -import com.fasterxml.jackson.annotation.JsonProperty; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.ToString; - -import jakarta.validation.constraints.NotNull; - -@Getter -@ToString -@NoArgsConstructor -@AllArgsConstructor -public class OAuthRegisterRequestDtoV1 { - - @NotNull - private String provider; - - @JsonProperty("providerAccessToken") - private String token; - -} diff --git a/archive-application/src/main/java/site/archive/dto/v1/user/OAuthRegisterRequestDtoV1.kt b/archive-application/src/main/java/site/archive/dto/v1/user/OAuthRegisterRequestDtoV1.kt new file mode 100644 index 0000000..e82bdaa --- /dev/null +++ b/archive-application/src/main/java/site/archive/dto/v1/user/OAuthRegisterRequestDtoV1.kt @@ -0,0 +1,8 @@ +package site.archive.dto.v1.user + +import com.fasterxml.jackson.annotation.JsonProperty + +data class OAuthRegisterRequestDtoV1( + val provider: String, + @field: JsonProperty("providerAccessToken") val token: String +) \ No newline at end of file diff --git a/archive-application/src/main/java/site/archive/dto/v1/user/SpecificUserDtoV1.java b/archive-application/src/main/java/site/archive/dto/v1/user/SpecificUserDtoV1.java deleted file mode 100644 index d92a9c5..0000000 --- a/archive-application/src/main/java/site/archive/dto/v1/user/SpecificUserDtoV1.java +++ /dev/null @@ -1,32 +0,0 @@ -package site.archive.dto.v1.user; - -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import site.archive.common.DateTimeUtils; -import site.archive.domain.user.BaseUser; -import site.archive.domain.user.UserRole; - -@RequiredArgsConstructor -@Getter -public class SpecificUserDtoV1 { - - private final Long userId; - private final String mailAddress; - private final UserRole userRole; - private final String createdAt; - private final String profileImage; - private final String nickname; - private final String userType; - - public static SpecificUserDtoV1 from(BaseUser baseUser) { - var createdAt = DateTimeUtils.getDateTimeFormatter().format(baseUser.getCreatedAt()); - return new SpecificUserDtoV1(baseUser.getId(), - baseUser.getMailAddress(), - baseUser.getRole(), - createdAt, - baseUser.getProfileImage(), - baseUser.getNickname(), - baseUser.getUserType()); - } - -} diff --git a/archive-application/src/main/java/site/archive/dto/v1/user/SpecificUserDtoV1.kt b/archive-application/src/main/java/site/archive/dto/v1/user/SpecificUserDtoV1.kt new file mode 100644 index 0000000..0562165 --- /dev/null +++ b/archive-application/src/main/java/site/archive/dto/v1/user/SpecificUserDtoV1.kt @@ -0,0 +1,33 @@ +package site.archive.dto.v1.user + +import site.archive.common.dateTimeFormatter +import site.archive.domain.user.BaseUser +import site.archive.domain.user.UserRole + +data class SpecificUserDtoV1( + val userId: Long, + val mailAddress: String, + val userRole: UserRole, + val createdAt: String, + val profileImage: String, + val nickname: String, + val userType: String +) { + + companion object { + @JvmStatic + fun from(baseUser: BaseUser) : SpecificUserDtoV1 { + val createdAt = dateTimeFormatter.format(baseUser.createdAt) + return SpecificUserDtoV1( + userId = baseUser.id, + mailAddress = baseUser.mailAddress, + userRole = baseUser.role, + createdAt = createdAt, + profileImage = baseUser.profileImage, + nickname = baseUser.nickname, + userType = baseUser.userType + ) + } + } + +} \ No newline at end of file diff --git a/archive-application/src/main/java/site/archive/dto/v1/user/UserEmailRequestDtoV1.java b/archive-application/src/main/java/site/archive/dto/v1/user/UserEmailRequestDtoV1.java deleted file mode 100644 index 03a811a..0000000 --- a/archive-application/src/main/java/site/archive/dto/v1/user/UserEmailRequestDtoV1.java +++ /dev/null @@ -1,21 +0,0 @@ -package site.archive.dto.v1.user; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; - -import jakarta.validation.constraints.Email; -import jakarta.validation.constraints.NotBlank; -import jakarta.validation.constraints.NotNull; - -@Getter -@NoArgsConstructor -@AllArgsConstructor -public class UserEmailRequestDtoV1 { - - @Email - @NotNull - @NotBlank - private String email; - -} diff --git a/archive-application/src/main/java/site/archive/dto/v1/user/UserEmailRequestDtoV1.kt b/archive-application/src/main/java/site/archive/dto/v1/user/UserEmailRequestDtoV1.kt new file mode 100644 index 0000000..01aa1a1 --- /dev/null +++ b/archive-application/src/main/java/site/archive/dto/v1/user/UserEmailRequestDtoV1.kt @@ -0,0 +1,10 @@ +package site.archive.dto.v1.user + +import jakarta.validation.constraints.Email +import jakarta.validation.constraints.NotBlank + +data class UserEmailRequestDtoV1( + @field: NotBlank(message = "이메일은 필수 입력 항목입니다.") + @field: Email(message = "올바른 이메일을 입력해 주세요.") + val email: String +) \ No newline at end of file diff --git a/archive-application/src/main/java/site/archive/dto/v1/user/UserPasswordResetRequestDtoV1.java b/archive-application/src/main/java/site/archive/dto/v1/user/UserPasswordResetRequestDtoV1.java deleted file mode 100644 index f2735f9..0000000 --- a/archive-application/src/main/java/site/archive/dto/v1/user/UserPasswordResetRequestDtoV1.java +++ /dev/null @@ -1,33 +0,0 @@ -package site.archive.dto.v1.user; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; - -import jakarta.validation.constraints.Email; -import jakarta.validation.constraints.NotBlank; -import jakarta.validation.constraints.NotEmpty; -import jakarta.validation.constraints.NotNull; -import jakarta.validation.constraints.Pattern; - -@Getter -@NoArgsConstructor -@AllArgsConstructor -public class UserPasswordResetRequestDtoV1 { - - @Email - @NotNull - @NotBlank - private String email; - - @NotNull - @NotEmpty - private String currentPassword; - - @NotNull - @NotEmpty - @Pattern(regexp = "(?=.*[a-zA-Z])(?=.*[0-9])[a-zA-Z0-9@$!%*#?&]{8,20}$", - message = "비밀번호는 영문/숫자 를 꼭 포함하여 8~20자리로 입력해 주세요.") - private String newPassword; - -} diff --git a/archive-application/src/main/java/site/archive/dto/v1/user/UserPasswordResetRequestDtoV1.kt b/archive-application/src/main/java/site/archive/dto/v1/user/UserPasswordResetRequestDtoV1.kt new file mode 100644 index 0000000..fd561d4 --- /dev/null +++ b/archive-application/src/main/java/site/archive/dto/v1/user/UserPasswordResetRequestDtoV1.kt @@ -0,0 +1,21 @@ +package site.archive.dto.v1.user + +import jakarta.validation.constraints.Email +import jakarta.validation.constraints.NotBlank +import jakarta.validation.constraints.Pattern + +data class UserPasswordResetRequestDtoV1( + @field: NotBlank(message = "이메일은 필수 입력 항목입니다.") + @field: Email(message = "올바른 이메일을 입력해 주세요.") + val email: String, + + @field: NotBlank(message = "현재 비밀번호는 필수 입력 항목입니다.") + val currentPassword: String, + + @field: NotBlank(message = "새로운 비밀번호는 필수 입력 항목입니다.") + @field: Pattern( + regexp = "(?=.*[a-zA-Z])(?=.*[0-9])[a-zA-Z0-9@$!%*#?&]{8,20}$", + message = "비밀번호는 영문/숫자 를 꼭 포함하여 8~20자리로 입력해 주세요." + ) + val newPassword: String +) \ No newline at end of file From 1ff4dc32fbe0729214ffc50ab003829df57d94ec Mon Sep 17 00:00:00 2001 From: KimDoubleB Date: Thu, 19 Jan 2023 02:23:41 +0900 Subject: [PATCH 28/46] feat(#53): v1 dto package java to kotlin directory --- .../site/archive/dto/v1/archive/ArchiveCountResponseDtoV1.kt | 0 .../{java => kotlin}/site/archive/dto/v1/archive/ArchiveDtoV1.kt | 0 .../site/archive/dto/v1/archive/ArchiveImageDtoV1.kt | 0 .../site/archive/dto/v1/archive/ArchiveImageUrlResponseDtoV1.kt | 0 .../site/archive/dto/v1/archive/ArchiveListResponseDtoV1.kt | 0 .../site/archive/dto/v1/archive/EmailDuplicateResponseDtoV1.kt | 0 .../site/archive/dto/v1/auth/BasicRegisterCommandV1.kt | 0 .../{java => kotlin}/site/archive/dto/v1/auth/LoginCommandV1.kt | 0 .../site/archive/dto/v1/auth/OAuthRegisterCommandV1.kt | 0 .../site/archive/dto/v1/auth/PasswordRegisterCommandV1.kt | 0 .../{java => kotlin}/site/archive/dto/v1/user/BaseUserDtoV1.kt | 0 .../site/archive/dto/v1/user/OAuthRegisterRequestDtoV1.kt | 0 .../site/archive/dto/v1/user/SpecificUserDtoV1.kt | 0 .../site/archive/dto/v1/user/UserEmailRequestDtoV1.kt | 0 .../site/archive/dto/v1/user/UserPasswordResetRequestDtoV1.kt | 0 15 files changed, 0 insertions(+), 0 deletions(-) rename archive-application/src/main/{java => kotlin}/site/archive/dto/v1/archive/ArchiveCountResponseDtoV1.kt (100%) rename archive-application/src/main/{java => kotlin}/site/archive/dto/v1/archive/ArchiveDtoV1.kt (100%) rename archive-application/src/main/{java => kotlin}/site/archive/dto/v1/archive/ArchiveImageDtoV1.kt (100%) rename archive-application/src/main/{java => kotlin}/site/archive/dto/v1/archive/ArchiveImageUrlResponseDtoV1.kt (100%) rename archive-application/src/main/{java => kotlin}/site/archive/dto/v1/archive/ArchiveListResponseDtoV1.kt (100%) rename archive-application/src/main/{java => kotlin}/site/archive/dto/v1/archive/EmailDuplicateResponseDtoV1.kt (100%) rename archive-application/src/main/{java => kotlin}/site/archive/dto/v1/auth/BasicRegisterCommandV1.kt (100%) rename archive-application/src/main/{java => kotlin}/site/archive/dto/v1/auth/LoginCommandV1.kt (100%) rename archive-application/src/main/{java => kotlin}/site/archive/dto/v1/auth/OAuthRegisterCommandV1.kt (100%) rename archive-application/src/main/{java => kotlin}/site/archive/dto/v1/auth/PasswordRegisterCommandV1.kt (100%) rename archive-application/src/main/{java => kotlin}/site/archive/dto/v1/user/BaseUserDtoV1.kt (100%) rename archive-application/src/main/{java => kotlin}/site/archive/dto/v1/user/OAuthRegisterRequestDtoV1.kt (100%) rename archive-application/src/main/{java => kotlin}/site/archive/dto/v1/user/SpecificUserDtoV1.kt (100%) rename archive-application/src/main/{java => kotlin}/site/archive/dto/v1/user/UserEmailRequestDtoV1.kt (100%) rename archive-application/src/main/{java => kotlin}/site/archive/dto/v1/user/UserPasswordResetRequestDtoV1.kt (100%) diff --git a/archive-application/src/main/java/site/archive/dto/v1/archive/ArchiveCountResponseDtoV1.kt b/archive-application/src/main/kotlin/site/archive/dto/v1/archive/ArchiveCountResponseDtoV1.kt similarity index 100% rename from archive-application/src/main/java/site/archive/dto/v1/archive/ArchiveCountResponseDtoV1.kt rename to archive-application/src/main/kotlin/site/archive/dto/v1/archive/ArchiveCountResponseDtoV1.kt diff --git a/archive-application/src/main/java/site/archive/dto/v1/archive/ArchiveDtoV1.kt b/archive-application/src/main/kotlin/site/archive/dto/v1/archive/ArchiveDtoV1.kt similarity index 100% rename from archive-application/src/main/java/site/archive/dto/v1/archive/ArchiveDtoV1.kt rename to archive-application/src/main/kotlin/site/archive/dto/v1/archive/ArchiveDtoV1.kt diff --git a/archive-application/src/main/java/site/archive/dto/v1/archive/ArchiveImageDtoV1.kt b/archive-application/src/main/kotlin/site/archive/dto/v1/archive/ArchiveImageDtoV1.kt similarity index 100% rename from archive-application/src/main/java/site/archive/dto/v1/archive/ArchiveImageDtoV1.kt rename to archive-application/src/main/kotlin/site/archive/dto/v1/archive/ArchiveImageDtoV1.kt diff --git a/archive-application/src/main/java/site/archive/dto/v1/archive/ArchiveImageUrlResponseDtoV1.kt b/archive-application/src/main/kotlin/site/archive/dto/v1/archive/ArchiveImageUrlResponseDtoV1.kt similarity index 100% rename from archive-application/src/main/java/site/archive/dto/v1/archive/ArchiveImageUrlResponseDtoV1.kt rename to archive-application/src/main/kotlin/site/archive/dto/v1/archive/ArchiveImageUrlResponseDtoV1.kt diff --git a/archive-application/src/main/java/site/archive/dto/v1/archive/ArchiveListResponseDtoV1.kt b/archive-application/src/main/kotlin/site/archive/dto/v1/archive/ArchiveListResponseDtoV1.kt similarity index 100% rename from archive-application/src/main/java/site/archive/dto/v1/archive/ArchiveListResponseDtoV1.kt rename to archive-application/src/main/kotlin/site/archive/dto/v1/archive/ArchiveListResponseDtoV1.kt diff --git a/archive-application/src/main/java/site/archive/dto/v1/archive/EmailDuplicateResponseDtoV1.kt b/archive-application/src/main/kotlin/site/archive/dto/v1/archive/EmailDuplicateResponseDtoV1.kt similarity index 100% rename from archive-application/src/main/java/site/archive/dto/v1/archive/EmailDuplicateResponseDtoV1.kt rename to archive-application/src/main/kotlin/site/archive/dto/v1/archive/EmailDuplicateResponseDtoV1.kt diff --git a/archive-application/src/main/java/site/archive/dto/v1/auth/BasicRegisterCommandV1.kt b/archive-application/src/main/kotlin/site/archive/dto/v1/auth/BasicRegisterCommandV1.kt similarity index 100% rename from archive-application/src/main/java/site/archive/dto/v1/auth/BasicRegisterCommandV1.kt rename to archive-application/src/main/kotlin/site/archive/dto/v1/auth/BasicRegisterCommandV1.kt diff --git a/archive-application/src/main/java/site/archive/dto/v1/auth/LoginCommandV1.kt b/archive-application/src/main/kotlin/site/archive/dto/v1/auth/LoginCommandV1.kt similarity index 100% rename from archive-application/src/main/java/site/archive/dto/v1/auth/LoginCommandV1.kt rename to archive-application/src/main/kotlin/site/archive/dto/v1/auth/LoginCommandV1.kt diff --git a/archive-application/src/main/java/site/archive/dto/v1/auth/OAuthRegisterCommandV1.kt b/archive-application/src/main/kotlin/site/archive/dto/v1/auth/OAuthRegisterCommandV1.kt similarity index 100% rename from archive-application/src/main/java/site/archive/dto/v1/auth/OAuthRegisterCommandV1.kt rename to archive-application/src/main/kotlin/site/archive/dto/v1/auth/OAuthRegisterCommandV1.kt diff --git a/archive-application/src/main/java/site/archive/dto/v1/auth/PasswordRegisterCommandV1.kt b/archive-application/src/main/kotlin/site/archive/dto/v1/auth/PasswordRegisterCommandV1.kt similarity index 100% rename from archive-application/src/main/java/site/archive/dto/v1/auth/PasswordRegisterCommandV1.kt rename to archive-application/src/main/kotlin/site/archive/dto/v1/auth/PasswordRegisterCommandV1.kt diff --git a/archive-application/src/main/java/site/archive/dto/v1/user/BaseUserDtoV1.kt b/archive-application/src/main/kotlin/site/archive/dto/v1/user/BaseUserDtoV1.kt similarity index 100% rename from archive-application/src/main/java/site/archive/dto/v1/user/BaseUserDtoV1.kt rename to archive-application/src/main/kotlin/site/archive/dto/v1/user/BaseUserDtoV1.kt diff --git a/archive-application/src/main/java/site/archive/dto/v1/user/OAuthRegisterRequestDtoV1.kt b/archive-application/src/main/kotlin/site/archive/dto/v1/user/OAuthRegisterRequestDtoV1.kt similarity index 100% rename from archive-application/src/main/java/site/archive/dto/v1/user/OAuthRegisterRequestDtoV1.kt rename to archive-application/src/main/kotlin/site/archive/dto/v1/user/OAuthRegisterRequestDtoV1.kt diff --git a/archive-application/src/main/java/site/archive/dto/v1/user/SpecificUserDtoV1.kt b/archive-application/src/main/kotlin/site/archive/dto/v1/user/SpecificUserDtoV1.kt similarity index 100% rename from archive-application/src/main/java/site/archive/dto/v1/user/SpecificUserDtoV1.kt rename to archive-application/src/main/kotlin/site/archive/dto/v1/user/SpecificUserDtoV1.kt diff --git a/archive-application/src/main/java/site/archive/dto/v1/user/UserEmailRequestDtoV1.kt b/archive-application/src/main/kotlin/site/archive/dto/v1/user/UserEmailRequestDtoV1.kt similarity index 100% rename from archive-application/src/main/java/site/archive/dto/v1/user/UserEmailRequestDtoV1.kt rename to archive-application/src/main/kotlin/site/archive/dto/v1/user/UserEmailRequestDtoV1.kt diff --git a/archive-application/src/main/java/site/archive/dto/v1/user/UserPasswordResetRequestDtoV1.kt b/archive-application/src/main/kotlin/site/archive/dto/v1/user/UserPasswordResetRequestDtoV1.kt similarity index 100% rename from archive-application/src/main/java/site/archive/dto/v1/user/UserPasswordResetRequestDtoV1.kt rename to archive-application/src/main/kotlin/site/archive/dto/v1/user/UserPasswordResetRequestDtoV1.kt From 285db7e127c9276bd4e525eb2c3f2e2d744ba8a9 Mon Sep 17 00:00:00 2001 From: KimDoubleB Date: Fri, 20 Jan 2023 10:10:09 +0900 Subject: [PATCH 29/46] feat(#53): converted application config classes java to kotlin --- .../archive/config/AsyncConfiguration.java | 64 ------------------- .../site/archive/config/ClientConfig.java | 27 -------- .../site/archive/config/AsyncConfiguration.kt | 54 ++++++++++++++++ .../site/archive/config/ClientConfig.kt | 32 ++++++++++ 4 files changed, 86 insertions(+), 91 deletions(-) delete mode 100644 archive-application/src/main/java/site/archive/config/AsyncConfiguration.java delete mode 100644 archive-application/src/main/java/site/archive/config/ClientConfig.java create mode 100644 archive-application/src/main/kotlin/site/archive/config/AsyncConfiguration.kt create mode 100644 archive-application/src/main/kotlin/site/archive/config/ClientConfig.kt diff --git a/archive-application/src/main/java/site/archive/config/AsyncConfiguration.java b/archive-application/src/main/java/site/archive/config/AsyncConfiguration.java deleted file mode 100644 index e17c8d3..0000000 --- a/archive-application/src/main/java/site/archive/config/AsyncConfiguration.java +++ /dev/null @@ -1,64 +0,0 @@ -package site.archive.config; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import lombok.ToString; -import lombok.extern.slf4j.Slf4j; -import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.scheduling.annotation.AsyncConfigurer; -import org.springframework.scheduling.annotation.EnableAsync; -import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; - -import java.util.concurrent.Executor; - -@Configuration -@EnableConfigurationProperties(AsyncConfiguration.MailExecutorProperty.class) -@EnableAsync -@RequiredArgsConstructor -@Slf4j -public class AsyncConfiguration implements AsyncConfigurer { - - private final MailExecutorProperty mailExecutorProperty; - - @Override - @Bean("mailExecutor") - public Executor getAsyncExecutor() { - var executor = new ThreadPoolTaskExecutor(); - executor.setCorePoolSize(mailExecutorProperty.getCorePoolSize()); - executor.setMaxPoolSize(mailExecutorProperty.getMaxPoolSize()); - executor.setQueueCapacity(mailExecutorProperty.getQueueCapacity()); - executor.setAwaitTerminationSeconds(mailExecutorProperty.getAwaitTerminationSeconds()); - executor.setWaitForTasksToCompleteOnShutdown(true); - executor.setThreadNamePrefix(MailExecutorProperty.THREAD_NAME_PREFIX); - executor.initialize(); - return executor; - } - - @Override - public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() { - return (exception, method, params) -> - log.error("Async Exception handler: '{}' threw unexpected exception ", - method.toGenericString(), exception); - } - - @ConfigurationProperties(prefix = "spring.mail.executor") - @AllArgsConstructor - @Getter - @ToString - public static class MailExecutorProperty { - - private static final String THREAD_NAME_PREFIX = "mail-executor-"; - - private int corePoolSize; - private int maxPoolSize; - private int queueCapacity; - private int awaitTerminationSeconds; - - } - -} diff --git a/archive-application/src/main/java/site/archive/config/ClientConfig.java b/archive-application/src/main/java/site/archive/config/ClientConfig.java deleted file mode 100644 index 12ca544..0000000 --- a/archive-application/src/main/java/site/archive/config/ClientConfig.java +++ /dev/null @@ -1,27 +0,0 @@ -package site.archive.config; - -import org.springframework.boot.web.client.RestTemplateBuilder; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.http.client.BufferingClientHttpRequestFactory; -import org.springframework.http.client.SimpleClientHttpRequestFactory; -import org.springframework.http.converter.StringHttpMessageConverter; -import org.springframework.web.client.RestTemplate; - -import java.nio.charset.StandardCharsets; -import java.time.Duration; - -@Configuration -public class ClientConfig { - - @Bean - public RestTemplate restTemplate(RestTemplateBuilder restTemplateBuilder) { - return restTemplateBuilder - .requestFactory(() -> new BufferingClientHttpRequestFactory(new SimpleClientHttpRequestFactory())) - .setConnectTimeout(Duration.ofMillis(3000)) - .setReadTimeout(Duration.ofMillis(3000)) - .additionalMessageConverters(new StringHttpMessageConverter(StandardCharsets.UTF_8)) - .build(); - } - -} diff --git a/archive-application/src/main/kotlin/site/archive/config/AsyncConfiguration.kt b/archive-application/src/main/kotlin/site/archive/config/AsyncConfiguration.kt new file mode 100644 index 0000000..cd3ad22 --- /dev/null +++ b/archive-application/src/main/kotlin/site/archive/config/AsyncConfiguration.kt @@ -0,0 +1,54 @@ +package site.archive.config + +import org.slf4j.LoggerFactory +import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler +import org.springframework.boot.context.properties.ConfigurationProperties +import org.springframework.boot.context.properties.EnableConfigurationProperties +import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.Configuration +import org.springframework.scheduling.annotation.AsyncConfigurer +import org.springframework.scheduling.annotation.EnableAsync +import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor +import site.archive.config.AsyncConfiguration.MailExecutorProperty +import java.lang.reflect.Method +import java.util.concurrent.Executor + +@Configuration +@EnableConfigurationProperties(MailExecutorProperty::class) +@EnableAsync +class AsyncConfiguration(val mailExecutorProperty: MailExecutorProperty) : AsyncConfigurer { + + private val log = LoggerFactory.getLogger(javaClass) + + @Bean("mailExecutor") + override fun getAsyncExecutor(): Executor? { + val executor = ThreadPoolTaskExecutor() + executor.corePoolSize = mailExecutorProperty.corePoolSize + executor.maxPoolSize = mailExecutorProperty.maxPoolSize + executor.queueCapacity = mailExecutorProperty.queueCapacity + executor.setAwaitTerminationSeconds(mailExecutorProperty.awaitTerminationSeconds) + executor.setWaitForTasksToCompleteOnShutdown(true) + executor.setThreadNamePrefix(MailExecutorProperty.THREAD_NAME_PREFIX) + executor.initialize() + return executor + } + + override fun getAsyncUncaughtExceptionHandler(): AsyncUncaughtExceptionHandler? { + return AsyncUncaughtExceptionHandler { exception: Throwable?, method: Method, _: Array? -> + log.error("Async Exception handler: '{}' threw unexpected exception ", method.toGenericString(), exception) + } + } + + @ConfigurationProperties(prefix = "spring.mail.executor") + class MailExecutorProperty( + val corePoolSize: Int = 0, + val maxPoolSize: Int = 0, + val queueCapacity: Int = 0, + val awaitTerminationSeconds: Int = 0 + ) { + companion object { + const val THREAD_NAME_PREFIX = "mail-executor-" + } + } + +} \ No newline at end of file diff --git a/archive-application/src/main/kotlin/site/archive/config/ClientConfig.kt b/archive-application/src/main/kotlin/site/archive/config/ClientConfig.kt new file mode 100644 index 0000000..2e3aac8 --- /dev/null +++ b/archive-application/src/main/kotlin/site/archive/config/ClientConfig.kt @@ -0,0 +1,32 @@ +package site.archive.config + +import org.springframework.boot.web.client.RestTemplateBuilder +import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.Configuration +import org.springframework.http.client.BufferingClientHttpRequestFactory +import org.springframework.http.client.SimpleClientHttpRequestFactory +import org.springframework.http.converter.StringHttpMessageConverter +import org.springframework.web.client.RestTemplate +import java.nio.charset.StandardCharsets +import java.time.Duration +import java.util.function.Supplier + +@Configuration +class ClientConfig { + + @Bean + fun restTemplateBuilder(): RestTemplateBuilder { + return RestTemplateBuilder() + } + + @Bean + fun restTemplate(restTemplateBuilder: RestTemplateBuilder): RestTemplate { + return restTemplateBuilder + .requestFactory(Supplier { BufferingClientHttpRequestFactory(SimpleClientHttpRequestFactory()) }) + .setConnectTimeout(Duration.ofMillis(3000)) + .setReadTimeout(Duration.ofMillis(3000)) + .additionalMessageConverters(StringHttpMessageConverter(StandardCharsets.UTF_8)) + .build() + } + +} \ No newline at end of file From 1888bdf102239c8456466fa9f26b61d818d8ccac Mon Sep 17 00:00:00 2001 From: KimDoubleB Date: Sat, 21 Jan 2023 23:57:46 +0900 Subject: [PATCH 30/46] feat(#53): converted dto v2 classes java to kotlin --- .../dto/v2/ArchiveCommunityResponseDto.java | 53 --------------- .../site/archive/dto/v2/ArchiveDtoV2.java | 66 ------------------- .../dto/v2/ArchiveLikeListResponseDto.java | 17 ----- .../dto/v2/ArchiveLikeResponseDto.java | 53 --------------- .../site/archive/dto/v2/LikesRequestDto.java | 14 ---- .../dto/v2/MyArchiveListResponseDto.java | 22 ------- .../archive/dto/v2/MyArchiveResponseDto.java | 47 ------------- .../dto/v2/ArchiveCommunityResponseDto.kt | 47 +++++++++++++ .../site/archive/dto/v2/ArchiveDtoV2.kt | 49 ++++++++++++++ .../dto/v2/ArchiveLikeListResponseDto.kt | 3 + .../archive/dto/v2/ArchiveLikeResponseDto.kt | 45 +++++++++++++ .../site/archive/dto/v2/LikesRequestDto.kt | 3 + .../dto/v2/MyArchiveListResponseDto.kt | 13 ++++ .../archive/dto/v2/MyArchiveResponseDto.kt | 41 ++++++++++++ 14 files changed, 201 insertions(+), 272 deletions(-) delete mode 100644 archive-application/src/main/java/site/archive/dto/v2/ArchiveCommunityResponseDto.java delete mode 100644 archive-application/src/main/java/site/archive/dto/v2/ArchiveDtoV2.java delete mode 100644 archive-application/src/main/java/site/archive/dto/v2/ArchiveLikeListResponseDto.java delete mode 100644 archive-application/src/main/java/site/archive/dto/v2/ArchiveLikeResponseDto.java delete mode 100644 archive-application/src/main/java/site/archive/dto/v2/LikesRequestDto.java delete mode 100644 archive-application/src/main/java/site/archive/dto/v2/MyArchiveListResponseDto.java delete mode 100644 archive-application/src/main/java/site/archive/dto/v2/MyArchiveResponseDto.java create mode 100644 archive-application/src/main/kotlin/site/archive/dto/v2/ArchiveCommunityResponseDto.kt create mode 100644 archive-application/src/main/kotlin/site/archive/dto/v2/ArchiveDtoV2.kt create mode 100644 archive-application/src/main/kotlin/site/archive/dto/v2/ArchiveLikeListResponseDto.kt create mode 100644 archive-application/src/main/kotlin/site/archive/dto/v2/ArchiveLikeResponseDto.kt create mode 100644 archive-application/src/main/kotlin/site/archive/dto/v2/LikesRequestDto.kt create mode 100644 archive-application/src/main/kotlin/site/archive/dto/v2/MyArchiveListResponseDto.kt create mode 100644 archive-application/src/main/kotlin/site/archive/dto/v2/MyArchiveResponseDto.kt diff --git a/archive-application/src/main/java/site/archive/dto/v2/ArchiveCommunityResponseDto.java b/archive-application/src/main/java/site/archive/dto/v2/ArchiveCommunityResponseDto.java deleted file mode 100644 index b5149d3..0000000 --- a/archive-application/src/main/java/site/archive/dto/v2/ArchiveCommunityResponseDto.java +++ /dev/null @@ -1,53 +0,0 @@ -package site.archive.dto.v2; - -import lombok.Builder; -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import site.archive.common.DateTimeUtils; -import site.archive.domain.archive.Archive; -import site.archive.domain.archive.CoverImageType; -import site.archive.domain.archive.Emotion; - -@RequiredArgsConstructor -@Builder -@Getter -public class ArchiveCommunityResponseDto { - - private final Long archiveId; - private final String name; - private final String watchedOn; - private final Emotion emotion; - private final String mainImage; - private final CoverImageType coverImageType; - private final Long authorId; - private final String authorNickname; - private final String authorProfileImage; - private final Boolean isLiked; - private final Long likeCount; - private final Long dateMilli; - - public static ArchiveCommunityResponseDto from(Archive archive, Long currentUserIdx, long dateMilli) { - var author = archive.getAuthor(); - var isLiked = archive.getLikes().stream() - .anyMatch(like -> !like.getIsDeleted() && like.getUser().getId().equals(currentUserIdx)); - var likeCount = archive.getLikes().stream() - .filter(like -> !like.getIsDeleted()).count(); - return ArchiveCommunityResponseDto.builder() - .archiveId(archive.getId()) - .name(archive.getName()) - .watchedOn(archive.getWatchedOn().format(DateTimeUtils.getYymmddFormatter())) - .emotion(archive.getEmotion()) - .mainImage(archive.getMainImage()) - .coverImageType(archive.getCoverImageType()) - .authorId(author.getId()) - .authorNickname(author.getNickname()) - .authorProfileImage(author.getProfileImage()) - .isLiked(isLiked) - .likeCount(likeCount) - .dateMilli(dateMilli) - .build(); - } - -} - - diff --git a/archive-application/src/main/java/site/archive/dto/v2/ArchiveDtoV2.java b/archive-application/src/main/java/site/archive/dto/v2/ArchiveDtoV2.java deleted file mode 100644 index bbbb159..0000000 --- a/archive-application/src/main/java/site/archive/dto/v2/ArchiveDtoV2.java +++ /dev/null @@ -1,66 +0,0 @@ -package site.archive.dto.v2; - -import com.fasterxml.jackson.annotation.JsonInclude; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; -import site.archive.common.DateTimeUtils; -import site.archive.domain.archive.Archive; -import site.archive.domain.archive.CoverImageType; -import site.archive.domain.archive.Emotion; -import site.archive.dto.v1.archive.ArchiveImageDtoV1; - -import java.util.List; - -@NoArgsConstructor -@AllArgsConstructor -@Getter -@Builder -@JsonInclude(JsonInclude.Include.NON_NULL) -public class ArchiveDtoV2 { - - private Long archiveId; - private String name; - private String watchedOn; - private Emotion emotion; - private String mainImage; - private Boolean isPublic; // Default value is false - private CoverImageType coverImageType; // Default value is EMOTION_COVER - - private long authorId; - private String nickname; - private String profileImage; - - private List companions; - private List images; - - /** - * 아카이브 상세 조회 DTO V2 - * 아카이브 작가의 닉네임, 프로필이미지 포함 - * 아카이브 연결 이미지들을 다 포함 - * - * @param archive Archive Entity - * @return ArchiveDtoV2 archive specific DTO - */ - public static ArchiveDtoV2 specificFrom(Archive archive) { - var archiveImages = archive.getArchiveImages().stream() - .map(ArchiveImageDtoV1::from) - .toList(); - var author = archive.getAuthor(); - return ArchiveDtoV2.builder() - .archiveId(archive.getId()) - .name(archive.getName()) - .watchedOn(archive.getWatchedOn().format(DateTimeUtils.getYymmddFormatter())) - .emotion(archive.getEmotion()) - .mainImage(archive.getMainImage()) - .companions(archive.getCompanions()) - .images(archiveImages) - .authorId(author.getId()) - .nickname(author.getNickname()) - .profileImage(author.getProfileImage()) - .isPublic(archive.getIsPublic()) - .coverImageType(archive.getCoverImageType()) - .build(); - } -} diff --git a/archive-application/src/main/java/site/archive/dto/v2/ArchiveLikeListResponseDto.java b/archive-application/src/main/java/site/archive/dto/v2/ArchiveLikeListResponseDto.java deleted file mode 100644 index 1ea4768..0000000 --- a/archive-application/src/main/java/site/archive/dto/v2/ArchiveLikeListResponseDto.java +++ /dev/null @@ -1,17 +0,0 @@ -package site.archive.dto.v2; - -import lombok.Getter; -import lombok.RequiredArgsConstructor; - -import java.util.List; - -@RequiredArgsConstructor -@Getter -public class ArchiveLikeListResponseDto { - - private final Integer archiveCount; - private final List archives; - -} - - diff --git a/archive-application/src/main/java/site/archive/dto/v2/ArchiveLikeResponseDto.java b/archive-application/src/main/java/site/archive/dto/v2/ArchiveLikeResponseDto.java deleted file mode 100644 index 0406219..0000000 --- a/archive-application/src/main/java/site/archive/dto/v2/ArchiveLikeResponseDto.java +++ /dev/null @@ -1,53 +0,0 @@ -package site.archive.dto.v2; - -import lombok.Builder; -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import lombok.ToString; -import site.archive.common.DateTimeUtils; -import site.archive.domain.archive.Archive; -import site.archive.domain.archive.CoverImageType; -import site.archive.domain.archive.Emotion; - -@RequiredArgsConstructor -@Builder -@Getter -@ToString -public class ArchiveLikeResponseDto { - - private final Long archiveId; - private final String name; - private final String watchedOn; - private final Emotion emotion; - private final String mainImage; - private final CoverImageType coverImageType; - private final Long authorId; - private final String authorNickname; - private final String authorProfileImage; - private final Boolean isLiked; - private final Long likeCount; - - public static ArchiveLikeResponseDto from(Archive archive, Long currentUserIdx) { - var author = archive.getAuthor(); - var isLiked = archive.getLikes().stream() - .anyMatch(like -> !like.getIsDeleted() && like.getUser().getId().equals(currentUserIdx)); - var likeCount = archive.getLikes().stream() - .filter(like -> !like.getIsDeleted()).count(); - return ArchiveLikeResponseDto.builder() - .archiveId(archive.getId()) - .name(archive.getName()) - .watchedOn(archive.getWatchedOn().format(DateTimeUtils.getYymmddFormatter())) - .emotion(archive.getEmotion()) - .mainImage(archive.getMainImage()) - .coverImageType(archive.getCoverImageType()) - .authorId(author.getId()) - .authorNickname(author.getNickname()) - .authorProfileImage(author.getProfileImage()) - .isLiked(isLiked) - .likeCount(likeCount) - .build(); - } - -} - - diff --git a/archive-application/src/main/java/site/archive/dto/v2/LikesRequestDto.java b/archive-application/src/main/java/site/archive/dto/v2/LikesRequestDto.java deleted file mode 100644 index 2bb36c8..0000000 --- a/archive-application/src/main/java/site/archive/dto/v2/LikesRequestDto.java +++ /dev/null @@ -1,14 +0,0 @@ -package site.archive.dto.v2; - -import lombok.Getter; -import lombok.NoArgsConstructor; - -import java.util.List; - -@NoArgsConstructor -@Getter -public class LikesRequestDto { - - private List archiveIds; - -} diff --git a/archive-application/src/main/java/site/archive/dto/v2/MyArchiveListResponseDto.java b/archive-application/src/main/java/site/archive/dto/v2/MyArchiveListResponseDto.java deleted file mode 100644 index 103215a..0000000 --- a/archive-application/src/main/java/site/archive/dto/v2/MyArchiveListResponseDto.java +++ /dev/null @@ -1,22 +0,0 @@ -package site.archive.dto.v2; - -import lombok.Getter; - -import java.util.List; - -@Getter -public class MyArchiveListResponseDto { - - private final Long archiveCount; - private final List archives; - - private MyArchiveListResponseDto(Long archiveCount, List archives) { - this.archiveCount = archiveCount; - this.archives = archives; - } - - public static MyArchiveListResponseDto from(Long archiveCount, List archiveDtos) { - return new MyArchiveListResponseDto(archiveCount, archiveDtos); - } - -} \ No newline at end of file diff --git a/archive-application/src/main/java/site/archive/dto/v2/MyArchiveResponseDto.java b/archive-application/src/main/java/site/archive/dto/v2/MyArchiveResponseDto.java deleted file mode 100644 index 80149e7..0000000 --- a/archive-application/src/main/java/site/archive/dto/v2/MyArchiveResponseDto.java +++ /dev/null @@ -1,47 +0,0 @@ -package site.archive.dto.v2; - -import lombok.Builder; -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import site.archive.common.DateTimeUtils; -import site.archive.domain.archive.Archive; -import site.archive.domain.archive.CoverImageType; -import site.archive.domain.archive.Emotion; - -@RequiredArgsConstructor -@Builder -@Getter -public class MyArchiveResponseDto { - - private final Long archiveId; - private final String name; - private final String watchedOn; - private final Emotion emotion; - private final String mainImage; - private final Boolean isPublic; - private final CoverImageType coverImageType; - private final Long authorId; - private final Long likeCount; - private final Long dateMilli; - - public static MyArchiveResponseDto from(Archive archive, long dateMilli) { - var author = archive.getAuthor(); - var likeCount = archive.getLikes().stream() - .filter(like -> !like.getIsDeleted()).count(); - return MyArchiveResponseDto.builder() - .archiveId(archive.getId()) - .name(archive.getName()) - .watchedOn(archive.getWatchedOn().format(DateTimeUtils.getYymmddFormatter())) - .emotion(archive.getEmotion()) - .mainImage(archive.getMainImage()) - .isPublic(archive.getIsPublic()) - .coverImageType(archive.getCoverImageType()) - .authorId(author.getId()) - .likeCount(likeCount) - .dateMilli(dateMilli) - .build(); - } - -} - - diff --git a/archive-application/src/main/kotlin/site/archive/dto/v2/ArchiveCommunityResponseDto.kt b/archive-application/src/main/kotlin/site/archive/dto/v2/ArchiveCommunityResponseDto.kt new file mode 100644 index 0000000..de7313d --- /dev/null +++ b/archive-application/src/main/kotlin/site/archive/dto/v2/ArchiveCommunityResponseDto.kt @@ -0,0 +1,47 @@ +package site.archive.dto.v2 + +import site.archive.common.yymmddFormatter +import site.archive.domain.archive.Archive +import site.archive.domain.archive.CoverImageType +import site.archive.domain.archive.Emotion + +class ArchiveCommunityResponseDto( + val archiveId: Long, + val name: String, + val watchedOn: String, + val emotion: Emotion, + val mainImage: String, + val coverImageType: CoverImageType, + val authorId: Long, + val authorNickname: String, + val authorProfileImage: String, + val isLiked: Boolean, + val likeCount: Long, + val dateMilli: Long +) { + companion object { + @JvmStatic + fun from(archive: Archive, currentUserIdx: Long, dateMilli: Long): ArchiveCommunityResponseDto { + val author = archive.author + val isLiked = archive.likes.stream() + .anyMatch { !it.isDeleted && it.user.id.equals(currentUserIdx) } + val likeCount = archive.likes.stream() + .filter { !it.isDeleted } + .count() + return ArchiveCommunityResponseDto( + archiveId = archive.id, + name = archive.name, + watchedOn = archive.watchedOn.format(yymmddFormatter), + emotion = archive.emotion, + mainImage = archive.mainImage, + coverImageType = archive.coverImageType, + authorId = author.id, + authorNickname = author.nickname, + authorProfileImage = author.profileImage, + isLiked = isLiked, + likeCount = likeCount, + dateMilli = dateMilli + ) + } + } +} \ No newline at end of file diff --git a/archive-application/src/main/kotlin/site/archive/dto/v2/ArchiveDtoV2.kt b/archive-application/src/main/kotlin/site/archive/dto/v2/ArchiveDtoV2.kt new file mode 100644 index 0000000..a156d83 --- /dev/null +++ b/archive-application/src/main/kotlin/site/archive/dto/v2/ArchiveDtoV2.kt @@ -0,0 +1,49 @@ +package site.archive.dto.v2 + +import com.fasterxml.jackson.annotation.JsonInclude +import site.archive.common.yymmddFormatter +import site.archive.domain.archive.Archive +import site.archive.domain.archive.CoverImageType +import site.archive.domain.archive.Emotion +import site.archive.dto.v1.archive.ArchiveImageDtoV1 + +@JsonInclude(JsonInclude.Include.NON_NULL) +class ArchiveDtoV2( + val archiveId: Long, + val name: String, + val watchedOn: String, + val emotion: Emotion, + val mainImage: String, + val isPublic: Boolean, + val coverImageType: CoverImageType, + val authorId: Long, + val nickname: String, + val profileImage: String, + val companions: List? = null, + val images: List? = null +) { + companion object { + @JvmStatic + fun specificFrom(archive: Archive): ArchiveDtoV2 { + val archiveImages = archive.archiveImages.stream() + .map(ArchiveImageDtoV1::from) + .toList() + val author = archive.author + return ArchiveDtoV2( + archiveId = archive.id, + name = archive.name, + watchedOn = archive.watchedOn.format(yymmddFormatter), + emotion = archive.emotion, + mainImage = archive.mainImage, + companions = archive.companions, + images = archiveImages, + authorId = author.id, + nickname = author.nickname, + profileImage = author.profileImage, + isPublic = archive.isPublic, + coverImageType = archive.coverImageType + ) + } + + } +} \ No newline at end of file diff --git a/archive-application/src/main/kotlin/site/archive/dto/v2/ArchiveLikeListResponseDto.kt b/archive-application/src/main/kotlin/site/archive/dto/v2/ArchiveLikeListResponseDto.kt new file mode 100644 index 0000000..3f10833 --- /dev/null +++ b/archive-application/src/main/kotlin/site/archive/dto/v2/ArchiveLikeListResponseDto.kt @@ -0,0 +1,3 @@ +package site.archive.dto.v2 + +class ArchiveLikeListResponseDto(val archiveCount: Int, val archives: List) \ No newline at end of file diff --git a/archive-application/src/main/kotlin/site/archive/dto/v2/ArchiveLikeResponseDto.kt b/archive-application/src/main/kotlin/site/archive/dto/v2/ArchiveLikeResponseDto.kt new file mode 100644 index 0000000..d744ffb --- /dev/null +++ b/archive-application/src/main/kotlin/site/archive/dto/v2/ArchiveLikeResponseDto.kt @@ -0,0 +1,45 @@ +package site.archive.dto.v2 + +import site.archive.common.yymmddFormatter +import site.archive.domain.archive.Archive +import site.archive.domain.archive.CoverImageType +import site.archive.domain.archive.Emotion + +class ArchiveLikeResponseDto( + val archiveId: Long, + val name: String, + val watchedOn: String, + val emotion: Emotion, + val mainImage: String, + val coverImageType: CoverImageType, + val authorId: Long, + val authorNickname: String, + val authorProfileImage: String, + val isLiked: Boolean, + val likeCount: Long +) { + companion object { + @JvmStatic + fun from(archive: Archive, currentUserIdx: Long): ArchiveLikeResponseDto { + val author = archive.author + val isLiked = archive.likes.stream() + .anyMatch { !it.isDeleted && it.user.id.equals(currentUserIdx) } + val likeCount = archive.likes.stream() + .filter { !it.isDeleted } + .count() + return ArchiveLikeResponseDto( + archiveId = archive.id, + name = archive.name, + watchedOn = archive.watchedOn.format(yymmddFormatter), + emotion = archive.emotion, + mainImage = archive.mainImage, + coverImageType = archive.coverImageType, + authorId = author.id, + authorNickname = author.nickname, + authorProfileImage = author.profileImage, + isLiked = isLiked, + likeCount = likeCount + ) + } + } +} \ No newline at end of file diff --git a/archive-application/src/main/kotlin/site/archive/dto/v2/LikesRequestDto.kt b/archive-application/src/main/kotlin/site/archive/dto/v2/LikesRequestDto.kt new file mode 100644 index 0000000..f8a92eb --- /dev/null +++ b/archive-application/src/main/kotlin/site/archive/dto/v2/LikesRequestDto.kt @@ -0,0 +1,3 @@ +package site.archive.dto.v2 + +class LikesRequestDto(val archiveIds: List) \ No newline at end of file diff --git a/archive-application/src/main/kotlin/site/archive/dto/v2/MyArchiveListResponseDto.kt b/archive-application/src/main/kotlin/site/archive/dto/v2/MyArchiveListResponseDto.kt new file mode 100644 index 0000000..cd9e381 --- /dev/null +++ b/archive-application/src/main/kotlin/site/archive/dto/v2/MyArchiveListResponseDto.kt @@ -0,0 +1,13 @@ +package site.archive.dto.v2 + +class MyArchiveListResponseDto( + val archiveCount: Long, + val archives: List +) { + companion object { + @JvmStatic + fun from(archiveCount: Long, archiveDtos: List): MyArchiveListResponseDto { + return MyArchiveListResponseDto(archiveCount, archiveDtos) + } + } +} \ No newline at end of file diff --git a/archive-application/src/main/kotlin/site/archive/dto/v2/MyArchiveResponseDto.kt b/archive-application/src/main/kotlin/site/archive/dto/v2/MyArchiveResponseDto.kt new file mode 100644 index 0000000..5b9d8cc --- /dev/null +++ b/archive-application/src/main/kotlin/site/archive/dto/v2/MyArchiveResponseDto.kt @@ -0,0 +1,41 @@ +package site.archive.dto.v2 + +import site.archive.common.yymmddFormatter +import site.archive.domain.archive.Archive +import site.archive.domain.archive.CoverImageType +import site.archive.domain.archive.Emotion + +class MyArchiveResponseDto( + val archiveId: Long, + val name: String, + val watchedOn: String, + val emotion: Emotion, + val mainImage: String, + val isPublic: Boolean, + val coverImageType: CoverImageType, + val authorId: Long, + val likeCount: Long, + val dateMilli: Long +) { + companion object { + @JvmStatic + fun from(archive: Archive, dateMilli: Long): MyArchiveResponseDto { + val author = archive.author + val likeCount = archive.likes.stream() + .filter { !it.isDeleted } + .count() + return MyArchiveResponseDto( + archiveId = archive.id, + name = archive.name, + watchedOn = archive.watchedOn.format(yymmddFormatter), + emotion = archive.emotion, + mainImage = archive.mainImage, + isPublic = archive.isPublic, + coverImageType = archive.coverImageType, + authorId = author.id, + likeCount = likeCount, + dateMilli = dateMilli + ) + } + } +} \ No newline at end of file From 388314f62e4a44d260b77f9492ca42c892da6e1f Mon Sep 17 00:00:00 2001 From: KimDoubleB Date: Sun, 22 Jan 2023 00:29:06 +0900 Subject: [PATCH 31/46] feat(#53): converted dto v2 classes java to kotlin --- .../dto/v2/ArchiveCountResponseDto.java | 4 -- .../archive/dto/v2/BannerListResponseDto.java | 6 --- .../archive/dto/v2/BannerResponseDto.java | 13 ------- .../dto/v2/NicknameDuplicateResponseDto.java | 4 -- .../archive/dto/v2/OAuthLoginRequestDto.java | 22 ----------- .../dto/v2/OAuthRegisterRequestDto.java | 27 ------------- .../dto/v2/OAuthUserInfoRequestDto.java | 27 ------------- .../dto/v2/PasswordRegisterRequestDto.java | 39 ------------------- .../archive/dto/v2/ReportCheckResponse.java | 4 -- .../site/archive/dto/v2/ReportRequestDto.java | 12 ------ .../archive/dto/v2/UnlikesRequestDto.java | 14 ------- .../dto/v2/UserNicknameUpdateRequest.java | 4 -- .../dto/v2/ArchiveCommunityResponseDto.kt | 2 +- .../archive/dto/v2/ArchiveCountResponseDto.kt | 3 ++ .../site/archive/dto/v2/ArchiveDtoV2.kt | 2 +- .../dto/v2/ArchiveLikeListResponseDto.kt | 2 +- .../archive/dto/v2/ArchiveLikeResponseDto.kt | 2 +- .../archive/dto/v2/BannerListResponseDto.kt | 3 ++ .../site/archive/dto/v2/BannerResponseDto.kt | 18 +++++++++ .../site/archive/dto/v2/LikesRequestDto.kt | 2 +- .../dto/v2/MyArchiveListResponseDto.kt | 2 +- .../archive/dto/v2/MyArchiveResponseDto.kt | 2 +- .../dto/v2/NicknameDuplicateResponseDto.kt | 3 ++ .../archive/dto/v2/OAuthLoginRequestDto.kt | 13 +++++++ .../archive/dto/v2/OAuthRegisterRequestDto.kt | 18 +++++++++ .../archive/dto/v2/OAuthUserInfoRequestDto.kt | 16 ++++++++ .../dto/v2/PasswordRegisterRequestDto.kt | 34 ++++++++++++++++ .../archive/dto/v2/ReportCheckResponse.kt | 3 ++ .../site/archive/dto/v2/ReportRequestDto.kt | 3 ++ .../site/archive/dto/v2/UnlikesRequestDto.kt | 3 ++ .../dto/v2/UserNicknameUpdateRequest.kt | 3 ++ .../service/archive/ArchiveServiceTest.java | 2 +- .../archive/web/api/v2/UserControllerV2.java | 2 +- 33 files changed, 129 insertions(+), 185 deletions(-) delete mode 100644 archive-application/src/main/java/site/archive/dto/v2/ArchiveCountResponseDto.java delete mode 100644 archive-application/src/main/java/site/archive/dto/v2/BannerListResponseDto.java delete mode 100644 archive-application/src/main/java/site/archive/dto/v2/BannerResponseDto.java delete mode 100644 archive-application/src/main/java/site/archive/dto/v2/NicknameDuplicateResponseDto.java delete mode 100644 archive-application/src/main/java/site/archive/dto/v2/OAuthLoginRequestDto.java delete mode 100644 archive-application/src/main/java/site/archive/dto/v2/OAuthRegisterRequestDto.java delete mode 100644 archive-application/src/main/java/site/archive/dto/v2/OAuthUserInfoRequestDto.java delete mode 100644 archive-application/src/main/java/site/archive/dto/v2/PasswordRegisterRequestDto.java delete mode 100644 archive-application/src/main/java/site/archive/dto/v2/ReportCheckResponse.java delete mode 100644 archive-application/src/main/java/site/archive/dto/v2/ReportRequestDto.java delete mode 100644 archive-application/src/main/java/site/archive/dto/v2/UnlikesRequestDto.java delete mode 100644 archive-application/src/main/java/site/archive/dto/v2/UserNicknameUpdateRequest.java create mode 100644 archive-application/src/main/kotlin/site/archive/dto/v2/ArchiveCountResponseDto.kt create mode 100644 archive-application/src/main/kotlin/site/archive/dto/v2/BannerListResponseDto.kt create mode 100644 archive-application/src/main/kotlin/site/archive/dto/v2/BannerResponseDto.kt create mode 100644 archive-application/src/main/kotlin/site/archive/dto/v2/NicknameDuplicateResponseDto.kt create mode 100644 archive-application/src/main/kotlin/site/archive/dto/v2/OAuthLoginRequestDto.kt create mode 100644 archive-application/src/main/kotlin/site/archive/dto/v2/OAuthRegisterRequestDto.kt create mode 100644 archive-application/src/main/kotlin/site/archive/dto/v2/OAuthUserInfoRequestDto.kt create mode 100644 archive-application/src/main/kotlin/site/archive/dto/v2/PasswordRegisterRequestDto.kt create mode 100644 archive-application/src/main/kotlin/site/archive/dto/v2/ReportCheckResponse.kt create mode 100644 archive-application/src/main/kotlin/site/archive/dto/v2/ReportRequestDto.kt create mode 100644 archive-application/src/main/kotlin/site/archive/dto/v2/UnlikesRequestDto.kt create mode 100644 archive-application/src/main/kotlin/site/archive/dto/v2/UserNicknameUpdateRequest.kt diff --git a/archive-application/src/main/java/site/archive/dto/v2/ArchiveCountResponseDto.java b/archive-application/src/main/java/site/archive/dto/v2/ArchiveCountResponseDto.java deleted file mode 100644 index f841822..0000000 --- a/archive-application/src/main/java/site/archive/dto/v2/ArchiveCountResponseDto.java +++ /dev/null @@ -1,4 +0,0 @@ -package site.archive.dto.v2; - -public record ArchiveCountResponseDto(Long count) { -} diff --git a/archive-application/src/main/java/site/archive/dto/v2/BannerListResponseDto.java b/archive-application/src/main/java/site/archive/dto/v2/BannerListResponseDto.java deleted file mode 100644 index 250c7a3..0000000 --- a/archive-application/src/main/java/site/archive/dto/v2/BannerListResponseDto.java +++ /dev/null @@ -1,6 +0,0 @@ -package site.archive.dto.v2; - -import java.util.List; - -public record BannerListResponseDto(List banners) { -} diff --git a/archive-application/src/main/java/site/archive/dto/v2/BannerResponseDto.java b/archive-application/src/main/java/site/archive/dto/v2/BannerResponseDto.java deleted file mode 100644 index d33043c..0000000 --- a/archive-application/src/main/java/site/archive/dto/v2/BannerResponseDto.java +++ /dev/null @@ -1,13 +0,0 @@ -package site.archive.dto.v2; - -import site.archive.domain.banner.Banner; - -public record BannerResponseDto(String type, String summaryImage, String mainContent) { - - public static BannerResponseDto from(Banner banner) { - return new BannerResponseDto(banner.getType().toString(), - banner.getSummaryImage(), - banner.getMainContent()); - } - -} diff --git a/archive-application/src/main/java/site/archive/dto/v2/NicknameDuplicateResponseDto.java b/archive-application/src/main/java/site/archive/dto/v2/NicknameDuplicateResponseDto.java deleted file mode 100644 index f54ba1b..0000000 --- a/archive-application/src/main/java/site/archive/dto/v2/NicknameDuplicateResponseDto.java +++ /dev/null @@ -1,4 +0,0 @@ -package site.archive.dto.v2; - -public record NicknameDuplicateResponseDto(boolean isDuplicatedNickname) { -} diff --git a/archive-application/src/main/java/site/archive/dto/v2/OAuthLoginRequestDto.java b/archive-application/src/main/java/site/archive/dto/v2/OAuthLoginRequestDto.java deleted file mode 100644 index 554801c..0000000 --- a/archive-application/src/main/java/site/archive/dto/v2/OAuthLoginRequestDto.java +++ /dev/null @@ -1,22 +0,0 @@ -package site.archive.dto.v2; - -import com.fasterxml.jackson.annotation.JsonProperty; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; - -import jakarta.validation.constraints.NotEmpty; - -@Getter -@NoArgsConstructor -@AllArgsConstructor -public class OAuthLoginRequestDto { - - @NotEmpty(message = "Oauth provider는 필수 값입니다.") - private String provider; - - @NotEmpty(message = "Provider access token은 필수 값입니다.") - @JsonProperty("providerAccessToken") - private String token; - -} \ No newline at end of file diff --git a/archive-application/src/main/java/site/archive/dto/v2/OAuthRegisterRequestDto.java b/archive-application/src/main/java/site/archive/dto/v2/OAuthRegisterRequestDto.java deleted file mode 100644 index c95996e..0000000 --- a/archive-application/src/main/java/site/archive/dto/v2/OAuthRegisterRequestDto.java +++ /dev/null @@ -1,27 +0,0 @@ -package site.archive.dto.v2; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import site.archive.domain.user.BaseUser; -import site.archive.domain.user.OAuthProvider; -import site.archive.domain.user.OAuthUser; -import site.archive.domain.user.UserRole; - -@Getter -@NoArgsConstructor -@AllArgsConstructor -public class OAuthRegisterRequestDto { - - private OAuthProvider provider; - private String email; - private String nickname; - - public BaseUser toUserEntity() { - return new OAuthUser(this.email, - UserRole.GENERAL, - this.provider, - this.nickname); - } - -} \ No newline at end of file diff --git a/archive-application/src/main/java/site/archive/dto/v2/OAuthUserInfoRequestDto.java b/archive-application/src/main/java/site/archive/dto/v2/OAuthUserInfoRequestDto.java deleted file mode 100644 index b4c521a..0000000 --- a/archive-application/src/main/java/site/archive/dto/v2/OAuthUserInfoRequestDto.java +++ /dev/null @@ -1,27 +0,0 @@ -package site.archive.dto.v2; - -import com.fasterxml.jackson.annotation.JsonProperty; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.ToString; - -import jakarta.validation.constraints.NotEmpty; - -@Getter -@ToString -@NoArgsConstructor -@AllArgsConstructor -public class OAuthUserInfoRequestDto { - - @NotEmpty(message = "Oauth provider는 필수 값입니다.") - private String provider; - - @NotEmpty(message = "Provider access token은 필수 값입니다.") - @JsonProperty("providerAccessToken") - private String token; - - @NotEmpty(message = "닉네임은 필수 값입니다.") - private String nickname; - -} \ No newline at end of file diff --git a/archive-application/src/main/java/site/archive/dto/v2/PasswordRegisterRequestDto.java b/archive-application/src/main/java/site/archive/dto/v2/PasswordRegisterRequestDto.java deleted file mode 100644 index 2917795..0000000 --- a/archive-application/src/main/java/site/archive/dto/v2/PasswordRegisterRequestDto.java +++ /dev/null @@ -1,39 +0,0 @@ -package site.archive.dto.v2; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import site.archive.domain.user.BaseUser; -import site.archive.domain.user.PasswordUser; -import site.archive.domain.user.UserRole; - -import jakarta.validation.constraints.Email; -import jakarta.validation.constraints.NotEmpty; -import jakarta.validation.constraints.Pattern; - -@Getter -@NoArgsConstructor -@AllArgsConstructor -public class PasswordRegisterRequestDto { - - @NotEmpty(message = "이메일은 필수 값입니다.") - @Email(message = "올바른 이메일을 입력해 주세요.") - private String email; - - @NotEmpty(message = "패스워드는 필수 값입니다.") - @Pattern(regexp = "(?=.*[a-zA-Z])(?=.*[0-9])[a-zA-Z0-9@$!%*#?&]{8,20}$", - message = "비밀번호는 영문/숫자 를 꼭 포함하여 8~20자리로 입력해 주세요.") - private String password; - - @NotEmpty(message = "닉네임은 필수 값입니다.") - private String nickname; - - public BaseUser toUserEntity() { - return new PasswordUser(this.email, UserRole.GENERAL, this.password, this.nickname); - } - - public void updatePasswordToEncrypt(String encryptPassword) { - this.password = encryptPassword; - } - -} diff --git a/archive-application/src/main/java/site/archive/dto/v2/ReportCheckResponse.java b/archive-application/src/main/java/site/archive/dto/v2/ReportCheckResponse.java deleted file mode 100644 index c5e3b8b..0000000 --- a/archive-application/src/main/java/site/archive/dto/v2/ReportCheckResponse.java +++ /dev/null @@ -1,4 +0,0 @@ -package site.archive.dto.v2; - -public record ReportCheckResponse(Boolean isReported) { -} diff --git a/archive-application/src/main/java/site/archive/dto/v2/ReportRequestDto.java b/archive-application/src/main/java/site/archive/dto/v2/ReportRequestDto.java deleted file mode 100644 index cd26249..0000000 --- a/archive-application/src/main/java/site/archive/dto/v2/ReportRequestDto.java +++ /dev/null @@ -1,12 +0,0 @@ -package site.archive.dto.v2; - -import lombok.Getter; -import lombok.NoArgsConstructor; - -@NoArgsConstructor -@Getter -public class ReportRequestDto { - - private String reason; - -} diff --git a/archive-application/src/main/java/site/archive/dto/v2/UnlikesRequestDto.java b/archive-application/src/main/java/site/archive/dto/v2/UnlikesRequestDto.java deleted file mode 100644 index b4cb69f..0000000 --- a/archive-application/src/main/java/site/archive/dto/v2/UnlikesRequestDto.java +++ /dev/null @@ -1,14 +0,0 @@ -package site.archive.dto.v2; - -import lombok.Getter; -import lombok.NoArgsConstructor; - -import java.util.List; - -@NoArgsConstructor -@Getter -public class UnlikesRequestDto { - - private List archiveIds; - -} diff --git a/archive-application/src/main/java/site/archive/dto/v2/UserNicknameUpdateRequest.java b/archive-application/src/main/java/site/archive/dto/v2/UserNicknameUpdateRequest.java deleted file mode 100644 index 852fac4..0000000 --- a/archive-application/src/main/java/site/archive/dto/v2/UserNicknameUpdateRequest.java +++ /dev/null @@ -1,4 +0,0 @@ -package site.archive.dto.v2; - -public record UserNicknameUpdateRequest(String nickname) { -} diff --git a/archive-application/src/main/kotlin/site/archive/dto/v2/ArchiveCommunityResponseDto.kt b/archive-application/src/main/kotlin/site/archive/dto/v2/ArchiveCommunityResponseDto.kt index de7313d..2dff1ed 100644 --- a/archive-application/src/main/kotlin/site/archive/dto/v2/ArchiveCommunityResponseDto.kt +++ b/archive-application/src/main/kotlin/site/archive/dto/v2/ArchiveCommunityResponseDto.kt @@ -5,7 +5,7 @@ import site.archive.domain.archive.Archive import site.archive.domain.archive.CoverImageType import site.archive.domain.archive.Emotion -class ArchiveCommunityResponseDto( +data class ArchiveCommunityResponseDto( val archiveId: Long, val name: String, val watchedOn: String, diff --git a/archive-application/src/main/kotlin/site/archive/dto/v2/ArchiveCountResponseDto.kt b/archive-application/src/main/kotlin/site/archive/dto/v2/ArchiveCountResponseDto.kt new file mode 100644 index 0000000..42525ac --- /dev/null +++ b/archive-application/src/main/kotlin/site/archive/dto/v2/ArchiveCountResponseDto.kt @@ -0,0 +1,3 @@ +package site.archive.dto.v2 + +data class ArchiveCountResponseDto(val count: Long) \ No newline at end of file diff --git a/archive-application/src/main/kotlin/site/archive/dto/v2/ArchiveDtoV2.kt b/archive-application/src/main/kotlin/site/archive/dto/v2/ArchiveDtoV2.kt index a156d83..561e892 100644 --- a/archive-application/src/main/kotlin/site/archive/dto/v2/ArchiveDtoV2.kt +++ b/archive-application/src/main/kotlin/site/archive/dto/v2/ArchiveDtoV2.kt @@ -8,7 +8,7 @@ import site.archive.domain.archive.Emotion import site.archive.dto.v1.archive.ArchiveImageDtoV1 @JsonInclude(JsonInclude.Include.NON_NULL) -class ArchiveDtoV2( +data class ArchiveDtoV2( val archiveId: Long, val name: String, val watchedOn: String, diff --git a/archive-application/src/main/kotlin/site/archive/dto/v2/ArchiveLikeListResponseDto.kt b/archive-application/src/main/kotlin/site/archive/dto/v2/ArchiveLikeListResponseDto.kt index 3f10833..90bb670 100644 --- a/archive-application/src/main/kotlin/site/archive/dto/v2/ArchiveLikeListResponseDto.kt +++ b/archive-application/src/main/kotlin/site/archive/dto/v2/ArchiveLikeListResponseDto.kt @@ -1,3 +1,3 @@ package site.archive.dto.v2 -class ArchiveLikeListResponseDto(val archiveCount: Int, val archives: List) \ No newline at end of file +data class ArchiveLikeListResponseDto(val archiveCount: Int, val archives: List) \ No newline at end of file diff --git a/archive-application/src/main/kotlin/site/archive/dto/v2/ArchiveLikeResponseDto.kt b/archive-application/src/main/kotlin/site/archive/dto/v2/ArchiveLikeResponseDto.kt index d744ffb..7408dac 100644 --- a/archive-application/src/main/kotlin/site/archive/dto/v2/ArchiveLikeResponseDto.kt +++ b/archive-application/src/main/kotlin/site/archive/dto/v2/ArchiveLikeResponseDto.kt @@ -5,7 +5,7 @@ import site.archive.domain.archive.Archive import site.archive.domain.archive.CoverImageType import site.archive.domain.archive.Emotion -class ArchiveLikeResponseDto( +data class ArchiveLikeResponseDto( val archiveId: Long, val name: String, val watchedOn: String, diff --git a/archive-application/src/main/kotlin/site/archive/dto/v2/BannerListResponseDto.kt b/archive-application/src/main/kotlin/site/archive/dto/v2/BannerListResponseDto.kt new file mode 100644 index 0000000..8f62a97 --- /dev/null +++ b/archive-application/src/main/kotlin/site/archive/dto/v2/BannerListResponseDto.kt @@ -0,0 +1,3 @@ +package site.archive.dto.v2 + +data class BannerListResponseDto(val banners: List) \ No newline at end of file diff --git a/archive-application/src/main/kotlin/site/archive/dto/v2/BannerResponseDto.kt b/archive-application/src/main/kotlin/site/archive/dto/v2/BannerResponseDto.kt new file mode 100644 index 0000000..c170dad --- /dev/null +++ b/archive-application/src/main/kotlin/site/archive/dto/v2/BannerResponseDto.kt @@ -0,0 +1,18 @@ +package site.archive.dto.v2 + +import site.archive.domain.banner.Banner + +data class BannerResponseDto(val type: String, val summaryImage: String, val mainContent: String) { + + companion object { + @JvmStatic + fun from(banner: Banner): BannerResponseDto { + return BannerResponseDto( + banner.type.toString(), + banner.summaryImage, + banner.mainContent + ) + } + } + +} \ No newline at end of file diff --git a/archive-application/src/main/kotlin/site/archive/dto/v2/LikesRequestDto.kt b/archive-application/src/main/kotlin/site/archive/dto/v2/LikesRequestDto.kt index f8a92eb..d84a356 100644 --- a/archive-application/src/main/kotlin/site/archive/dto/v2/LikesRequestDto.kt +++ b/archive-application/src/main/kotlin/site/archive/dto/v2/LikesRequestDto.kt @@ -1,3 +1,3 @@ package site.archive.dto.v2 -class LikesRequestDto(val archiveIds: List) \ No newline at end of file +data class LikesRequestDto(val archiveIds: List) \ No newline at end of file diff --git a/archive-application/src/main/kotlin/site/archive/dto/v2/MyArchiveListResponseDto.kt b/archive-application/src/main/kotlin/site/archive/dto/v2/MyArchiveListResponseDto.kt index cd9e381..e2e660c 100644 --- a/archive-application/src/main/kotlin/site/archive/dto/v2/MyArchiveListResponseDto.kt +++ b/archive-application/src/main/kotlin/site/archive/dto/v2/MyArchiveListResponseDto.kt @@ -1,6 +1,6 @@ package site.archive.dto.v2 -class MyArchiveListResponseDto( +data class MyArchiveListResponseDto( val archiveCount: Long, val archives: List ) { diff --git a/archive-application/src/main/kotlin/site/archive/dto/v2/MyArchiveResponseDto.kt b/archive-application/src/main/kotlin/site/archive/dto/v2/MyArchiveResponseDto.kt index 5b9d8cc..788d052 100644 --- a/archive-application/src/main/kotlin/site/archive/dto/v2/MyArchiveResponseDto.kt +++ b/archive-application/src/main/kotlin/site/archive/dto/v2/MyArchiveResponseDto.kt @@ -5,7 +5,7 @@ import site.archive.domain.archive.Archive import site.archive.domain.archive.CoverImageType import site.archive.domain.archive.Emotion -class MyArchiveResponseDto( +data class MyArchiveResponseDto( val archiveId: Long, val name: String, val watchedOn: String, diff --git a/archive-application/src/main/kotlin/site/archive/dto/v2/NicknameDuplicateResponseDto.kt b/archive-application/src/main/kotlin/site/archive/dto/v2/NicknameDuplicateResponseDto.kt new file mode 100644 index 0000000..60e5bf5 --- /dev/null +++ b/archive-application/src/main/kotlin/site/archive/dto/v2/NicknameDuplicateResponseDto.kt @@ -0,0 +1,3 @@ +package site.archive.dto.v2 + +data class NicknameDuplicateResponseDto(val isDuplicatedNickname: Boolean) diff --git a/archive-application/src/main/kotlin/site/archive/dto/v2/OAuthLoginRequestDto.kt b/archive-application/src/main/kotlin/site/archive/dto/v2/OAuthLoginRequestDto.kt new file mode 100644 index 0000000..7d818af --- /dev/null +++ b/archive-application/src/main/kotlin/site/archive/dto/v2/OAuthLoginRequestDto.kt @@ -0,0 +1,13 @@ +package site.archive.dto.v2 + +import com.fasterxml.jackson.annotation.JsonProperty +import jakarta.validation.constraints.NotBlank + +data class OAuthLoginRequestDto( + @NotBlank(message = "Oauth provider는 필수 값입니다.") + val provider: String, + + @NotBlank(message = "Provider access token은 필수 값입니다.") + @JsonProperty("providerAccessToken") + val token: String +) \ No newline at end of file diff --git a/archive-application/src/main/kotlin/site/archive/dto/v2/OAuthRegisterRequestDto.kt b/archive-application/src/main/kotlin/site/archive/dto/v2/OAuthRegisterRequestDto.kt new file mode 100644 index 0000000..19f5c48 --- /dev/null +++ b/archive-application/src/main/kotlin/site/archive/dto/v2/OAuthRegisterRequestDto.kt @@ -0,0 +1,18 @@ +package site.archive.dto.v2 + +import site.archive.domain.user.BaseUser +import site.archive.domain.user.OAuthProvider +import site.archive.domain.user.OAuthUser +import site.archive.domain.user.UserRole + +data class OAuthRegisterRequestDto( + val provider: OAuthProvider, + val email: String, + val nickname: String +) { + + fun toUserEntity(): BaseUser { + return OAuthUser(email, UserRole.GENERAL, provider, nickname) + } + +} \ No newline at end of file diff --git a/archive-application/src/main/kotlin/site/archive/dto/v2/OAuthUserInfoRequestDto.kt b/archive-application/src/main/kotlin/site/archive/dto/v2/OAuthUserInfoRequestDto.kt new file mode 100644 index 0000000..d0829c4 --- /dev/null +++ b/archive-application/src/main/kotlin/site/archive/dto/v2/OAuthUserInfoRequestDto.kt @@ -0,0 +1,16 @@ +package site.archive.dto.v2 + +import com.fasterxml.jackson.annotation.JsonProperty +import jakarta.validation.constraints.NotBlank + +data class OAuthUserInfoRequestDto( + @NotBlank(message = "Oauth provider는 필수 값입니다.") + val provider: String, + + @NotBlank(message = "Provider access token은 필수 값입니다.") + @JsonProperty("providerAccessToken") + val token: String, + + @NotBlank(message = "닉네임은 필수 값입니다.") + val nickname: String +) \ No newline at end of file diff --git a/archive-application/src/main/kotlin/site/archive/dto/v2/PasswordRegisterRequestDto.kt b/archive-application/src/main/kotlin/site/archive/dto/v2/PasswordRegisterRequestDto.kt new file mode 100644 index 0000000..dfd7830 --- /dev/null +++ b/archive-application/src/main/kotlin/site/archive/dto/v2/PasswordRegisterRequestDto.kt @@ -0,0 +1,34 @@ +package site.archive.dto.v2 + +import jakarta.validation.constraints.Email +import jakarta.validation.constraints.NotBlank +import jakarta.validation.constraints.Pattern +import site.archive.domain.user.BaseUser +import site.archive.domain.user.PasswordUser +import site.archive.domain.user.UserRole + +data class PasswordRegisterRequestDto( + @NotBlank(message = "이메일은 필수 값입니다.") + @Email(message = "올바른 이메일을 입력해 주세요.") + val email: String, + + @NotBlank(message = "닉네임은 필수 값입니다.") + val nickname: String, + + @NotBlank(message = "패스워드는 필수 값입니다.") + @Pattern( + regexp = "(?=.*[a-zA-Z])(?=.*\\d)[a-zA-Z\\d@$!%*#?&]{8,20}$", + message = "비밀번호는 영문/숫자 를 꼭 포함하여 8~20자리로 입력해 주세요." + ) + var password: String +) { + + fun toUserEntity(): BaseUser { + return PasswordUser(email, UserRole.GENERAL, password, nickname) + } + + fun updatePasswordToEncrypt(encryptPassword: String) { + password = encryptPassword + } + +} \ No newline at end of file diff --git a/archive-application/src/main/kotlin/site/archive/dto/v2/ReportCheckResponse.kt b/archive-application/src/main/kotlin/site/archive/dto/v2/ReportCheckResponse.kt new file mode 100644 index 0000000..07d3996 --- /dev/null +++ b/archive-application/src/main/kotlin/site/archive/dto/v2/ReportCheckResponse.kt @@ -0,0 +1,3 @@ +package site.archive.dto.v2 + +data class ReportCheckResponse(val isReported: Boolean) \ No newline at end of file diff --git a/archive-application/src/main/kotlin/site/archive/dto/v2/ReportRequestDto.kt b/archive-application/src/main/kotlin/site/archive/dto/v2/ReportRequestDto.kt new file mode 100644 index 0000000..adfe5b0 --- /dev/null +++ b/archive-application/src/main/kotlin/site/archive/dto/v2/ReportRequestDto.kt @@ -0,0 +1,3 @@ +package site.archive.dto.v2 + +data class ReportRequestDto(val reason: String) \ No newline at end of file diff --git a/archive-application/src/main/kotlin/site/archive/dto/v2/UnlikesRequestDto.kt b/archive-application/src/main/kotlin/site/archive/dto/v2/UnlikesRequestDto.kt new file mode 100644 index 0000000..77b7468 --- /dev/null +++ b/archive-application/src/main/kotlin/site/archive/dto/v2/UnlikesRequestDto.kt @@ -0,0 +1,3 @@ +package site.archive.dto.v2 + +data class UnlikesRequestDto(val archiveIds: List) \ No newline at end of file diff --git a/archive-application/src/main/kotlin/site/archive/dto/v2/UserNicknameUpdateRequest.kt b/archive-application/src/main/kotlin/site/archive/dto/v2/UserNicknameUpdateRequest.kt new file mode 100644 index 0000000..1620bbe --- /dev/null +++ b/archive-application/src/main/kotlin/site/archive/dto/v2/UserNicknameUpdateRequest.kt @@ -0,0 +1,3 @@ +package site.archive.dto.v2 + +data class UserNicknameUpdateRequest(val nickname: String) \ No newline at end of file diff --git a/archive-application/src/test/java/site/archive/service/archive/ArchiveServiceTest.java b/archive-application/src/test/java/site/archive/service/archive/ArchiveServiceTest.java index 4ec4934..7574119 100644 --- a/archive-application/src/test/java/site/archive/service/archive/ArchiveServiceTest.java +++ b/archive-application/src/test/java/site/archive/service/archive/ArchiveServiceTest.java @@ -113,7 +113,7 @@ void canViewOnlyPublicArchiveWhenOtherArchive() { assertThat(allArchives.getArchiveCount()).isEqualTo(archivePublicCount); allArchives.getArchives() .forEach(archiveDto -> { - assertThat(archiveDto.getIsPublic()).isTrue(); + assertThat(archiveDto.isPublic()).isTrue(); assertThat(archiveDto.getAuthorId()).isEqualTo(USER_ID); }); } diff --git a/archive-web/src/main/java/site/archive/web/api/v2/UserControllerV2.java b/archive-web/src/main/java/site/archive/web/api/v2/UserControllerV2.java index fc39e3d..d1ed0f9 100644 --- a/archive-web/src/main/java/site/archive/web/api/v2/UserControllerV2.java +++ b/archive-web/src/main/java/site/archive/web/api/v2/UserControllerV2.java @@ -38,7 +38,7 @@ public ResponseEntity checkDuplicatedNickname(@Req @PutMapping("/nickname") public ResponseEntity updateProfileNickname(@RequestUser UserInfo user, @RequestBody UserNicknameUpdateRequest request) { - userService.updateUserNickname(user.getUserId(), request.nickname()); + userService.updateUserNickname(user.getUserId(), request.getNickname()); return ResponseEntity.noContent().build(); } From 1244b2fafdc8bdb16b0d8c069fb6c401c6379644 Mon Sep 17 00:00:00 2001 From: KimDoubleB Date: Sun, 22 Jan 2023 02:10:21 +0900 Subject: [PATCH 32/46] feat(#53): converted Like Service java to kotlin --- .../archive/service/like/LikeService.java | 57 ------------------- .../site/archive/service/like/LikeService.kt | 49 ++++++++++++++++ 2 files changed, 49 insertions(+), 57 deletions(-) delete mode 100644 archive-application/src/main/java/site/archive/service/like/LikeService.java create mode 100644 archive-application/src/main/kotlin/site/archive/service/like/LikeService.kt diff --git a/archive-application/src/main/java/site/archive/service/like/LikeService.java b/archive-application/src/main/java/site/archive/service/like/LikeService.java deleted file mode 100644 index cdb2df8..0000000 --- a/archive-application/src/main/java/site/archive/service/like/LikeService.java +++ /dev/null @@ -1,57 +0,0 @@ -package site.archive.service.like; - -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import site.archive.common.exception.common.ResourceNotFoundException; -import site.archive.domain.common.BaseTimeEntity; -import site.archive.domain.like.Like; -import site.archive.domain.like.LikeRepository; - -import java.util.List; - -@Service -@Transactional(readOnly = true) -@RequiredArgsConstructor -public class LikeService { - - private final LikeRepository likeRepository; - - @Transactional - public void save(Long userId, Long archiveId) { - likeRepository.findByUserIdAndArchiveId(userId, archiveId) - .ifPresentOrElse(BaseTimeEntity::softDeleteCancel, - () -> likeRepository.save(Like.of(userId, archiveId))); - } - - @Transactional - public void save(Long userId, List archiveIds) { - archiveIds.forEach(archiveId -> likeRepository.findByUserIdAndArchiveId(userId, archiveId) - .ifPresentOrElse(BaseTimeEntity::softDeleteCancel, - () -> likeRepository.save(Like.of(userId, archiveId)))); - } - - @Transactional - public void delete(Long userId, Long archiveId) { - likeRepository.findByUserIdAndArchiveId(userId, archiveId) - .ifPresentOrElse(likeRepository::delete, - () -> {throw new ResourceNotFoundException("조건에 맞는 Like 데이터가 없습니다");}); - } - - @Transactional - public void delete(Long userId, List archiveIds) { - archiveIds.forEach(archiveId -> likeRepository.findByUserIdAndArchiveId(userId, archiveId) - .ifPresentOrElse(likeRepository::delete, - () -> { - throw new ResourceNotFoundException("조건에 맞는 Like 데이터가 없습니다"); - })); - } - - public List likeArchiveIds(Long userId) { - return likeRepository.findAllByUserId(userId).stream() - .filter(like -> !like.getIsDeleted()) - .map(like -> like.getArchive().getId()) - .toList(); - } - -} diff --git a/archive-application/src/main/kotlin/site/archive/service/like/LikeService.kt b/archive-application/src/main/kotlin/site/archive/service/like/LikeService.kt new file mode 100644 index 0000000..59a35a0 --- /dev/null +++ b/archive-application/src/main/kotlin/site/archive/service/like/LikeService.kt @@ -0,0 +1,49 @@ +package site.archive.service.like + +import org.springframework.stereotype.Service +import org.springframework.transaction.annotation.Transactional +import site.archive.common.exception.common.ResourceNotFoundException +import site.archive.domain.common.BaseTimeEntity +import site.archive.domain.like.Like +import site.archive.domain.like.LikeRepository + +@Service +@Transactional(readOnly = true) +class LikeService(private val likeRepository: LikeRepository) { + + @Transactional + fun save(userId: Long, archiveId: Long) { + likeRepository.findByUserIdAndArchiveId(userId, archiveId) + .ifPresentOrElse(BaseTimeEntity::softDeleteCancel) { likeRepository.save(Like.of(userId, archiveId)) } + } + + @Transactional + fun save(userId: Long, archiveIds: List) { + archiveIds.forEach { + likeRepository.findByUserIdAndArchiveId(userId, it) + .ifPresentOrElse(BaseTimeEntity::softDeleteCancel) { likeRepository.save(Like.of(userId, it)) } + } + } + + @Transactional + fun delete(userId: Long, archiveId: Long) { + likeRepository.findByUserIdAndArchiveId(userId, archiveId) + .ifPresentOrElse(likeRepository::delete) { throw ResourceNotFoundException("조건에 맞는 Like 데이터가 없습니다") } + } + + @Transactional + fun delete(userId: Long, archiveIds: List) { + archiveIds.forEach { + likeRepository.findByUserIdAndArchiveId(userId, it) + .ifPresentOrElse(likeRepository::delete) { throw ResourceNotFoundException("조건에 맞는 Like 데이터가 없습니다") } + } + } + + fun likeArchiveIds(userId: Long): List { + return likeRepository.findAllByUserId(userId) + .filter { !it.isDeleted } + .map { it.archive.id } + .toList() + } + +} \ No newline at end of file From a9e0a42dab5efd1cfb94a38d771aa72c948bf919 Mon Sep 17 00:00:00 2001 From: KimDoubleB Date: Sun, 22 Jan 2023 02:10:28 +0900 Subject: [PATCH 33/46] feat(#53): converted Report Service java to kotlin --- .../archive/service/report/ReportService.java | 37 ------------------- .../archive/service/report/ReportService.kt | 33 +++++++++++++++++ 2 files changed, 33 insertions(+), 37 deletions(-) delete mode 100644 archive-application/src/main/java/site/archive/service/report/ReportService.java create mode 100644 archive-application/src/main/kotlin/site/archive/service/report/ReportService.kt diff --git a/archive-application/src/main/java/site/archive/service/report/ReportService.java b/archive-application/src/main/java/site/archive/service/report/ReportService.java deleted file mode 100644 index f58c55e..0000000 --- a/archive-application/src/main/java/site/archive/service/report/ReportService.java +++ /dev/null @@ -1,37 +0,0 @@ -package site.archive.service.report; - -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; -import site.archive.domain.common.BaseTimeEntity; -import site.archive.domain.report.Report; -import site.archive.domain.report.ReportRepository; - -import jakarta.transaction.Transactional; - -@Service -@RequiredArgsConstructor -public class ReportService { - - private final ReportRepository reportRepository; - - public boolean isReportedBy(Long archiveId, Long userId) { - return reportRepository.findByArchiveIdAndUserId(archiveId, userId) - .filter(report -> !report.getIsDeleted()) - .isPresent(); - } - - @Transactional - public void reportArchive(Long archiveId, Long userId, String reason) { - var report = reportRepository.findByArchiveIdAndUserId(archiveId, userId) - .orElseGet(() -> Report.of(reason, archiveId, userId)); - report.softDeleteCancel(); - reportRepository.save(report); - } - - @Transactional - public void cancelReportArchive(Long archiveId, Long userId) { - reportRepository.findByArchiveIdAndUserId(archiveId, userId) - .ifPresent(BaseTimeEntity::softDelete); - } - -} diff --git a/archive-application/src/main/kotlin/site/archive/service/report/ReportService.kt b/archive-application/src/main/kotlin/site/archive/service/report/ReportService.kt new file mode 100644 index 0000000..40251d6 --- /dev/null +++ b/archive-application/src/main/kotlin/site/archive/service/report/ReportService.kt @@ -0,0 +1,33 @@ +package site.archive.service.report + +import org.springframework.stereotype.Service +import org.springframework.transaction.annotation.Transactional +import site.archive.domain.common.BaseTimeEntity +import site.archive.domain.report.Report +import site.archive.domain.report.ReportRepository + +@Service +@Transactional(readOnly = true) +class ReportService(private val reportRepository: ReportRepository) { + + fun isReportedBy(archiveId: Long, userId: Long): Boolean { + return reportRepository.findByArchiveIdAndUserId(archiveId, userId) + .filter { !it.isDeleted } + .isPresent + } + + @Transactional + fun reportArchive(archiveId: Long, userId: Long, reason: String) { + val report = reportRepository.findByArchiveIdAndUserId(archiveId, userId) + .orElseGet { Report.of(reason, archiveId, userId) } + report.softDeleteCancel() + reportRepository.save(report) + } + + @Transactional + fun cancelReportArchive(archiveId: Long, userId: Long) { + reportRepository.findByArchiveIdAndUserId(archiveId, userId) + .ifPresent(BaseTimeEntity::softDelete) + } + +} \ No newline at end of file From 3567db54e04ecc0ff27ec69cd7c83a1eaa37c4cd Mon Sep 17 00:00:00 2001 From: KimDoubleB Date: Sun, 22 Jan 2023 02:11:38 +0900 Subject: [PATCH 34/46] feat(#53): set logging level of hibernate for logging query - temporary because Spring Boot DataSource Decorator (net.ttddyy.dsproxy.listener) is not working at Spring boot 3.0 --- archive-web/src/main/resources/logback-spring.xml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/archive-web/src/main/resources/logback-spring.xml b/archive-web/src/main/resources/logback-spring.xml index dd6dbba..e3d38da 100644 --- a/archive-web/src/main/resources/logback-spring.xml +++ b/archive-web/src/main/resources/logback-spring.xml @@ -88,12 +88,23 @@ + + + + + + + + + + + From d15f2584dbe92204d462dfae7a1af3fc1e76e4d3 Mon Sep 17 00:00:00 2001 From: KimDoubleB Date: Sun, 22 Jan 2023 13:41:39 +0900 Subject: [PATCH 35/46] feat(#53): converted banner service classes java to kotlin --- .../archive/service/banner/BannerService.java | 39 ------------------- .../archive/service/banner/BannerService.kt | 33 ++++++++++++++++ 2 files changed, 33 insertions(+), 39 deletions(-) delete mode 100644 archive-application/src/main/java/site/archive/service/banner/BannerService.java create mode 100644 archive-application/src/main/kotlin/site/archive/service/banner/BannerService.kt diff --git a/archive-application/src/main/java/site/archive/service/banner/BannerService.java b/archive-application/src/main/java/site/archive/service/banner/BannerService.java deleted file mode 100644 index b558415..0000000 --- a/archive-application/src/main/java/site/archive/service/banner/BannerService.java +++ /dev/null @@ -1,39 +0,0 @@ -package site.archive.service.banner; - -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import site.archive.domain.banner.Banner; -import site.archive.domain.banner.BannerRepository; -import site.archive.domain.banner.BannerType; -import site.archive.dto.v2.BannerListResponseDto; -import site.archive.dto.v2.BannerResponseDto; - -@Service -@Transactional(readOnly = true) -@RequiredArgsConstructor -public class BannerService { - - private final BannerRepository bannerRepository; - - public BannerListResponseDto getAllBanner() { - var bannerResponse = bannerRepository.findAllByOrderByCreatedAtDesc().stream() - .map(banner -> new BannerResponseDto(banner.getType().toString(), - banner.getSummaryImage(), - banner.getMainContent())) - .toList(); - return new BannerListResponseDto(bannerResponse); - } - - @Transactional - public BannerResponseDto createBanner(String summaryImageUri, String mainContent, BannerType type) { - var banner = bannerRepository.save(new Banner(summaryImageUri, mainContent, type)); - return BannerResponseDto.from(banner); - } - - @Transactional - public void deleteBanner(Long bannerId) { - bannerRepository.deleteById(bannerId); - } - -} diff --git a/archive-application/src/main/kotlin/site/archive/service/banner/BannerService.kt b/archive-application/src/main/kotlin/site/archive/service/banner/BannerService.kt new file mode 100644 index 0000000..197fdbf --- /dev/null +++ b/archive-application/src/main/kotlin/site/archive/service/banner/BannerService.kt @@ -0,0 +1,33 @@ +package site.archive.service.banner + +import org.springframework.stereotype.Service +import org.springframework.transaction.annotation.Transactional +import site.archive.domain.banner.Banner +import site.archive.domain.banner.BannerRepository +import site.archive.domain.banner.BannerType +import site.archive.dto.v2.BannerListResponseDto +import site.archive.dto.v2.BannerResponseDto + +@Service +@Transactional(readOnly = true) +class BannerService(val bannerRepository: BannerRepository) { + + fun getAllBanner(): BannerListResponseDto { + val bannerResponse = bannerRepository.findAllByOrderByCreatedAtDesc() + .map { BannerResponseDto(it.type.toString(), it.summaryImage, it.mainContent) } + .toList() + return BannerListResponseDto(bannerResponse) + } + + @Transactional + fun createBanner(summaryImageUri: String, mainContent: String, type: BannerType): BannerResponseDto { + val banner = bannerRepository.save(Banner(summaryImageUri, mainContent, type)) + return BannerResponseDto.from(banner) + } + + @Transactional + fun deleteBanner(bannerId: Long) { + bannerRepository.deleteById(bannerId) + } + +} \ No newline at end of file From 7ad0d73e0dd96edaf58c9a5dc983403ff6a2e80f Mon Sep 17 00:00:00 2001 From: KimDoubleB Date: Sun, 22 Jan 2023 13:41:47 +0900 Subject: [PATCH 36/46] feat(#53): converted messaging service classes java to kotlin --- .../site/archive/service/message/MessagingService.java | 9 --------- .../site/archive/service/message/MessagingService.kt | 9 +++++++++ 2 files changed, 9 insertions(+), 9 deletions(-) delete mode 100644 archive-application/src/main/java/site/archive/service/message/MessagingService.java create mode 100644 archive-application/src/main/kotlin/site/archive/service/message/MessagingService.kt diff --git a/archive-application/src/main/java/site/archive/service/message/MessagingService.java b/archive-application/src/main/java/site/archive/service/message/MessagingService.java deleted file mode 100644 index f2241de..0000000 --- a/archive-application/src/main/java/site/archive/service/message/MessagingService.java +++ /dev/null @@ -1,9 +0,0 @@ -package site.archive.service.message; - -import site.archive.dto.v1.user.BaseUserDtoV1; - -public interface MessagingService { - - void sendUserRegisterMessage(BaseUserDtoV1 user, String registerType); - -} diff --git a/archive-application/src/main/kotlin/site/archive/service/message/MessagingService.kt b/archive-application/src/main/kotlin/site/archive/service/message/MessagingService.kt new file mode 100644 index 0000000..5cf3946 --- /dev/null +++ b/archive-application/src/main/kotlin/site/archive/service/message/MessagingService.kt @@ -0,0 +1,9 @@ +package site.archive.service.message + +import site.archive.dto.v1.user.BaseUserDtoV1 + +interface MessagingService { + + fun sendUserRegisterMessage(user: BaseUserDtoV1, registerType: String) + +} \ No newline at end of file From 0e3c52a3b2e4dcdf22e07246770eda302b5bc7dc Mon Sep 17 00:00:00 2001 From: KimDoubleB Date: Sun, 22 Jan 2023 14:35:41 +0900 Subject: [PATCH 37/46] feat(#53): converted user service classes java to kotlin --- .../archive/service/user/UserAuthService.java | 83 ------------------- .../service/user/UserProfileImageService.java | 20 ----- .../service/user/UserRegisterServiceV1.java | 58 ------------- .../service/user/UserRegisterServiceV2.java | 47 ----------- .../archive/service/user/UserService.java | 60 -------------- .../archive/service/user/UserAuthService.kt | 78 +++++++++++++++++ .../service/user/UserProfileImageService.kt | 16 ++++ .../service/user/UserRegisterServiceV1.kt | 59 +++++++++++++ .../service/user/UserRegisterServiceV2.kt | 47 +++++++++++ .../site/archive/service/user/UserService.kt | 58 +++++++++++++ 10 files changed, 258 insertions(+), 268 deletions(-) delete mode 100644 archive-application/src/main/java/site/archive/service/user/UserAuthService.java delete mode 100644 archive-application/src/main/java/site/archive/service/user/UserProfileImageService.java delete mode 100644 archive-application/src/main/java/site/archive/service/user/UserRegisterServiceV1.java delete mode 100644 archive-application/src/main/java/site/archive/service/user/UserRegisterServiceV2.java delete mode 100644 archive-application/src/main/java/site/archive/service/user/UserService.java create mode 100644 archive-application/src/main/kotlin/site/archive/service/user/UserAuthService.kt create mode 100644 archive-application/src/main/kotlin/site/archive/service/user/UserProfileImageService.kt create mode 100644 archive-application/src/main/kotlin/site/archive/service/user/UserRegisterServiceV1.kt create mode 100644 archive-application/src/main/kotlin/site/archive/service/user/UserRegisterServiceV2.kt create mode 100644 archive-application/src/main/kotlin/site/archive/service/user/UserService.kt diff --git a/archive-application/src/main/java/site/archive/service/user/UserAuthService.java b/archive-application/src/main/java/site/archive/service/user/UserAuthService.java deleted file mode 100644 index cf37cd5..0000000 --- a/archive-application/src/main/java/site/archive/service/user/UserAuthService.java +++ /dev/null @@ -1,83 +0,0 @@ -package site.archive.service.user; - -import lombok.RequiredArgsConstructor; -import org.springframework.security.crypto.password.PasswordEncoder; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import site.archive.common.exception.common.ResourceNotFoundException; -import site.archive.common.exception.common.UnauthorizedResourceException; -import site.archive.common.exception.user.LoginFailException; -import site.archive.common.exception.user.OAuthUserHasNotPasswordException; -import site.archive.domain.user.BaseUser; -import site.archive.domain.user.PasswordUser; -import site.archive.domain.user.PasswordUserRepository; -import site.archive.domain.user.UserInfo; -import site.archive.domain.user.UserRepository; -import site.archive.dto.v1.auth.LoginCommandV1; -import site.archive.dto.v1.user.UserPasswordResetRequestDtoV1; -import site.archive.infra.mail.MailService; - -import java.util.Objects; - -@Service -@Transactional(readOnly = true) -@RequiredArgsConstructor -public class UserAuthService { - - private final UserRepository userRepository; - private final PasswordUserRepository passwordUserRepository; - private final PasswordEncoder encoder; - private final MailService mailService; - - public UserInfo tryLoginAndReturnInfo(LoginCommandV1 command) throws LoginFailException { - var user = verifyPasswordReturnUser(command.getEmail(), command.getPassword()); - return user.convertToUserInfo(); - } - - @Transactional - public void updateTemporaryPassword(final String email, final String temporaryPassword) { - var passwordUser = userRepository.findByMailAddress(email) - .map(this::convertPasswordUser) - .orElseThrow(() -> new ResourceNotFoundException("Email")); - passwordUser.updatePassword(encoder.encode(temporaryPassword), true); - mailService.sendTemporaryPassword(email, temporaryPassword); - } - - @Transactional - public void resetPassword(UserInfo userInfo, UserPasswordResetRequestDtoV1 userPasswordResetRequestDtoV1) { - if (!Objects.equals(userInfo.getMailAddress(), userPasswordResetRequestDtoV1.getEmail())) { - throw new UnauthorizedResourceException("해당 이메일에 대한 비밀번호 초기화 권한이 없습니다."); - } - this.resetPassword(userPasswordResetRequestDtoV1); - } - - @Transactional - public void resetPassword(UserPasswordResetRequestDtoV1 userPasswordResetRequestDtoV1) { - var passwordUser = verifyPasswordReturnUser( - userPasswordResetRequestDtoV1.getEmail(), userPasswordResetRequestDtoV1.getCurrentPassword()); - passwordUser.updatePassword(encoder.encode(userPasswordResetRequestDtoV1.getNewPassword()), false); - } - - public boolean isTemporaryPasswordLogin(long userId) { - return passwordUserRepository.findById(userId) - .map(PasswordUser::isCurrentTemporaryPassword) - .orElse(false); - } - - private PasswordUser verifyPasswordReturnUser(final String email, final String password) { - var user = passwordUserRepository.findByMailAddress(email) - .orElseThrow(() -> new ResourceNotFoundException("Email")); - if (!encoder.matches(password, user.getPassword())) { - throw new LoginFailException("비밀번호가 다릅니다"); - } - return user; - } - - private PasswordUser convertPasswordUser(BaseUser user) { - if (!(user instanceof PasswordUser)) { - throw new OAuthUserHasNotPasswordException(); - } - return (PasswordUser) user; - } - -} diff --git a/archive-application/src/main/java/site/archive/service/user/UserProfileImageService.java b/archive-application/src/main/java/site/archive/service/user/UserProfileImageService.java deleted file mode 100644 index e9b3f0c..0000000 --- a/archive-application/src/main/java/site/archive/service/user/UserProfileImageService.java +++ /dev/null @@ -1,20 +0,0 @@ -package site.archive.service.user; - -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import site.archive.domain.user.UserRepository; - -@Service -@Transactional(readOnly = true) -@RequiredArgsConstructor -public class UserProfileImageService { - - private final UserRepository userRepository; - - @Transactional - public void updateUserProfileImage(Long userId, String profileImageUri) { - userRepository.updateUserProfileImage(userId, profileImageUri); - } - -} diff --git a/archive-application/src/main/java/site/archive/service/user/UserRegisterServiceV1.java b/archive-application/src/main/java/site/archive/service/user/UserRegisterServiceV1.java deleted file mode 100644 index 034b7a4..0000000 --- a/archive-application/src/main/java/site/archive/service/user/UserRegisterServiceV1.java +++ /dev/null @@ -1,58 +0,0 @@ -package site.archive.service.user; - -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.dao.DataIntegrityViolationException; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import site.archive.common.exception.common.DuplicateResourceException; -import site.archive.domain.user.BaseUser; -import site.archive.domain.user.PasswordUser; -import site.archive.domain.user.UserInfo; -import site.archive.domain.user.UserRepository; -import site.archive.dto.v1.auth.BasicRegisterCommandV1; -import site.archive.dto.v1.auth.OAuthRegisterCommandV1; -import site.archive.dto.v1.user.BaseUserDtoV1; -import site.archive.service.message.MessagingService; - -@Service -@Transactional -@Slf4j -@RequiredArgsConstructor -public class UserRegisterServiceV1 { - - private final UserRepository userRepository; - private final MessagingService messagingService; - - public long getOrRegisterUser(BasicRegisterCommandV1 registerCommand) { - var user = userRepository.findByMailAddress(registerCommand.getEmail()) - .orElseGet(() -> registerUser(registerCommand)); - return user.getId(); - } - - public UserInfo getOrRegisterUserReturnInfo(BasicRegisterCommandV1 registerCommand) { - var user = userRepository.findByMailAddress(registerCommand.getEmail()) - .orElseGet(() -> registerUser(registerCommand)); - return user.convertToUserInfo(); - } - - public BaseUser registerUser(BasicRegisterCommandV1 registerCommand) { - try { - var user = userRepository.save(registerCommand.toUserEntity()); - sendRegisterNotification(registerCommand, user); - return user; - } catch (DataIntegrityViolationException e) { - throw new DuplicateResourceException("이메일이 이미 존재합니다."); - } - } - - private void sendRegisterNotification(BasicRegisterCommandV1 registerCommand, BaseUser user) { - if (registerCommand instanceof OAuthRegisterCommandV1 oAuthRegisterCommand) { - var oauthProvider = oAuthRegisterCommand.getProvider().getRegistrationId(); - messagingService.sendUserRegisterMessage(BaseUserDtoV1.from(user), oauthProvider); - } else { - messagingService.sendUserRegisterMessage(BaseUserDtoV1.from(user), PasswordUser.PASSWORD_TYPE); - } - } - -} diff --git a/archive-application/src/main/java/site/archive/service/user/UserRegisterServiceV2.java b/archive-application/src/main/java/site/archive/service/user/UserRegisterServiceV2.java deleted file mode 100644 index 77503f0..0000000 --- a/archive-application/src/main/java/site/archive/service/user/UserRegisterServiceV2.java +++ /dev/null @@ -1,47 +0,0 @@ -package site.archive.service.user; - -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.dao.DataIntegrityViolationException; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import site.archive.common.exception.common.DuplicateResourceException; -import site.archive.domain.user.PasswordUser; -import site.archive.domain.user.UserInfo; -import site.archive.domain.user.UserRepository; -import site.archive.dto.v1.user.BaseUserDtoV1; -import site.archive.dto.v2.OAuthRegisterRequestDto; -import site.archive.dto.v2.PasswordRegisterRequestDto; -import site.archive.service.message.MessagingService; - -@Service -@Transactional -@Slf4j -@RequiredArgsConstructor -public class UserRegisterServiceV2 { - - private final UserRepository userRepository; - private final MessagingService messagingService; - - public UserInfo registerUser(PasswordRegisterRequestDto registerRequest) { - try { - var user = userRepository.save(registerRequest.toUserEntity()); - messagingService.sendUserRegisterMessage(BaseUserDtoV1.from(user), PasswordUser.PASSWORD_TYPE); - return user.convertToUserInfo(); - } catch (DataIntegrityViolationException e) { - throw new DuplicateResourceException("이메일 또는 닉네임이 중복되었습니다. 중복을 다시 확인해주세요."); - } - } - - public UserInfo registerUser(OAuthRegisterRequestDto registerCommand) { - try { - var user = userRepository.save(registerCommand.toUserEntity()); - var oauthProvider = registerCommand.getProvider().getRegistrationId(); - messagingService.sendUserRegisterMessage(BaseUserDtoV1.from(user), oauthProvider); - return user.convertToUserInfo(); - } catch (DataIntegrityViolationException e) { - throw new DuplicateResourceException("이메일 또는 닉네임이 중복되었습니다. 중복을 다시 확인해주세요."); - } - } - -} diff --git a/archive-application/src/main/java/site/archive/service/user/UserService.java b/archive-application/src/main/java/site/archive/service/user/UserService.java deleted file mode 100644 index 823b862..0000000 --- a/archive-application/src/main/java/site/archive/service/user/UserService.java +++ /dev/null @@ -1,60 +0,0 @@ -package site.archive.service.user; - -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import site.archive.common.exception.common.DuplicateFieldValueException; -import site.archive.common.exception.common.ResourceNotFoundException; -import site.archive.domain.user.UserRepository; -import site.archive.dto.v1.user.BaseUserDtoV1; -import site.archive.dto.v1.user.SpecificUserDtoV1; - -@Service -@Transactional(readOnly = true) -@Slf4j -@RequiredArgsConstructor -public class UserService { - - private final UserRepository userRepository; - - public BaseUserDtoV1 findUserById(long userId) { - return userRepository.findById(userId) - .map(BaseUserDtoV1::from) - .orElseThrow(() -> new ResourceNotFoundException("아이디에 해당하는 유저가 존재하지 않습니다.")); - } - - public BaseUserDtoV1 findUserByEmail(String email) { - return userRepository.findByMailAddress(email) - .map(BaseUserDtoV1::from) - .orElseThrow(() -> new ResourceNotFoundException("가입되지 않은 Email 입니다.")); - } - - public SpecificUserDtoV1 findSpecificUserById(long userId) { - var user = userRepository.findById(userId) - .orElseThrow(() -> new ResourceNotFoundException("아이디에 해당하는 유저가 존재하지 않습니다.")); - return SpecificUserDtoV1.from(user); - } - - public boolean existsEmail(String email) { - return userRepository.findByMailAddress(email).isPresent(); - } - - public boolean existsNickname(String nickname) { - return userRepository.findByNickname(nickname).isPresent(); - } - - @Transactional - public void deleteUser(long userId) { - userRepository.deleteById(userId); - } - - @Transactional - public void updateUserNickname(long userId, String nickname) { - if (existsNickname(nickname)) { - throw new DuplicateFieldValueException("nickname", nickname); - } - userRepository.updateNickName(userId, nickname); - } - -} diff --git a/archive-application/src/main/kotlin/site/archive/service/user/UserAuthService.kt b/archive-application/src/main/kotlin/site/archive/service/user/UserAuthService.kt new file mode 100644 index 0000000..bc7862a --- /dev/null +++ b/archive-application/src/main/kotlin/site/archive/service/user/UserAuthService.kt @@ -0,0 +1,78 @@ +package site.archive.service.user + +import org.springframework.security.crypto.password.PasswordEncoder +import org.springframework.stereotype.Service +import org.springframework.transaction.annotation.Transactional +import site.archive.common.exception.common.ResourceNotFoundException +import site.archive.common.exception.common.UnauthorizedResourceException +import site.archive.common.exception.user.LoginFailException +import site.archive.common.exception.user.OAuthUserHasNotPasswordException +import site.archive.domain.user.BaseUser +import site.archive.domain.user.PasswordUser +import site.archive.domain.user.PasswordUserRepository +import site.archive.domain.user.UserInfo +import site.archive.domain.user.UserRepository +import site.archive.dto.v1.auth.LoginCommandV1 +import site.archive.dto.v1.user.UserPasswordResetRequestDtoV1 +import site.archive.infra.mail.MailService + +@Service +@Transactional(readOnly = true) +class UserAuthService( + val userRepository: UserRepository, + val passwordUserRepository: PasswordUserRepository, + val encoder: PasswordEncoder, + val mailService: MailService +) { + + fun tryLoginAndReturnInfo(command: LoginCommandV1): UserInfo { + val user = verifyPasswordReturnUser(command.email, command.password) + return user.convertToUserInfo() + } + + @Transactional + fun updateTemporaryPassword(email: String, temporaryPassword: String) { + val passwordUser = userRepository.findByMailAddress(email) + .map { convertPasswordUser(it) } + .orElseThrow { ResourceNotFoundException("Email") } + passwordUser.updatePassword(encoder.encode(temporaryPassword), true) + mailService.sendTemporaryPassword(email, temporaryPassword) + } + + @Transactional + fun resetPassword(userInfo: UserInfo, userPasswordResetRequestDtoV1: UserPasswordResetRequestDtoV1) { + if (userInfo.mailAddress != userPasswordResetRequestDtoV1.email) { + throw UnauthorizedResourceException("해당 이메일에 대한 비밀번호 초기화 권한이 없습니다.") + } + this.resetPassword(userPasswordResetRequestDtoV1) + } + + @Transactional + fun resetPassword(userPasswordResetRequestDtoV1: UserPasswordResetRequestDtoV1) { + val passwordUser = verifyPasswordReturnUser(userPasswordResetRequestDtoV1.email, userPasswordResetRequestDtoV1.currentPassword) + passwordUser.updatePassword(encoder.encode(userPasswordResetRequestDtoV1.newPassword), false) + } + + fun isTemporaryPasswordLogin(userId: Long): Boolean { + return passwordUserRepository.findById(userId) + .map(PasswordUser::isCurrentTemporaryPassword) + .orElse(false) + } + + private fun verifyPasswordReturnUser(email: String, password: String): PasswordUser { + val user = passwordUserRepository.findByMailAddress(email) + .orElseThrow { ResourceNotFoundException("Email") } + if (!encoder.matches(password, user.password)) { + throw LoginFailException("비밀번호가 다릅니다") + } + return user + } + + private fun convertPasswordUser(user: BaseUser): PasswordUser { + if (user !is PasswordUser) { + throw OAuthUserHasNotPasswordException() + } + return user + } + +} \ No newline at end of file diff --git a/archive-application/src/main/kotlin/site/archive/service/user/UserProfileImageService.kt b/archive-application/src/main/kotlin/site/archive/service/user/UserProfileImageService.kt new file mode 100644 index 0000000..bbc84cf --- /dev/null +++ b/archive-application/src/main/kotlin/site/archive/service/user/UserProfileImageService.kt @@ -0,0 +1,16 @@ +package site.archive.service.user + +import org.springframework.stereotype.Service +import org.springframework.transaction.annotation.Transactional +import site.archive.domain.user.UserRepository + +@Service +@Transactional(readOnly = true) +class UserProfileImageService(val userRepository: UserRepository) { + + @Transactional + fun updateUserProfileImage(userId: Long, profileImageUri: String) { + userRepository.updateUserProfileImage(userId, profileImageUri) + } + +} \ No newline at end of file diff --git a/archive-application/src/main/kotlin/site/archive/service/user/UserRegisterServiceV1.kt b/archive-application/src/main/kotlin/site/archive/service/user/UserRegisterServiceV1.kt new file mode 100644 index 0000000..2f7bd75 --- /dev/null +++ b/archive-application/src/main/kotlin/site/archive/service/user/UserRegisterServiceV1.kt @@ -0,0 +1,59 @@ +package site.archive.service.user + +import org.slf4j.LoggerFactory +import org.springframework.dao.DataIntegrityViolationException +import org.springframework.stereotype.Service +import org.springframework.transaction.annotation.Transactional +import site.archive.common.exception.common.DuplicateResourceException +import site.archive.domain.user.BaseUser +import site.archive.domain.user.PasswordUser +import site.archive.domain.user.UserInfo +import site.archive.domain.user.UserRepository +import site.archive.dto.v1.auth.BasicRegisterCommandV1 +import site.archive.dto.v1.auth.OAuthRegisterCommandV1 +import site.archive.dto.v1.user.BaseUserDtoV1 +import site.archive.service.message.MessagingService + +@Service +@Transactional(readOnly = true) +class UserRegisterServiceV1(val userRepository: UserRepository, val messagingService: MessagingService) { + + private val log = LoggerFactory.getLogger(javaClass) + + + @Transactional + fun getOrRegisterUser(registerCommand: BasicRegisterCommandV1): Long { + val user = userRepository.findByMailAddress(registerCommand.email) + .orElseGet { registerUser(registerCommand) } + return user.id + } + + @Transactional + fun getOrRegisterUserReturnInfo(registerCommand: BasicRegisterCommandV1): UserInfo { + val user = userRepository.findByMailAddress(registerCommand.email) + .orElseGet { registerUser(registerCommand) } + return user.convertToUserInfo() + } + + @Transactional + fun registerUser(registerCommand: BasicRegisterCommandV1): BaseUser { + try { + val user = userRepository.save(registerCommand.toUserEntity()) + sendRegisterNotification(registerCommand, user) + return user + } catch (e: DataIntegrityViolationException) { + log.error("[v1] 이메일이 이미 존재합니다.", e) + throw DuplicateResourceException("이메일이 이미 존재합니다.") + } + } + + private fun sendRegisterNotification(registerCommand: BasicRegisterCommandV1, user: BaseUser) { + if (registerCommand is OAuthRegisterCommandV1) { + val oauthProvider = registerCommand.provider.registrationId + messagingService.sendUserRegisterMessage(BaseUserDtoV1.from(user), oauthProvider) + } else { + messagingService.sendUserRegisterMessage(BaseUserDtoV1.from(user), PasswordUser.PASSWORD_TYPE) + } + } + +} \ No newline at end of file diff --git a/archive-application/src/main/kotlin/site/archive/service/user/UserRegisterServiceV2.kt b/archive-application/src/main/kotlin/site/archive/service/user/UserRegisterServiceV2.kt new file mode 100644 index 0000000..58e0761 --- /dev/null +++ b/archive-application/src/main/kotlin/site/archive/service/user/UserRegisterServiceV2.kt @@ -0,0 +1,47 @@ +package site.archive.service.user + +import org.slf4j.LoggerFactory +import org.springframework.dao.DataIntegrityViolationException +import org.springframework.stereotype.Service +import org.springframework.transaction.annotation.Transactional +import site.archive.common.exception.common.DuplicateResourceException +import site.archive.domain.user.PasswordUser +import site.archive.domain.user.UserInfo +import site.archive.domain.user.UserRepository +import site.archive.dto.v1.user.BaseUserDtoV1 +import site.archive.dto.v2.OAuthRegisterRequestDto +import site.archive.dto.v2.PasswordRegisterRequestDto +import site.archive.service.message.MessagingService + +@Service +@Transactional(readOnly = true) +class UserRegisterServiceV2(val userRepository: UserRepository, val messagingService: MessagingService) { + + private val log = LoggerFactory.getLogger(javaClass) + + @Transactional + fun registerUser(registerRequest: PasswordRegisterRequestDto): UserInfo { + try { + val user = userRepository.save(registerRequest.toUserEntity()) + messagingService.sendUserRegisterMessage(BaseUserDtoV1.from(user), PasswordUser.PASSWORD_TYPE) + return user.convertToUserInfo() + } catch (e: DataIntegrityViolationException) { + log.error("[v2] 이메일 또는 닉네임이 중복되었습니다.", e) + throw DuplicateResourceException("이메일 또는 닉네임이 중복되었습니다. 중복을 다시 확인해주세요.") + } + } + + @Transactional + fun registerUser(registerCommand: OAuthRegisterRequestDto): UserInfo { + try { + val user = userRepository.save(registerCommand.toUserEntity()) + val oAuthProvider = registerCommand.provider.registrationId + messagingService.sendUserRegisterMessage(BaseUserDtoV1.from(user), oAuthProvider) + return user.convertToUserInfo() + } catch (e: DataIntegrityViolationException) { + log.error("[v2] 이메일 또는 닉네임이 중복되었습니다.", e) + throw DuplicateResourceException("이메일 또는 닉네임이 중복되었습니다. 중복을 다시 확인해주세요.") + } + } + +} \ No newline at end of file diff --git a/archive-application/src/main/kotlin/site/archive/service/user/UserService.kt b/archive-application/src/main/kotlin/site/archive/service/user/UserService.kt new file mode 100644 index 0000000..e4a2cc7 --- /dev/null +++ b/archive-application/src/main/kotlin/site/archive/service/user/UserService.kt @@ -0,0 +1,58 @@ +package site.archive.service.user + +import org.slf4j.LoggerFactory +import org.springframework.stereotype.Service +import org.springframework.transaction.annotation.Transactional +import site.archive.common.exception.common.DuplicateFieldValueException +import site.archive.common.exception.common.ResourceNotFoundException +import site.archive.domain.user.UserRepository +import site.archive.dto.v1.user.BaseUserDtoV1 +import site.archive.dto.v1.user.SpecificUserDtoV1 + +@Service +@Transactional(readOnly = true) +class UserService(val userRepository: UserRepository) { + + private val log = LoggerFactory.getLogger(javaClass) + + fun findUserById(userId: Long): BaseUserDtoV1 { + return userRepository.findById(userId) + .map(BaseUserDtoV1::from) + .orElseThrow { ResourceNotFoundException("아이디에 해당하는 유저가 존재하지 않습니다.") } + } + + fun findUserByEmail(email: String): BaseUserDtoV1 { + return userRepository.findByMailAddress(email) + .map(BaseUserDtoV1::from) + .orElseThrow { ResourceNotFoundException("가입되지 않은 Email 입니다.") } + } + + fun findSpecificUserById(userId: Long): SpecificUserDtoV1 { + val user = userRepository.findById(userId) + .orElseThrow { ResourceNotFoundException("아이디에 해당하는 유저가 존재하지 않습니다.") } + return SpecificUserDtoV1.from(user) + } + + fun existsEmail(email: String): Boolean { + return userRepository.findByMailAddress(email).isPresent + } + + fun existsNickname(nickname: String): Boolean { + return userRepository.findByNickname(nickname).isPresent + } + + @Transactional + fun deleteUser(userId: Long) { + log.info("User($userId)이 탈퇴했습니다") + userRepository.deleteById(userId) + } + + @Transactional + fun updateUserNickname(userId: Long, nickname: String) { + if (existsNickname(nickname)) { + throw DuplicateFieldValueException("nickname", nickname) + } + userRepository.updateNickName(userId, nickname) + } + +} \ No newline at end of file From 6c636257d359c54a50b16f23f001e16b83761aae Mon Sep 17 00:00:00 2001 From: KimDoubleB Date: Sun, 22 Jan 2023 14:45:19 +0900 Subject: [PATCH 38/46] fix(#53): fix DTO NPE at test --- .../java/site/archive/service/archive/ArchiveServiceTest.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/archive-application/src/test/java/site/archive/service/archive/ArchiveServiceTest.java b/archive-application/src/test/java/site/archive/service/archive/ArchiveServiceTest.java index 7574119..d7646d9 100644 --- a/archive-application/src/test/java/site/archive/service/archive/ArchiveServiceTest.java +++ b/archive-application/src/test/java/site/archive/service/archive/ArchiveServiceTest.java @@ -9,6 +9,7 @@ import site.archive.common.exception.common.UnauthorizedResourceException; import site.archive.domain.archive.Archive; import site.archive.domain.archive.ArchiveRepository; +import site.archive.domain.archive.CoverImageType; import site.archive.domain.archive.Emotion; import site.archive.domain.user.BaseUser; import site.archive.domain.user.UserInfo; @@ -158,6 +159,7 @@ void cannotViewPrivateSpecificArchiveWhenOtherArchive() { private List dummyArchives(BaseUser user) { return List.of( Archive.builder() + .id(1L) .name("archive_1") .author(user) .watchedOn(LocalDate.now()) @@ -167,6 +169,7 @@ private List dummyArchives(BaseUser user) { .isPublic(true) .build(), Archive.builder() + .id(2L) .name("archive_2") .author(user) .watchedOn(LocalDate.now()) @@ -188,6 +191,7 @@ private Archive dummyArchive(long archiveId, BaseUser user, boolean isPublic) { .mainImage("main_image_1") .companions(Collections.emptyList()) .isPublic(isPublic) + .coverImageType(CoverImageType.EMOTION_COVER) .build(); } From bad896081f278f2ca4f4c5e8b56fa9a6f9cbcfee Mon Sep 17 00:00:00 2001 From: KimDoubleB Date: Sun, 22 Jan 2023 14:53:19 +0900 Subject: [PATCH 39/46] feat(#53): set id field of request dto to nullable --- .../main/kotlin/site/archive/dto/v1/archive/ArchiveDtoV1.kt | 2 +- .../kotlin/site/archive/dto/v1/archive/ArchiveImageDtoV1.kt | 2 +- .../site/archive/dto/v1/auth/PasswordRegisterCommandV1.kt | 1 + .../src/main/kotlin/site/archive/dto/v1/user/BaseUserDtoV1.kt | 2 +- .../site/archive/dto/v1/user/OAuthRegisterRequestDtoV1.kt | 4 +++- .../main/kotlin/site/archive/dto/v1/user/SpecificUserDtoV1.kt | 2 +- .../src/main/kotlin/site/archive/dto/v2/ArchiveDtoV2.kt | 2 +- 7 files changed, 9 insertions(+), 6 deletions(-) diff --git a/archive-application/src/main/kotlin/site/archive/dto/v1/archive/ArchiveDtoV1.kt b/archive-application/src/main/kotlin/site/archive/dto/v1/archive/ArchiveDtoV1.kt index 1362c19..ae37e9a 100644 --- a/archive-application/src/main/kotlin/site/archive/dto/v1/archive/ArchiveDtoV1.kt +++ b/archive-application/src/main/kotlin/site/archive/dto/v1/archive/ArchiveDtoV1.kt @@ -10,7 +10,7 @@ import java.time.LocalDate @JsonInclude(JsonInclude.Include.NON_NULL) data class ArchiveDtoV1( - val archiveId: Long, + val archiveId: Long?, val name: String, val watchedOn: String, val emotion: Emotion, diff --git a/archive-application/src/main/kotlin/site/archive/dto/v1/archive/ArchiveImageDtoV1.kt b/archive-application/src/main/kotlin/site/archive/dto/v1/archive/ArchiveImageDtoV1.kt index 51c51f8..16d7d1a 100644 --- a/archive-application/src/main/kotlin/site/archive/dto/v1/archive/ArchiveImageDtoV1.kt +++ b/archive-application/src/main/kotlin/site/archive/dto/v1/archive/ArchiveImageDtoV1.kt @@ -4,7 +4,7 @@ import site.archive.domain.archive.Archive import site.archive.domain.archive.ArchiveImage data class ArchiveImageDtoV1( - val archiveImageId: Long, + val archiveImageId: Long?, val image: String, val review: String, val backgroundColor: String diff --git a/archive-application/src/main/kotlin/site/archive/dto/v1/auth/PasswordRegisterCommandV1.kt b/archive-application/src/main/kotlin/site/archive/dto/v1/auth/PasswordRegisterCommandV1.kt index 7fde82f..5b1e337 100644 --- a/archive-application/src/main/kotlin/site/archive/dto/v1/auth/PasswordRegisterCommandV1.kt +++ b/archive-application/src/main/kotlin/site/archive/dto/v1/auth/PasswordRegisterCommandV1.kt @@ -9,6 +9,7 @@ import site.archive.domain.user.UserRole class PasswordRegisterCommandV1( email: String, + @field: NotBlank(message = "비밀번호는 필수 입력 항목입니다.") @field: Pattern( regexp = "(?=.*[a-zA-Z])(?=.*[0-9])[a-zA-Z0-9@$!%*#?&]{8,20}$", diff --git a/archive-application/src/main/kotlin/site/archive/dto/v1/user/BaseUserDtoV1.kt b/archive-application/src/main/kotlin/site/archive/dto/v1/user/BaseUserDtoV1.kt index cd889d1..34e4992 100644 --- a/archive-application/src/main/kotlin/site/archive/dto/v1/user/BaseUserDtoV1.kt +++ b/archive-application/src/main/kotlin/site/archive/dto/v1/user/BaseUserDtoV1.kt @@ -6,7 +6,7 @@ import site.archive.domain.user.UserRole import java.time.LocalDateTime data class BaseUserDtoV1( - val userId: Long, + val userId: Long?, val mailAddress: String, val userRole: UserRole, val profileImage: String, diff --git a/archive-application/src/main/kotlin/site/archive/dto/v1/user/OAuthRegisterRequestDtoV1.kt b/archive-application/src/main/kotlin/site/archive/dto/v1/user/OAuthRegisterRequestDtoV1.kt index e82bdaa..d05fad3 100644 --- a/archive-application/src/main/kotlin/site/archive/dto/v1/user/OAuthRegisterRequestDtoV1.kt +++ b/archive-application/src/main/kotlin/site/archive/dto/v1/user/OAuthRegisterRequestDtoV1.kt @@ -4,5 +4,7 @@ import com.fasterxml.jackson.annotation.JsonProperty data class OAuthRegisterRequestDtoV1( val provider: String, - @field: JsonProperty("providerAccessToken") val token: String + + @field: JsonProperty("providerAccessToken") + val token: String ) \ No newline at end of file diff --git a/archive-application/src/main/kotlin/site/archive/dto/v1/user/SpecificUserDtoV1.kt b/archive-application/src/main/kotlin/site/archive/dto/v1/user/SpecificUserDtoV1.kt index 0562165..4b36168 100644 --- a/archive-application/src/main/kotlin/site/archive/dto/v1/user/SpecificUserDtoV1.kt +++ b/archive-application/src/main/kotlin/site/archive/dto/v1/user/SpecificUserDtoV1.kt @@ -5,7 +5,7 @@ import site.archive.domain.user.BaseUser import site.archive.domain.user.UserRole data class SpecificUserDtoV1( - val userId: Long, + val userId: Long?, val mailAddress: String, val userRole: UserRole, val createdAt: String, diff --git a/archive-application/src/main/kotlin/site/archive/dto/v2/ArchiveDtoV2.kt b/archive-application/src/main/kotlin/site/archive/dto/v2/ArchiveDtoV2.kt index 561e892..bed4bfe 100644 --- a/archive-application/src/main/kotlin/site/archive/dto/v2/ArchiveDtoV2.kt +++ b/archive-application/src/main/kotlin/site/archive/dto/v2/ArchiveDtoV2.kt @@ -9,7 +9,7 @@ import site.archive.dto.v1.archive.ArchiveImageDtoV1 @JsonInclude(JsonInclude.Include.NON_NULL) data class ArchiveDtoV2( - val archiveId: Long, + val archiveId: Long?, val name: String, val watchedOn: String, val emotion: Emotion, From 478aee46ee31c3ff617287eaf5ed7ca66dc997a0 Mon Sep 17 00:00:00 2001 From: KimDoubleB Date: Sun, 22 Jan 2023 16:46:00 +0900 Subject: [PATCH 40/46] refactor(#53): use default RestTemplateBuilder autowired --- .../src/main/kotlin/site/archive/config/ClientConfig.kt | 5 ----- 1 file changed, 5 deletions(-) diff --git a/archive-application/src/main/kotlin/site/archive/config/ClientConfig.kt b/archive-application/src/main/kotlin/site/archive/config/ClientConfig.kt index 2e3aac8..6565047 100644 --- a/archive-application/src/main/kotlin/site/archive/config/ClientConfig.kt +++ b/archive-application/src/main/kotlin/site/archive/config/ClientConfig.kt @@ -14,11 +14,6 @@ import java.util.function.Supplier @Configuration class ClientConfig { - @Bean - fun restTemplateBuilder(): RestTemplateBuilder { - return RestTemplateBuilder() - } - @Bean fun restTemplate(restTemplateBuilder: RestTemplateBuilder): RestTemplate { return restTemplateBuilder From fa021b1e5b4681854a60dd886eac9fc66b21f334 Mon Sep 17 00:00:00 2001 From: KimDoubleB Date: Sun, 22 Jan 2023 16:59:55 +0900 Subject: [PATCH 41/46] fix: ignore jwt filter at actuator path --- .../token/jwt/JwtTokenPersistFilter.java | 26 +++++++++++-------- .../security/token/jwt/JwtTokenSupport.java | 2 +- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/archive-web/src/main/java/site/archive/web/config/security/token/jwt/JwtTokenPersistFilter.java b/archive-web/src/main/java/site/archive/web/config/security/token/jwt/JwtTokenPersistFilter.java index 03fec1c..1729926 100644 --- a/archive-web/src/main/java/site/archive/web/config/security/token/jwt/JwtTokenPersistFilter.java +++ b/archive-web/src/main/java/site/archive/web/config/security/token/jwt/JwtTokenPersistFilter.java @@ -1,5 +1,10 @@ package site.archive.web.config.security.token.jwt; +import jakarta.servlet.FilterChain; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.security.core.context.SecurityContextHolder; @@ -7,29 +12,28 @@ import site.archive.web.config.security.token.HttpAuthTokenSupport; import site.archive.web.config.security.token.TokenProvider; -import jakarta.servlet.FilterChain; -import jakarta.servlet.ServletException; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; - import java.io.IOException; @RequiredArgsConstructor @Slf4j public class JwtTokenPersistFilter extends OncePerRequestFilter { + private static final String MONITORING_PATH_PREFIX = "/actuator"; + private final HttpAuthTokenSupport httpTokenExtractor; private final TokenProvider tokenProvider; @Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { - try { - var tokenStr = httpTokenExtractor.extractToken(request); - var authToken = tokenProvider.parseUserInfoFromToken(tokenStr); - SecurityContextHolder.getContext().setAuthentication(new JwtAuthenticationToken(authToken)); - } catch (Exception e) { - SecurityContextHolder.clearContext(); + if (!request.getRequestURI().startsWith(MONITORING_PATH_PREFIX)) { + try { + var tokenStr = httpTokenExtractor.extractToken(request); + var authToken = tokenProvider.parseUserInfoFromToken(tokenStr); + SecurityContextHolder.getContext().setAuthentication(new JwtAuthenticationToken(authToken)); + } catch (Exception e) { + SecurityContextHolder.clearContext(); + } } filterChain.doFilter(request, response); } diff --git a/archive-web/src/main/java/site/archive/web/config/security/token/jwt/JwtTokenSupport.java b/archive-web/src/main/java/site/archive/web/config/security/token/jwt/JwtTokenSupport.java index de55756..cef1383 100644 --- a/archive-web/src/main/java/site/archive/web/config/security/token/jwt/JwtTokenSupport.java +++ b/archive-web/src/main/java/site/archive/web/config/security/token/jwt/JwtTokenSupport.java @@ -17,7 +17,7 @@ public class JwtTokenSupport implements HttpAuthTokenSupport { public String extractToken(HttpServletRequest target) { try { String tokenTypeAndStr = target.getHeader(HttpHeaders.AUTHORIZATION); - log.debug("Parsing token in header: {}", tokenTypeAndStr); + log.debug("Parsing token in header: {} - Request path: {}", tokenTypeAndStr, target.getRequestURI()); return tokenTypeAndStr.split(" ")[1]; } catch (Exception e) { throw new TokenNotFoundException(); From 8fad931c39b4eafb86de09237aecdb92b366fff4 Mon Sep 17 00:00:00 2001 From: KimDoubleB Date: Mon, 23 Jan 2023 22:59:43 +0900 Subject: [PATCH 42/46] fix(#53): isDuplicated to duplicated (wrong field fix) --- .../site/archive/dto/v1/archive/EmailDuplicateResponseDtoV1.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/archive-application/src/main/kotlin/site/archive/dto/v1/archive/EmailDuplicateResponseDtoV1.kt b/archive-application/src/main/kotlin/site/archive/dto/v1/archive/EmailDuplicateResponseDtoV1.kt index 839b2dd..7d0471f 100644 --- a/archive-application/src/main/kotlin/site/archive/dto/v1/archive/EmailDuplicateResponseDtoV1.kt +++ b/archive-application/src/main/kotlin/site/archive/dto/v1/archive/EmailDuplicateResponseDtoV1.kt @@ -1,3 +1,3 @@ package site.archive.dto.v1.archive -data class EmailDuplicateResponseDtoV1(val isDuplicatedEmail: Boolean) \ No newline at end of file +data class EmailDuplicateResponseDtoV1(val duplicatedEmail: Boolean) \ No newline at end of file From ba44b89effc403bdff7a3559d3fa7320a1848c8f Mon Sep 17 00:00:00 2001 From: KimDoubleB Date: Tue, 24 Jan 2023 16:34:51 +0900 Subject: [PATCH 43/46] fix: added allEntry evict option to CacheEvict annotation --- .../java/site/archive/web/api/v2/BannerControllerV2.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/archive-web/src/main/java/site/archive/web/api/v2/BannerControllerV2.java b/archive-web/src/main/java/site/archive/web/api/v2/BannerControllerV2.java index a3b0297..12ef322 100644 --- a/archive-web/src/main/java/site/archive/web/api/v2/BannerControllerV2.java +++ b/archive-web/src/main/java/site/archive/web/api/v2/BannerControllerV2.java @@ -40,7 +40,7 @@ public ResponseEntity archiveCommunityBannerView() { return ResponseEntity.ok(bannerService.getAllBanner()); } - @CacheEvict(CacheInfo.BANNERS) + @CacheEvict(value = CacheInfo.BANNERS, allEntries = true) @RequirePermission(handler = AdminChecker.class) @PostMapping(path = "/type/image", consumes = MediaType.MULTIPART_FORM_DATA_VALUE, @@ -53,7 +53,7 @@ public ResponseEntity createArchiveCommunityBanner(@RequestParam(name = "s return ResponseEntity.noContent().build(); } - @CacheEvict(CacheInfo.BANNERS) + @CacheEvict(value = CacheInfo.BANNERS, allEntries = true) @RequirePermission(handler = AdminChecker.class) @PostMapping(path = "/type/url", consumes = MediaType.MULTIPART_FORM_DATA_VALUE, @@ -65,7 +65,7 @@ public ResponseEntity createArchiveCommunityBanner(@RequestParam(name = "s return ResponseEntity.noContent().build(); } - @CacheEvict(CacheInfo.BANNERS) + @CacheEvict(value = CacheInfo.BANNERS, allEntries = true) @RequirePermission(handler = AdminChecker.class) @DeleteMapping("/{bannerId}") public ResponseEntity deleteArchiveCommunityBanner(@PathVariable Long bannerId) { From 4f780af2b92087952071b399ab9797ff8d6d6601 Mon Sep 17 00:00:00 2001 From: KimDoubleB Date: Tue, 24 Jan 2023 16:35:23 +0900 Subject: [PATCH 44/46] refactor: rename banner expireAfterWrite variable name - added SECONDS suffix --- .../main/kotlin/site/archive/common/cache/CacheType.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/archive-common/src/main/kotlin/site/archive/common/cache/CacheType.kt b/archive-common/src/main/kotlin/site/archive/common/cache/CacheType.kt index 2cf83b1..098de1d 100644 --- a/archive-common/src/main/kotlin/site/archive/common/cache/CacheType.kt +++ b/archive-common/src/main/kotlin/site/archive/common/cache/CacheType.kt @@ -2,18 +2,18 @@ package site.archive.common.cache enum class CacheType(val key: String, val expireAfterWrite: Int, val maximumSize: Int) { - BANNERS(CacheInfo.BANNERS, CacheInfo.BANNERS_GET_EXPIRE_TIME, CacheInfo.BANNERS_CACHE_SIZE), - ARCHIVE_COMMUNITIES(CacheInfo.ARCHIVE_COMMUNITIES, CacheInfo.ARCHIVE_COMMUNITIES_GET_EXPIRE_TIME, CacheInfo.ARCHIVE_COMMUNITIES_CACHE_SIZE) + BANNERS(CacheInfo.BANNERS, CacheInfo.BANNERS_GET_EXPIRE_SECONDS, CacheInfo.BANNERS_CACHE_SIZE), + ARCHIVE_COMMUNITIES(CacheInfo.ARCHIVE_COMMUNITIES, CacheInfo.ARCHIVE_COMMUNITIES_GET_EXPIRE_SECONDS, CacheInfo.ARCHIVE_COMMUNITIES_CACHE_SIZE) ; class CacheInfo { companion object { const val BANNERS: String = "banners" - const val BANNERS_GET_EXPIRE_TIME: Int = 3_600 + const val BANNERS_GET_EXPIRE_SECONDS: Int = 3_600 const val BANNERS_CACHE_SIZE: Int = 1 const val ARCHIVE_COMMUNITIES: String = "archive-communities" - const val ARCHIVE_COMMUNITIES_GET_EXPIRE_TIME: Int = 30 + const val ARCHIVE_COMMUNITIES_GET_EXPIRE_SECONDS: Int = 30 const val ARCHIVE_COMMUNITIES_CACHE_SIZE: Int = 200 } } From 488ce751e6c54bfb049cc572e5f264f32cf22082 Mon Sep 17 00:00:00 2001 From: Bobae Kim Date: Tue, 24 Jan 2023 17:15:27 +0900 Subject: [PATCH 45/46] Update README.md --- README.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 77a3af8..cbe53d7 100644 --- a/README.md +++ b/README.md @@ -6,17 +6,19 @@ ## Tech stack -- Jdk 17, Gradle -- Spring framework - - Spring boot +- Jdk 17, Kotlin, Gradle +- Spring framework (v6.0.2) + - Spring boot (v3.0.0) - Spring security - Spring data jpa - Spring mail - ... -- MySQL, JPA, QueryDSL +- MySQL, JPA, QueryDSL, Caffeine cache - Junit5, Spring test, Mockito, Testcontainer - swagger, JWT ## Infra architecture -![architecture image](./assets/architecture.png) \ No newline at end of file +![architecture image](./assets/architecture.png) + +- Migrated to Oracle cloud From 49dc576838cfce59359c3ba54612690b44bfde6e Mon Sep 17 00:00:00 2001 From: Bobae Kim Date: Fri, 27 Jan 2023 00:15:15 +0900 Subject: [PATCH 46/46] chore: deactivate push github action --- .github/workflows/push.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index 4f58d42..8aa8a4f 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -3,7 +3,7 @@ name: Deploy for push on: push: branches: - - 'releases/**' + - 'temp/**' # currently use oracle server jobs: build-deploy: @@ -64,4 +64,4 @@ jobs: run: aws s3 cp --region ap-northeast-2 --acl private ./archive.zip s3://archive-depromeet/ - name: CodeDeploy - run: aws deploy create-deployment --application-name depromeet-deploy --deployment-group-name depromeet-deploy --s3-location bucket=archive-depromeet,key=archive.zip,bundleType=zip \ No newline at end of file + run: aws deploy create-deployment --application-name depromeet-deploy --deployment-group-name depromeet-deploy --s3-location bucket=archive-depromeet,key=archive.zip,bundleType=zip