Skip to content

Commit

Permalink
♻️ : 에러 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
imenuuu committed Feb 5, 2024
1 parent 44ec03e commit cb99343
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.example.matchapi.admin.user.service.context;

import static com.example.matchcommon.exception.errorcode.FilterErrorCode.*;

import java.util.EnumMap;
import java.util.List;
import java.util.Map;
Expand All @@ -9,6 +11,7 @@

import com.example.matchapi.admin.user.enums.UserFilter;
import com.example.matchapi.admin.user.service.strategy.UserStrategy;
import com.example.matchcommon.exception.BadRequestException;

@Component
public class UserContextFactory {
Expand All @@ -21,11 +24,11 @@ public UserContextFactory(List<UserStrategy> strategies) {
contextMap.put(strategy.getFilter(), new UserContext(strategy));
}
}

public UserContext getContextByFilter(UserFilter filter) {
UserContext context = contextMap.get(filter);
if (context == null) {
throw new IllegalArgumentException("Unknown filter " + filter);
throw new BadRequestException(NOT_EXISTS_FILTER);
}
return context;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public ResponseEntity onException(Exception exception, @AuthenticationPrincipal
else{
discordService.sendUnKnownMessage(user.getUsername(), exception, request);
}

log.error("INTERNAL_SERVER_ERROR", exception);
return new ResponseEntity<>(CommonResponse.onFailure("500", exception.getMessage(), null), null,
HttpStatus.INTERNAL_SERVER_ERROR);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ public void patchProjectStatus(ProjectStatus projectStatus, Long projectId) {
projectAdaptor.save(project);
}

@Transactional
public void deleteProject(Long projectId) {
Project project = projectAdaptor.findById(projectId);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.example.matchcommon.exception;

import com.example.matchcommon.exception.errorcode.BaseErrorCode;

public class IllegalArgumentException extends BaseException{
public IllegalArgumentException(BaseErrorCode errorCode) {
super(errorCode);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.example.matchcommon.exception.errorcode;

import java.lang.reflect.Field;
import java.util.Objects;

import org.springframework.http.HttpStatus;

import com.example.matchcommon.annotation.ExplainError;
import com.example.matchcommon.dto.ErrorReason;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public enum FilterErrorCode implements BaseErrorCode{

/**
* 잘못된 요청
*/
NOT_EXISTS_FILTER(HttpStatus.BAD_REQUEST, "FILTER_001", "필터값이 존재하지 않습니다.");


private final HttpStatus httpStatus;
private final String code;
private final String message;


@Override
public ErrorReason getErrorReason() {
return ErrorReason.builder().message(message).code(code).isSuccess(false).build();
}

@Override
public String getExplainError() throws NoSuchFieldException {
Field field = this.getClass().getField(this.name());
ExplainError annotation = field.getAnnotation(ExplainError.class);
return Objects.nonNull(annotation) ? annotation.value() : this.getMessage();
}

@Override
public ErrorReason getErrorReasonHttpStatus(){
return ErrorReason.builder().message(message).code(code).isSuccess(false).httpStatus(httpStatus).build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,27 +97,6 @@ public Long getMonthUserCnt(LocalDate localDate) {
return userRepository.countByCreatedAtGreaterThanAndCreatedAtLessThan(LocalDateTime.parse(localDate.with(TemporalAdjusters.firstDayOfMonth())+FIRST_TIME), LocalDateTime.parse(localDate.with(TemporalAdjusters.lastDayOfMonth())+LAST_TIME));
}

public Page<UserRepository.UserList> getUserList(int page, int size, Status status, String content) {
Pageable pageable = PageRequest.of(page, size);

Page<UserRepository.UserList> userList = null;

if(status == null && content ==null) {
userList = userRepository.getUserList(pageable);
}
else if (status !=null && content ==null){
userList = userRepository.getUserListByStatus(pageable, status.getValue());
}
else if(status!=null){
userList = userRepository.getUserListByStatusAndName(pageable, status.getValue(),content);
}
else{
userList = userRepository.getUserListByName(pageable, content);
}

return userList;
}

public UserRepository.UserList getUserDetail(Long userId) {
return userRepository.getUserDetail(userId);
}
Expand Down

0 comments on commit cb99343

Please sign in to comment.