diff --git a/src/main/java/sopt/org/motivooServer/domain/common/BaseTimeEntity.java b/src/main/java/sopt/org/motivooServer/domain/common/BaseTimeEntity.java new file mode 100644 index 00000000..84672e2e --- /dev/null +++ b/src/main/java/sopt/org/motivooServer/domain/common/BaseTimeEntity.java @@ -0,0 +1,23 @@ +package sopt.org.motivooServer.domain.common; + +import java.time.LocalDateTime; + +import org.springframework.data.annotation.CreatedDate; +import org.springframework.data.annotation.LastModifiedDate; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +import jakarta.persistence.EntityListeners; +import jakarta.persistence.MappedSuperclass; +import lombok.Getter; + +@Getter +@MappedSuperclass +@EntityListeners(AuditingEntityListener.class) +public abstract class BaseTimeEntity { + + @CreatedDate + private LocalDateTime createdAt; + + @LastModifiedDate + private LocalDateTime updatedAt; +} diff --git a/src/main/java/sopt/org/motivooServer/domain/health/entity/ExerciseFrequency.java b/src/main/java/sopt/org/motivooServer/domain/health/entity/ExerciseFrequency.java new file mode 100644 index 00000000..c8b48770 --- /dev/null +++ b/src/main/java/sopt/org/motivooServer/domain/health/entity/ExerciseFrequency.java @@ -0,0 +1,6 @@ +package sopt.org.motivooServer.domain.health.entity; + +public enum ExerciseFrequency { + + // 1회 미만 | 1~2회 | 3~4회 | 5회 이상 +} diff --git a/src/main/java/sopt/org/motivooServer/domain/health/entity/ExerciseTime.java b/src/main/java/sopt/org/motivooServer/domain/health/entity/ExerciseTime.java new file mode 100644 index 00000000..f4151d48 --- /dev/null +++ b/src/main/java/sopt/org/motivooServer/domain/health/entity/ExerciseTime.java @@ -0,0 +1,6 @@ +package sopt.org.motivooServer.domain.health.entity; + +public enum ExerciseTime { + + // 30분 미만 | 30분~1시간 | 1시간~2시간 | 2시간 이상 +} diff --git a/src/main/java/sopt/org/motivooServer/domain/health/entity/ExerciseType.java b/src/main/java/sopt/org/motivooServer/domain/health/entity/ExerciseType.java new file mode 100644 index 00000000..9664790e --- /dev/null +++ b/src/main/java/sopt/org/motivooServer/domain/health/entity/ExerciseType.java @@ -0,0 +1,6 @@ +package sopt.org.motivooServer.domain.health.entity; + +public enum ExerciseType { + + // 고강도 | 중강도 | 저강도 +} diff --git a/src/main/java/sopt/org/motivooServer/domain/health/entity/Health.java b/src/main/java/sopt/org/motivooServer/domain/health/entity/Health.java new file mode 100644 index 00000000..70f697bb --- /dev/null +++ b/src/main/java/sopt/org/motivooServer/domain/health/entity/Health.java @@ -0,0 +1,49 @@ +package sopt.org.motivooServer.domain.health.entity; + +import java.util.ArrayList; +import java.util.List; + +import jakarta.persistence.Column; +import jakarta.persistence.ElementCollection; +import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.OneToOne; +import sopt.org.motivooServer.domain.common.BaseTimeEntity; +import sopt.org.motivooServer.domain.user.entity.User; + +@Entity +public class Health extends BaseTimeEntity { + + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "health_id") + private Long id; + + @OneToOne + @JoinColumn(name = "user_id") + private User user; + + @Column(nullable = false) + private Boolean isExercise; + + @Enumerated(EnumType.STRING) + @Column(nullable = false) + private ExerciseType exerciseType; + + @Enumerated(EnumType.STRING) + @Column(nullable = false) + private ExerciseFrequency exerciseFrequency; + + @Enumerated(EnumType.STRING) + @Column(nullable = false) + private ExerciseTime exerciseTime; + + @Enumerated(EnumType.STRING) + @Column(nullable = false) + @ElementCollection + private List healthNotes = new ArrayList<>(); +} diff --git a/src/main/java/sopt/org/motivooServer/domain/health/entity/HealthNote.java b/src/main/java/sopt/org/motivooServer/domain/health/entity/HealthNote.java new file mode 100644 index 00000000..09483148 --- /dev/null +++ b/src/main/java/sopt/org/motivooServer/domain/health/entity/HealthNote.java @@ -0,0 +1,29 @@ +package sopt.org.motivooServer.domain.health.entity; + +import static sopt.org.motivooServer.domain.health.exception.HealthExceptionType.*; + +import java.util.Arrays; + +import lombok.AccessLevel; +import lombok.RequiredArgsConstructor; +import sopt.org.motivooServer.domain.health.exception.HealthException; + +@RequiredArgsConstructor(access = AccessLevel.PRIVATE) +public enum HealthNote { + + WAIST("허리"), + KNEE("무릎"), + NECK("목"), + WRIST("손목"), + SHOULDER("어깨"), + ANKLE("발목"); + + private final String value; + + public static HealthNote of(String value) { + return Arrays.stream(HealthNote.values()) + .filter(healthNote -> value.equals(healthNote.value)) + .findFirst() + .orElseThrow(() -> new HealthException(INVALID_HEALTH_NOTE)); + } +} diff --git a/src/main/java/sopt/org/motivooServer/domain/health/exception/HealthException.java b/src/main/java/sopt/org/motivooServer/domain/health/exception/HealthException.java new file mode 100644 index 00000000..9395a443 --- /dev/null +++ b/src/main/java/sopt/org/motivooServer/domain/health/exception/HealthException.java @@ -0,0 +1,11 @@ +package sopt.org.motivooServer.domain.health.exception; + +import sopt.org.motivooServer.global.advice.BusinessException; +import sopt.org.motivooServer.global.advice.BusinessExceptionType; + +public class HealthException extends BusinessException { + + public HealthException(BusinessExceptionType exceptionType) { + super(exceptionType); + } +} diff --git a/src/main/java/sopt/org/motivooServer/domain/health/exception/HealthExceptionType.java b/src/main/java/sopt/org/motivooServer/domain/health/exception/HealthExceptionType.java new file mode 100644 index 00000000..dc320a6d --- /dev/null +++ b/src/main/java/sopt/org/motivooServer/domain/health/exception/HealthExceptionType.java @@ -0,0 +1,37 @@ +package sopt.org.motivooServer.domain.health.exception; + +import org.springframework.http.HttpStatus; + +import lombok.AccessLevel; +import lombok.RequiredArgsConstructor; +import sopt.org.motivooServer.global.advice.BusinessExceptionType; + +@RequiredArgsConstructor(access = AccessLevel.PRIVATE) +public enum HealthExceptionType implements BusinessExceptionType { + + /** + * 400 Bad Request + */ + INVALID_HEALTH_NOTE(HttpStatus.BAD_REQUEST, "유효하지 않는 건강 주의사항입니다."), + + /** + * 404 Not Found + */ + HEALTH_NOT_FOUND(HttpStatus.NOT_FOUND, "존재하지 않는 건강정보입니다.") + + + ; + + private final HttpStatus status; + private final String message; + + @Override + public HttpStatus status() { + return this.status; + } + + @Override + public String message() { + return this.message; + } +} diff --git a/src/main/java/sopt/org/motivooServer/domain/mission/entity/CompletedStatus.java b/src/main/java/sopt/org/motivooServer/domain/mission/entity/CompletedStatus.java new file mode 100644 index 00000000..778520a3 --- /dev/null +++ b/src/main/java/sopt/org/motivooServer/domain/mission/entity/CompletedStatus.java @@ -0,0 +1,16 @@ +package sopt.org.motivooServer.domain.mission.entity; + +import lombok.AccessLevel; +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor(access = AccessLevel.PRIVATE) +public enum CompletedStatus { + + SUCCESS("성공"), + FAIL("실패"), + IN_PROGRESS("진행중"); + + private final String value; +} diff --git a/src/main/java/sopt/org/motivooServer/domain/mission/entity/Mission.java b/src/main/java/sopt/org/motivooServer/domain/mission/entity/Mission.java new file mode 100644 index 00000000..f38ad37c --- /dev/null +++ b/src/main/java/sopt/org/motivooServer/domain/mission/entity/Mission.java @@ -0,0 +1,29 @@ +package sopt.org.motivooServer.domain.mission.entity; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import sopt.org.motivooServer.domain.common.BaseTimeEntity; + +@Entity +public class Mission extends BaseTimeEntity { + + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "mission_id") + private Long id; + + @Column(nullable = false) + private String content; + + @Enumerated(EnumType.STRING) + @Column(nullable = false) + private MissionType type; + + @Column(columnDefinition = "TEXT") + private String descriptionUrl; + +} diff --git a/src/main/java/sopt/org/motivooServer/domain/mission/entity/MissionType.java b/src/main/java/sopt/org/motivooServer/domain/mission/entity/MissionType.java new file mode 100644 index 00000000..8591b0de --- /dev/null +++ b/src/main/java/sopt/org/motivooServer/domain/mission/entity/MissionType.java @@ -0,0 +1,10 @@ +package sopt.org.motivooServer.domain.mission.entity; + +import lombok.AccessLevel; +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor(access = AccessLevel.PRIVATE) +public enum MissionType { + + +} diff --git a/src/main/java/sopt/org/motivooServer/domain/mission/entity/UserMission.java b/src/main/java/sopt/org/motivooServer/domain/mission/entity/UserMission.java new file mode 100644 index 00000000..c628ad11 --- /dev/null +++ b/src/main/java/sopt/org/motivooServer/domain/mission/entity/UserMission.java @@ -0,0 +1,51 @@ +package sopt.org.motivooServer.domain.mission.entity; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.OneToOne; +import lombok.Getter; +import sopt.org.motivooServer.domain.common.BaseTimeEntity; +import sopt.org.motivooServer.domain.user.entity.User; + +@Getter +@Entity +public class UserMission extends BaseTimeEntity { + + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "user_mission_id") + private Long id; + + @Column(nullable = false) + private Double completedRate; + + @Enumerated(EnumType.STRING) + @Column(nullable = false) + private CompletedStatus completedStatus; + + @Column(columnDefinition = "TEXT") + private String imgUrl; + + @OneToOne + @JoinColumn(name = "mission_id", nullable = false) + private Mission mission; + + @ManyToOne + @JoinColumn(name = "user_id") + private User user; + + //== 연관관계 메서드 ==// + public void setUser(User user) { + this.user = user; + + if (!user.getUserMissions().contains(this)) { + user.getUserMissions().add(this); + } + } +} diff --git a/src/main/java/sopt/org/motivooServer/domain/mission/exception/MissionException.java b/src/main/java/sopt/org/motivooServer/domain/mission/exception/MissionException.java index 6ca0f1ed..d4b5dda7 100644 --- a/src/main/java/sopt/org/motivooServer/domain/mission/exception/MissionException.java +++ b/src/main/java/sopt/org/motivooServer/domain/mission/exception/MissionException.java @@ -1,11 +1,11 @@ package sopt.org.motivooServer.domain.mission.exception; -import sopt.org.motivooServer.global.advice.ErrorType; import sopt.org.motivooServer.global.advice.BusinessException; +import sopt.org.motivooServer.global.advice.BusinessExceptionType; public class MissionException extends BusinessException { - public MissionException(ErrorType errorType) { - super(errorType); + public MissionException(BusinessExceptionType exceptionType) { + super(exceptionType); } } diff --git a/src/main/java/sopt/org/motivooServer/domain/mission/exception/MissionExceptionType.java b/src/main/java/sopt/org/motivooServer/domain/mission/exception/MissionExceptionType.java index 56b2c7d0..3a279c28 100644 --- a/src/main/java/sopt/org/motivooServer/domain/mission/exception/MissionExceptionType.java +++ b/src/main/java/sopt/org/motivooServer/domain/mission/exception/MissionExceptionType.java @@ -3,12 +3,10 @@ import org.springframework.http.HttpStatus; import lombok.AccessLevel; -import lombok.AllArgsConstructor; -import lombok.Getter; +import lombok.RequiredArgsConstructor; import sopt.org.motivooServer.global.advice.BusinessExceptionType; -@Getter -@AllArgsConstructor(access = AccessLevel.PRIVATE) +@RequiredArgsConstructor(access = AccessLevel.PRIVATE) public enum MissionExceptionType implements BusinessExceptionType { /** diff --git a/src/main/java/sopt/org/motivooServer/domain/parentchild/entity/Parentchild.java b/src/main/java/sopt/org/motivooServer/domain/parentchild/entity/Parentchild.java new file mode 100644 index 00000000..9006ef15 --- /dev/null +++ b/src/main/java/sopt/org/motivooServer/domain/parentchild/entity/Parentchild.java @@ -0,0 +1,22 @@ +package sopt.org.motivooServer.domain.parentchild.entity; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import sopt.org.motivooServer.domain.common.BaseTimeEntity; + +@Entity +public class Parentchild extends BaseTimeEntity { + + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "parentchild_id") + private Long id; + + @Column(nullable = false) + private Boolean isMatched; + + @Column(nullable = false) + private String inviteCode; +} diff --git a/src/main/java/sopt/org/motivooServer/domain/parentchild/exception/ParentchildException.java b/src/main/java/sopt/org/motivooServer/domain/parentchild/exception/ParentchildException.java new file mode 100644 index 00000000..8e760a2e --- /dev/null +++ b/src/main/java/sopt/org/motivooServer/domain/parentchild/exception/ParentchildException.java @@ -0,0 +1,11 @@ +package sopt.org.motivooServer.domain.parentchild.exception; + +import sopt.org.motivooServer.global.advice.BusinessException; +import sopt.org.motivooServer.global.advice.BusinessExceptionType; + +public class ParentchildException extends BusinessException { + + public ParentchildException(BusinessExceptionType exceptionType) { + super(exceptionType); + } +} diff --git a/src/main/java/sopt/org/motivooServer/domain/parentchild/exception/ParentchildExceptionType.java b/src/main/java/sopt/org/motivooServer/domain/parentchild/exception/ParentchildExceptionType.java new file mode 100644 index 00000000..ec31d5b0 --- /dev/null +++ b/src/main/java/sopt/org/motivooServer/domain/parentchild/exception/ParentchildExceptionType.java @@ -0,0 +1,32 @@ +package sopt.org.motivooServer.domain.parentchild.exception; + +import org.springframework.http.HttpStatus; + +import lombok.AccessLevel; +import lombok.RequiredArgsConstructor; +import sopt.org.motivooServer.global.advice.BusinessExceptionType; + +@RequiredArgsConstructor(access = AccessLevel.PRIVATE) +public enum ParentchildExceptionType implements BusinessExceptionType { + + /** + * 404 Not Found + */ + PARENTCHILD_NOT_FOUND(HttpStatus.NOT_FOUND, "존재하지 않는 부모-자녀 관계입니다.") + + + ; + + private final HttpStatus status; + private final String message; + + @Override + public HttpStatus status() { + return this.status; + } + + @Override + public String message() { + return this.message; + } +} diff --git a/src/main/java/sopt/org/motivooServer/domain/step/entity/Step.java b/src/main/java/sopt/org/motivooServer/domain/step/entity/Step.java new file mode 100644 index 00000000..e9ddd5d5 --- /dev/null +++ b/src/main/java/sopt/org/motivooServer/domain/step/entity/Step.java @@ -0,0 +1,26 @@ +package sopt.org.motivooServer.domain.step.entity; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.OneToOne; +import sopt.org.motivooServer.domain.common.BaseTimeEntity; +import sopt.org.motivooServer.domain.user.entity.User; + +@Entity +public class Step extends BaseTimeEntity { + + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "step_id") + private Long id; + + @Column(nullable = false) + private Integer count; + + @OneToOne + @JoinColumn(name = "user_id") + private User user; +} diff --git a/src/main/java/sopt/org/motivooServer/domain/step/exception/StepException.java b/src/main/java/sopt/org/motivooServer/domain/step/exception/StepException.java new file mode 100644 index 00000000..3a1cddcf --- /dev/null +++ b/src/main/java/sopt/org/motivooServer/domain/step/exception/StepException.java @@ -0,0 +1,11 @@ +package sopt.org.motivooServer.domain.step.exception; + +import sopt.org.motivooServer.global.advice.BusinessException; +import sopt.org.motivooServer.global.advice.BusinessExceptionType; + +public class StepException extends BusinessException { + + public StepException(BusinessExceptionType exceptionType) { + super(exceptionType); + } +} diff --git a/src/main/java/sopt/org/motivooServer/domain/step/exception/StepExceptionType.java b/src/main/java/sopt/org/motivooServer/domain/step/exception/StepExceptionType.java new file mode 100644 index 00000000..c49eb9d2 --- /dev/null +++ b/src/main/java/sopt/org/motivooServer/domain/step/exception/StepExceptionType.java @@ -0,0 +1,36 @@ +package sopt.org.motivooServer.domain.step.exception; + +import org.springframework.http.HttpStatus; + +import lombok.AccessLevel; +import lombok.RequiredArgsConstructor; +import sopt.org.motivooServer.global.advice.BusinessExceptionType; + +@RequiredArgsConstructor(access = AccessLevel.PRIVATE) +public enum StepExceptionType implements BusinessExceptionType { + + /** + * 400 Bad Request + */ + + + /** + * 404 Not Found + */ + + + ; + + private final HttpStatus status; + private final String message; + + @Override + public HttpStatus status() { + return this.status; + } + + @Override + public String message() { + return this.message; + } +} diff --git a/src/main/java/sopt/org/motivooServer/domain/user/entity/SocialPlatform.java b/src/main/java/sopt/org/motivooServer/domain/user/entity/SocialPlatform.java new file mode 100644 index 00000000..a6f40b64 --- /dev/null +++ b/src/main/java/sopt/org/motivooServer/domain/user/entity/SocialPlatform.java @@ -0,0 +1,25 @@ +package sopt.org.motivooServer.domain.user.entity; + +import static sopt.org.motivooServer.domain.user.exception.UserExceptionType.*; + +import java.util.Arrays; + +import lombok.AccessLevel; +import lombok.RequiredArgsConstructor; +import sopt.org.motivooServer.domain.user.exception.UserException; + +@RequiredArgsConstructor(access = AccessLevel.PRIVATE) +public enum SocialPlatform { + + KAKAO("카카오"), + APPLE("애플"); + + private final String value; + + public static SocialPlatform of(String value) { + return Arrays.stream(SocialPlatform.values()) + .filter(socialPlatform -> value.equals(socialPlatform.value)) + .findFirst() + .orElseThrow(() -> new UserException(INVALID_SOCIAL_PLATFORM)); + } +} diff --git a/src/main/java/sopt/org/motivooServer/domain/user/entity/User.java b/src/main/java/sopt/org/motivooServer/domain/user/entity/User.java new file mode 100644 index 00000000..18a7f97f --- /dev/null +++ b/src/main/java/sopt/org/motivooServer/domain/user/entity/User.java @@ -0,0 +1,73 @@ +package sopt.org.motivooServer.domain.user.entity; + +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; + +import org.hibernate.annotations.SQLDelete; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.OneToMany; +import jakarta.persistence.Table; +import lombok.Getter; +import sopt.org.motivooServer.domain.common.BaseTimeEntity; +import sopt.org.motivooServer.domain.mission.entity.UserMission; +import sopt.org.motivooServer.domain.parentchild.entity.Parentchild; + +@Getter +@Entity +@Table(name = "`user`") +@SQLDelete(sql = "UPDATE user SET user.deleted=true WHERE user_id=?") +public class User extends BaseTimeEntity { + + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "user_id") + private Long id; + + private String username; + + private Integer age; + + @Enumerated(EnumType.STRING) + @Column(nullable = false) + private UserType type; + + @Column(nullable = false) + private Boolean deleted = Boolean.FALSE; + + @Column(nullable = false) + private Long socialId; + + private String socialNickname; + + private String socialAccessToken; + + @Enumerated(EnumType.STRING) + @Column(nullable = false) + private SocialPlatform socialPlatform; + + + @ManyToOne + @JoinColumn(name = "parentchild_id") + private Parentchild parentchild; + + @OneToMany(mappedBy = "user") + private List userMissions = new ArrayList<>(); + + + //== 연관관계 메서드 ==// + public void addUserMission(UserMission userMission) { + this.userMissions.add(userMission); + if (userMission.getUser() != this) { + userMission.setUser(this); + } + } +} diff --git a/src/main/java/sopt/org/motivooServer/domain/user/entity/UserType.java b/src/main/java/sopt/org/motivooServer/domain/user/entity/UserType.java new file mode 100644 index 00000000..324e5e01 --- /dev/null +++ b/src/main/java/sopt/org/motivooServer/domain/user/entity/UserType.java @@ -0,0 +1,27 @@ +package sopt.org.motivooServer.domain.user.entity; + +import static sopt.org.motivooServer.domain.user.exception.UserExceptionType.*; + +import java.util.Arrays; + +import lombok.AccessLevel; +import lombok.RequiredArgsConstructor; +import sopt.org.motivooServer.domain.user.exception.UserException; + +@RequiredArgsConstructor(access = AccessLevel.PRIVATE) +public enum UserType { + + PARENT("부모"), + CHILD("자녀"), + NONE("없음") + ; + + private final String value; + + public static UserType of(String value) { + return Arrays.stream(UserType.values()) + .filter(userType -> value.equals(userType.value)) + .findFirst() + .orElseThrow(() -> new UserException(INVALID_USER_TYPE)); + } +} diff --git a/src/main/java/sopt/org/motivooServer/domain/user/exception/UserException.java b/src/main/java/sopt/org/motivooServer/domain/user/exception/UserException.java index 94b9e1d0..56932196 100644 --- a/src/main/java/sopt/org/motivooServer/domain/user/exception/UserException.java +++ b/src/main/java/sopt/org/motivooServer/domain/user/exception/UserException.java @@ -1,11 +1,11 @@ package sopt.org.motivooServer.domain.user.exception; -import sopt.org.motivooServer.global.advice.ErrorType; import sopt.org.motivooServer.global.advice.BusinessException; +import sopt.org.motivooServer.global.advice.BusinessExceptionType; public class UserException extends BusinessException { - public UserException(ErrorType errorType) { - super(errorType); + public UserException(BusinessExceptionType exceptionType) { + super(exceptionType); } } diff --git a/src/main/java/sopt/org/motivooServer/domain/user/exception/UserExceptionType.java b/src/main/java/sopt/org/motivooServer/domain/user/exception/UserExceptionType.java index f5278c85..07255bf3 100644 --- a/src/main/java/sopt/org/motivooServer/domain/user/exception/UserExceptionType.java +++ b/src/main/java/sopt/org/motivooServer/domain/user/exception/UserExceptionType.java @@ -3,14 +3,18 @@ import org.springframework.http.HttpStatus; import lombok.AccessLevel; -import lombok.AllArgsConstructor; -import lombok.Getter; +import lombok.RequiredArgsConstructor; import sopt.org.motivooServer.global.advice.BusinessExceptionType; -@Getter -@AllArgsConstructor(access = AccessLevel.PRIVATE) +@RequiredArgsConstructor(access = AccessLevel.PRIVATE) public enum UserExceptionType implements BusinessExceptionType { + /** + * 400 Bad Request + */ + INVALID_USER_TYPE(HttpStatus.BAD_REQUEST, "유효하지 않은 회원 유형입니다."), + INVALID_SOCIAL_PLATFORM(HttpStatus.BAD_REQUEST, "유효하지 않은 소셜 플랫폼입니다."), + /** * 404 Not Found */ diff --git a/src/main/java/sopt/org/motivooServer/global/advice/BusinessException.java b/src/main/java/sopt/org/motivooServer/global/advice/BusinessException.java index 1fdb8c0f..e9b2e354 100644 --- a/src/main/java/sopt/org/motivooServer/global/advice/BusinessException.java +++ b/src/main/java/sopt/org/motivooServer/global/advice/BusinessException.java @@ -5,14 +5,14 @@ @Getter public class BusinessException extends RuntimeException { - private final ErrorType errorType; + private final BusinessExceptionType exceptionType; - public BusinessException(ErrorType errorType) { - super(errorType.getMessage()); - this.errorType = errorType; + public BusinessException(BusinessExceptionType exceptionType) { + super(exceptionType.message()); + this.exceptionType = exceptionType; } public int getHttpStatus() { - return errorType.getHttpStatusCode(); + return exceptionType.status().value(); } } \ No newline at end of file diff --git a/src/main/java/sopt/org/motivooServer/global/advice/BusinessExceptionType.java b/src/main/java/sopt/org/motivooServer/global/advice/BusinessExceptionType.java index 4b39d50a..2017bfc4 100644 --- a/src/main/java/sopt/org/motivooServer/global/advice/BusinessExceptionType.java +++ b/src/main/java/sopt/org/motivooServer/global/advice/BusinessExceptionType.java @@ -5,4 +5,8 @@ public interface BusinessExceptionType { HttpStatus status(); String message(); + + default int getHttpStatusCode() { + return status().value(); + } } diff --git a/src/main/java/sopt/org/motivooServer/global/advice/ErrorResponse.java b/src/main/java/sopt/org/motivooServer/global/advice/ErrorResponse.java index 8e0f7095..d838d7ff 100644 --- a/src/main/java/sopt/org/motivooServer/global/advice/ErrorResponse.java +++ b/src/main/java/sopt/org/motivooServer/global/advice/ErrorResponse.java @@ -14,10 +14,10 @@ public static ErrorResponse of(ErrorType errorType) { ); } - public static ErrorResponse of(ErrorType errorType, String message) { + public static ErrorResponse of(BusinessExceptionType exceptionType) { return new ErrorResponse( - errorType.getHttpStatusCode(), - message, + exceptionType.getHttpStatusCode(), + exceptionType.message(), false ); } diff --git a/src/main/java/sopt/org/motivooServer/global/advice/ErrorType.java b/src/main/java/sopt/org/motivooServer/global/advice/ErrorType.java index 097d5e45..aa62397e 100644 --- a/src/main/java/sopt/org/motivooServer/global/advice/ErrorType.java +++ b/src/main/java/sopt/org/motivooServer/global/advice/ErrorType.java @@ -3,11 +3,11 @@ import org.springframework.http.HttpStatus; import lombok.AccessLevel; -import lombok.AllArgsConstructor; import lombok.Getter; +import lombok.RequiredArgsConstructor; @Getter -@AllArgsConstructor(access = AccessLevel.PRIVATE) +@RequiredArgsConstructor(access = AccessLevel.PRIVATE) public enum ErrorType { /** diff --git a/src/main/java/sopt/org/motivooServer/global/advice/GlobalExceptionHandler.java b/src/main/java/sopt/org/motivooServer/global/advice/GlobalExceptionHandler.java index 8d6ff11c..e327b330 100644 --- a/src/main/java/sopt/org/motivooServer/global/advice/GlobalExceptionHandler.java +++ b/src/main/java/sopt/org/motivooServer/global/advice/GlobalExceptionHandler.java @@ -24,11 +24,11 @@ public class GlobalExceptionHandler { * Custom Error */ @ExceptionHandler(BusinessException.class) - public ResponseEntity handleCustomException(final BusinessException e) { + public ResponseEntity handleBusinessException(final BusinessException e) { - log.error("🚨🚨🚨 CustomException occured: {} 🚨🚨🚨", e.getMessage()); + log.error("🚨🚨🚨 BusinessException occured: {} 🚨🚨🚨", e.getMessage()); return ResponseEntity.status(e.getHttpStatus()) - .body(ErrorResponse.of(e.getErrorType(), e.getMessage())); + .body(ErrorResponse.of(e.getExceptionType())); } } diff --git a/src/main/java/sopt/org/motivooServer/global/response/ApiResponse.java b/src/main/java/sopt/org/motivooServer/global/response/ApiResponse.java index 552ae6d2..b973cb1e 100644 --- a/src/main/java/sopt/org/motivooServer/global/response/ApiResponse.java +++ b/src/main/java/sopt/org/motivooServer/global/response/ApiResponse.java @@ -9,11 +9,9 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; -import lombok.RequiredArgsConstructor; @Getter @Builder -@RequiredArgsConstructor(access = AccessLevel.PRIVATE) @AllArgsConstructor(access = AccessLevel.PRIVATE) @JsonPropertyOrder({"code", "message", "success", "data"}) public class ApiResponse { diff --git a/src/main/java/sopt/org/motivooServer/global/response/SuccessType.java b/src/main/java/sopt/org/motivooServer/global/response/SuccessType.java index 39769482..20df00c2 100644 --- a/src/main/java/sopt/org/motivooServer/global/response/SuccessType.java +++ b/src/main/java/sopt/org/motivooServer/global/response/SuccessType.java @@ -3,11 +3,11 @@ import org.springframework.http.HttpStatus; import lombok.AccessLevel; -import lombok.AllArgsConstructor; import lombok.Getter; +import lombok.RequiredArgsConstructor; @Getter -@AllArgsConstructor(access = AccessLevel.PRIVATE) +@RequiredArgsConstructor(access = AccessLevel.PRIVATE) public enum SuccessType { /**