diff --git a/src/main/java/com/gdg/kkia/common/config/SwaggerConfig.java b/src/main/java/com/gdg/kkia/common/config/SwaggerConfig.java index 8f22a54..2d21061 100644 --- a/src/main/java/com/gdg/kkia/common/config/SwaggerConfig.java +++ b/src/main/java/com/gdg/kkia/common/config/SwaggerConfig.java @@ -14,7 +14,7 @@ @Configuration public class SwaggerConfig { private static final String LOCAL_SERVER_URL = "http://localhost:8080"; - private static final String PROD_SERVER_URL = "https://kkia.backapi.site"; + private static final String PROD_SERVER_URL = "https://dandani.site"; private final Environment environment; public SwaggerConfig(Environment environment) { diff --git a/src/main/java/com/gdg/kkia/common/exception/EmptyFieldException.java b/src/main/java/com/gdg/kkia/common/exception/EmptyFieldException.java new file mode 100644 index 0000000..6cb05de --- /dev/null +++ b/src/main/java/com/gdg/kkia/common/exception/EmptyFieldException.java @@ -0,0 +1,7 @@ +package com.gdg.kkia.common.exception; + +public class EmptyFieldException extends RuntimeException { + public EmptyFieldException(String message) { + super(message); + } +} diff --git a/src/main/java/com/gdg/kkia/common/exception/GlobalExceptionHandler.java b/src/main/java/com/gdg/kkia/common/exception/GlobalExceptionHandler.java index 07f759e..4ca6941 100644 --- a/src/main/java/com/gdg/kkia/common/exception/GlobalExceptionHandler.java +++ b/src/main/java/com/gdg/kkia/common/exception/GlobalExceptionHandler.java @@ -82,4 +82,12 @@ public ResponseEntity handleNoWrittenSurveyException(NoWrittenSur return ResponseEntity.status(HttpStatusCode.valueOf(463)).body(problemDetail); } + @ExceptionHandler(EmptyFieldException.class) + public ResponseEntity handleEmptyFieldException(EmptyFieldException e) { + + ProblemDetail problemDetail = ProblemDetail.forStatusAndDetail(HttpStatusCode.valueOf(463), e.getMessage()); + problemDetail.setTitle("Empty Field Exception"); + return ResponseEntity.status(HttpStatusCode.valueOf(464)).body(problemDetail); + } + } diff --git a/src/main/java/com/gdg/kkia/dailyresponse/entity/DailyResponse.java b/src/main/java/com/gdg/kkia/dailyresponse/entity/DailyResponse.java index ca3c804..345a428 100644 --- a/src/main/java/com/gdg/kkia/dailyresponse/entity/DailyResponse.java +++ b/src/main/java/com/gdg/kkia/dailyresponse/entity/DailyResponse.java @@ -1,7 +1,9 @@ package com.gdg.kkia.dailyresponse.entity; +import com.gdg.kkia.common.exception.EmptyFieldException; import com.gdg.kkia.member.entity.Member; import jakarta.persistence.*; +import jakarta.validation.constraints.NotEmpty; import jakarta.validation.constraints.NotNull; import lombok.*; import org.hibernate.annotations.OnDelete; @@ -30,6 +32,7 @@ public class DailyResponse { @NotNull private LocalDate responseDate; @NotNull + @NotEmpty private String response; @ManyToOne @JoinColumn(name = "member_id") @@ -43,6 +46,9 @@ public class DailyResponse { private DailyQuestion dailyQuestion; public DailyResponse(String response, Member member, DailyQuestion dailyQuestion) { + if (response.isBlank() || response.isEmpty()) { + throw new EmptyFieldException("비어있을 수 없습니다."); + } this.response = response; this.member = member; this.dailyQuestion = dailyQuestion; diff --git a/src/main/java/com/gdg/kkia/diary/entity/Diary.java b/src/main/java/com/gdg/kkia/diary/entity/Diary.java index 100a5f4..5deeca4 100644 --- a/src/main/java/com/gdg/kkia/diary/entity/Diary.java +++ b/src/main/java/com/gdg/kkia/diary/entity/Diary.java @@ -1,8 +1,10 @@ package com.gdg.kkia.diary.entity; import com.gdg.kkia.common.exception.BadRequestException; +import com.gdg.kkia.common.exception.EmptyFieldException; import com.gdg.kkia.member.entity.Member; import jakarta.persistence.*; +import jakarta.validation.constraints.NotEmpty; import jakarta.validation.constraints.NotNull; import lombok.*; import org.hibernate.annotations.OnDelete; @@ -26,6 +28,7 @@ public class Diary { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; @NotNull + @NotEmpty private String content; @NotNull @CreatedDate @@ -42,6 +45,9 @@ public class Diary { private Member member; public Diary(Diary.Type type, String content, Member member) { + if (content.isBlank() || content.isEmpty()) { + throw new EmptyFieldException("비어있을 수 없습니다."); + } this.type = type; this.content = content; this.member = member; diff --git a/src/main/java/com/gdg/kkia/memo/entity/Memo.java b/src/main/java/com/gdg/kkia/memo/entity/Memo.java index a6f1f59..39689bc 100644 --- a/src/main/java/com/gdg/kkia/memo/entity/Memo.java +++ b/src/main/java/com/gdg/kkia/memo/entity/Memo.java @@ -1,8 +1,10 @@ package com.gdg.kkia.memo.entity; +import com.gdg.kkia.common.exception.EmptyFieldException; import com.gdg.kkia.diary.entity.Diary; import com.gdg.kkia.member.entity.Member; import jakarta.persistence.*; +import jakarta.validation.constraints.NotEmpty; import jakarta.validation.constraints.NotNull; import lombok.*; import org.hibernate.annotations.OnDelete; @@ -24,6 +26,7 @@ public class Memo { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; @NotNull + @NotEmpty @Setter private String content; @NotNull @@ -37,6 +40,9 @@ public class Memo { private Member member; public Memo(String content, Member member) { + if (content.isBlank() || content.isEmpty()) { + throw new EmptyFieldException("비어있을 수 없습니다."); + } this.content = content; this.member = member; } diff --git a/src/main/java/com/gdg/kkia/pet/entity/Pet.java b/src/main/java/com/gdg/kkia/pet/entity/Pet.java index 880d30a..8cc4cb3 100644 --- a/src/main/java/com/gdg/kkia/pet/entity/Pet.java +++ b/src/main/java/com/gdg/kkia/pet/entity/Pet.java @@ -1,8 +1,10 @@ package com.gdg.kkia.pet.entity; import com.gdg.kkia.common.exception.BadRequestException; +import com.gdg.kkia.common.exception.EmptyFieldException; import com.gdg.kkia.member.entity.Member; import jakarta.persistence.*; +import jakarta.validation.constraints.NotEmpty; import jakarta.validation.constraints.NotNull; import lombok.*; import org.hibernate.annotations.OnDelete; @@ -28,6 +30,7 @@ public class Pet { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; @NotNull + @NotEmpty private String name; @NotNull private int level; @@ -42,6 +45,9 @@ public class Pet { private Member member; public Pet(String name, Member member) { + if (name.isBlank() || name.isEmpty()) { + throw new EmptyFieldException("비어있을 수 없습니다."); + } this.name = name; this.member = member; this.level = INITIAL_LEVEL;