working state

This commit is contained in:
Wvader 2022-07-31 22:09:39 +01:00
parent f999e96b6f
commit de94c8671c
13 changed files with 55 additions and 86 deletions

View File

@ -4,48 +4,33 @@ using MessagePack;
namespace BlueWest.Data 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] [MessagePackObject]
[MapFrom(typeof(FinanceTransactionInsertDto))] [MapFrom(typeof(FinanceTransactionInsertDto))]
public partial struct FinanceTransaction public partial struct FinanceTransaction
{ {
[Key(1)] public int Id { get; set; } [Key(1)] public TimeSpan CreationDate { get; set; }
[Key(2)] public int UserId { get; set; } [Key(2)] public TimeSpan UserId { get; set; }
[Key(3)] public FinanceTransactionType FinanceTransactionType { get; }
[Key(4)] public FinanceSymbol FinanceSymbol { get; } [Key(4)] public string Currency { get; }
[Key(5)] public double Amount { get; } // To Buy [Key(5)] public double Amount { get; } // To Buy
[Key(6)] public double Quantity { get; } // Bought [Key(6)] public double Quantity { get; } // Bought
[Key(7)] public double Fee { get; } [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, public FinanceTransaction(TimeSpan creationDate, TimeSpan userId,
FinanceSymbol financeSymbol, double amount, double quantity, double fee, DateTime dateTime) string currency, double amount, double quantity, double fee, TimeSpan uploadedDate, TimeSpan transactionDate)
{ {
Id = id; CreationDate = creationDate;
UserId = userId; UserId = userId;
FinanceTransactionType = financeTransactionType;
FinanceSymbol = financeSymbol;
Amount = amount; Amount = amount;
Quantity = quantity; Quantity = quantity;
Fee = fee; Fee = fee;
DateTime = dateTime; Currency = currency;
UploadedDate = uploadedDate;
TransactionDate = transactionDate;
} }
} }
} }

View File

@ -9,30 +9,29 @@ namespace BlueWest.Data
public partial struct FinanceTransactionInsertDto public partial struct FinanceTransactionInsertDto
{ {
public int UserId { get; } public string Currency { get; }
public FinanceTransactionType FinanceTransactionType { get; } public double Amount { get; } // To Buy
public FinanceSymbol FinanceSymbol { get; } public double Quantity { get; } // Bought
public double Amount { get; } // To Buy public double Fee { get; }
public double Quantity { get; } // Bought public TimeSpan UploadedDate { get; }
public double Fee { get; } public TimeSpan TransactionDate { get; }
public DateTime DateTime { get; }
public FinanceTransactionInsertDto( public FinanceTransactionInsertDto(
int userId, string currency,
FinanceTransactionType financeTransactionType,
FinanceSymbol financeSymbol,
double amount , double amount ,
double quantity, double quantity,
double fee, double fee,
DateTime dateTime) TimeSpan uploadedDate,
TimeSpan transactionDate)
{ {
UserId = userId; Currency = currency;
FinanceTransactionType = financeTransactionType;
FinanceSymbol = financeSymbol;
Amount = amount; Amount = amount;
Quantity = quantity; Quantity = quantity;
Fee = fee; Fee = fee;
DateTime = dateTime; UploadedDate = uploadedDate;
TransactionDate = transactionDate;
} }
} }
} }

View File

@ -9,13 +9,14 @@ namespace BlueWest.Data
public partial struct FinanceTransactionReadDto public partial struct FinanceTransactionReadDto
{ {
public int Id { get; set; } public TimeSpan CreationDate { get; set; }
public int UserId { get; set; } public TimeSpan UserId { get; set; }
public FinanceTransactionType FinanceTransactionType { get; }
public FinanceSymbol FinanceSymbol { get; } public string Currency { get; }
public double Amount { get; } // To Buy public double Amount { get; } // To Buy
public double Quantity { get; } // Bought public double Quantity { get; } // Bought
public double Fee { get; } public double Fee { get; }
public DateTime DateTime { get; } public TimeSpan UploadedDate { get; }
public TimeSpan TransactionDate { get; }
} }
} }

View File

