Skip to content

Commit

Permalink
Merge pull request #37 from GDG-Hackathon-77ia/refactor/changeDomain
Browse files Browse the repository at this point in the history
Refactor/change domain
  • Loading branch information
GitJIHO authored Nov 15, 2024
2 parents 9ec16b0 + 5d7cc7a commit e9ad2fa
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.gdg.kkia.common.exception;

public class EmptyFieldException extends RuntimeException {
public EmptyFieldException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,12 @@ public ResponseEntity<ProblemDetail> handleNoWrittenSurveyException(NoWrittenSur
return ResponseEntity.status(HttpStatusCode.valueOf(463)).body(problemDetail);
}

@ExceptionHandler(EmptyFieldException.class)
public ResponseEntity<ProblemDetail> 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);
}

}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -30,6 +32,7 @@ public class DailyResponse {
@NotNull
private LocalDate responseDate;
@NotNull
@NotEmpty
private String response;
@ManyToOne
@JoinColumn(name = "member_id")
Expand All @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/gdg/kkia/diary/entity/Diary.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -26,6 +28,7 @@ public class Diary {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@NotNull
@NotEmpty
private String content;
@NotNull
@CreatedDate
Expand All @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/gdg/kkia/memo/entity/Memo.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -24,6 +26,7 @@ public class Memo {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@NotNull
@NotEmpty
@Setter
private String content;
@NotNull
Expand All @@ -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;
}
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/gdg/kkia/pet/entity/Pet.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -28,6 +30,7 @@ public class Pet {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@NotNull
@NotEmpty
private String name;
@NotNull
private int level;
Expand All @@ -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;
Expand Down

0 comments on commit e9ad2fa

Please sign in to comment.