From de94c8671c4fac38e8887ad8d611bb9331e98641 Mon Sep 17 00:00:00 2001 From: Wvader <34067397+wvader@users.noreply.github.com> Date: Sun, 31 Jul 2022 22:09:39 +0100 Subject: [PATCH] working state --- .../Binance.cs | 0 .../BlueWest.DataAgent.csproj | 0 .../Core/Http/AgentHttp.cs | 0 BlueWest.Data/Finance/FinanceTransaction.cs | 39 ++++++------------- .../Finance/FinanceTransactionInsertDto.cs | 29 +++++++------- .../Finance/FinanceTransactionReadDto.cs | 11 +++--- BlueWest.Data/User/User.cs | 18 ++------- BlueWest.Data/User/UserUpdateDto.cs | 12 +----- BlueWest.Data/UserList.cs | 6 ++- BlueWest.WebApi/Controllers/UserController.cs | 7 ++-- BlueWest/Artefacts/BlueConsole.cs | 2 +- BlueWest/Artefacts/WorldArtefact.cs | 4 +- BlueWest/Data/MemoryData.cs | 13 ++++--- 13 files changed, 55 insertions(+), 86 deletions(-) rename {BlueWest.DataAgent => BlueWest.BinanceDataAgent}/Binance.cs (100%) rename {BlueWest.DataAgent => BlueWest.BinanceDataAgent}/BlueWest.DataAgent.csproj (100%) rename {BlueWest.DataAgent => BlueWest.BinanceDataAgent}/Core/Http/AgentHttp.cs (100%) diff --git a/BlueWest.DataAgent/Binance.cs b/BlueWest.BinanceDataAgent/Binance.cs similarity index 100% rename from BlueWest.DataAgent/Binance.cs rename to BlueWest.BinanceDataAgent/Binance.cs diff --git a/BlueWest.DataAgent/BlueWest.DataAgent.csproj b/BlueWest.BinanceDataAgent/BlueWest.DataAgent.csproj similarity index 100% rename from BlueWest.DataAgent/BlueWest.DataAgent.csproj rename to BlueWest.BinanceDataAgent/BlueWest.DataAgent.csproj diff --git a/BlueWest.DataAgent/Core/Http/AgentHttp.cs b/BlueWest.BinanceDataAgent/Core/Http/AgentHttp.cs similarity index 100% rename from BlueWest.DataAgent/Core/Http/AgentHttp.cs rename to BlueWest.BinanceDataAgent/Core/Http/AgentHttp.cs diff --git a/BlueWest.Data/Finance/FinanceTransaction.cs b/BlueWest.Data/Finance/FinanceTransaction.cs index b06f586..c8222ae 100644 --- a/BlueWest.Data/Finance/FinanceTransaction.cs +++ b/BlueWest.Data/Finance/FinanceTransaction.cs @@ -4,48 +4,33 @@ using MessagePack; namespace BlueWest.Data { - public enum FinanceSymbol - { - BTC_EUR, - BTC_BUSD, - BTC_USD, - BTC_USDT, - LTC_EUR, - LTC_BUSD, - LTC_USDT - } - - public enum FinanceTransactionType - { - Buy, - Sell - } [MessagePackObject] [MapFrom(typeof(FinanceTransactionInsertDto))] public partial struct FinanceTransaction { - [Key(1)] public int Id { get; set; } - [Key(2)] public int UserId { get; set; } - [Key(3)] public FinanceTransactionType FinanceTransactionType { get; } - [Key(4)] public FinanceSymbol FinanceSymbol { get; } + [Key(1)] public TimeSpan CreationDate { get; set; } + [Key(2)] public TimeSpan UserId { get; set; } + + [Key(4)] public string Currency { get; } [Key(5)] public double Amount { get; } // To Buy [Key(6)] public double Quantity { get; } // Bought [Key(7)] public double Fee { get; } - [Key(8)] public DateTime DateTime { get; } + [Key(8)] public TimeSpan UploadedDate { get; } + [Key(9)] public TimeSpan TransactionDate { get; } - public FinanceTransaction(int id, int userId, FinanceTransactionType financeTransactionType, - FinanceSymbol financeSymbol, double amount, double quantity, double fee, DateTime dateTime) + public FinanceTransaction(TimeSpan creationDate, TimeSpan userId, + string currency, double amount, double quantity, double fee, TimeSpan uploadedDate, TimeSpan transactionDate) { - Id = id; + CreationDate = creationDate; UserId = userId; - FinanceTransactionType = financeTransactionType; - FinanceSymbol = financeSymbol; Amount = amount; Quantity = quantity; Fee = fee; - DateTime = dateTime; + Currency = currency; + UploadedDate = uploadedDate; + TransactionDate = transactionDate; } } } \ No newline at end of file diff --git a/BlueWest.Data/Finance/FinanceTransactionInsertDto.cs b/BlueWest.Data/Finance/FinanceTransactionInsertDto.cs index a890c0b..d8a83cf 100644 --- a/BlueWest.Data/Finance/FinanceTransactionInsertDto.cs +++ b/BlueWest.Data/Finance/FinanceTransactionInsertDto.cs @@ -9,30 +9,29 @@ namespace BlueWest.Data public partial struct FinanceTransactionInsertDto { - public int UserId { get; } - public FinanceTransactionType FinanceTransactionType { get; } - public FinanceSymbol FinanceSymbol { get; } - public double Amount { get; } // To Buy - public double Quantity { get; } // Bought - public double Fee { get; } - public DateTime DateTime { get; } + public string Currency { get; } + public double Amount { get; } // To Buy + public double Quantity { get; } // Bought + public double Fee { get; } + public TimeSpan UploadedDate { get; } + public TimeSpan TransactionDate { get; } + + public FinanceTransactionInsertDto( - int userId, - FinanceTransactionType financeTransactionType, - FinanceSymbol financeSymbol, + string currency, double amount , double quantity, double fee, - DateTime dateTime) + TimeSpan uploadedDate, + TimeSpan transactionDate) { - UserId = userId; - FinanceTransactionType = financeTransactionType; - FinanceSymbol = financeSymbol; + Currency = currency; Amount = amount; Quantity = quantity; Fee = fee; - DateTime = dateTime; + UploadedDate = uploadedDate; + TransactionDate = transactionDate; } } } diff --git a/BlueWest.Data/Finance/FinanceTransactionReadDto.cs b/BlueWest.Data/Finance/FinanceTransactionReadDto.cs index ca36fb4..b292f8b 100644 --- a/BlueWest.Data/Finance/FinanceTransactionReadDto.cs +++ b/BlueWest.Data/Finance/FinanceTransactionReadDto.cs @@ -9,13 +9,14 @@ namespace BlueWest.Data public partial struct FinanceTransactionReadDto { - public int Id { get; set; } - public int UserId { get; set; } - public FinanceTransactionType FinanceTransactionType { get; } - public FinanceSymbol FinanceSymbol { get; } + public TimeSpan CreationDate { get; set; } + public TimeSpan UserId { get; set; } + + public string Currency { get; } public double Amount { get; } // To Buy public double Quantity { get; } // Bought public double Fee { get; } - public DateTime DateTime { get; } + public TimeSpan UploadedDate { get; } + public TimeSpan TransactionDate { get; } } } diff --git a/BlueWest.Data/User/User.cs b/BlueWest.Data/User/User.cs index 3e9e56d..57b3d7f 100644 --- a/BlueWest.Data/User/User.cs +++ b/BlueWest.Data/User/User.cs @@ -15,27 +15,16 @@ namespace BlueWest.Data [MapFrom(typeof(UserUpdateDto))] public partial class User { - [Key(1)] public int Id { get; } + [Key(1)] public TimeSpan Id { get; } [Key(2)] public string Name { get; set; } - [Key(3)] public string Address { get; set; } - - [Key(4)] public string BTCAddress { get; set; } - [Key(5)] public string LTCAddress { get; set; } - [Key(6)] public double BTCAmount { get; set; } - [Key(7)] public double LTCAmount { get; set; } [Key(8)] public FastDictionary FinanceTransactions { get; } - public User(int id, string name, string address, string btcAddress, string ltcAddress, double btcAmount, double ltcAmount, FastDictionary financeTransactions) + public User(TimeSpan id, string name, string address, string btcAddress, string ltcAddress, double btcAmount, double ltcAmount, FastDictionary financeTransactions) { Id = id; Name = name; - Address = address; - BTCAddress = btcAddress; - LTCAddress = ltcAddress; - BTCAmount = btcAmount; - LTCAmount = ltcAmount; FinanceTransactions = financeTransactions; } @@ -45,7 +34,8 @@ namespace BlueWest.Data } public void AddTransaction(FinanceTransactionInsertDto financeTransaction) { - FinanceTransactions.Add(FinanceTransactions.Count + 1, new FinanceTransaction(financeTransaction, FinanceTransactions.Count + 1)); + FinanceTransactions.Add(FinanceTransactions.Count + 1, + new FinanceTransaction(financeTransaction, TimeSpan.FromTicks(DateTime.Now.Ticks), Id)); } internal bool HasTransaction(int transactionId) diff --git a/BlueWest.Data/User/UserUpdateDto.cs b/BlueWest.Data/User/UserUpdateDto.cs index 48844fd..8ee0f1f 100644 --- a/BlueWest.Data/User/UserUpdateDto.cs +++ b/BlueWest.Data/User/UserUpdateDto.cs @@ -6,16 +6,6 @@ namespace BlueWest.Data public partial struct UserUpdateDto { - public string Name { get; set; } - public string Address { get; set; } - - public string BTCAddress { get; set; } - public string LTCAddress { get; set; } - - public double BTCAmount { get; set; } - public double LTCAmount { get; set; } - - - + public string Name { get; set; } } } \ No newline at end of file diff --git a/BlueWest.Data/UserList.cs b/BlueWest.Data/UserList.cs index 48ff02b..475eda8 100644 --- a/BlueWest.Data/UserList.cs +++ b/BlueWest.Data/UserList.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Collections.Immutable; using System.Transactions; using BlueWest.Collections; @@ -100,7 +101,8 @@ namespace BlueWest.Data { if (Users.ContainsKey(userId)) { - var financeTransaction = new FinanceTransaction(financeTransactionDto, Users[userId].FinanceTransactions.Count + 1); + var now = TimeSpan.FromTicks(DateTime.Now.Ticks); + var financeTransaction = new FinanceTransaction(financeTransactionDto, now, Users[userId].Id); Users[userId].AddTransaction(financeTransaction); return new DataQueryResult(financeTransaction); } diff --git a/BlueWest.WebApi/Controllers/UserController.cs b/BlueWest.WebApi/Controllers/UserController.cs index 35e9741..aafc23b 100644 --- a/BlueWest.WebApi/Controllers/UserController.cs +++ b/BlueWest.WebApi/Controllers/UserController.cs @@ -1,4 +1,5 @@ -using System.Collections.Immutable; +using System; +using System.Collections.Immutable; using BlueWest.Collections; using BlueWest.Data; using Microsoft.AspNetCore.Http; @@ -57,7 +58,7 @@ namespace BlueWest.WebApi.Controllers [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] [HttpGet("{userId}/transactions/{transactionId}")] - public ActionResult GetTransactionsById(int userId, int transactionId) + public ActionResult GetTransactionsById(int userId, TimeSpan transactionId) { var user = MemoryData.UserList.GetUserById(userId); @@ -65,7 +66,7 @@ namespace BlueWest.WebApi.Controllers var transactions = user?.Value.FinanceTransactions; - FinanceTransaction? transaction = transactions?.Values.ToImmutableArray().FirstOrNull(t => t.Id == transactionId); + FinanceTransaction? transaction = transactions?.Values.ToImmutableArray().FirstOrNull(t => t.CreationDate == transactionId); if (transaction != null) { diff --git a/BlueWest/Artefacts/BlueConsole.cs b/BlueWest/Artefacts/BlueConsole.cs index 8476735..1c5a61e 100644 --- a/BlueWest/Artefacts/BlueConsole.cs +++ b/BlueWest/Artefacts/BlueConsole.cs @@ -51,7 +51,7 @@ namespace BlueWest.Core { //Console.WriteLine(Time.time); } - else if (input == "user") + else if (input == "user" || input == "users") { _eventManager.TriggerEvent(new CommandRequestEvent(CommandRequestEventType.GetUsers)); //Console.WriteLine(Time.time); diff --git a/BlueWest/Artefacts/WorldArtefact.cs b/BlueWest/Artefacts/WorldArtefact.cs index cb3ba63..62c1c9f 100644 --- a/BlueWest/Artefacts/WorldArtefact.cs +++ b/BlueWest/Artefacts/WorldArtefact.cs @@ -4,7 +4,7 @@ using BlueWest.Core.ComponentSystem; namespace BlueWest.Artefacts { - public class WorldArtefact: Artefact + /*public class WorldArtefact: Artefact { public WorldArtefact() @@ -33,5 +33,5 @@ namespace BlueWest.Artefacts { base.OnDisable(); } - } + }*/ } \ No newline at end of file diff --git a/BlueWest/Data/MemoryData.cs b/BlueWest/Data/MemoryData.cs index 2a05ad3..59a166c 100644 --- a/BlueWest/Data/MemoryData.cs +++ b/BlueWest/Data/MemoryData.cs @@ -1,7 +1,5 @@ using System; -using System.Collections.Generic; using System.Collections.Immutable; -using System.Transactions; using BlueWest.Collections; using BlueWest.Data; using PerformanceSolution.Tools; @@ -13,6 +11,8 @@ namespace PerformanceSolution.Data public static UserList UserList = new UserList(new FastDictionary()); private const string SavePathName = "userData"; + + public static TimeSpan DateKey = new TimeSpan(2386, 0,0,0,0 ); private static bool DEBUG = true; @@ -55,12 +55,13 @@ namespace PerformanceSolution.Data var transactions = new FastDictionary(); - var financeTransaction = new FinanceTransaction(0, 1, FinanceTransactionType.Buy, FinanceSymbol.BTC_EUR, 0, - 0, 0.1, DateTime.Now); + + var u = new User(DateTime.Now.TimeOfDay, "Rui Sousa", "Sagres", "NOADD", "NOADD", 0, 0, transactions); + var list = new FastDictionary(10); + var financeTransaction = new FinanceTransaction(TimeSpan.FromTicks(DateTime.Now.Ticks), u.Id, "", 0.00, 0.00, 0.00, + TimeSpan.FromTicks(DateTime.Now.Ticks), TimeSpan.FromTicks(DateTime.Now.Ticks)); transactions.Add(1, financeTransaction); - var u = new User(1, "Rui Sousa", "Sagres", "NOADD", "NOADD", 0, 0, transactions); - var list = new FastDictionary(10); list.Add(0, u); return new UserList(list);