Рефакторинг

This commit is contained in:
Mark Struchkov 2019-05-27 09:57:51 +03:00
parent 8e5edc1e9e
commit 3184e46d1b
3 changed files with 18 additions and 10 deletions

View File

@ -2,7 +2,7 @@ package org.sadtech.bot.core.domain.content.attachment;
public abstract class Attachment { public abstract class Attachment {
AttachmentType type; protected AttachmentType type;
public AttachmentType getType() { public AttachmentType getType() {
return type; return type;

View File

@ -23,18 +23,26 @@ public class AccountServiceImpl implements AccountService {
@Override @Override
public Boolean pay(Integer accountId, Integer extinguishedPersonId, Double sum) { public Boolean pay(Integer accountId, Integer extinguishedPersonId, Double sum) {
Account account = accountRepository.findById(accountId); Account account = accountRepository.findById(accountId);
if (account.getTotalSum().equals(sum)) { if (validStatus(account.getAccountStatus())) {
account.setAccountStatus(AccountStatus.CLOSED); if (account.getTotalSum().equals(sum)) {
account.setExtinguishedPersonId(extinguishedPersonId); account.setAccountStatus(AccountStatus.CLOSED);
accountRepository.edit(accountId, account); account.setExtinguishedPersonId(extinguishedPersonId);
accountRepository.edit(accountId, account);
} else {
account.setAccountStatus(AccountStatus.EXCEPTION);
accountRepository.edit(accountId, account);
throw new PaymentException(2, "Неверная сумма");
}
} else { } else {
account.setAccountStatus(AccountStatus.EXCEPTION); throw new PaymentException(3, "Счет уже оплачен");
accountRepository.edit(accountId, account);
throw new PaymentException(2, "Неверная сумма");
} }
return true; return true;
} }
private boolean validStatus(AccountStatus accountStatus) {
return AccountStatus.EXCEPTION.equals(accountStatus) || AccountStatus.EXPOSED.equals(accountStatus);
}
@Override @Override
public Boolean paymentVerification(Integer accountId) { public Boolean paymentVerification(Integer accountId) {
return AccountStatus.CLOSED.equals(accountRepository.findById(accountId).getAccountStatus()); return AccountStatus.CLOSED.equals(accountRepository.findById(accountId).getAccountStatus());

View File

@ -12,9 +12,9 @@ public class RawEventServiceImpl implements RawEventService {
private static final Logger log = LoggerFactory.getLogger(RawEventServiceImpl.class); private static final Logger log = LoggerFactory.getLogger(RawEventServiceImpl.class);
private final EventRepository eventRepository; private final EventRepository<JsonObject> eventRepository;
public RawEventServiceImpl(EventRepository eventRepository) { public RawEventServiceImpl(EventRepository<JsonObject> eventRepository) {
this.eventRepository = eventRepository; this.eventRepository = eventRepository;
} }