1 | package org.cardanofoundation.explorer.api.mapper; | |
2 | ||
3 | import java.util.Objects; | |
4 | ||
5 | import org.springframework.beans.factory.annotation.Value; | |
6 | ||
7 | import org.mapstruct.Mapper; | |
8 | import org.mapstruct.Mapping; | |
9 | import org.mapstruct.Named; | |
10 | ||
11 | import org.cardanofoundation.explorer.api.model.response.token.TokenMetadataResponse; | |
12 | import org.cardanofoundation.explorer.api.model.response.token.TokenMintTxResponse; | |
13 | import org.cardanofoundation.explorer.api.model.response.tx.TxMintingResponse; | |
14 | import org.cardanofoundation.explorer.api.projection.AddressInputOutputProjection; | |
15 | import org.cardanofoundation.explorer.api.projection.MintProjection; | |
16 | import org.cardanofoundation.explorer.api.util.HexUtils; | |
17 | import org.cardanofoundation.explorer.common.entity.ledgersync.MaTxMint; | |
18 | ||
19 | @Mapper( | |
20 | componentModel = "spring", | |
21 | imports = {HexUtils.class}) | |
22 | public abstract class MaTxMintMapper { | |
23 | ||
24 | @Value("${application.token-logo-endpoint}") | |
25 | protected String tokenLogoEndpoint; | |
26 | ||
27 | @Mapping( | |
28 | target = "assetName", | |
29 | expression = "java(HexUtils.fromHex(input.getAssetName(), input.getAssetId()))") | |
30 | @Mapping(target = "assetId", expression = "java(input.getAssetId())") | |
31 | public abstract TxMintingResponse fromAddressInputOutputProjection( | |
32 | AddressInputOutputProjection input); | |
33 | ||
34 | @Mapping(target = "txHash", expression = "java(maTxMint.getTx().getHash())") | |
35 | @Mapping(target = "amount", source = "quantity") | |
36 | @Mapping(target = "time", source = "tx.block.time") | |
37 | public abstract TokenMintTxResponse fromMaTxMintToTokenMintTx(MaTxMint maTxMint); | |
38 | ||
39 | @Mapping( | |
40 | target = "assetName", | |
41 | expression = | |
42 | "java(HexUtils.fromHex(mintProjection.getName(), mintProjection.getFingerprint()))") | |
43 | @Mapping(target = "policy", source = "policy") | |
44 | @Mapping(target = "assetQuantity", source = "assetQuantity") | |
45 | @Mapping(target = "assetId", source = "fingerprint") | |
46 | @Mapping(target = "metadata", expression = "java(getMetadata(mintProjection))") | |
47 | public abstract TxMintingResponse fromMintProjectionToTxMintingResponse( | |
48 | MintProjection mintProjection); | |
49 | ||
50 | @Named("getTokenLogoURL") | |
51 | String getTokenLogoEndpoint(String logo) { | |
52 |
2
1. getTokenLogoEndpoint : negated conditional → NO_COVERAGE 2. getTokenLogoEndpoint : replaced return value with "" for org/cardanofoundation/explorer/api/mapper/MaTxMintMapper::getTokenLogoEndpoint → NO_COVERAGE |
return Objects.isNull(logo) ? null : (tokenLogoEndpoint + logo); |
53 | } | |
54 | ||
55 | TokenMetadataResponse getMetadata(MintProjection mintProjection) { | |
56 | TokenMetadataResponse tokenMetadataResponse = new TokenMetadataResponse(); | |
57 |
1
1. getMetadata : removed call to org/cardanofoundation/explorer/api/model/response/token/TokenMetadataResponse::setUrl → NO_COVERAGE |
tokenMetadataResponse.setUrl(mintProjection.getUrl()); |
58 |
1
1. getMetadata : removed call to org/cardanofoundation/explorer/api/model/response/token/TokenMetadataResponse::setTicker → NO_COVERAGE |
tokenMetadataResponse.setTicker(mintProjection.getTicker()); |
59 |
1
1. getMetadata : removed call to org/cardanofoundation/explorer/api/model/response/token/TokenMetadataResponse::setLogo → NO_COVERAGE |
tokenMetadataResponse.setLogo(getTokenLogoEndpoint(mintProjection.getLogo())); |
60 |
1
1. getMetadata : removed call to org/cardanofoundation/explorer/api/model/response/token/TokenMetadataResponse::setDecimals → NO_COVERAGE |
tokenMetadataResponse.setDecimals(mintProjection.getDecimals()); |
61 |
1
1. getMetadata : removed call to org/cardanofoundation/explorer/api/model/response/token/TokenMetadataResponse::setDescription → NO_COVERAGE |
tokenMetadataResponse.setDescription(mintProjection.getDescription()); |
62 |
1
1. getMetadata : replaced return value with null for org/cardanofoundation/explorer/api/mapper/MaTxMintMapper::getMetadata → NO_COVERAGE |
return tokenMetadataResponse; |
63 | } | |
64 | } | |
Mutations | ||
52 |
1.1 2.2 |
|
57 |
1.1 |
|
58 |
1.1 |
|
59 |
1.1 |
|
60 |
1.1 |
|
61 |
1.1 |
|
62 |
1.1 |