Skip to content

Commit

Permalink
Merge pull request #7 from Team-Motivoo/feat/#6-entity_class
Browse files Browse the repository at this point in the history
  • Loading branch information
jun02160 authored Jan 3, 2024
2 parents 28dab01 + 48b4699 commit f9ddeac
Show file tree
Hide file tree
Showing 32 changed files with 571 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package sopt.org.motivooServer.domain.health.entity;

public enum ExerciseFrequency {

// 1회 미만 | 1~2회 | 3~4회 | 5회 이상
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package sopt.org.motivooServer.domain.health.entity;

public enum ExerciseTime {

// 30분 미만 | 30분~1시간 | 1시간~2시간 | 2시간 이상
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package sopt.org.motivooServer.domain.health.entity;

public enum ExerciseType {

// 고강도 | 중강도 | 저강도
}
Original file line number Diff line number Diff line change
@@ -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<HealthNote> healthNotes = new ArrayList<>();
}
Original file line number Diff line number Diff line change
@@ -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));
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package sopt.org.motivooServer.domain.mission.entity;

import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
public enum MissionType {


}
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Loading

0 comments on commit f9ddeac

Please sign in to comment.