Skip to content

Commit

Permalink
Merge pull request #258 from techeer-sv/BE/#257
Browse files Browse the repository at this point in the history
BE/#257 프로젝트 목록 조회 시 검색이 제대로 되지 않는 오류 수정
  • Loading branch information
kimhalin authored Oct 4, 2023
2 parents 8848732 + c432018 commit 41cd47a
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package com.graphy.backend.domain.project.dto.request;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.*;

@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ public Page<Project> findFollowingProjects(Pageable pageable, Long fromId) {
}

private BooleanExpression projectNameLike(String projectName) {
return projectName != null ? project.projectName.eq(projectName) : null;
return projectName != null ? project.projectName.contains(projectName) : null;
}

private BooleanExpression contentLike(String content) {
return content != null ? project.content.eq(content) : null;
return content != null ? project.content.contains(content) : null;
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
package com.graphy.backend.global.common;

import com.graphy.backend.global.error.exception.BusinessException;
import org.springframework.data.domain.Sort;

import static com.graphy.backend.global.error.ErrorCode.INPUT_INVALID_VALUE;


public class PageRequest {
private static final int DEFAULT_SIZE = 10;
private static final int MAX_SIZE = 50;

private int page = 1;
private int size = 10;
private Sort.Direction direction = Sort.Direction.DESC;

public void setPage(int page) {
this.page = page <= 0 ? 1 : page;
}

public void setSize(int size) {
int DEFAULT_SIZE = 10;
int MAX_SIZE = 50;
this.size = size > MAX_SIZE ? DEFAULT_SIZE : size;
}

Expand All @@ -24,6 +27,9 @@ public void setDirection(Sort.Direction direction) {
}

public org.springframework.data.domain.PageRequest of() {
if (size <= 0) {
throw new BusinessException(INPUT_INVALID_VALUE);
}
return org.springframework.data.domain.PageRequest.of(page - 1, size, direction, "createdAt");
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.graphy.backend.global.error;

import com.graphy.backend.global.error.exception.*;
import com.graphy.backend.global.error.exception.AlreadyExistException;
import com.graphy.backend.global.error.exception.BusinessException;
import com.graphy.backend.global.error.exception.EmptyResultException;
import com.graphy.backend.global.error.exception.LongRequestException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.http.HttpHeaders;
Expand All @@ -25,7 +28,7 @@ protected ResponseEntity<ErrorResponse> handleException(Exception e) {
}

@ExceptionHandler({
InvalidMemberException.class,
BusinessException.class,
})
protected ResponseEntity<ErrorResponse> handleRuntimeException(BusinessException e) {
final ErrorCode errorCode = e.getErrorCode();
Expand Down Expand Up @@ -58,31 +61,25 @@ protected ResponseEntity<ErrorResponse> handleDataIntegrityViolationException(Al
return new ResponseEntity<>(response, errorCode.getStatus());
}


@Override
protected ResponseEntity<Object> handleMethodArgumentNotValid(MethodArgumentNotValidException e, HttpHeaders headers, HttpStatus status, WebRequest request) {
log.warn(e.getMessage());
return handleExceptionInternal(e, ErrorCode.INPUT_INVALID_VALUE, e.getBindingResult(),request);
}


private ResponseEntity<Object> handleExceptionInternal(
Exception e, ErrorCode errorCode, WebRequest request) {
log.error(e.getMessage(), e);
return super.handleExceptionInternal(e, ErrorResponse.of(errorCode), HttpHeaders.EMPTY, errorCode.getStatus(), request);
return handleExceptionInternal(e, e.getBindingResult(),request);
}

private ResponseEntity<Object> handleExceptionInternal(
Exception e, ErrorCode errorCode, BindingResult bindingResult, WebRequest request) {
Exception e, BindingResult bindingResult, WebRequest request) {
log.error(e.getMessage(), e);
ErrorResponse errorResponse = makeErrorResponse(errorCode,bindingResult);
return super.handleExceptionInternal(e, errorResponse, HttpHeaders.EMPTY, errorCode.getStatus(), request);
ErrorResponse errorResponse = makeErrorResponse(bindingResult);
return super.handleExceptionInternal(e, errorResponse, HttpHeaders.EMPTY, ErrorCode.INPUT_INVALID_VALUE.getStatus(), request);
}


private ErrorResponse makeErrorResponse(ErrorCode errorCode, BindingResult bindingResult) {
private ErrorResponse makeErrorResponse(BindingResult bindingResult) {
return ErrorResponse.builder()
.message(errorCode.getMessage())
.code(errorCode.getErrorCode())
.message(ErrorCode.INPUT_INVALID_VALUE.getMessage())
.code(ErrorCode.INPUT_INVALID_VALUE.getErrorCode())
.errors(ErrorResponse.FieldError.of(bindingResult))
.build();
}
Expand Down

0 comments on commit 41cd47a

Please sign in to comment.