Добавил JPA для личных сообщений
This commit is contained in:
parent
346b3029af
commit
e771e1ff34
10
pom.xml
10
pom.xml
@ -52,6 +52,16 @@
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.8</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-jpa</artifactId>
|
||||
<version>2.1.3.RELEASE</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.persistence</groupId>
|
||||
<artifactId>javax.persistence-api</artifactId>
|
||||
<version>2.2</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<developers>
|
||||
|
@ -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("Вложения к сообщению")
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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<Mail> {
|
||||
|
||||
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<Mail> findByTime(LocalDateTime timeFrom, LocalDateTime timeTo) {
|
||||
return mailRepository.findByCreateDateBetween(timeFrom, timeTo);
|
||||
}
|
||||
}
|
@ -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<Mail, Integer> {
|
||||
|
||||
List<Mail> findByCreateDateBetween(LocalDateTime from, LocalDateTime to);
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user