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);
+
+}