Skip to content

Commit

Permalink
remove ISIN from API
Browse files Browse the repository at this point in the history
  • Loading branch information
OlliL committed Apr 28, 2024
1 parent b1e89d6 commit ba172f9
Show file tree
Hide file tree
Showing 18 changed files with 33 additions and 110 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;

import org.laladev.moneyjinn.core.error.ErrorCode;
import org.laladev.moneyjinn.model.etf.Etf;
Expand All @@ -43,11 +42,9 @@
import org.laladev.moneyjinn.model.etf.EtfFlowID;
import org.laladev.moneyjinn.model.etf.EtfFlowWithTaxInfo;
import org.laladev.moneyjinn.model.etf.EtfID;
import org.laladev.moneyjinn.model.etf.EtfIsin;
import org.laladev.moneyjinn.model.etf.EtfValue;
import org.laladev.moneyjinn.model.setting.ClientCalcEtfSaleAskPrice;
import org.laladev.moneyjinn.model.setting.ClientCalcEtfSaleBidPrice;
import org.laladev.moneyjinn.model.setting.ClientCalcEtfSaleIsin;
import org.laladev.moneyjinn.model.setting.ClientCalcEtfSalePieces;
import org.laladev.moneyjinn.model.setting.ClientCalcEtfSaleTransactionCosts;
import org.laladev.moneyjinn.model.validation.ValidationResult;
Expand Down Expand Up @@ -112,7 +109,6 @@ public ResponseEntity<ListEtfOverviewResponse> listEtfOverview(
if (etfFlows != null && !etfFlows.isEmpty()) {
final EtfSummaryTransport transport = new EtfSummaryTransport();
transport.setEtfId(etf.getId().getId());
transport.setIsin(etf.getIsin().getId());
transport.setName(etf.getName());
transport.setChartUrl(etf.getChartUrl());
if (etfValue != null) {
Expand Down Expand Up @@ -151,15 +147,13 @@ public ResponseEntity<ListEtfFlowsResponse> listEtfFlows() {
for (final Etf etf : etfs) {
final List<EtfFlow> etfFlows = this.etfService.getAllEtfFlowsUntil(etf.getId(), LocalDateTime.now());
final List<EtfFlowTransport> etfFlowTransports = super.mapList(etfFlows, EtfFlowTransport.class);
etfFlowTransports.forEach(a -> a.setIsin(etf.getIsin().getId()));
transports.addAll(etfFlowTransports);

final List<EtfFlowWithTaxInfo> etfEffectiveFlows = new ArrayList<>(
this.etfService.calculateEffectiveEtfFlows(etfFlows));
Collections.sort(etfEffectiveFlows, Collections.reverseOrder(new EtfFlowComparator()));
final List<EtfEffectiveFlowTransport> etfEffectiveFlowTransports = super.mapList(etfEffectiveFlows,
EtfEffectiveFlowTransport.class);
etfEffectiveFlowTransports.forEach(a -> a.setIsin(etf.getIsin().getId()));
effectiveTransports.addAll(etfEffectiveFlowTransports);
}
response.setEtfFlowTransports(transports);
Expand All @@ -168,8 +162,9 @@ public ResponseEntity<ListEtfFlowsResponse> listEtfFlows() {
.ifPresent(s -> response.setCalcEtfAskPrice(s.getSetting()));
this.settingService.getClientCalcEtfSaleBidPrice(this.getUserId())
.ifPresent(s -> response.setCalcEtfBidPrice(s.getSetting()));
this.settingService.getClientCalcEtfSaleIsin(this.getUserId())
.ifPresent(s -> response.setCalcEtfSaleIsin(s.getSetting()));
// TODO
// this.settingService.getClientCalcEtfSaleIsin(this.getUserId())
// .ifPresent(s -> response.setCalcEtfSaleIsin(s.getSetting()));
this.settingService.getClientCalcEtfSalePieces(this.getUserId())
.ifPresent(s -> response.setCalcEtfSalePieces(s.getSetting()));
this.settingService.getClientCalcEtfSaleTransactionCosts(this.getUserId())
Expand All @@ -183,7 +178,7 @@ public ResponseEntity<ListEtfFlowsResponse> listEtfFlows() {
public ResponseEntity<CalcEtfSaleResponse> calcEtfSale(@RequestBody final CalcEtfSaleRequest request) {
final CalcEtfSaleResponse response = new CalcEtfSaleResponse();

if (request.getAskPrice() == null || request.getBidPrice() == null || request.getIsin() == null
if (request.getAskPrice() == null || request.getBidPrice() == null || request.getEtfId() == null
|| request.getPieces() == null || request.getTransactionCosts() == null) {
return ResponseEntity.ok(response);
}
Expand All @@ -193,19 +188,14 @@ public ResponseEntity<CalcEtfSaleResponse> calcEtfSale(@RequestBody final CalcEt
final BigDecimal bidPrice = request.getBidPrice().abs();
this.settingService.setClientCalcEtfSaleAskPrice(this.getUserId(), new ClientCalcEtfSaleAskPrice(askPrice));
this.settingService.setClientCalcEtfSaleBidPrice(this.getUserId(), new ClientCalcEtfSaleBidPrice(bidPrice));
this.settingService.setClientCalcEtfSaleIsin(this.getUserId(), new ClientCalcEtfSaleIsin(request.getIsin()));
// TODO
// this.settingService.setClientCalcEtfSaleIsin(this.getUserId(), new
// ClientCalcEtfSaleIsin(request.getIsin()));
this.settingService.setClientCalcEtfSalePieces(this.getUserId(), new ClientCalcEtfSalePieces(pieces));
this.settingService.setClientCalcEtfSaleTransactionCosts(this.getUserId(),
new ClientCalcEtfSaleTransactionCosts(request.getTransactionCosts()));

final EtfIsin etfIsin = new EtfIsin(request.getIsin());

final EtfID etfId;
if (request.getEtfId() != null) {
etfId = new EtfID(request.getEtfId());
} else {
etfId = this.getEtfID(etfIsin);
}
final EtfID etfId = new EtfID(request.getEtfId());
BigDecimal openPieces = pieces;
BigDecimal originalBuyPrice = BigDecimal.ZERO;
BigDecimal overallPreliminaryLumpSum = BigDecimal.ZERO;
Expand Down Expand Up @@ -249,7 +239,6 @@ public ResponseEntity<CalcEtfSaleResponse> calcEtfSale(@RequestBody final CalcEt
response.setSellPrice(sellPrice);
response.setTransactionCosts(transactionCosts);
response.setEtfId(etfId.getId());
response.setIsin(etfIsin.getId());
response.setPieces(pieces);
response.setOriginalBuyPrice(originalBuyPrice);
response.setProfit(profit);
Expand All @@ -269,14 +258,6 @@ public ResponseEntity<CreateEtfFlowResponse> createEtfFlow(@RequestBody final Cr

if (etfFlow != null) {
etfFlow.setId(null);
final EtfID etfId;
if (request.getEtfFlowTransport().getEtfId() != null) {
etfId = new EtfID(request.getEtfFlowTransport().getEtfId());
} else {
etfId = this.getEtfID(new EtfIsin(request.getEtfFlowTransport().getIsin()));
}
etfFlow.setEtfId(etfId);

final ValidationResult validationResult = this.etfService.validateEtfFlow(etfFlow);

this.throwValidationExceptionIfInvalid(validationResult);
Expand All @@ -294,13 +275,6 @@ public ResponseEntity<Void> updateEtfFlow(@RequestBody final UpdateEtfFlowReques
final EtfFlow etfFlow = super.map(request.getEtfFlowTransport(), EtfFlow.class);

if (etfFlow != null) {
final EtfID etfId;
if (request.getEtfFlowTransport().getEtfId() != null) {
etfId = new EtfID(request.getEtfFlowTransport().getEtfId());
} else {
etfId = this.getEtfID(new EtfIsin(request.getEtfFlowTransport().getIsin()));
}
etfFlow.setEtfId(etfId);

final ValidationResult validationResult = this.etfService.validateEtfFlow(etfFlow);

Expand All @@ -312,13 +286,6 @@ public ResponseEntity<Void> updateEtfFlow(@RequestBody final UpdateEtfFlowReques
return ResponseEntity.noContent().build();
}

@Deprecated(since = "Compatiblilty until Issue #53 is done only")
private EtfID getEtfID(final EtfIsin isin) {
final var etfs = this.etfService.getAllEtf();
final Optional<EtfID> etfId = etfs.stream().filter(e -> isin.equals(e.getIsin())).map(Etf::getId).findFirst();
return etfId.isPresent() ? etfId.get() : new EtfID(-1L);
}

@Override
public ResponseEntity<Void> deleteEtfFlow(@PathVariable(value = "id") final Long id) {
this.etfService.deleteEtfFlow(new EtfFlowID(id));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public interface EtfEffectiveFlowTransportMapper
@Mapping(target = "etfId", source = "etfId")
@Mapping(target = "nanoseconds", source = "time.nano")
@Mapping(target = "timestamp", source = "time")
@Mapping(target = "isin", ignore = true)
EtfEffectiveFlowTransport mapAToB(EtfFlowWithTaxInfo etfFlow);

@AfterMapping
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ public interface EtfFlowTransportMapper extends IMapstructMapper<EtfFlow, EtfFlo
@Mapping(target = "etfflowid", source = "id")
@Mapping(target = "nanoseconds", source = "time.nano")
@Mapping(target = "timestamp", source = "time")
@Mapping(target = "isin", ignore = true)
EtfFlowTransport mapAToB(EtfFlow etfFlow);

@AfterMapping
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"crud-etf-preliminary-lump-sum-controller"
],
"operationId": "readOne",
"description": "Returns the preliminary lump sum specified by the ISIN and year.",
"description": "Returns the preliminary lump sum specified by the ETF ID and year.",
"responses": {
"200": {
"description": "OK",
Expand All @@ -49,7 +49,7 @@
"crud-etf-preliminary-lump-sum-controller"
],
"operationId": "delete",
"description": "Deletes the preliminary lump sum specified by the ISIN and year.",
"description": "Deletes the preliminary lump sum specified by the ETF ID and year.",
"responses": {
"204": {
"description": "OK"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
"type": "integer",
"format": "int64"
},
"isin": {
"type": "string",
"deprecated": true
},
"pieces": {
"type": "number"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"type": "object",
"required": [
"etfId",
"isin",
"originalBuyPrice",
"sellPrice",
"newBuyPrice",
Expand All @@ -19,9 +18,6 @@
"type": "integer",
"format": "int64"
},
"isin": {
"type": "string"
},
"originalBuyPrice": {
"type": "number"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
"$ref": "../../transport/EtfEffectiveFlowTransport.json"
}
},
"calcEtfSaleIsin": {
"type": "string"
"calcEtfSaleEtfId": {
"type": "integer",
"format": "int64"
},
"calcEtfSalePieces": {
"type": "number"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"required": [
"etfflowid",
"etfId",
"isin",
"timestamp",
"nanoseconds",
"amount",
Expand All @@ -18,10 +17,6 @@
"type": "integer",
"format": "int64"
},
"isin": {
"type": "string",
"deprecated": true
},
"timestamp": {
"type": "string",
"format": "date-time"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"required": [
"etfflowid",
"etfId",
"isin",
"timestamp",
"nanoseconds",
"amount",
Expand All @@ -18,10 +17,6 @@
"type": "integer",
"format": "int64"
},
"isin": {
"type": "string",
"deprecated": true
},
"timestamp": {
"type": "string",
"format": "date-time"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"type": "object",
"required": [
"etfId",
"isin",
"name",
"chartUrl",
"amount",
Expand All @@ -16,10 +15,6 @@
"type": "integer",
"format": "int64"
},
"isin": {
"type": "string",
"deprecated": true
},
"name": {
"type": "string"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@ public class EtfEffectiveFlowTransportBuilder extends EtfEffectiveFlowTransport
public static final Long ETF_FLOW_8ID = 8L;
public static final Long ETF_FLOW_9ID = 9L;
public static final Long ETF_FLOW_11ID = 11L;
public static final String ISIN = EtfTransportBuilder.ISIN;
public static final Long ETF_ID_1 = EtfTransportBuilder.ETF_ID_1;

public EtfEffectiveFlowTransportBuilder forFlow6() {
super.setEtfflowid(ETF_FLOW_6ID);
super.setEtfId(ETF_ID_1);
super.setAmount(new BigDecimal("2.234"));
super.setIsin(ISIN);
super.setNanoseconds(999000000);
super.setPrice(new BigDecimal("889.123"));
super.setTimestamp(OffsetDateTime.of(2009, 2, 20, 23, 59, 59, 999000000, ZoneOffset.UTC));
Expand All @@ -30,7 +28,6 @@ public EtfEffectiveFlowTransportBuilder forFlow8() {
super.setEtfflowid(ETF_FLOW_8ID);
super.setEtfId(ETF_ID_1);
super.setAmount(new BigDecimal("81.000"));
super.setIsin(ISIN);
super.setNanoseconds(320000000);
super.setPrice(new BigDecimal("777.000"));
super.setTimestamp(OffsetDateTime.of(2010, 01, 01, 15, 16, 20, 320000000, ZoneOffset.UTC));
Expand All @@ -41,7 +38,6 @@ public EtfEffectiveFlowTransportBuilder forFlow9() {
super.setEtfflowid(ETF_FLOW_9ID);
super.setEtfId(ETF_ID_1);
super.setAmount(new BigDecimal("80.000"));
super.setIsin(ISIN);
super.setNanoseconds(320000000);
super.setPrice(new BigDecimal("777.000"));
super.setTimestamp(OffsetDateTime.of(2010, 02, 02, 15, 16, 20, 320000000, ZoneOffset.UTC));
Expand All @@ -52,7 +48,6 @@ public EtfEffectiveFlowTransportBuilder forFlow11() {
super.setEtfflowid(ETF_FLOW_11ID);
super.setEtfId(ETF_ID_1);
super.setAmount(new BigDecimal("30.000"));
super.setIsin(ISIN);
super.setNanoseconds(320000000);
super.setPrice(new BigDecimal("750.000"));
super.setTimestamp(OffsetDateTime.of(2010, 02, 04, 15, 16, 20, 320000000, ZoneOffset.UTC));
Expand All @@ -64,7 +59,6 @@ public EtfEffectiveFlowTransport build() {
transport.setEtfflowid(super.getEtfflowid());
transport.setEtfId(super.getEtfId());
transport.setAmount(super.getAmount());
transport.setIsin(super.getIsin());
transport.setNanoseconds(super.getNanoseconds());
transport.setPrice(super.getPrice());
transport.setTimestamp(super.getTimestamp());
Expand Down
Loading

0 comments on commit ba172f9

Please sign in to comment.