#29 pass: notification entity
This commit is contained in:
@@ -32,6 +32,8 @@ dependencies {
|
|||||||
implementation 'org.mapstruct:mapstruct:1.5.2.Final'
|
implementation 'org.mapstruct:mapstruct:1.5.2.Final'
|
||||||
annotationProcessor 'org.mapstruct:mapstruct-processor:1.5.2.Final'
|
annotationProcessor 'org.mapstruct:mapstruct-processor:1.5.2.Final'
|
||||||
|
|
||||||
|
implementation 'org.apache.commons:commons-lang3:3.12.0'
|
||||||
|
|
||||||
runtimeOnly 'com.h2database:h2'
|
runtimeOnly 'com.h2database:h2'
|
||||||
runtimeOnly 'com.mysql:mysql-connector-j'
|
runtimeOnly 'com.mysql:mysql-connector-j'
|
||||||
|
|
||||||
@@ -40,6 +42,7 @@ dependencies {
|
|||||||
|
|
||||||
testCompileOnly 'org.projectlombok:lombok'
|
testCompileOnly 'org.projectlombok:lombok'
|
||||||
testAnnotationProcessor 'org.projectlombok:lombok'
|
testAnnotationProcessor 'org.projectlombok:lombok'
|
||||||
|
testImplementation 'org.apache.commons:commons-lang3:3.12.0'
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.named('test') {
|
tasks.named('test') {
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package com.example.passbatch.repository.notification;
|
||||||
|
|
||||||
|
import com.example.passbatch.repository.BaseEntity;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import lombok.ToString;
|
||||||
|
|
||||||
|
import javax.persistence.*;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@ToString
|
||||||
|
@Entity
|
||||||
|
@Table(name = "notification")
|
||||||
|
public class NotificationEntity extends BaseEntity {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY) // 기본 키 생성을 DB에 위임합니다. (AUTO_INCREMENT)
|
||||||
|
private Integer notificationSeq;
|
||||||
|
private String uuid;
|
||||||
|
|
||||||
|
private NotificationEvent event;
|
||||||
|
private String text;
|
||||||
|
private boolean sent;
|
||||||
|
private LocalDateTime sentAt;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package com.example.passbatch.repository.notification;
|
||||||
|
|
||||||
|
public enum NotificationEvent {
|
||||||
|
BEFORE_CLASS
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package com.example.passbatch.repository.notification;
|
||||||
|
|
||||||
|
import com.example.passbatch.repository.booking.BookingEntity;
|
||||||
|
import com.example.passbatch.utils.LocalDateTimeUtils;
|
||||||
|
import org.mapstruct.Mapper;
|
||||||
|
import org.mapstruct.Mapping;
|
||||||
|
import org.mapstruct.Named;
|
||||||
|
import org.mapstruct.ReportingPolicy;
|
||||||
|
import org.mapstruct.factory.Mappers;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
// ReportingPolicy.IGNORE: 일치하지 않은 필드를 무시합니다.
|
||||||
|
@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE)
|
||||||
|
public interface NotificationModelMapper {
|
||||||
|
NotificationModelMapper INSTANCE = Mappers.getMapper(NotificationModelMapper.class);
|
||||||
|
|
||||||
|
// 필드명이 같지 않거나 custom하게 매핑해주기 위해서는 @Mapping을 추가해주면 됩니다.
|
||||||
|
@Mapping(target = "uuid", source = "bookingEntity.userEntity.uuid")
|
||||||
|
@Mapping(target = "text", source = "bookingEntity.startedAt", qualifiedByName = "text")
|
||||||
|
NotificationEntity toNotificationEntity(BookingEntity bookingEntity, NotificationEvent event);
|
||||||
|
|
||||||
|
// 알람 보낼 메시지 생성
|
||||||
|
@Named("text")
|
||||||
|
default String text(LocalDateTime startedAt) {
|
||||||
|
return String.format("안녕하세요. %s 수업 시작합니다. 수업 전 출석 체크 부탁드립니다. \uD83D\uDE0A", LocalDateTimeUtils.format(startedAt));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package com.example.passbatch.repository.notification;
|
||||||
|
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
public interface NotificationRepository extends JpaRepository<NotificationEntity, Integer> {
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
package com.example.passbatch.utils;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.time.temporal.WeekFields;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
public class LocalDateTimeUtils {
|
||||||
|
public static final DateTimeFormatter YYYY_MM_DD_HH_MM = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
|
||||||
|
public static final DateTimeFormatter YYYY_MM_DD = DateTimeFormatter.ofPattern("yyyyMMdd");
|
||||||
|
|
||||||
|
public static String format(final LocalDateTime localDateTime) {
|
||||||
|
return localDateTime.format(YYYY_MM_DD_HH_MM);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String format(final LocalDateTime localDateTime, DateTimeFormatter formatter) {
|
||||||
|
return localDateTime.format(formatter);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static LocalDateTime parse(final String localDateTimeString) {
|
||||||
|
if (StringUtils.isBlank(localDateTimeString)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return LocalDateTime.parse(localDateTimeString, YYYY_MM_DD_HH_MM);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getWeekOfYear(final LocalDateTime localDateTime) {
|
||||||
|
return localDateTime.get(WeekFields.of(Locale.KOREA).weekOfYear());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user