diff --git a/src/main/java/org/sadtech/social/core/domain/money/Account.java b/src/main/java/org/sadtech/social/core/domain/money/Account.java index 55847c4..d3cf621 100644 --- a/src/main/java/org/sadtech/social/core/domain/money/Account.java +++ b/src/main/java/org/sadtech/social/core/domain/money/Account.java @@ -1,5 +1,6 @@ package org.sadtech.social.core.domain.money; +import com.sun.istack.internal.NotNull; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.EqualsAndHashCode; @@ -9,6 +10,14 @@ import lombok.Setter; import lombok.ToString; import org.sadtech.social.core.utils.Description; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.Table; + /** * Сущность, которая отвечает за выставленный пользователю счет. * @@ -21,23 +30,34 @@ import org.sadtech.social.core.utils.Description; @ToString @NoArgsConstructor @AllArgsConstructor +@Entity +@Table(name = "account") public class Account { + @Id + @GeneratedValue @Description("Идентификатор счета") private Integer id; + @NotNull + @Column(name = "totalSum") @Description("Сумма к оплате") private Integer totalSum; + @Column(name = "belongs_person_id") @Description("Идентификатор пользователя, которому выставлен счет") private Integer belongsPersonId; + @Column(name = "extinguished_person_id") @Description("Идентификатор пользователя, который оплатил счет") private Integer extinguishedPersonId; + @Column(name = "description") @Description("Описание платежа") private String description; + @Enumerated(EnumType.STRING) + @Column(name = "status") @Description("Статус оплаты счета") private AccountStatus accountStatus; diff --git a/src/main/java/org/sadtech/social/core/repository/impl/jpa/AccountRepositoryJpaImpl.java b/src/main/java/org/sadtech/social/core/repository/impl/jpa/AccountRepositoryJpaImpl.java new file mode 100644 index 0000000..a6cfc6a --- /dev/null +++ b/src/main/java/org/sadtech/social/core/repository/impl/jpa/AccountRepositoryJpaImpl.java @@ -0,0 +1,37 @@ +package org.sadtech.social.core.repository.impl.jpa; + +import org.sadtech.social.core.domain.money.Account; +import org.sadtech.social.core.repository.AccountRepository; +import org.sadtech.social.core.repository.jpa.AccountRepositoryJpa; +import org.springframework.stereotype.Repository; + +/** + * TODO: Добавить описание класса. + * + * @author upagge [27/07/2019] + */ +@Repository +public class AccountRepositoryJpaImpl implements AccountRepository { + + private final AccountRepositoryJpa accountRepositoryJpa; + + public AccountRepositoryJpaImpl(AccountRepositoryJpa accountRepositoryJpa) { + this.accountRepositoryJpa = accountRepositoryJpa; + } + + @Override + public Integer add(Account account) { + return accountRepositoryJpa.saveAndFlush(account).getId(); + } + + @Override + public void edit(Integer accountId, Account account) { + account.setId(accountId); + accountRepositoryJpa.saveAndFlush(account); + } + + @Override + public Account findById(Integer accountId) { + return accountRepositoryJpa.getOne(accountId); + } +} diff --git a/src/main/java/org/sadtech/social/core/repository/impl/jpa/MailRepositoryJpaImpl.java b/src/main/java/org/sadtech/social/core/repository/impl/jpa/MailRepositoryJpaImpl.java new file mode 100644 index 0000000..595d651 --- /dev/null +++ b/src/main/java/org/sadtech/social/core/repository/impl/jpa/MailRepositoryJpaImpl.java @@ -0,0 +1,34 @@ +package org.sadtech.social.core.repository.impl.jpa; + +import org.sadtech.social.core.domain.content.Mail; +import org.sadtech.social.core.repository.ContentRepository; +import org.sadtech.social.core.repository.jpa.MailRepositoryJpa; +import org.springframework.stereotype.Repository; + +import java.time.LocalDateTime; +import java.util.List; + +/** + * Реализация репозитория. + * + * @author upagge [25/07/2019] + */ +@Repository +public class MailRepositoryJpaImpl implements ContentRepository { + + private final MailRepositoryJpa mailRepositoryJpa; + + public MailRepositoryJpaImpl(MailRepositoryJpa mailRepositoryJpa) { + this.mailRepositoryJpa = mailRepositoryJpa; + } + + @Override + public Integer add(Mail content) { + return mailRepositoryJpa.saveAndFlush(content).getId(); + } + + @Override + public List findByTime(LocalDateTime timeFrom, LocalDateTime timeTo) { + return mailRepositoryJpa.findByCreateDateBetween(timeFrom, timeTo); + } +} diff --git a/src/main/java/org/sadtech/social/core/repository/impl/AccountRepositoryMap.java b/src/main/java/org/sadtech/social/core/repository/impl/local/AccountRepositoryMap.java similarity index 96% rename from src/main/java/org/sadtech/social/core/repository/impl/AccountRepositoryMap.java rename to src/main/java/org/sadtech/social/core/repository/impl/local/AccountRepositoryMap.java index 8b2624a..c952737 100644 --- a/src/main/java/org/sadtech/social/core/repository/impl/AccountRepositoryMap.java +++ b/src/main/java/org/sadtech/social/core/repository/impl/local/AccountRepositoryMap.java @@ -1,4 +1,4 @@ -package org.sadtech.social.core.repository.impl; +package org.sadtech.social.core.repository.impl.local; import org.sadtech.social.core.domain.money.Account; import org.sadtech.social.core.exception.AccessException; diff --git a/src/main/java/org/sadtech/social/core/repository/impl/BoardCommentRepositoryMap.java b/src/main/java/org/sadtech/social/core/repository/impl/local/BoardCommentRepositoryMap.java similarity index 95% rename from src/main/java/org/sadtech/social/core/repository/impl/BoardCommentRepositoryMap.java rename to src/main/java/org/sadtech/social/core/repository/impl/local/BoardCommentRepositoryMap.java index 9935340..53e7650 100644 --- a/src/main/java/org/sadtech/social/core/repository/impl/BoardCommentRepositoryMap.java +++ b/src/main/java/org/sadtech/social/core/repository/impl/local/BoardCommentRepositoryMap.java @@ -1,4 +1,4 @@ -package org.sadtech.social.core.repository.impl; +package org.sadtech.social.core.repository.impl.local; import org.sadtech.social.core.domain.content.BoardComment; import org.sadtech.social.core.repository.ContentRepository; diff --git a/src/main/java/org/sadtech/social/core/repository/impl/EventRepositoryQueue.java b/src/main/java/org/sadtech/social/core/repository/impl/local/EventRepositoryQueue.java similarity index 91% rename from src/main/java/org/sadtech/social/core/repository/impl/EventRepositoryQueue.java rename to src/main/java/org/sadtech/social/core/repository/impl/local/EventRepositoryQueue.java index 4c3fc26..8fee934 100644 --- a/src/main/java/org/sadtech/social/core/repository/impl/EventRepositoryQueue.java +++ b/src/main/java/org/sadtech/social/core/repository/impl/local/EventRepositoryQueue.java @@ -1,4 +1,4 @@ -package org.sadtech.social.core.repository.impl; +package org.sadtech.social.core.repository.impl.local; import com.google.gson.JsonObject; import org.sadtech.social.core.repository.EventRepository; diff --git a/src/main/java/org/sadtech/social/core/repository/impl/MailRepositoryList.java b/src/main/java/org/sadtech/social/core/repository/impl/local/MailRepositoryList.java similarity index 79% rename from src/main/java/org/sadtech/social/core/repository/impl/MailRepositoryList.java rename to src/main/java/org/sadtech/social/core/repository/impl/local/MailRepositoryList.java index 41cec39..844b217 100644 --- a/src/main/java/org/sadtech/social/core/repository/impl/MailRepositoryList.java +++ b/src/main/java/org/sadtech/social/core/repository/impl/local/MailRepositoryList.java @@ -1,4 +1,4 @@ -package org.sadtech.social.core.repository.impl; +package org.sadtech.social.core.repository.impl.local; import org.sadtech.social.core.domain.content.Mail; import org.sadtech.social.core.repository.ContentRepository; @@ -7,6 +7,11 @@ import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; +/** + * Локальная реализация репозитория на основе {@link ArrayList} для взаимодействия с сущностью {@link Mail}. + * + * @author upagge [27/07/2019] + */ public class MailRepositoryList implements ContentRepository { private final List mails = new ArrayList<>(); diff --git a/src/main/java/org/sadtech/social/core/repository/jpa/AccountRepositoryJpa.java b/src/main/java/org/sadtech/social/core/repository/jpa/AccountRepositoryJpa.java new file mode 100644 index 0000000..36f59e0 --- /dev/null +++ b/src/main/java/org/sadtech/social/core/repository/jpa/AccountRepositoryJpa.java @@ -0,0 +1,13 @@ +package org.sadtech.social.core.repository.jpa; + +import org.sadtech.social.core.domain.money.Account; +import org.springframework.data.jpa.repository.JpaRepository; + +/** + * TODO: Добавить описание интерфейса. + * + * @author upagge [27/07/2019] + */ +public interface AccountRepositoryJpa extends JpaRepository { + +} 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 index 71d88ed..58bd49c 100644 --- a/src/main/java/org/sadtech/social/core/repository/jpa/MailRepositoryJpa.java +++ b/src/main/java/org/sadtech/social/core/repository/jpa/MailRepositoryJpa.java @@ -1,32 +1,19 @@ 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 org.springframework.data.jpa.repository.JpaRepository; import java.time.LocalDateTime; import java.util.List; /** - * TODO: Добавить описание класса. + * Интерфейс JPA репозитория для сущности {@link Mail}. При этом сам не является репозиторием, а подставляется в + * {@link org.sadtech.social.core.repository.impl.jpa.MailRepositoryJpaImpl} * - * @author upagge [25/07/2019] + * @author upagge [27/07/2019] */ -public class MailRepositoryJpa implements ContentRepository { +public interface MailRepositoryJpa extends JpaRepository { - private final MailRepository mailRepository; + List findByCreateDateBetween(LocalDateTime from, LocalDateTime to); - 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 deleted file mode 100644 index b422fec..0000000 --- a/src/main/java/org/sadtech/social/core/repository/jpa/impl/MailRepository.java +++ /dev/null @@ -1,18 +0,0 @@ -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); - -}