Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.livable.server.config;
package com.livable.server.core.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/livable/server/core/exception/ErrorCode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.livable.server.core.exception;

import org.springframework.http.HttpStatus;

public interface ErrorCode {

String getMessage();

HttpStatus getHttpStatus();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.livable.server.core.exception;

import com.livable.server.core.response.ApiResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.BindException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;

@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {

@ExceptionHandler(MethodArgumentTypeMismatchException.class)
public ResponseEntity<ApiResponse.Error> methodMethodArgumentTypeMismatchExceptionHandle(MethodArgumentTypeMismatchException e) {
return ApiResponse.error(e.getMessage(), HttpStatus.BAD_REQUEST);
}

@ExceptionHandler(BindException.class)
public ResponseEntity<ApiResponse.Error> bindException(BindException e) {
log.error("bindException", e);

return ApiResponse.error(e.getBindingResult().getFieldError().getDefaultMessage(), HttpStatus.BAD_REQUEST);
}

@ExceptionHandler(GlobalRuntimeException.class)
public ResponseEntity<ApiResponse.Error> globalRuntimeExceptionHandle(GlobalRuntimeException e) {
log.error("globalRuntimeExceptionHandle", e);

return ApiResponse.error(e.getErrorCode());
}

@ExceptionHandler(RuntimeException.class)
public ResponseEntity<ApiResponse.Error> runtimeExceptionHandle(RuntimeException e) {
log.error("runtimeExceptionHandle", e);

return ApiResponse.error(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
}

@ExceptionHandler(Exception.class)
public ResponseEntity<ApiResponse.Error> exceptionHandle(Exception e) {
log.error("exceptionHandle", e);

return ApiResponse.error(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.livable.server.core.exception;

import lombok.Getter;

@Getter
public class GlobalRuntimeException extends RuntimeException {

private final ErrorCode errorCode;

public GlobalRuntimeException(ErrorCode errorCode) {
super();
this.errorCode = errorCode;
}
}
56 changes: 56 additions & 0 deletions src/main/java/com/livable/server/core/response/ApiResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.livable.server.core.response;

import com.livable.server.core.exception.ErrorCode;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.lang.NonNull;

@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class ApiResponse {

public static <T> ResponseEntity<Success<T>> success(@NonNull HttpStatus httpStatus) {
return ResponseEntity.status(httpStatus)
.build();
}

public static <T> ResponseEntity<Success<T>> success(@NonNull T data, @NonNull HttpStatus httpStatus) {
return ResponseEntity.status(httpStatus)
.body(Success.of(data));
}

public static ResponseEntity<Error> error(@NonNull String message, @NonNull HttpStatus httpStatus) {
return ResponseEntity.status(httpStatus)
.body(Error.of(message));
}

public static ResponseEntity<Error> error(@NonNull ErrorCode errorCode) {
return ResponseEntity.status(errorCode.getHttpStatus())
.body(Error.of(errorCode.getMessage()));
}

@Getter
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public static class Error {

private String message;

public static Error of(@NonNull String errorMessage) {
return new Error(errorMessage);
}
}

@Getter
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public static class Success<T> {

private T data;

public static <T> Success<T> of(@NonNull T data) {
return new Success<>(data);
}
}
}
2 changes: 0 additions & 2 deletions src/main/java/com/livable/server/entity/BaseTimeEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@


import lombok.Getter;
import lombok.experimental.SuperBuilder;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.Column;
import javax.persistence.EntityListeners;
import javax.persistence.MappedSuperclass;
import java.time.LocalDateTime;
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/com/livable/server/entity/Building.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package com.livable.server.entity;

import lombok.*;
import org.hibernate.annotations.ColumnDefault;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.*;
import java.time.LocalDateTime;
import java.time.LocalTime;

@Getter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class CafeteriaReview extends Review {
@Column(nullable = false)
private Evaluation taste;

@JoinColumn(nullable = false)
@ManyToOne(fetch = FetchType.LAZY)
private Building building;
}
3 changes: 3 additions & 0 deletions src/main/java/com/livable/server/entity/CommonPlace.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ public class CommonPlace extends BaseTimeEntity {
@ManyToOne(fetch = FetchType.LAZY)
private Building building;

@Column(nullable = false)
private String name;

@Column(nullable = false)
private String floor;

@Column(nullable = false)
private String roomNumber;
}
3 changes: 1 addition & 2 deletions src/main/java/com/livable/server/entity/Evaluation.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@
public enum Evaluation {

GOOD,
BAD,
;
BAD;
}
3 changes: 0 additions & 3 deletions src/main/java/com/livable/server/entity/Invitation.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package com.livable.server.entity;

import lombok.*;
import org.hibernate.annotations.ColumnDefault;

import javax.persistence.*;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;

@Getter
Expand Down Expand Up @@ -43,5 +41,4 @@ public class Invitation extends BaseTimeEntity {

@Column(nullable = false)
private LocalTime endTime;

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@ public enum InvitationPurpose {
PERIOD_WORK,
SEMINAR,
AFTER_SERVICE,
ETC,
;
ETC;
}
6 changes: 4 additions & 2 deletions src/main/java/com/livable/server/entity/LunchBoxReview.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.livable.server.entity;

import lombok.*;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

import javax.persistence.*;
import javax.persistence.Entity;

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/livable/server/entity/Member.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.livable.server.entity;

import lombok.*;
import org.hibernate.annotations.ColumnDefault;

import javax.persistence.*;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.livable.server.entity;

import lombok.*;
import org.hibernate.annotations.ColumnDefault;

import javax.persistence.*;
import java.time.LocalDate;
Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/livable/server/entity/Point.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.livable.server.entity;

import lombok.*;
import org.hibernate.annotations.ColumnDefault;

import javax.persistence.*;

Expand Down
3 changes: 1 addition & 2 deletions src/main/java/com/livable/server/entity/PointCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ public enum PointCode {
PA03("오점완 7일차 달성 보상"),
PA04("오점완 14일차 달성 보상"),
PA05("오점완 21일차 달성 보상"),
PM00("제휴 카페 메뉴 할인에 대한 포인트 사용"),
;
PM00("제휴 카페 메뉴 할인에 대한 포인트 사용");

private final String description;
}
1 change: 0 additions & 1 deletion src/main/java/com/livable/server/entity/PointLog.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import lombok.*;

import javax.persistence.*;
import java.time.LocalDate;

@Getter
@Builder
Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/livable/server/entity/Reservation.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import javax.persistence.*;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;

@Getter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@
public enum RestaurantCategory {

RESTAURANT,
CAFE,
;
CAFE;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.livable.server.entity;

import lombok.*;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

import javax.persistence.*;
Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/livable/server/entity/Review.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import lombok.*;
import lombok.experimental.SuperBuilder;
import org.hibernate.annotations.DynamicInsert;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/livable/server/entity/Role.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.livable.server.entity;

public enum Role {
ADMIN, USER
ADMIN,
USER;
}
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.livable.server;

import com.livable.server.core.response.ApiResponse;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

Expand Down