-
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.
Merge pull request #170 from sopt-makers/sohyeon_#169
[CHORE] Entity 추가 설계
- Loading branch information
Showing
9 changed files
with
160 additions
and
13 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
src/main/java/org/sopt/makers/operation/converter/LongListConverter.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,39 @@ | ||
package org.sopt.makers.operation.converter; | ||
|
||
import static com.fasterxml.jackson.databind.DeserializationFeature.*; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
import javax.persistence.AttributeConverter; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.core.type.TypeReference; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
public class LongListConverter implements AttributeConverter<List<Long>, String> { | ||
private static final ObjectMapper mapper = new ObjectMapper() | ||
.configure(FAIL_ON_UNKNOWN_PROPERTIES, false) | ||
.configure(FAIL_ON_NULL_FOR_PRIMITIVES, false); | ||
|
||
@Override | ||
public String convertToDatabaseColumn(List<Long> attribute) { | ||
try { | ||
return mapper.writeValueAsString(attribute); | ||
} catch (JsonProcessingException e) { | ||
throw new IllegalArgumentException(); | ||
} | ||
} | ||
|
||
@Override | ||
public List<Long> convertToEntityAttribute(String dbData) { | ||
TypeReference<List<Long>> typeReference = new TypeReference<>() { | ||
}; | ||
|
||
try { | ||
return mapper.readValue(dbData, typeReference); | ||
} catch (IOException e) { | ||
throw new IllegalArgumentException(); | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/org/sopt/makers/operation/dto/alarm/AlarmRequestDTO.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,20 @@ | ||
package org.sopt.makers.operation.dto.alarm; | ||
|
||
import java.util.List; | ||
|
||
import org.sopt.makers.operation.entity.Part; | ||
import org.sopt.makers.operation.entity.alarm.Attribute; | ||
import org.sopt.makers.operation.entity.alarm.Status; | ||
|
||
public record AlarmRequestDTO( | ||
int generation, | ||
Attribute attribute, | ||
String title, | ||
String content, | ||
String link, | ||
boolean isActive, | ||
Part part, | ||
List<Long> targetList, | ||
Status status | ||
) { | ||
} |
1 change: 0 additions & 1 deletion
1
src/main/java/org/sopt/makers/operation/dto/member/MemberRequestDTO.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
This file was deleted.
Oops, something went wrong.
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
71 changes: 71 additions & 0 deletions
71
src/main/java/org/sopt/makers/operation/entity/alarm/Alarm.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,71 @@ | ||
package org.sopt.makers.operation.entity.alarm; | ||
|
||
import static javax.persistence.EnumType.*; | ||
import static javax.persistence.GenerationType.*; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
|
||
import javax.persistence.Column; | ||
import javax.persistence.Convert; | ||
import javax.persistence.Entity; | ||
import javax.persistence.Enumerated; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.Id; | ||
|
||
import org.sopt.makers.operation.converter.LongListConverter; | ||
import org.sopt.makers.operation.dto.alarm.AlarmRequestDTO; | ||
import org.sopt.makers.operation.entity.BaseEntity; | ||
import org.sopt.makers.operation.entity.Part; | ||
|
||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Entity | ||
@NoArgsConstructor | ||
@Getter | ||
public class Alarm extends BaseEntity { | ||
@Id | ||
@GeneratedValue(strategy = IDENTITY) | ||
@Column(name = "alarm_id") | ||
private Long id; | ||
|
||
private int generation; | ||
|
||
@Column(nullable = false) | ||
@Enumerated(value = STRING) | ||
private Attribute attribute; | ||
|
||
private String title; | ||
|
||
@Column(columnDefinition = "TEXT") | ||
private String content; | ||
|
||
private String link; | ||
|
||
private boolean isActive; | ||
|
||
@Enumerated(value = STRING) | ||
private Part part; | ||
|
||
@Column(columnDefinition = "TEXT") | ||
@Convert(converter = LongListConverter.class) | ||
private List<Long> targetList; | ||
|
||
@Column(nullable = false) | ||
@Enumerated(value = STRING) | ||
private Status status; | ||
|
||
private LocalDateTime sendAt; | ||
|
||
public Alarm(AlarmRequestDTO requestDTO) { | ||
this.generation = requestDTO.generation(); | ||
this.attribute = requestDTO.attribute(); | ||
this.title = requestDTO.title(); | ||
this.content = requestDTO.content(); | ||
this.link = requestDTO.link(); | ||
this.isActive = requestDTO.isActive(); | ||
this.part = requestDTO.part(); | ||
this.targetList = requestDTO.targetList(); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/org/sopt/makers/operation/entity/alarm/Attribute.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,13 @@ | ||
package org.sopt.makers.operation.entity.alarm; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public enum Attribute { | ||
NOTICE("공지"), | ||
NEWS("소식"); | ||
|
||
private final String name; | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/org/sopt/makers/operation/entity/alarm/Status.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,13 @@ | ||
package org.sopt.makers.operation.entity.alarm; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public enum Status { | ||
BEFORE("발송 전"), | ||
AFTER("발송 후"); | ||
|
||
private final String name; | ||
} |
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