From e771e1ff34385511099ee87c4f43184065fc98fc Mon Sep 17 00:00:00 2001 From: Mark Struchkov Date: Sat, 27 Jul 2019 08:06:47 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20JP?= =?UTF-8?q?A=20=D0=B4=D0=BB=D1=8F=20=D0=BB=D0=B8=D1=87=D0=BD=D1=8B=D1=85?= =?UTF-8?q?=20=D1=81=D0=BE=D0=BE=D0=B1=D1=89=D0=B5=D0=BD=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 10 ++++++ .../social/core/domain/content/Mail.java | 6 +++- .../social/core/domain/content/Message.java | 9 ++++++ .../repository/jpa/MailRepositoryJpa.java | 32 +++++++++++++++++++ .../repository/jpa/impl/MailRepository.java | 18 +++++++++++ 5 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 src/main/java/org/sadtech/social/core/repository/jpa/MailRepositoryJpa.java create mode 100644 src/main/java/org/sadtech/social/core/repository/jpa/impl/MailRepository.java diff --git a/pom.xml b/pom.xml index f6c8753..a0fc767 100644 --- a/pom.xml +++ b/pom.xml @@ -52,6 +52,16 @@ lombok 1.18.8 + + org.springframework.data + spring-data-jpa + 2.1.3.RELEASE + + + javax.persistence + javax.persistence-api + 2.2 + diff --git a/src/main/java/org/sadtech/social/core/domain/content/Mail.java b/src/main/java/org/sadtech/social/core/domain/content/Mail.java index 5eda997..248a6b3 100644 --- a/src/main/java/org/sadtech/social/core/domain/content/Mail.java +++ b/src/main/java/org/sadtech/social/core/domain/content/Mail.java @@ -5,6 +5,8 @@ import lombok.EqualsAndHashCode; import org.sadtech.social.core.domain.content.attachment.Attachment; import org.sadtech.social.core.utils.Description; +import javax.persistence.Entity; +import javax.persistence.Table; import java.util.List; /** @@ -12,8 +14,10 @@ import java.util.List; * * @author upagge [08/07/2019] */ -@EqualsAndHashCode(callSuper = true) @Data +@Entity +@Table(name = "mail") +@EqualsAndHashCode(callSuper = true) public class Mail extends Message { @Description("Вложения к сообщению") diff --git a/src/main/java/org/sadtech/social/core/domain/content/Message.java b/src/main/java/org/sadtech/social/core/domain/content/Message.java index 0ab18f3..2b4566a 100644 --- a/src/main/java/org/sadtech/social/core/domain/content/Message.java +++ b/src/main/java/org/sadtech/social/core/domain/content/Message.java @@ -1,8 +1,12 @@ package org.sadtech.social.core.domain.content; +import com.sun.istack.internal.NotNull; import lombok.Data; import org.sadtech.social.core.utils.Description; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; import java.time.LocalDateTime; /** @@ -11,17 +15,22 @@ import java.time.LocalDateTime; * @author upagge [08/07/2019] */ @Data +@Entity public abstract class Message { + @Id + @GeneratedValue @Description("Идентификатор сообщения") private Integer id; @Description("Тип сообщения") protected ContentType type; + @NotNull @Description("Дата создания") private LocalDateTime createDate; + @NotNull @Description("Идентификатор пользователя, отправившего сообщение") private Integer personId; diff --git a/src/main/java/org/sadtech/social/core/repository/jpa/MailRepositoryJpa.java b/src/main/java/org/sadtech/social/core/repository/jpa/MailRepositoryJpa.java new file mode 100644 index 0000000..71d88ed --- /dev/null +++ b/src/main/java/org/sadtech/social/core/repository/jpa/MailRepositoryJpa.java @@ -0,0 +1,32 @@ +package org.sadtech.social.core.repository.jpa; + +import org.sadtech.social.core.domain.content.Mail; +import org.sadtech.social.core.repository.ContentRepository; +import org.sadtech.social.core.repository.jpa.impl.MailRepository; + +import java.time.LocalDateTime; +import java.util.List; + +/** + * TODO: Добавить описание класса. + * + * @author upagge [25/07/2019] + */ +public class MailRepositoryJpa implements ContentRepository { + + private final MailRepository mailRepository; + + public MailRepositoryJpa(MailRepository mailRepository) { + this.mailRepository = mailRepository; + } + + @Override + public Integer add(Mail content) { + return mailRepository.saveAndFlush(content).getId(); + } + + @Override + public List findByTime(LocalDateTime timeFrom, LocalDateTime timeTo) { + return mailRepository.findByCreateDateBetween(timeFrom, timeTo); + } +} diff --git a/src/main/java/org/sadtech/social/core/repository/jpa/impl/MailRepository.java b/src/main/java/org/sadtech/social/core/repository/jpa/impl/MailRepository.java new file mode 100644 index 0000000..b422fec --- /dev/null +++ b/src/main/java/org/sadtech/social/core/repository/jpa/impl/MailRepository.java @@ -0,0 +1,18 @@ +package org.sadtech.social.core.repository.jpa.impl; + +import org.sadtech.social.core.domain.content.Mail; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.time.LocalDateTime; +import java.util.List; + +/** + * TODO: Добавить описание интерфейса. + * + * @author upagge [27/07/2019] + */ +public interface MailRepository extends JpaRepository { + + List findByCreateDateBetween(LocalDateTime from, LocalDateTime to); + +}