diff --git a/src/main/java/org/sopt/makers/operation/converter/LongListConverter.java b/src/main/java/org/sopt/makers/operation/converter/LongListConverter.java new file mode 100644 index 00000000..896cc625 --- /dev/null +++ b/src/main/java/org/sopt/makers/operation/converter/LongListConverter.java @@ -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, 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 attribute) { + try { + return mapper.writeValueAsString(attribute); + } catch (JsonProcessingException e) { + throw new IllegalArgumentException(); + } + } + + @Override + public List convertToEntityAttribute(String dbData) { + TypeReference> typeReference = new TypeReference<>() { + }; + + try { + return mapper.readValue(dbData, typeReference); + } catch (IOException e) { + throw new IllegalArgumentException(); + } + } +} diff --git a/src/main/java/org/sopt/makers/operation/dto/alarm/AlarmRequestDTO.java b/src/main/java/org/sopt/makers/operation/dto/alarm/AlarmRequestDTO.java new file mode 100644 index 00000000..b0ce3e9a --- /dev/null +++ b/src/main/java/org/sopt/makers/operation/dto/alarm/AlarmRequestDTO.java @@ -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 targetList, + Status status +) { +} diff --git a/src/main/java/org/sopt/makers/operation/dto/member/MemberRequestDTO.java b/src/main/java/org/sopt/makers/operation/dto/member/MemberRequestDTO.java index 89c03f50..423bb1f1 100644 --- a/src/main/java/org/sopt/makers/operation/dto/member/MemberRequestDTO.java +++ b/src/main/java/org/sopt/makers/operation/dto/member/MemberRequestDTO.java @@ -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; diff --git a/src/main/java/org/sopt/makers/operation/entity/Gender.java b/src/main/java/org/sopt/makers/operation/entity/Gender.java deleted file mode 100644 index 997c3713..00000000 --- a/src/main/java/org/sopt/makers/operation/entity/Gender.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.sopt.makers.operation.entity; - -public enum Gender { - Female, Male -} diff --git a/src/main/java/org/sopt/makers/operation/entity/Member.java b/src/main/java/org/sopt/makers/operation/entity/Member.java index e0b3de09..6cf13b7e 100644 --- a/src/main/java/org/sopt/makers/operation/entity/Member.java +++ b/src/main/java/org/sopt/makers/operation/entity/Member.java @@ -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; @@ -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; diff --git a/src/main/java/org/sopt/makers/operation/entity/alarm/Alarm.java b/src/main/java/org/sopt/makers/operation/entity/alarm/Alarm.java new file mode 100644 index 00000000..7777c18d --- /dev/null +++ b/src/main/java/org/sopt/makers/operation/entity/alarm/Alarm.java @@ -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 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(); + } +} diff --git a/src/main/java/org/sopt/makers/operation/entity/alarm/Attribute.java b/src/main/java/org/sopt/makers/operation/entity/alarm/Attribute.java new file mode 100644 index 00000000..0a64f842 --- /dev/null +++ b/src/main/java/org/sopt/makers/operation/entity/alarm/Attribute.java @@ -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; +} diff --git a/src/main/java/org/sopt/makers/operation/entity/alarm/Status.java b/src/main/java/org/sopt/makers/operation/entity/alarm/Status.java new file mode 100644 index 00000000..682a4247 --- /dev/null +++ b/src/main/java/org/sopt/makers/operation/entity/alarm/Status.java @@ -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; +} diff --git a/src/main/java/org/sopt/makers/operation/repository/attendance/AttendanceRepositoryImpl.java b/src/main/java/org/sopt/makers/operation/repository/attendance/AttendanceRepositoryImpl.java index a0fd92e3..8472c25a 100644 --- a/src/main/java/org/sopt/makers/operation/repository/attendance/AttendanceRepositoryImpl.java +++ b/src/main/java/org/sopt/makers/operation/repository/attendance/AttendanceRepositoryImpl.java @@ -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.*; @@ -53,15 +54,15 @@ public List findAttendanceByMemberId(Long memberId) { public List 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();