refactor(assets): update asset entity mappings, database migrations, and MQTT RPC handlers

This commit is contained in:
2026-08-24 21:37:21 +02:00
parent 7060f0f7b1
commit 6974b2075b
26 changed files with 645 additions and 2237 deletions
+55 -57
View File
@@ -1,3 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using FinlyticAssets.Entities;
using FinlyticCore.Dtos.Assets;
@@ -14,6 +17,8 @@ public static class AssetMapper
Type = t.Type
}).ToList();
var dynamicLogoUrl = $"/api/v1/logo/{entity.Isin}";
return entity switch
{
StockEntity stock => new StockDto
@@ -23,7 +28,7 @@ public static class AssetMapper
Type = stock.Type,
InstrumentCategory = stock.InstrumentCategory,
HasCfd = stock.HasCfd,
ImageId = stock.ImageId,
ImageId = dynamicLogoUrl,
LastUpdatedAt = stock.LastUpdatedAt,
Tags = dtoTags,
DerivativeProductCategories = stock.DerivativeProductCategories
@@ -35,7 +40,7 @@ public static class AssetMapper
Type = etf.Type,
InstrumentCategory = etf.InstrumentCategory,
HasCfd = etf.HasCfd,
ImageId = etf.ImageId,
ImageId = dynamicLogoUrl,
LastUpdatedAt = etf.LastUpdatedAt,
Tags = dtoTags,
DerivativeProductCategories = etf.DerivativeProductCategories,
@@ -44,59 +49,6 @@ public static class AssetMapper
Subtitle = etf.Subtitle,
SearchSubtitle = etf.SearchSubtitle
},
CryptoEntity crypto => new CryptoDto
{
Isin = crypto.Isin,
Name = crypto.Name,
Type = crypto.Type,
InstrumentCategory = crypto.InstrumentCategory,
HasCfd = crypto.HasCfd,
ImageId = crypto.ImageId,
LastUpdatedAt = crypto.LastUpdatedAt,
Tags = dtoTags,
Subtitle = crypto.Subtitle,
SearchSubtitle = crypto.SearchSubtitle
},
BondEntity bond => new BondDto
{
Isin = bond.Isin,
Name = bond.Name,
Type = bond.Type,
InstrumentCategory = bond.InstrumentCategory,
HasCfd = bond.HasCfd,
ImageId = bond.ImageId,
LastUpdatedAt = bond.LastUpdatedAt,
Tags = dtoTags,
BondIssuerName = bond.BondIssuerName,
SearchSubtitle = bond.SearchSubtitle
},
DerivativeEntity deriv => new DerivativeDto
{
Isin = deriv.Isin,
Name = deriv.Name,
Type = deriv.Type,
InstrumentCategory = deriv.InstrumentCategory,
HasCfd = deriv.HasCfd,
ImageId = deriv.ImageId,
LastUpdatedAt = deriv.LastUpdatedAt,
Tags = dtoTags,
DerivativeProductCategories = deriv.DerivativeProductCategories,
UnderlyingIsin = deriv.UnderlyingIsin,
OptionType = deriv.OptionType.ToString(),
ProductCategoryName = deriv.ProductCategoryName,
NextGenProductCategoryName = deriv.NextGenProductCategoryName,
Strike = deriv.Strike,
Barrier = deriv.Barrier,
Leverage = deriv.Leverage,
Size = deriv.Size,
Factor = deriv.Factor,
Delta = deriv.Delta,
Currency = deriv.Currency,
Expiry = deriv.Expiry,
Issuer = deriv.Issuer,
IssuerDisplayName = deriv.IssuerDisplayName,
IssuerImageId = deriv.IssuerImageId
},
SyntheticEntity synth => new SyntheticDto
{
Isin = synth.Isin,
@@ -104,12 +56,53 @@ public static class AssetMapper
Type = synth.Type,
InstrumentCategory = synth.InstrumentCategory,
HasCfd = synth.HasCfd,
ImageId = synth.ImageId,
ImageId = dynamicLogoUrl,
LastUpdatedAt = synth.LastUpdatedAt,
Tags = dtoTags,
DerivativeProductCategories = synth.DerivativeProductCategories
},
_ => throw new NotSupportedException($"Mapping for type {entity.GetType().Name} is not supported.")
_ => new StockDto
{
Isin = entity.Isin,
Name = entity.Name,
Type = entity.Type,
InstrumentCategory = entity.InstrumentCategory,
HasCfd = entity.HasCfd,
ImageId = dynamicLogoUrl,
LastUpdatedAt = entity.LastUpdatedAt,
Tags = dtoTags
}
};
}
public static DerivativeDto ToDto(this DerivativeEntity deriv)
{
return new DerivativeDto
{
Isin = deriv.Isin,
Name = deriv.Name,
Type = "derivative",
InstrumentCategory = "derivative",
HasCfd = false,
ImageId = $"/api/v1/logo/{deriv.UnderlyingIsin}",
LastUpdatedAt = deriv.LastUpdatedAt,
Tags = new List<TagDto>(),
DerivativeProductCategories = deriv.DerivativeProductCategories,
UnderlyingIsin = deriv.UnderlyingIsin,
OptionType = deriv.OptionType.ToString(),
ProductCategoryName = deriv.ProductCategoryName,
NextGenProductCategoryName = deriv.NextGenProductCategoryName,
Strike = deriv.Strike,
Barrier = deriv.Barrier,
Leverage = deriv.Leverage,
Size = deriv.Size,
Factor = deriv.Factor,
Delta = deriv.Delta,
Currency = deriv.Currency,
Expiry = deriv.Expiry,
Issuer = deriv.Issuer,
IssuerDisplayName = deriv.IssuerDisplayName,
IssuerImageId = null
};
}
@@ -117,4 +110,9 @@ public static class AssetMapper
{
return entities.Select(e => e.ToDto()).ToList();
}
public static List<DerivativeDto> ToDtoList(this IEnumerable<DerivativeEntity> derivatives)
{
return derivatives.Select(d => d.ToDto()).ToList();
}
}