-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DDING-83] Form 및 FormField 엔터티 세팅 (#229)
- Loading branch information
Showing
7 changed files
with
201 additions
and
0 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
src/main/java/ddingdong/ddingdongBE/common/converter/StringListConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package ddingdong.ddingdongBE.common.converter; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import jakarta.persistence.AttributeConverter; | ||
import jakarta.persistence.Converter; | ||
import java.util.List; | ||
|
||
@Converter | ||
public class StringListConverter implements AttributeConverter<List<String>, String> { | ||
|
||
private final ObjectMapper mapper = new ObjectMapper(); | ||
|
||
@Override | ||
public String convertToDatabaseColumn(List<String> dataList) { | ||
try { | ||
return mapper.writeValueAsString(dataList); | ||
} catch (JsonProcessingException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
@Override | ||
public List<String> convertToEntityAttribute(String data) { | ||
try { | ||
return mapper.readValue(data, List.class); | ||
} catch (JsonProcessingException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/ddingdong/ddingdongBE/domain/form/entity/FieldType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package ddingdong.ddingdongBE.domain.form.entity; | ||
|
||
public enum FieldType { | ||
CHECK_BOX, | ||
RADIO, | ||
TEXT, | ||
LONG_TEXT, | ||
FILE | ||
} |
54 changes: 54 additions & 0 deletions
54
src/main/java/ddingdong/ddingdongBE/domain/form/entity/Form.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package ddingdong.ddingdongBE.domain.form.entity; | ||
|
||
import ddingdong.ddingdongBE.common.BaseEntity; | ||
import ddingdong.ddingdongBE.domain.club.entity.Club; | ||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.FetchType; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.ManyToOne; | ||
import java.time.LocalDate; | ||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Entity | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Getter | ||
public class Form extends BaseEntity { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@Column(nullable = false) | ||
private String title; | ||
|
||
private String description; | ||
|
||
@Column(nullable = false) | ||
private LocalDate startDate; | ||
|
||
@Column(nullable = false) | ||
private LocalDate endDate; | ||
|
||
@Column(nullable = false) | ||
private boolean hasInterview; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
private Club club; | ||
|
||
@Builder | ||
private Form(String title, String description, LocalDate startDate, LocalDate endDate, boolean hasInterview, | ||
Club club) { | ||
this.title = title; | ||
this.description = description; | ||
this.startDate = startDate; | ||
this.endDate = endDate; | ||
this.hasInterview = hasInterview; | ||
this.club = club; | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
src/main/java/ddingdong/ddingdongBE/domain/form/entity/FormField.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package ddingdong.ddingdongBE.domain.form.entity; | ||
|
||
import ddingdong.ddingdongBE.common.BaseEntity; | ||
import ddingdong.ddingdongBE.common.converter.StringListConverter; | ||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Convert; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.EnumType; | ||
import jakarta.persistence.Enumerated; | ||
import jakarta.persistence.FetchType; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.ManyToOne; | ||
import java.util.List; | ||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Entity | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Getter | ||
public class FormField extends BaseEntity { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@Column(nullable = false) | ||
private String question; | ||
|
||
@Column(nullable = false) | ||
private boolean required; | ||
|
||
@Column(nullable = false) | ||
private int fieldOrder; | ||
|
||
@Column(nullable = false) | ||
private String section; | ||
|
||
@Convert(converter = StringListConverter.class) | ||
private List<String> options; | ||
|
||
@Enumerated(EnumType.STRING) | ||
@Column(nullable = false) | ||
private FieldType fieldType; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
private Form form; | ||
|
||
@Builder | ||
private FormField(String question, FieldType fieldType, boolean required, int fieldOrder, String section, | ||
List<String> options, Form form) { | ||
this.question = question; | ||
this.fieldType = fieldType; | ||
this.required = required; | ||
this.fieldOrder = fieldOrder; | ||
this.section = section; | ||
this.options = options; | ||
this.form = form; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/ddingdong/ddingdongBE/domain/form/repository/FormFieldRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package ddingdong.ddingdongBE.domain.form.repository; | ||
|
||
import ddingdong.ddingdongBE.domain.form.entity.FormField; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface FormFieldRepository extends JpaRepository<FormField, Long> { | ||
|
||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/ddingdong/ddingdongBE/domain/form/repository/FormRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package ddingdong.ddingdongBE.domain.form.repository; | ||
|
||
import ddingdong.ddingdongBE.domain.form.entity.Form; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface FormRepository extends JpaRepository<Form, Long> { | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
src/main/resources/db/migration/V34__from_and_field_create_table.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
CREATE TABLE form | ||
( | ||
id BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, | ||
title VARCHAR(255) NOT NULL, | ||
description VARCHAR(255), | ||
start_date DATE NOT NULL, | ||
end_date DATE NOT NULL, | ||
has_interview BOOLEAN NOT NULL, | ||
club_id BIGINT, | ||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP NULL, | ||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP NULL, | ||
CONSTRAINT fk_form_club FOREIGN KEY (club_id) REFERENCES club (id) ON DELETE CASCADE | ||
); | ||
|
||
CREATE TABLE form_field | ||
( | ||
id BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, | ||
question VARCHAR(255) NOT NULL, | ||
field_type VARCHAR(50) NOT NULL, | ||
required BOOLEAN NOT NULL, | ||
field_order INT NOT NULL, | ||
section VARCHAR(255) NOT NULL, | ||
options TEXT, | ||
form_id BIGINT, | ||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP NULL, | ||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP NULL, | ||
CONSTRAINT fk_form_field_form FOREIGN KEY (form_id) REFERENCES form (id) ON DELETE CASCADE | ||
); |