backend-api мелкий рефакторинг 2
This commit is contained in:
parent
c46f4ebf07
commit
a28cf54bbd
8 changed files with 26 additions and 272 deletions
|
|
@ -16,7 +16,8 @@ import ru.spcex.clearing.backendapi.controller.request.cud.common.CommonDeleteAc
|
|||
import ru.spcex.clearing.backendapi.controller.response.BasicSpcexResponse;
|
||||
import ru.spcex.clearing.backendapi.controller.response.cud.CudResponse;
|
||||
import ru.spcex.clearing.backendapi.controller.response.entity.CommonGetAllResponse;
|
||||
import ru.spcex.clearing.backendapi.controller.response.entity.account.BankAccountBackendGetById;
|
||||
import ru.spcex.clearing.backendapi.controller.response.entity.CommonGetByIdResponse;
|
||||
import ru.spcex.clearing.backendapi.meta.GetResponseFactory;
|
||||
import ru.spcex.clearing.backendapi.service.IOperator;
|
||||
import ru.spcex.clearing.backendapi.service.IStateLoader;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
|
|
@ -31,11 +32,13 @@ import java.util.concurrent.ExecutionException;
|
|||
@RequestMapping("/accounting/bank-accounts")
|
||||
public class BankAccountController extends AbstractQueueController {
|
||||
private final IStateLoader stateLoader;
|
||||
private final GetResponseFactory responseMetaFactory;
|
||||
|
||||
@Autowired
|
||||
public BankAccountController(IOperator operator, IStateLoader stateLoader) {
|
||||
public BankAccountController(GetResponseFactory responseMetaFactory, IOperator operator, IStateLoader stateLoader) {
|
||||
super(operator);
|
||||
this.stateLoader = stateLoader;
|
||||
this.responseMetaFactory = responseMetaFactory;
|
||||
}
|
||||
|
||||
@ApiOperation(value = "create bank account.")
|
||||
|
|
@ -73,14 +76,17 @@ public class BankAccountController extends AbstractQueueController {
|
|||
}
|
||||
|
||||
@ApiOperation(value = "get bank account.")
|
||||
@ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = BankAccountBackendGetById.class), @ApiResponse(code = 400, message = "Ошибка валидации", response = BasicSpcexResponse.class)})
|
||||
@ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = CommonGetByIdResponse.class), @ApiResponse(code = 400, message = "Ошибка валидации", response = BasicSpcexResponse.class)})
|
||||
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public BankAccountBackendGetById getById(@ApiParam(value = "Идентификатор объекта", required = true, example = "1234")
|
||||
public CommonGetByIdResponse getById(@ApiParam(value = "Идентификатор объекта", required = true, example = "1234")
|
||||
@PathVariable("id") Long id) {
|
||||
Optional<BankAccount> bankAccount = stateLoader.getById(id, IMDGDistributedNames.Map_BankAccount, BankAccount.class);
|
||||
BankAccountBackendGetById response = new BankAccountBackendGetById();
|
||||
bankAccount.ifPresentOrElse(response::fromEntity, () -> response.setCode(404));
|
||||
CommonGetByIdResponse response = new CommonGetByIdResponse();
|
||||
bankAccount.ifPresentOrElse( r -> {
|
||||
Map<String, Object> extractedByMeta = responseMetaFactory.responseFromObject(r);
|
||||
response.fromEntity(extractedByMeta);
|
||||
}, () -> response.setCode(404));
|
||||
return response;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ import ru.spcex.clearing.backendapi.controller.queue.AbstractQueueController;
|
|||
import ru.spcex.clearing.backendapi.controller.response.BasicSpcexResponse;
|
||||
import ru.spcex.clearing.backendapi.controller.response.entity.CommonGetAllResponse;
|
||||
import ru.spcex.clearing.backendapi.controller.response.entity.CommonGetByIdResponse;
|
||||
import ru.spcex.clearing.backendapi.controller.response.entity.account.BankAccountBackendGetById;
|
||||
import ru.spcex.clearing.backendapi.errors.NotFound404Exception;
|
||||
import ru.spcex.clearing.backendapi.meta.GetResponseFactory;
|
||||
import ru.spcex.clearing.backendapi.service.IOperator;
|
||||
|
|
@ -51,7 +50,7 @@ public class StatementController extends AbstractQueueController {
|
|||
}
|
||||
|
||||
@ApiOperation(value = "get Statement by Id.")
|
||||
@ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = BankAccountBackendGetById.class), @ApiResponse(code = 400, message = "Ошибка валидации", response = BasicSpcexResponse.class)})
|
||||
@ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = CommonGetByIdResponse.class), @ApiResponse(code = 400, message = "Ошибка валидации", response = BasicSpcexResponse.class)})
|
||||
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public CommonGetByIdResponse getById(@ApiParam(value = "Идентификатор объекта", required = true, example = "1234")
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ public class AccountBackendGetAll extends BasicSpcexResponse {
|
|||
singleItem.setRelationId(account.getRelationId());
|
||||
singleItem.setStatus(account.getStatus());
|
||||
singleItem.setProcessingSign(account.getProcessingSign());
|
||||
singleItem.setCompanyId(account.getCompanyId());
|
||||
singleItem.setCreated(account.getCreated());
|
||||
singleItem.setUpdated(account.getUpdated());
|
||||
payload.getItems().add(singleItem);
|
||||
|
|
|
|||
|
|
@ -20,6 +20,8 @@ public class AccountBackendGetFields {
|
|||
@JsonProperty
|
||||
private String processingSign;
|
||||
@JsonProperty
|
||||
private Long companyId;
|
||||
@JsonProperty
|
||||
@JsonSerialize(using = InstantSerializer.class)
|
||||
private Instant created;
|
||||
@JsonProperty
|
||||
|
|
@ -74,6 +76,14 @@ public class AccountBackendGetFields {
|
|||
this.processingSign = processingSign;
|
||||
}
|
||||
|
||||
public Long getCompanyId() {
|
||||
return companyId;
|
||||
}
|
||||
|
||||
public void setCompanyId(Long companyId) {
|
||||
this.companyId = companyId;
|
||||
}
|
||||
|
||||
public Instant getCreated() {
|
||||
return created;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,64 +0,0 @@
|
|||
package ru.spcex.clearing.backendapi.controller.response.entity.account;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import ru.clearing.classes.statics.data.account.BankAccount;
|
||||
import ru.spcex.clearing.backendapi.controller.response.BasicSpcexResponse;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Банковские реквизиты для перечисления денежных средств
|
||||
**/
|
||||
@ApiModel(description = "Ответ при получении объектов BankAccount.")
|
||||
public class BankAccountBackendGetAll extends BasicSpcexResponse {
|
||||
|
||||
@JsonProperty
|
||||
@ApiModelProperty(value = "Полезная нагрузка")
|
||||
private BankAccountBackendPayload payload = new BankAccountBackendPayload();
|
||||
|
||||
public BankAccountBackendPayload getPayload() {
|
||||
return payload;
|
||||
}
|
||||
|
||||
public void setPayload(BankAccountBackendPayload payload) {
|
||||
this.payload = payload;
|
||||
}
|
||||
|
||||
public void fromEntity(Collection<BankAccount> bankAccounts) {
|
||||
var payload = this.getPayload();
|
||||
for (BankAccount bankAccount : bankAccounts) {
|
||||
var singleItem = new BankAccountBackendGetFields();
|
||||
singleItem.setId(bankAccount.getId());
|
||||
singleItem.setAccountId(bankAccount.getAccountId());
|
||||
singleItem.setBankIdentificationCode(bankAccount.getBankIdentificationCode());
|
||||
singleItem.setBankName(bankAccount.getBankName());
|
||||
singleItem.setCorrespondentAccount(bankAccount.getCorrespondentAccount());
|
||||
singleItem.setCorrespondentAccountName(bankAccount.getCorrespondentAccountName());
|
||||
singleItem.setCurrency(bankAccount.getCurrency());
|
||||
singleItem.setDestination(bankAccount.getDestination());
|
||||
singleItem.setIban(bankAccount.getIban());
|
||||
singleItem.setInternationalTransferSign(bankAccount.getInternationalTransferSign());
|
||||
singleItem.setSwiftCode(bankAccount.getSwiftCode());
|
||||
singleItem.setTaxpayerIdentificationNumber(bankAccount.getTaxpayerIdentificationNumber());
|
||||
singleItem.setTaxRegistrationReasonCode(bankAccount.getTaxRegistrationReasonCode());
|
||||
payload.getItems().add(singleItem);
|
||||
}
|
||||
}
|
||||
|
||||
private static class BankAccountBackendPayload {
|
||||
private List<BankAccountBackendGetFields> items = new ArrayList<>();
|
||||
|
||||
public List<BankAccountBackendGetFields> getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
public void setItems(List<BankAccountBackendGetFields> items) {
|
||||
this.items = items;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,48 +0,0 @@
|
|||
package ru.spcex.clearing.backendapi.controller.response.entity.account;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import ru.clearing.classes.statics.data.account.BankAccount;
|
||||
import ru.spcex.clearing.backendapi.controller.response.BasicSpcexResponse;
|
||||
|
||||
/**
|
||||
* Банковские реквизиты для перечисления денежных средств
|
||||
*
|
||||
* @ApiModel(description = "Ответ в результате отправки операции в топик Kafka.")
|
||||
* @ApiModelProperty(value = "Информация о принятом запросе")
|
||||
**/
|
||||
@ApiModel(description = "Ответ при получении объекта BankAccount.")
|
||||
public class BankAccountBackendGetById extends BasicSpcexResponse {
|
||||
|
||||
@JsonProperty
|
||||
@ApiModelProperty(value = "Поля объекта")
|
||||
private BankAccountBackendGetFields payload;
|
||||
|
||||
public BankAccountBackendGetFields getPayload() {
|
||||
return payload;
|
||||
}
|
||||
|
||||
public void setPayload(BankAccountBackendGetFields payload) {
|
||||
this.payload = payload;
|
||||
}
|
||||
|
||||
public void fromEntity(BankAccount bankAccount) {
|
||||
var payload = new BankAccountBackendGetFields();
|
||||
this.setPayload(payload);
|
||||
payload.setId(bankAccount.getId());
|
||||
payload.setAccountId(bankAccount.getAccountId());
|
||||
payload.setBankIdentificationCode(bankAccount.getBankIdentificationCode());
|
||||
payload.setBankName(bankAccount.getBankName());
|
||||
payload.setCorrespondentAccount(bankAccount.getCorrespondentAccount());
|
||||
payload.setCorrespondentAccountName(bankAccount.getCorrespondentAccountName());
|
||||
payload.setCurrency(bankAccount.getCurrency());
|
||||
payload.setDestination(bankAccount.getDestination());
|
||||
payload.setIban(bankAccount.getIban());
|
||||
payload.setInternationalTransferSign(bankAccount.getInternationalTransferSign());
|
||||
payload.setSwiftCode(bankAccount.getSwiftCode());
|
||||
payload.setTaxpayerIdentificationNumber(bankAccount.getTaxpayerIdentificationNumber());
|
||||
payload.setTaxRegistrationReasonCode(bankAccount.getTaxRegistrationReasonCode());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,150 +0,0 @@
|
|||
package ru.spcex.clearing.backendapi.controller.response.entity.account;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
public class BankAccountBackendGetFields {
|
||||
@JsonProperty
|
||||
@ApiModelProperty(value = "Идентификатор", example = "1234")
|
||||
private Long id;
|
||||
@JsonProperty
|
||||
@ApiModelProperty(value = "", example = "")
|
||||
private Long accountId;
|
||||
@JsonProperty
|
||||
@ApiModelProperty(value = "", example = "ABCD")
|
||||
private String bankIdentificationCode;
|
||||
@JsonProperty
|
||||
@ApiModelProperty(value = "Имя банка", example = "Сбербанк")
|
||||
private String bankName;
|
||||
@JsonProperty
|
||||
@ApiModelProperty(value = "", example = "")
|
||||
private String correspondentAccount;
|
||||
@JsonProperty
|
||||
@ApiModelProperty(value = "", example = "")
|
||||
private String correspondentAccountName;
|
||||
@JsonProperty
|
||||
@ApiModelProperty(value = "", example = "")
|
||||
private String currency;
|
||||
@JsonProperty
|
||||
@ApiModelProperty(value = "", example = "")
|
||||
private String destination;
|
||||
@JsonProperty
|
||||
@ApiModelProperty(value = "", example = "")
|
||||
private String iban;
|
||||
@JsonProperty
|
||||
@ApiModelProperty(value = "", example = "")
|
||||
private String internationalTransferSign;
|
||||
@JsonProperty
|
||||
@ApiModelProperty(value = "", example = "")
|
||||
private String swiftCode;
|
||||
@JsonProperty
|
||||
@ApiModelProperty(value = "", example = "")
|
||||
private String taxpayerIdentificationNumber;
|
||||
@JsonProperty
|
||||
@ApiModelProperty(value = "", example = "")
|
||||
private String taxRegistrationReasonCode;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Long getAccountId() {
|
||||
return accountId;
|
||||
}
|
||||
|
||||
public void setAccountId(Long value) {
|
||||
this.accountId = value;
|
||||
}
|
||||
|
||||
public String getBankIdentificationCode() {
|
||||
return bankIdentificationCode;
|
||||
}
|
||||
|
||||
public void setBankIdentificationCode(String value) {
|
||||
this.bankIdentificationCode = value;
|
||||
}
|
||||
|
||||
public String getBankName() {
|
||||
return bankName;
|
||||
}
|
||||
|
||||
public void setBankName(String value) {
|
||||
this.bankName = value;
|
||||
}
|
||||
|
||||
public String getCorrespondentAccount() {
|
||||
return correspondentAccount;
|
||||
}
|
||||
|
||||
public void setCorrespondentAccount(String value) {
|
||||
this.correspondentAccount = value;
|
||||
}
|
||||
|
||||
public String getCorrespondentAccountName() {
|
||||
return correspondentAccountName;
|
||||
}
|
||||
|
||||
public void setCorrespondentAccountName(String value) {
|
||||
this.correspondentAccountName = value;
|
||||
}
|
||||
|
||||
public String getCurrency() {
|
||||
return currency;
|
||||
}
|
||||
|
||||
public void setCurrency(String value) {
|
||||
this.currency = value;
|
||||
}
|
||||
|
||||
public String getDestination() {
|
||||
return destination;
|
||||
}
|
||||
|
||||
public void setDestination(String value) {
|
||||
this.destination = value;
|
||||
}
|
||||
|
||||
public String getIban() {
|
||||
return iban;
|
||||
}
|
||||
|
||||
public void setIban(String value) {
|
||||
this.iban = value;
|
||||
}
|
||||
|
||||
public String getInternationalTransferSign() {
|
||||
return internationalTransferSign;
|
||||
}
|
||||
|
||||
public void setInternationalTransferSign(String value) {
|
||||
this.internationalTransferSign = value;
|
||||
}
|
||||
|
||||
public String getSwiftCode() {
|
||||
return swiftCode;
|
||||
}
|
||||
|
||||
public void setSwiftCode(String value) {
|
||||
this.swiftCode = value;
|
||||
}
|
||||
|
||||
public String getTaxpayerIdentificationNumber() {
|
||||
return taxpayerIdentificationNumber;
|
||||
}
|
||||
|
||||
public void setTaxpayerIdentificationNumber(String value) {
|
||||
this.taxpayerIdentificationNumber = value;
|
||||
}
|
||||
|
||||
public String getTaxRegistrationReasonCode() {
|
||||
return taxRegistrationReasonCode;
|
||||
}
|
||||
|
||||
public void setTaxRegistrationReasonCode(String value) {
|
||||
this.taxRegistrationReasonCode = value;
|
||||
}
|
||||
}
|
||||
|
|
@ -22,7 +22,7 @@ public class DefaultController implements InitializingBean {
|
|||
|
||||
@ApiOperation(value = "Test backend-api availability.")
|
||||
@ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = String.class)})
|
||||
@RequestMapping(method = RequestMethod.GET, path = "/api/system/ping", produces = MediaType.TEXT_PLAIN_VALUE)
|
||||
@RequestMapping(method = RequestMethod.GET, path = "/system/ping", produces = MediaType.TEXT_PLAIN_VALUE)
|
||||
@ResponseBody
|
||||
public String processGet() {
|
||||
log.info("Call test method for backend-api controller");
|
||||
|
|
@ -31,7 +31,7 @@ public class DefaultController implements InitializingBean {
|
|||
|
||||
@ApiOperation(value = "Test backend-api availability (for authorized access). Available for anonymous, if authorization-disabled=true.")
|
||||
@ApiResponses(value = {@ApiResponse(code = 200, message = "OK")})
|
||||
@RequestMapping(method = RequestMethod.GET, path = "/api/system/ping/authorized", produces = MediaType.TEXT_PLAIN_VALUE)
|
||||
@RequestMapping(method = RequestMethod.GET, path = "/system/ping/authorized", produces = MediaType.TEXT_PLAIN_VALUE)
|
||||
@ResponseBody
|
||||
public String processProtectedGet() {
|
||||
log.info("controller method2");
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue