Skip to content

Commit

Permalink
work on #57, do some preparation for #56 while on it.
Browse files Browse the repository at this point in the history
  • Loading branch information
OlliL committed May 5, 2024
1 parent 87abea0 commit 53498e6
Show file tree
Hide file tree
Showing 30 changed files with 278 additions and 269 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.laladev.moneyjinn.converter;

import org.laladev.moneyjinn.converter.config.MapStructConfig;
import org.laladev.moneyjinn.model.etf.EtfPreliminaryLumpSumID;
import org.mapstruct.Mapper;

@Mapper(config = MapStructConfig.class)
public interface EtfPreliminaryLumpSumIdMapper extends EntityIdMapper<EtfPreliminaryLumpSumID, Long> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
package org.laladev.moneyjinn.model.etf;

import java.math.BigDecimal;
import java.time.Year;

import org.laladev.moneyjinn.model.AbstractEntity;

Expand All @@ -39,6 +40,10 @@
@ToString(callSuper = true)
public class EtfPreliminaryLumpSum extends AbstractEntity<EtfPreliminaryLumpSumID> {
private static final long serialVersionUID = 1L;
private EtfID etfId;
private Year year;
private EtfPreliminaryLumpSumType type;
private BigDecimal amountPerPiece;
private BigDecimal amountJanuary;
private BigDecimal amountFebruary;
private BigDecimal amountMarch;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@

import org.laladev.moneyjinn.model.AbstractEntityID;

public class EtfPreliminaryLumpSumID extends AbstractEntityID<EtfPreliminaryLumpSumIDValues> {
public class EtfPreliminaryLumpSumID extends AbstractEntityID<Long> {
private static final long serialVersionUID = 1L;

public EtfPreliminaryLumpSumID(final EtfPreliminaryLumpSumIDValues id) {
public EtfPreliminaryLumpSumID(final Long id) {
super(id);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.laladev.moneyjinn.model.etf;

public enum EtfPreliminaryLumpSumType {
AMOUNT_PER_MONTH,
AMOUNT_PER_PIECE;
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.laladev.moneyjinn.model.etf.EtfID;
import org.laladev.moneyjinn.model.etf.EtfPreliminaryLumpSum;
import org.laladev.moneyjinn.model.etf.EtfPreliminaryLumpSumID;
import org.laladev.moneyjinn.model.etf.EtfPreliminaryLumpSumIDValues;
import org.laladev.moneyjinn.model.validation.ValidationResult;
import org.laladev.moneyjinn.server.controller.api.CrudEtfPreliminaryLumpSumControllerApi;
import org.laladev.moneyjinn.server.controller.impl.AbstractController;
Expand Down Expand Up @@ -76,13 +75,9 @@ public ResponseEntity<List<Integer>> readAllYears(@PathVariable("etfId") final L
}

@Override
public ResponseEntity<EtfPreliminaryLumpSumTransport> readOne(@PathVariable("etfId") final Long requestEtfId,
@PathVariable("year") final Integer requestYear) {
public ResponseEntity<EtfPreliminaryLumpSumTransport> readOne(@PathVariable("id") final Long requestId) {
final UserID userId = super.getUserId();
final EtfID etfId = new EtfID(requestEtfId);
final Year year = Year.of(requestYear);
final EtfPreliminaryLumpSumID id = new EtfPreliminaryLumpSumID(
new EtfPreliminaryLumpSumIDValues(etfId, year));
final var id = new EtfPreliminaryLumpSumID(requestId);

final EtfPreliminaryLumpSum etfPreliminaryLumpSum = this.etfService.getEtfPreliminaryLumpSum(userId, id);

Expand Down Expand Up @@ -123,13 +118,9 @@ public ResponseEntity<EtfPreliminaryLumpSumTransport> update(
}

@Override
public ResponseEntity<Void> delete(@PathVariable("etfId") final Long requestEtfId,
@PathVariable("year") final Integer requestYear) {
public ResponseEntity<Void> delete(@PathVariable("id") final Long requestId) {
final UserID userId = super.getUserId();
final EtfID etfId = new EtfID(requestEtfId);
final Year year = Year.of(requestYear);
final EtfPreliminaryLumpSumID id = new EtfPreliminaryLumpSumID(
new EtfPreliminaryLumpSumIDValues(etfId, year));
final var id = new EtfPreliminaryLumpSumID(requestId);

this.etfService.deleteEtfPreliminaryLumpSum(userId, id);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,21 @@
package org.laladev.moneyjinn.server.controller.mapper;

import org.laladev.moneyjinn.converter.EtfIdMapper;
import org.laladev.moneyjinn.converter.EtfPreliminaryLumpSumIdMapper;
import org.laladev.moneyjinn.converter.IMapstructMapper;
import org.laladev.moneyjinn.converter.config.MapStructConfig;
import org.laladev.moneyjinn.converter.javatypes.YearToIntegerMapper;
import org.laladev.moneyjinn.model.etf.EtfPreliminaryLumpSum;
import org.laladev.moneyjinn.server.model.EtfPreliminaryLumpSumTransport;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;

@Mapper(config = MapStructConfig.class, uses = { EtfIdMapper.class, YearToIntegerMapper.class })
@Mapper(config = MapStructConfig.class, uses = { EtfPreliminaryLumpSumIdMapper.class, EtfIdMapper.class,
YearToIntegerMapper.class, EtfPreliminaryLumpSumTypeMapper.class })
public interface EtfPreliminaryLumpSumTransportMapper
extends IMapstructMapper<EtfPreliminaryLumpSum, EtfPreliminaryLumpSumTransport> {
@Override
@Mapping(target = "id.id.etfId", source = "etfId")
@Mapping(target = "id.id.year", source = "year")
EtfPreliminaryLumpSum mapBToA(EtfPreliminaryLumpSumTransport etfPreliminaryLumpSumData);

@Override
@Mapping(target = "etfId", source = "id.id.etfId")
@Mapping(target = "year", source = "id.id.year")
EtfPreliminaryLumpSumTransport mapAToB(EtfPreliminaryLumpSum etfPreliminaryLumpSum);
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,41 @@
// SUCH DAMAGE.
//

package org.laladev.moneyjinn.model.etf;
package org.laladev.moneyjinn.server.controller.mapper;

import java.io.Serializable;
import java.time.Year;
import org.laladev.moneyjinn.core.error.ErrorCode;
import org.laladev.moneyjinn.model.etf.EtfPreliminaryLumpSumType;
import org.laladev.moneyjinn.model.exception.TechnicalException;

import lombok.Data;
public class EtfPreliminaryLumpSumTypeMapper {
private static final int AMOUNT_PER_MONTH = 1;
private static final int AMOUNT_PER_PIECE = 2;
private static final int RESERVE_ASSET_INT = 3;
private static final int PROVISION_ASSET_INT = 4;
private static final int CREDIT_INT = 5;

@Data
public class EtfPreliminaryLumpSumIDValues implements Serializable {
private EtfPreliminaryLumpSumTypeMapper() {
}

private static final long serialVersionUID = 1L;
private final EtfID etfId;
private final Year year;
}
public static EtfPreliminaryLumpSumType map(final Integer type) {
if (type != null) {
return switch (type) {
case AMOUNT_PER_MONTH -> EtfPreliminaryLumpSumType.AMOUNT_PER_MONTH;
case AMOUNT_PER_PIECE -> EtfPreliminaryLumpSumType.AMOUNT_PER_PIECE;
default -> throw new TechnicalException("Type " + type + " not defined!", ErrorCode.UNKNOWN);
};
}
return null;
}

public static Integer map(final EtfPreliminaryLumpSumType type) {
if (type != null) {
return switch (type) {
case AMOUNT_PER_MONTH -> AMOUNT_PER_MONTH;
case AMOUNT_PER_PIECE -> AMOUNT_PER_PIECE;
default -> throw new TechnicalException("Type " + type + " not defined!", ErrorCode.UNKNOWN);
};
}
return null;
}
}
6 changes: 3 additions & 3 deletions moneyjinn-server/src/main/resources/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@
"/moneyflow/server/etfpreliminarylumpsumps": {
"$ref": "openapi/etf/paths/CrudEtfPreliminaryLumpSum.json"
},
"/moneyflow/server/etfpreliminarylumpsumps/{etfId}": {
"/moneyflow/server/etfpreliminarylumpsumps/getAllYears/{etfId}": {
"$ref": "openapi/etf/paths/CrudEtfPreliminaryLumpSumEtfId.json"
},
"/moneyflow/server/etfpreliminarylumpsumps/{etfId}/{year}": {
"$ref": "openapi/etf/paths/CrudEtfPreliminaryLumpSumEtfIdYear.json"
"/moneyflow/server/etfpreliminarylumpsumps/{id}": {
"$ref": "openapi/etf/paths/CrudEtfPreliminaryLumpSumId.json"
},
"/moneyflow/server/user/changePassword": {
"$ref": "openapi/user/paths/ChangePassword.json"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,21 @@
{
"parameters": [
{
"name": "etfId",
"name": "id",
"in": "path",
"required": true,
"schema": {
"type": "integer",
"format": "int64"
}
},
{
"name": "year",
"in": "path",
"required": true,
"schema": {
"type": "integer",
"format": "int32"
}
}
],
"get": {
"tags": [
"crud-etf-preliminary-lump-sum-controller"
],
"operationId": "readOne",
"description": "Returns the preliminary lump sum specified by the ETF ID and year.",
"description": "Returns the preliminary lump sum specified by its ID.",
"responses": {
"200": {
"description": "OK",
Expand All @@ -49,7 +40,7 @@
"crud-etf-preliminary-lump-sum-controller"
],
"operationId": "delete",
"description": "Deletes the preliminary lump sum specified by the ETF ID and year.",
"description": "Deletes the preliminary lump sum specified by its ID.",
"responses": {
"204": {
"description": "OK"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
{
"type": "object",
"required": [
"id",
"etfId",
"year",
"amountJanuary",
"amountFebruary",
"amountMarch",
"amountApril",
"amountMay",
"amountJune",
"amountJuly",
"amountAugust",
"amountSeptember",
"amountOctober",
"amountNovember",
"amountDecember"
"type"
],
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"etfId": {
"type": "integer",
"format": "int64"
Expand All @@ -25,6 +19,13 @@
"type": "integer",
"format": "int32"
},
"type": {
"type": "integer",
"format": "int32"
},
"amountPerPiece": {
"type": "number"
},
"amountJanuary": {
"type": "number"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class EtfEffectiveFlowTransportBuilder extends EtfEffectiveFlowTransport
public EtfEffectiveFlowTransportBuilder forFlow6() {
super.setEtfflowid(ETF_FLOW_6ID);
super.setEtfId(ETF_ID_1);
super.setAmount(new BigDecimal("2.234"));
super.setAmount(new BigDecimal("2.23400"));
super.setNanoseconds(999000000);
super.setPrice(new BigDecimal("889.123"));
super.setTimestamp(OffsetDateTime.of(2009, 2, 20, 23, 59, 59, 999000000, ZoneOffset.UTC));
Expand All @@ -27,7 +27,7 @@ public EtfEffectiveFlowTransportBuilder forFlow6() {
public EtfEffectiveFlowTransportBuilder forFlow8() {
super.setEtfflowid(ETF_FLOW_8ID);
super.setEtfId(ETF_ID_1);
super.setAmount(new BigDecimal("81.000"));
super.setAmount(new BigDecimal("81.00000"));
super.setNanoseconds(320000000);
super.setPrice(new BigDecimal("777.000"));
super.setTimestamp(OffsetDateTime.of(2010, 01, 01, 15, 16, 20, 320000000, ZoneOffset.UTC));
Expand All @@ -37,7 +37,7 @@ public EtfEffectiveFlowTransportBuilder forFlow8() {
public EtfEffectiveFlowTransportBuilder forFlow9() {
super.setEtfflowid(ETF_FLOW_9ID);
super.setEtfId(ETF_ID_1);
super.setAmount(new BigDecimal("80.000"));
super.setAmount(new BigDecimal("80.00000"));
super.setNanoseconds(320000000);
super.setPrice(new BigDecimal("777.000"));
super.setTimestamp(OffsetDateTime.of(2010, 02, 02, 15, 16, 20, 320000000, ZoneOffset.UTC));
Expand All @@ -47,7 +47,7 @@ public EtfEffectiveFlowTransportBuilder forFlow9() {
public EtfEffectiveFlowTransportBuilder forFlow11() {
super.setEtfflowid(ETF_FLOW_11ID);
super.setEtfId(ETF_ID_1);
super.setAmount(new BigDecimal("30.000"));
super.setAmount(new BigDecimal("30.00000"));
super.setNanoseconds(320000000);
super.setPrice(new BigDecimal("750.000"));
super.setTimestamp(OffsetDateTime.of(2010, 02, 04, 15, 16, 20, 320000000, ZoneOffset.UTC));
Expand Down
Loading

0 comments on commit 53498e6

Please sign in to comment.