Добавил API создания начальных остатков и тесты валидации запросов
This commit is contained in:
1 parent
0af9111103
commit
e8ec273693
9 files changed
+260
-21
No files matched your search
@@ -1,14 +1,18 @@
|
||||
package service;
|
||||
|
||||
import model.Account;
|
||||
import model.Operation;
|
||||
import model.OperationJournal;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.util.Objects;
|
||||
|
||||
public class OperationService {
|
||||
|
||||
private final OperationJournal journal;
|
||||
private final Ledger ledger;
|
||||
private Long counterId = 0L;
|
||||
|
||||
public OperationService(OperationJournal journal, Ledger ledger) {
|
||||
|
||||
@@ -20,34 +24,40 @@ public class OperationService {
|
||||
);
|
||||
}
|
||||
|
||||
public void save(Operation operation) {
|
||||
public synchronized void save(Operation operation) {
|
||||
journal.saveOperation(operation);
|
||||
}
|
||||
|
||||
public void post(Long operationId) {
|
||||
public synchronized void post(Long operationId) {
|
||||
post(requiredOperation(operationId));
|
||||
}
|
||||
|
||||
public void post(Operation operation) {
|
||||
public synchronized void post(Operation operation) {
|
||||
ledger.post(operation);
|
||||
journal.saveOperation(operation);
|
||||
}
|
||||
|
||||
public void unpost(Long operationId) {
|
||||
public synchronized void unpost(Long operationId) {
|
||||
ledger.unpost(requiredOperation(operationId).getId());
|
||||
}
|
||||
|
||||
public boolean isPosted(Operation operation) {
|
||||
public synchronized boolean isPosted(Operation operation) {
|
||||
if (operation == null) {
|
||||
throw new IllegalArgumentException("Не указан документ");
|
||||
}
|
||||
return ledger.isPosted(operation.getId());
|
||||
}
|
||||
|
||||
public Operation getById(Long operationId) {
|
||||
public synchronized Operation getById(Long operationId) {
|
||||
return requiredOperation(operationId);
|
||||
}
|
||||
|
||||
public synchronized Operation createOpeningBalance(LocalDate date, Account account, BigDecimal amount) {
|
||||
Operation operation = Operation.openingBalance(date, counterId++, account, amount);
|
||||
journal.saveOperation(operation);
|
||||
return operation;
|
||||
}
|
||||
|
||||
private Operation requiredOperation(Long operationId) {
|
||||
Operation operation = journal.getOperationById(operationId);
|
||||
|
||||
|
||||
Reference in new issue
Block a user