Skip to content

Commit

Permalink
chore : indent, import 수정 (#602)
Browse files Browse the repository at this point in the history
  • Loading branch information
mjKim1229 committed Jan 24, 2025
1 parent 8e2240b commit 78f9b2c
Show file tree
Hide file tree
Showing 54 changed files with 703 additions and 684 deletions.
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
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,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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,29 @@
@Component
public class AccessDeniedFilter extends OncePerRequestFilter {

private final ObjectMapper objectMapper;
private final ObjectMapper objectMapper;

@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
FilterChain filterChain) throws ServletException, IOException {
try{
filterChain.doFilter(request, response);
}catch (AccessDeniedException e){
responseToClient(response,
getErrorResponse(UserErrorCode.ACCESS_TOKEN_NOT_EXIST,
request.getRequestURI().toString()));
}
}
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
FilterChain filterChain) throws ServletException, IOException {
try {
filterChain.doFilter(request, response);
} catch (AccessDeniedException e) {
responseToClient(response,
getErrorResponse(UserErrorCode.ACCESS_TOKEN_NOT_EXIST,
request.getRequestURI().toString()));
}
}

private ErrorResponse getErrorResponse(BaseErrorCode code, String path){
return new ErrorResponse(code.getErrorReason(), path);
}
private void responseToClient(HttpServletResponse response, ErrorResponse errorResponse)
throws IOException {
response.setCharacterEncoding("UTF-8");
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
response.setStatus(errorResponse.getStatus());
response.getWriter().write(objectMapper.writeValueAsString(errorResponse));
}

private void responseToClient(HttpServletResponse response, ErrorResponse errorResponse)
throws IOException {
response.setCharacterEncoding("UTF-8");
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
response.setStatus(errorResponse.getStatus());
response.getWriter().write(objectMapper.writeValueAsString(errorResponse));
}
private ErrorResponse getErrorResponse(BaseErrorCode code, String path) {
return new ErrorResponse(code.getErrorReason(), path);
}
}
Loading

0 comments on commit 78f9b2c

Please sign in to comment.