Skip to content

Commit

Permalink
Merge pull request #170 from sopt-makers/sohyeon_#169
Browse files Browse the repository at this point in the history
[CHORE] Entity 추가 설계
  • Loading branch information
thguss authored Oct 23, 2023
2 parents 4c69328 + 39fe862 commit 8f6a1d3
Show file tree
Hide file tree
Showing 9 changed files with 160 additions and 13 deletions.
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();
}
}
}
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
) {
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.sopt.makers.operation.dto.member;

import org.sopt.makers.operation.entity.Gender;
import org.sopt.makers.operation.entity.ObYb;
import org.sopt.makers.operation.entity.Part;

Expand Down
5 changes: 0 additions & 5 deletions src/main/java/org/sopt/makers/operation/entity/Gender.java

This file was deleted.

4 changes: 0 additions & 4 deletions src/main/java/org/sopt/makers/operation/entity/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import javax.persistence.OneToMany;

import org.sopt.makers.operation.dto.member.MemberRequestDTO;
import org.sopt.makers.operation.entity.lecture.Lecture;

import lombok.Getter;
import lombok.NoArgsConstructor;
Expand All @@ -40,9 +39,6 @@ public class Member {
@Enumerated(EnumType.STRING)
private Part part;

@Enumerated(EnumType.STRING)
private Gender gender;

private String university;
private float score;
private String phone;
Expand Down
71 changes: 71 additions & 0 deletions src/main/java/org/sopt/makers/operation/entity/alarm/Alarm.java
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();
}
}
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 src/main/java/org/sopt/makers/operation/entity/alarm/Status.java
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;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.sopt.makers.operation.repository.attendance;

import static com.querydsl.core.types.dsl.Expressions.*;
import static org.sopt.makers.operation.entity.Part.*;
import static org.sopt.makers.operation.entity.QAttendance.*;
import static org.sopt.makers.operation.entity.QMember.*;
Expand Down Expand Up @@ -53,15 +54,15 @@ public List<Attendance> findAttendanceByMemberId(Long memberId) {
public List<Attendance> findByLecture(Long lectureId, Part part, Pageable pageable) {
return queryFactory
.selectFrom(attendance)
.leftJoin(attendance.subAttendances, subAttendance).fetchJoin().distinct()
.leftJoin(attendance.subAttendances, subAttendance).fetchJoin()
.leftJoin(subAttendance.subLecture, subLecture).fetchJoin()
.leftJoin(attendance.lecture, lecture).fetchJoin()
.leftJoin(attendance.member, member).fetchJoin().distinct()
.leftJoin(attendance.member, member).fetchJoin()
.where(
attendance.lecture.id.eq(lectureId),
partEq(part)
)
.orderBy(member.name.asc())
.orderBy(stringTemplate("SUBSTR({0}, 1, 1)", member.name).asc())
.offset(pageable.getOffset())
.limit(pageable.getPageSize())
.fetch();
Expand Down

0 comments on commit 8f6a1d3

Please sign in to comment.