Skip to content

Commit

Permalink
Merge pull request #606 from Clubber2024/refactor/#602-refactor-enabl…
Browse files Browse the repository at this point in the history
…e-설정-클래스-분리

refactor : 602 refactor enable 설정 클래스 분리
  • Loading branch information
mjKim1229 authored Jan 25, 2025
2 parents c92bbd7 + 78f9b2c commit ae77a1c
Show file tree
Hide file tree
Showing 60 changed files with 728 additions and 735 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,8 @@
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.data.redis.repository.configuration.EnableRedisRepositories;

@EnableJpaAuditing
@EnableFeignClients
@EnableRedisRepositories
@ConfigurationPropertiesScan
@ConfigurationPropertiesScan(basePackages = "com.clubber.ClubberServer.global.properties")
@SpringBootApplication
public class ClubberServerApplication {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@

@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class ClubberStatic {
public static final int MILLI_TO_SECOND = 1000;
public static final String TOKEN_TYPE = "type";
public static final String TOKEN_ISSUER = "Clubber";
public static final String ACCESS_TOKEN = "ACCESS_TOKEN";
public static final String REFRESH_TOKEN= "REFRESH_TOKEN";
public static final String AUTH_HEADER = "Authorization";
public static final String BEARER = "Bearer ";
public static final String TOKEN_ROLE = "role";
public static final String LOCAL_SERVER = "localhost:8080";
public static final String LOCAL_CLIENT = "http://localhost:3000";
public static final String PROD_CLIENT = "https://ssuclubber.com";
public static final String DEV_CLIENT = "https://dev.ssuclubber.com";
public static final String IMAGE_SERVER = "https://image.ssuclubber.com/";

public static final int MILLI_TO_SECOND = 1000;
public static final String TOKEN_TYPE = "type";
public static final String TOKEN_ISSUER = "Clubber";
public static final String ACCESS_TOKEN = "ACCESS_TOKEN";
public static final String REFRESH_TOKEN = "REFRESH_TOKEN";
public static final String AUTH_HEADER = "Authorization";
public static final String BEARER = "Bearer ";
public static final String TOKEN_ROLE = "role";
public static final String LOCAL_SERVER = "localhost:8080";
public static final String LOCAL_CLIENT = "http://localhost:3000";
public static final String PROD_CLIENT = "https://ssuclubber.com";
public static final String DEV_CLIENT = "https://dev.ssuclubber.com";
public static final String IMAGE_SERVER = "https://image.ssuclubber.com/";
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@
import org.springframework.data.domain.Page;

public record PageResponse<T>(
List<T> content,
int page,
int size,
long totalElements,
int totalPages,
boolean hasNextPage) {
public static <T> PageResponse<T> of(Page<T> page) {
return new PageResponse<>(
page.getContent(),
page.getNumber() + 1,
page.getNumberOfElements(),
page.getTotalElements(),
page.getTotalPages(),
page.hasNext());
}
List<T> content,
int page,
int size,
long totalElements,
int totalPages,
boolean hasNextPage) {

public static <T> PageResponse<T> of(Page<T> page) {
return new PageResponse<>(
page.getContent(),
page.getNumber() + 1,
page.getNumberOfElements(),
page.getTotalElements(),
page.getTotalPages(),
page.hasNext());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import java.util.List;

public record SliceResponse<T>(List<T> content, long size, boolean hasNext) {
public static <T> SliceResponse<T> of(List<T> content, long size, boolean hasNext){

public static <T> SliceResponse<T> of(List<T> content, long size, boolean hasNext) {
return new SliceResponse<>(
content,
size,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package com.clubber.ClubberServer.global.config.enums;


import com.clubber.ClubberServer.domain.club.domain.*;
import com.clubber.ClubberServer.domain.club.domain.ClubType;
import com.clubber.ClubberServer.domain.club.domain.College;
import com.clubber.ClubberServer.domain.club.domain.Department;
import com.clubber.ClubberServer.domain.club.domain.Division;
import com.clubber.ClubberServer.domain.club.domain.Hashtag;
import com.clubber.ClubberServer.domain.review.domain.Keyword;
import com.clubber.ClubberServer.global.mapper.enums.EnumMapper;
import org.springframework.context.annotation.Bean;
Expand All @@ -10,15 +14,15 @@
@Configuration
public class EnumConfig {

@Bean
public EnumMapper getEnumMapper() {
EnumMapper enumMapper = new EnumMapper();
enumMapper.put("Keyword", Keyword.class);
enumMapper.put("Hashtag", Hashtag.class);
enumMapper.put("Division", Division.class);
enumMapper.put("Department", Department.class);
enumMapper.put("College", College.class);
enumMapper.put("ClubType", ClubType.class);
return enumMapper;
}
@Bean
public EnumMapper getEnumMapper() {
EnumMapper enumMapper = new EnumMapper();
enumMapper.put("Keyword", Keyword.class);
enumMapper.put("Hashtag", Hashtag.class);
enumMapper.put("Division", Division.class);
enumMapper.put("Department", Department.class);
enumMapper.put("College", College.class);
enumMapper.put("ClubType", ClubType.class);
return enumMapper;
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package com.clubber.ClubberServer.global.infrastructure.outer.config;
package com.clubber.ClubberServer.global.config.feign;

import feign.Request;
import feign.Retryer;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.TimeUnit;

@Configuration
@EnableFeignClients(basePackages = "com.clubber.ClubberServer.global.infrastructure")
public class FeignConfig {
//Feign 사용시 TimeOut 설정
private static final long CONNECTION_TIMEOUT = 10;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.clubber.ClubberServer.global.config.jpa;

import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;

@EnableJpaAuditing
@Configuration
public class JpaAuditingConfig {

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
@Configuration
public class QueryDslConfig {

@PersistenceContext private EntityManager entityManager;
@PersistenceContext
private EntityManager entityManager;

@Bean
public JPAQueryFactory jpaQueryFactory() {
return new JPAQueryFactory(entityManager);
}
@Bean
public JPAQueryFactory jpaQueryFactory() {
return new JPAQueryFactory(entityManager);
}
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
package com.clubber.ClubberServer.global.config.redis;


import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.repository.configuration.EnableRedisRepositories;

@Configuration
@EnableRedisRepositories
public class RedisConfig {

@Value("${spring.data.redis.host}")
private String redisHost;

@Value("${spring.data.redis.port}")
private int redisPort;
@Value("${spring.data.redis.host}")
private String redisHost;

@Bean
public LettuceConnectionFactory redisConnectionFactory() {
return new LettuceConnectionFactory(new RedisStandaloneConfiguration(redisHost, redisPort));
}
@Value("${spring.data.redis.port}")
private int redisPort;

@Bean
public LettuceConnectionFactory redisConnectionFactory() {
return new LettuceConnectionFactory(new RedisStandaloneConfiguration(redisHost, redisPort));
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package com.clubber.ClubberServer.global.config.response;

import java.util.List;

import com.clubber.ClubberServer.global.dto.ErrorResponse;
import com.clubber.ClubberServer.global.event.exceptionalarm.ExceptionAlarmEventPublisher;
import com.clubber.ClubberServer.global.exception.BaseErrorCode;
import com.clubber.ClubberServer.global.exception.BaseException;
import com.clubber.ClubberServer.global.exception.ErrorReason;
import com.clubber.ClubberServer.global.exception.GlobalErrorCode;
import com.clubber.ClubberServer.global.event.exceptionalarm.ExceptionAlarmEventPublisher;
import jakarta.servlet.http.HttpServletRequest;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.HttpStatusCode;
Expand All @@ -21,12 +24,6 @@
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;

import com.clubber.ClubberServer.global.dto.ErrorResponse;

import jakarta.servlet.http.HttpServletRequest;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;

@RestControllerAdvice
@Slf4j
@RequiredArgsConstructor
Expand All @@ -49,15 +46,16 @@ public ResponseEntity<ErrorResponse> handleBaseException(
protected ResponseEntity<Object> handleExceptionInternal(Exception ex, Object body,
HttpHeaders headers, HttpStatusCode statusCode, WebRequest request) {

ServletWebRequest servletWebRequest = (ServletWebRequest)request;
ServletWebRequest servletWebRequest = (ServletWebRequest) request;
String uri = servletWebRequest.getRequest().getRequestURI();
ErrorResponse errorResponse =
new ErrorResponse(statusCode.value(), ex.getMessage(), uri);
return super.handleExceptionInternal(ex, errorResponse, headers, statusCode, request);
}

@ExceptionHandler({MethodArgumentTypeMismatchException.class})
protected ResponseEntity<Object> handleMethodArgumentTypeMismatch(MethodArgumentTypeMismatchException e){
protected ResponseEntity<Object> handleMethodArgumentTypeMismatch(
MethodArgumentTypeMismatchException e) {
return ResponseEntity.status(GlobalErrorCode.INVALID_METHOD_ARGUMENT_TYPE.getStatus())
.body(GlobalErrorCode.INVALID_METHOD_ARGUMENT_TYPE.getErrorReason());
}
Expand All @@ -77,10 +75,11 @@ protected ResponseEntity<Object> handleMethodArgumentNotValid(
}

//uri 추출
ServletWebRequest servletWebRequest = (ServletWebRequest)request;
ServletWebRequest servletWebRequest = (ServletWebRequest) request;
String uri = servletWebRequest.getRequest().getRequestURI();

ErrorResponse errorResponse = new ErrorResponse(status.value(), errorMessages.toString(), uri);
ErrorResponse errorResponse = new ErrorResponse(status.value(), errorMessages.toString(),
uri);
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(errorResponse);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,24 @@
@RestControllerAdvice(basePackages = "com.clubber")
public class SuccessResponseAdvice implements ResponseBodyAdvice {

@Override
public boolean supports(MethodParameter returnType, Class converterType) { return true; }
@Override
public boolean supports(MethodParameter returnType, Class converterType) {
return true;
}

@Override
public Object beforeBodyWrite(Object body, MethodParameter returnType,
MediaType selectedContentType, Class selectedConverterType, ServerHttpRequest request,
ServerHttpResponse response) {
@Override
public Object beforeBodyWrite(Object body, MethodParameter returnType,
MediaType selectedContentType, Class selectedConverterType, ServerHttpRequest request,
ServerHttpResponse response) {

HttpServletResponse servletResponse =
((ServletServerHttpResponse) response).getServletResponse();
int status = servletResponse.getStatus();
HttpStatus resolve = HttpStatus.resolve(status);
HttpServletResponse servletResponse =
((ServletServerHttpResponse) response).getServletResponse();
int status = servletResponse.getStatus();
HttpStatus resolve = HttpStatus.resolve(status);

if(resolve.is2xxSuccessful()){
return new SuccessResponse(body);
}
return body;
}
if (resolve.is2xxSuccessful()) {
return new SuccessResponse(body);
}
return body;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
@Getter
@AllArgsConstructor
public enum ImageFileExtension {
JPEG("jpeg"),
JPG("jpeg"),
PNG("png");
JPEG("jpeg"),
JPG("jpeg"),
PNG("png");

private final String uploadExtension;
private final String uploadExtension;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@
@Configuration
public class S3Config {

@Value("${aws.access-key}")
private String accessKey;
@Value("${aws.access-key}")
private String accessKey;

@Value("${aws.secret-key}")
private String secretKey;
@Value("${aws.secret-key}")
private String secretKey;

@Bean
public AmazonS3 getAmazonS3Bean() {
BasicAWSCredentials credentials = new BasicAWSCredentials(this.accessKey, this.secretKey);
return AmazonS3ClientBuilder.standard()
.withCredentials(new AWSStaticCredentialsProvider(credentials))
.withRegion(Regions.AP_NORTHEAST_2)
.build();
}
@Bean
public AmazonS3 getAmazonS3Bean() {
BasicAWSCredentials credentials = new BasicAWSCredentials(this.accessKey, this.secretKey);
return AmazonS3ClientBuilder.standard()
.withCredentials(new AWSStaticCredentialsProvider(credentials))
.withRegion(Regions.AP_NORTHEAST_2)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
@Configuration
public class SchedulerConfig {

@Bean
public ThreadPoolTaskScheduler taskScheduler() {
ThreadPoolTaskScheduler threadPoolTaskScheduler = new ThreadPoolTaskScheduler();
threadPoolTaskScheduler.setPoolSize(10);
return threadPoolTaskScheduler;
}
@Bean
public ThreadPoolTaskScheduler taskScheduler() {
ThreadPoolTaskScheduler threadPoolTaskScheduler = new ThreadPoolTaskScheduler();
threadPoolTaskScheduler.setPoolSize(10);
return threadPoolTaskScheduler;
}
}
Loading

0 comments on commit ae77a1c

Please sign in to comment.