Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Entity 추가 #7

Merged
merged 3 commits into from
Jan 22, 2024
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
26 changes: 26 additions & 0 deletions src/main/java/gdsc/sc/bsafe/domain/AIRecord.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package gdsc.sc.bsafe.domain;

import jakarta.persistence.Column;
import jakarta.persistence.DiscriminatorValue;
import jakarta.persistence.Entity;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@DiscriminatorValue("AI")
public class AIRecord extends Record {

@Column(nullable = false)
private Integer grade;

@Builder
public AIRecord(User user, String image, String title, String detail, Integer grade){
super(user, image, title, detail);
this.grade = grade;
}

}
21 changes: 21 additions & 0 deletions src/main/java/gdsc/sc/bsafe/domain/BasicRecord.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package gdsc.sc.bsafe.domain;

import jakarta.persistence.DiscriminatorValue;
import jakarta.persistence.Entity;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@DiscriminatorValue("BASIC")
public class BasicRecord extends Record {

@Builder
public BasicRecord(User user, String image, String title, String detail){
super(user, image, title, detail);
}

}
46 changes: 46 additions & 0 deletions src/main/java/gdsc/sc/bsafe/domain/Record.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package gdsc.sc.bsafe.domain;

import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@DiscriminatorColumn
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

유저 롤 타입도 이렇게 DType으로 일반 사용자랑 봉사자 구분해서 설정하는 걸로 생각하면 될까요?!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

유저 롤 타입도 이렇게 DType으로 일반 사용자랑 봉사자 구분해서 설정하는 걸로 생각하면 될까요?!

유저는 타입에 따라서 컬럼이 달라지지는 않는거 같아서 그냥 ENUM 타입으로 넣어도될거같습니다!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

유저는 타입에 따라서 컬럼이 달라지지는 않는거 같아서 그냥 ENUM 타입으로 넣어도될거같습니다!

그럼 봉사자 신청할 때 개인 / 기관(단체) 나누지 않고 그냥 롤만 바뀌는 건가요??

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

유저는 타입에 따라서 컬럼이 달라지지는 않는거 같아서 그냥 ENUM 타입으로 넣어도될거같습니다!

그럼 봉사자 신청할 때 개인 / 기관(단체) 나누지 않고 그냥 롤만 바뀌는 건가요??

넵 저는 그렇게 생각했는데, �롤에 따라 추가될 컬럼이 있을까요?

@Table(name = "record")
public class Record {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "record_id")
private Long recordId;

@ManyToOne
@JoinColumn(name = "user_id", nullable = false)
private User user;

@Column(nullable = false)
private String image;

@Column(nullable = false)
private String title;

@Column(nullable = false)
private String detail;

/*
ENUM 타입으로 변경하기
private String category;
*/

public Record(User user, String image, String title, String detail){
this.user = user;
this.image = image;
this.title = title;
this.detail = detail;
}


}
10 changes: 10 additions & 0 deletions src/main/java/gdsc/sc/bsafe/domain/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@

import gdsc.sc.bsafe.domain.common.BaseTimeEntity;
import gdsc.sc.bsafe.domain.enums.Authority;
import gdsc.sc.bsafe.domain.mapping.HelpRecord;
import gdsc.sc.bsafe.global.auth.Password;
import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;

import static gdsc.sc.bsafe.domain.enums.Authority.ROLE_USER;

@Entity
Expand All @@ -30,12 +34,18 @@ public class User extends BaseTimeEntity {
@Column(nullable = false, unique = true)
private String email;

@Column(nullable = false, unique = true)
private String tel;

@Column(nullable = false)
private String name;

@Enumerated(EnumType.STRING)
private Authority authority = ROLE_USER;

@OneToMany(mappedBy = "helper")
private List<HelpRecord> helpedRecords = new ArrayList<>();

public User(String id, Password password, String email, String name) {
this.id = id;
this.password = password;
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/gdsc/sc/bsafe/domain/enums/RequestStatus.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package gdsc.sc.bsafe.domain.enums;

public enum RequestStatus {
REQUESTED("요청"),
PROCEEDING("진행"),
COMPLETED("완료");

private String description;
RequestStatus(String description){this.description=description;}
}
47 changes: 47 additions & 0 deletions src/main/java/gdsc/sc/bsafe/domain/mapping/HelpRecord.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package gdsc.sc.bsafe.domain.mapping;

import gdsc.sc.bsafe.domain.Record;
import gdsc.sc.bsafe.domain.User;
import gdsc.sc.bsafe.domain.common.BaseTimeEntity;
import gdsc.sc.bsafe.domain.enums.RequestStatus;
import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.Date;

@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Table(name = "help_record")
public class HelpRecord extends BaseTimeEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "report_id")
private Long reportId;

@ManyToOne
@JoinColumn(name = "record_id", nullable = false)
private Record record;

@ManyToOne
@JoinColumn(name = "helper_id", nullable = false)
private User helper;

@Column(nullable = false)
private RequestStatus status;

@Column(nullable = false)
private Date date;

@Column(nullable = false)
private String placeId;

@Column(nullable = false)
private String district;

@Column(nullable = false)
private String address;
Comment on lines +35 to +45
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

생각해봤는데 이 부분에 대한 값을 사용자가 보수 신청할 때 함께 요청하는 거면 Record로 옮겨야 할 것 같아요!
보수 신청 ui에서 주소랑 희망 일자를 같이 입력하는 구조면 이 값들까지 한번에 묶어서 Record 엔티티로 저장해야 하지 않을까 싶어서요 😶

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

생각해봤는데 이 부분에 대한 값을 사용자가 보수 신청할 때 함께 요청하는 거면 Record로 옮겨야 할 것 같아요! 보수 신청 ui에서 주소랑 희망 일자를 같이 입력하는 구조면 이 값들까지 한번에 묶어서 Record 엔티티로 저장해야 하지 않을까 싶어서요 😶

일반 저장(기록용)/ 수리 요청 이렇게 나눠서 저장하는걸로 얘기했던거 같아서 엔티티를 분리했어요!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image
참고 화면입니당

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

확인했습니다!


}
Loading