@ -15,27 +15,16 @@ namespace BlueWest.Data
[MapFrom(typeof(UserUpdateDto))] [MapFrom(typeof(UserUpdateDto))]
public partial class User public partial class User
{ {
[Key(1)] public int Id { get; } [Key(1)] public TimeSpan Id { get; }
[Key(2)] public string Name { get; set; } [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<int, FinanceTransaction> FinanceTransactions { get; } [Key(8)] public FastDictionary<int, FinanceTransaction> FinanceTransactions { get; }
public User(int id, string name, string address, string btcAddress, string ltcAddress, double btcAmount, double ltcAmount, FastDictionary<int, FinanceTransaction> financeTransactions) public User(TimeSpan id, string name, string address, string btcAddress, string ltcAddress, double btcAmount, double ltcAmount, FastDictionary<int, FinanceTransaction> financeTransactions)
{ {
Id = id; Id = id;
Name = name; Name = name;
Address = address;
BTCAddress = btcAddress;
LTCAddress = ltcAddress;
BTCAmount = btcAmount;
LTCAmount = ltcAmount;
FinanceTransactions = financeTransactions; FinanceTransactions = financeTransactions;
} }
@ -45,7 +34,8 @@ namespace BlueWest.Data
} }
public void AddTransaction(FinanceTransactionInsertDto financeTransaction) 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) internal bool HasTransaction(int transactionId)

View File

@ -6,16 +6,6 @@ namespace BlueWest.Data
public partial struct UserUpdateDto public partial struct UserUpdateDto
{ {
public string Name { get; set; } 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; }
} }
} }

View File

@ -1,4 +1,5 @@
using System.Collections.Generic; using System;
using System.Collections.Generic;
using System.Collections.Immutable; using System.Collections.Immutable;
using System.Transactions; using System.Transactions;
using BlueWest.Collections; using BlueWest.Collections;
@ -100,7 +101,8 @@ namespace BlueWest.Data
{ {
if (Users.ContainsKey(userId)) 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); Users[userId].AddTransaction(financeTransaction);
return new DataQueryResult<FinanceTransaction>(financeTransaction); return new DataQueryResult<FinanceTransaction>(financeTransaction);
} }

View File

@ -1,4 +1,5 @@
using System.Collections.Immutable; using System;
using System.Collections.Immutable;
using BlueWest.Collections; using BlueWest.Collections;
using BlueWest.Data; using BlueWest.Data;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
@ -57,7 +58,7 @@ namespace BlueWest.WebApi.Controllers
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
[HttpGet("{userId}/transactions/{transactionId}")] [HttpGet("{userId}/transactions/{transactionId}")]
public ActionResult GetTransactionsById(int userId, int transactionId) public ActionResult GetTransactionsById(int userId, TimeSpan transactionId)
{ {
var user = MemoryData.UserList.GetUserById(userId); var user = MemoryData.UserList.GetUserById(userId);
@ -65,7 +66,7 @@ namespace BlueWest.WebApi.Controllers
var transactions = user?.Value.FinanceTransactions; 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) if (transaction != null)
{ {

View File

@ -51,7 +51,7 @@ namespace BlueWest.Core
{ {
//Console.WriteLine(Time.time); //Console.WriteLine(Time.time);
} }
else if (input == "user") else if (input == "user" || input == "users")
{ {
_eventManager.TriggerEvent(new CommandRequestEvent(CommandRequestEventType.GetUsers)); _eventManager.TriggerEvent(new CommandRequestEvent(CommandRequestEventType.GetUsers));
//Console.WriteLine(Time.time); //Console.WriteLine(Time.time);

View File

@ -4,7 +4,7 @@ using BlueWest.Core.ComponentSystem;
namespace BlueWest.Artefacts namespace BlueWest.Artefacts
{ {
public class WorldArtefact: Artefact /*public class WorldArtefact: Artefact
{ {
public WorldArtefact() public WorldArtefact()
@ -33,5 +33,5 @@ namespace BlueWest.Artefacts
{ {
base.OnDisable(); base.OnDisable();
} }
} }*/
} }

View File

@ -1,7 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.Collections.Immutable; using System.Collections.Immutable;
using System.Transactions;
using BlueWest.Collections; using BlueWest.Collections;
using BlueWest.Data; using BlueWest.Data;
using PerformanceSolution.Tools; using PerformanceSolution.Tools;
@ -13,6 +11,8 @@ namespace PerformanceSolution.Data
public static UserList UserList = new UserList(new FastDictionary<int, User>()); public static UserList UserList = new UserList(new FastDictionary<int, User>());
private const string SavePathName = "userData"; private const string SavePathName = "userData";
public static TimeSpan DateKey = new TimeSpan(2386, 0,0,0,0 );
private static bool DEBUG = true; private static bool DEBUG = true;
@ -55,12 +55,13 @@ namespace PerformanceSolution.Data
var transactions = new FastDictionary<int, FinanceTransaction>(); var transactions = new FastDictionary<int, FinanceTransaction>();
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<int, User>(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); transactions.Add(1, financeTransaction);
var u = new User(1, "Rui Sousa", "Sagres", "NOADD", "NOADD", 0, 0, transactions);
var list = new FastDictionary<int, User>(10);
list.Add(0, u); list.Add(0, u);
return new UserList(list); return new UserList(list);