From b9dd32ee4d7c64cd49709934796adc9226a3f928 Mon Sep 17 00:00:00 2001 From: Maciej Maciejewski Date: Fri, 27 Dec 2024 11:06:14 +0100 Subject: [PATCH] zmiany --- Authentication/AuthenticationSettings.cs | 4 +- Controllers/PdfController.cs | 55 +++++++++++-------- Controllers/WorkDayController.cs | 2 +- Models/CreateUserDto.cs | 8 +-- Models/DayDetailsDto.cs | 6 +-- Models/UpdatePasswordDto.cs | 8 +++ Program.cs | 1 + Services/UserService.cs | 7 +++ TestClass.cs | 67 ++++++++++++++++++++++++ nHIbernate/PdfData.cs | 19 +++++++ 10 files changed, 146 insertions(+), 31 deletions(-) create mode 100644 Models/UpdatePasswordDto.cs diff --git a/Authentication/AuthenticationSettings.cs b/Authentication/AuthenticationSettings.cs index cd15356..36bd3a2 100644 --- a/Authentication/AuthenticationSettings.cs +++ b/Authentication/AuthenticationSettings.cs @@ -2,8 +2,8 @@ { public class AuthenticationSettings { - public string JwtSecKey { get; set; } + public string JwtSecKey { get; set; } public int JwtExpireDays { get; set; } - public string JwtIssuer { get; set; } + public string JwtIssuer { get; set; } } } diff --git a/Controllers/PdfController.cs b/Controllers/PdfController.cs index bfb24fa..f054a4a 100644 --- a/Controllers/PdfController.cs +++ b/Controllers/PdfController.cs @@ -20,11 +20,13 @@ namespace FirmTracker_Server.Controllers { private readonly IExpenseRepository _expenseRepository; private readonly ITransactionRepository _transactionRepository; + private readonly IProductRepository _productRepository; - public PdfController(IExpenseRepository expenseRepository, ITransactionRepository transactionRepository) + public PdfController(IExpenseRepository expenseRepository, ITransactionRepository transactionRepository, IProductRepository productRepository) { _expenseRepository = expenseRepository; _transactionRepository = transactionRepository; + _productRepository = productRepository; } [HttpGet("download")] @@ -112,8 +114,9 @@ namespace FirmTracker_Server.Controllers // Main header page.Header() .Text("Raport transakcji") - .FontSize(20) + .FontSize(22) .SemiBold() + .FontColor(Colors.Blue.Medium) .AlignCenter(); // Summary section @@ -122,16 +125,18 @@ namespace FirmTracker_Server.Controllers column.Spacing(10); column.Item().Text($"Transakcje od ({startDate:yyyy-MM-dd} do {endDate:yyyy-MM-dd})") - .FontSize(16).Underline(); + .FontSize(16) + .Underline() + .FontColor(Colors.Grey.Medium); // Add table header column.Item().Row(row => { - row.RelativeItem().Text("Data").SemiBold(); - row.RelativeItem().Text("Typ płatności").SemiBold(); - row.RelativeItem().Text("Kwota razem").SemiBold(); - row.RelativeItem().Text("Rabat").SemiBold(); - row.RelativeItem().Text("Opis").SemiBold(); + row.RelativeItem().Text("Data").SemiBold().FontColor(Colors.Blue.Darken1); + row.RelativeItem().Text("Typ płatności").SemiBold().FontColor(Colors.Blue.Darken1); + row.RelativeItem().Text("Kwota razem").SemiBold().FontColor(Colors.Blue.Darken1); + row.RelativeItem().Text("Rabat").SemiBold().FontColor(Colors.Blue.Darken1); + row.RelativeItem().Text("Opis").SemiBold().FontColor(Colors.Blue.Darken1); }); // Populate table rows with transaction data @@ -153,13 +158,15 @@ namespace FirmTracker_Server.Controllers if (products.Any()) { - column.Item().Text("Produkty:").SemiBold(); + column.Item().Text("Produkty:").SemiBold().FontColor(Colors.Blue.Medium); foreach (var product in products) { + var productQuery = _productRepository.GetProduct(product.Id); column.Item().Row(productRow => { - productRow.RelativeItem().Text($"Nazwa produktu: {product.ProductName}"); + productRow.RelativeItem().Text($"Nazwa produktu: {productQuery.Name}"); productRow.RelativeItem().Text($"Ilość: {product.Quantity}"); + productRow.RelativeItem().Text($"Cena 1 szt. bez rabatu: {productQuery.Price.ToString("F2")}"); }); } } @@ -171,8 +178,8 @@ namespace FirmTracker_Server.Controllers .AlignCenter() .Text(text => { - text.Span("Wygenerowano przez automat FT: "); - text.Span(DateTime.Now.ToString("yyyy-MM-dd")).SemiBold(); + text.Span("Wygenerowano przez automat FT: ").FontColor(Colors.Grey.Medium); + text.Span(DateTime.Now.ToString("yyyy-MM-dd")).SemiBold().FontColor(Colors.Grey.Medium); }); }); }).GeneratePdf(ms); @@ -200,8 +207,9 @@ namespace FirmTracker_Server.Controllers // Main header page.Header() .Text("Raport wydatków") - .FontSize(20) + .FontSize(22) .SemiBold() + .FontColor(Colors.Green.Medium) .AlignCenter(); // Summary section @@ -211,18 +219,20 @@ namespace FirmTracker_Server.Controllers column.Item().Row(row => { - row.RelativeItem().Text($"Łączne wydatki: {totalExpenses:C}").FontSize(14).Bold(); - row.RelativeItem().Text($"Średnie wydatki dzienne: {averageExpense:C}").FontSize(14).Bold(); + row.RelativeItem().Text($"Łączne wydatki: {totalExpenses:C}").FontSize(14).Bold().FontColor(Colors.Green.Darken1); + row.RelativeItem().Text($"Średnie wydatki dzienne: {averageExpense:C}").FontSize(14).Bold().FontColor(Colors.Green.Darken1); }); column.Item().Text($"Szczegóły wydatków od ({startDate:yyyy-MM-dd} do {endDate:yyyy-MM-dd})") - .FontSize(16).Underline(); + .FontSize(16) + .Underline() + .FontColor(Colors.Grey.Medium); column.Item().Row(row => { - row.RelativeItem().Text("Data").SemiBold(); - row.RelativeItem().Text("Kwota").SemiBold(); - row.RelativeItem().Text("Opis").SemiBold(); + row.RelativeItem().Text("Data").SemiBold().FontColor(Colors.Green.Darken1); + row.RelativeItem().Text("Kwota").SemiBold().FontColor(Colors.Green.Darken1); + row.RelativeItem().Text("Opis").SemiBold().FontColor(Colors.Green.Darken1); }); foreach (var expense in expenses) @@ -236,12 +246,13 @@ namespace FirmTracker_Server.Controllers } }); + // Footer with generation date page.Footer() .AlignCenter() .Text(text => { - text.Span("Wygenerowano przez automat FT: "); - text.Span(DateTime.Now.ToString("yyyy-MM-dd")).SemiBold(); + text.Span("Wygenerowano przez automat FT: ").FontColor(Colors.Grey.Medium); + text.Span(DateTime.Now.ToString("yyyy-MM-dd")).SemiBold().FontColor(Colors.Grey.Medium); }); }); }).GeneratePdf(ms); @@ -249,5 +260,7 @@ namespace FirmTracker_Server.Controllers return ms.ToArray(); } } + + } } diff --git a/Controllers/WorkDayController.cs b/Controllers/WorkDayController.cs index f233454..9ed9a42 100644 --- a/Controllers/WorkDayController.cs +++ b/Controllers/WorkDayController.cs @@ -147,7 +147,7 @@ namespace FirmTracker_Server.Controllers { try { - var userId = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier)?.Value ; + var userId = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier)?.Value; var dayDetails = _workdayCRUD.GetDayDetailsForLoggedUser(int.Parse(userId), date); return Ok(dayDetails); diff --git a/Models/CreateUserDto.cs b/Models/CreateUserDto.cs index b282e21..41895b9 100644 --- a/Models/CreateUserDto.cs +++ b/Models/CreateUserDto.cs @@ -2,10 +2,10 @@ { public class CreateUserDto { - public string Login { get; set; } - public string Password { get; set; } - public string Email { get; set; } - public string Role { get; set; } + public required string Login { get; set; } + public required string Password { get; set; } + public required string Email { get; set; } + public required string Role { get; set; } public bool NewEncryption { get; set; } = true; } } diff --git a/Models/DayDetailsDto.cs b/Models/DayDetailsDto.cs index 09f1a01..bad9080 100644 --- a/Models/DayDetailsDto.cs +++ b/Models/DayDetailsDto.cs @@ -4,9 +4,9 @@ namespace FirmTracker_Server.Models { public class DayDetailsDto { - public string Email { get; set; } + public required string Email { get; set; } public DateTime Date { get; set; } - public string TotalWorkedHours { get; set; } - public List WorkdayDetails { get; set; } + public required string TotalWorkedHours { get; set; } + public required List WorkdayDetails { get; set; } } } diff --git a/Models/UpdatePasswordDto.cs b/Models/UpdatePasswordDto.cs new file mode 100644 index 0000000..251b9dd --- /dev/null +++ b/Models/UpdatePasswordDto.cs @@ -0,0 +1,8 @@ +namespace FirmTracker_Server.Models +{ + public class UpdatePasswordDto + { + public string Email { get; set; } + public string Password { get; set; } + } +} diff --git a/Program.cs b/Program.cs index 355a24c..3d36ac7 100644 --- a/Program.cs +++ b/Program.cs @@ -179,6 +179,7 @@ namespace FirmTracker_Server services.AddScoped, PasswordHasher>(); services.AddScoped(); services.AddScoped(); + services.AddScoped(); // services.AddScoped(); services.AddMvc(); } diff --git a/Services/UserService.cs b/Services/UserService.cs index 0957662..8e9d3b9 100644 --- a/Services/UserService.cs +++ b/Services/UserService.cs @@ -15,6 +15,8 @@ using szyfrowanie; using FirmTracker_Server.nHibernate; using NHibernate; using NHibernate.Criterion; +using Microsoft.CodeAnalysis.CSharp.Syntax; +using NHibernate.Type; namespace FirmTracker_Server.Services { @@ -24,6 +26,7 @@ namespace FirmTracker_Server.Services int AddUser(CreateUserDto dto); string CreateTokenJwt(LoginDto dto); IEnumerable GetAllUserEmails(); + bool UpdatePassword(UpdatePasswordDto dto); } public class UserService : IUserService @@ -44,6 +47,10 @@ namespace FirmTracker_Server.Services SimplerAES = new SimplerAES(); //SessionFactory = sessionFactory; } + public bool UpdatePassword(UpdatePasswordDto dto) + { + return true; + } public IEnumerable GetAllUserEmails() { using (var session = SessionFactory.OpenSession()) diff --git a/TestClass.cs b/TestClass.cs index 9797a9d..761d907 100644 --- a/TestClass.cs +++ b/TestClass.cs @@ -237,6 +237,73 @@ namespace FirmTracker_Server expenseCrud.AddExpense(expense1); expenseCrud.AddExpense(expense2); expenseCrud.AddExpense(expense3); + expenseCrud.AddExpense(expense3); + expenseCrud.AddExpense(expense3); + expenseCrud.AddExpense(expense3); + expenseCrud.AddExpense(expense3); + expenseCrud.AddExpense(expense3); + expenseCrud.AddExpense(expense3); + expenseCrud.AddExpense(expense3); + expenseCrud.AddExpense(expense3); + expenseCrud.AddExpense(expense3); + expenseCrud.AddExpense(expense3); + expenseCrud.AddExpense(expense3); + expenseCrud.AddExpense(expense3); + expenseCrud.AddExpense(expense3); + expenseCrud.AddExpense(expense3); + expenseCrud.AddExpense(expense3); + expenseCrud.AddExpense(expense3); + expenseCrud.AddExpense(expense3); + expenseCrud.AddExpense(expense3); + expenseCrud.AddExpense(expense3); + expenseCrud.AddExpense(expense3); + expenseCrud.AddExpense(expense3); + expenseCrud.AddExpense(expense3); + expenseCrud.AddExpense(expense3); + expenseCrud.AddExpense(expense3); + expenseCrud.AddExpense(expense3); + expenseCrud.AddExpense(expense3); + expenseCrud.AddExpense(expense3); + expenseCrud.AddExpense(expense3); + expenseCrud.AddExpense(expense3); + expenseCrud.AddExpense(expense3); + expenseCrud.AddExpense(expense3); + expenseCrud.AddExpense(expense3); + expenseCrud.AddExpense(expense3); + expenseCrud.AddExpense(expense3); + expenseCrud.AddExpense(expense3); + expenseCrud.AddExpense(expense3); + expenseCrud.AddExpense(expense3); + expenseCrud.AddExpense(expense3); + expenseCrud.AddExpense(expense3); + expenseCrud.AddExpense(expense3); + expenseCrud.AddExpense(expense3); + expenseCrud.AddExpense(expense3); + expenseCrud.AddExpense(expense3); + expenseCrud.AddExpense(expense3); + expenseCrud.AddExpense(expense3); + expenseCrud.AddExpense(expense3); + expenseCrud.AddExpense(expense3); + expenseCrud.AddExpense(expense3); + expenseCrud.AddExpense(expense3); + expenseCrud.AddExpense(expense3); + expenseCrud.AddExpense(expense3); + expenseCrud.AddExpense(expense3); + expenseCrud.AddExpense(expense3); + expenseCrud.AddExpense(expense3); + expenseCrud.AddExpense(expense3); + expenseCrud.AddExpense(expense3); + expenseCrud.AddExpense(expense3); + expenseCrud.AddExpense(expense3); + expenseCrud.AddExpense(expense3); + expenseCrud.AddExpense(expense3); + expenseCrud.AddExpense(expense3); + expenseCrud.AddExpense(expense3); + expenseCrud.AddExpense(expense3); + expenseCrud.AddExpense(expense3); + expenseCrud.AddExpense(expense3); + expenseCrud.AddExpense(expense3); + List testTransactionProducts = new List { new TransactionProduct { ProductID =17, Quantity = 3 }, diff --git a/nHIbernate/PdfData.cs b/nHIbernate/PdfData.cs index 5792f4b..ee02a54 100644 --- a/nHIbernate/PdfData.cs +++ b/nHIbernate/PdfData.cs @@ -1,11 +1,19 @@ using System.Collections.Generic; using System.Linq; +using System.Transactions; using FirmTracker_Server.nHibernate.Expenses; +using FirmTracker_Server.nHibernate.Products; using FirmTracker_Server.nHibernate.Transactions; using NHibernate; +using Transaction = FirmTracker_Server.nHibernate.Transactions.Transaction; namespace FirmTracker_Server.nHibernate { + public interface IProductRepository + { + Product GetProduct(int id); + } + public interface IExpenseRepository { List GetAllExpenses(); @@ -25,6 +33,17 @@ namespace FirmTracker_Server.nHibernate void DeleteTransaction(int transactionId); List GetTransactionProductsForTransactions(List transactionIds); } + public class ProductRepository : IProductRepository + { + public Product GetProduct(int id) + { + using (var session = SessionFactory.OpenSession()) + { + return session.Get(id); + } + } + } + public class TransactionRepository : ITransactionRepository { // Retrieve all transactions