Compare commits
23 Commits
Author | SHA1 | Date | |
---|---|---|---|
47b72e38a5 | |||
57c8925e9c | |||
ab61013bc8 | |||
a10f69c0df | |||
655fb781ba | |||
174468c672 | |||
f181886c2e | |||
da508f3015 | |||
b21c9fa149 | |||
58deef30d0 | |||
724b19f97a | |||
ee665070d8 | |||
490f915ec7 | |||
567c3539ad | |||
30378d95ab | |||
b9dd32ee4d | |||
ba4f8a717c | |||
43da6a5d93 | |||
5e4a57cb12 | |||
422668dc65 | |||
a6e58135d2 | |||
326a1f1210 | |||
6e6cfef8df |
@ -1,4 +1,21 @@
|
|||||||
using System;
|
/*
|
||||||
|
* This file is part of FirmTracker - Server.
|
||||||
|
*
|
||||||
|
* FirmTracker - Server is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* FirmTracker - Server is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with FirmTracker - Server. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@ -20,11 +37,13 @@ namespace FirmTracker_Server.Controllers
|
|||||||
{
|
{
|
||||||
private readonly IExpenseRepository _expenseRepository;
|
private readonly IExpenseRepository _expenseRepository;
|
||||||
private readonly ITransactionRepository _transactionRepository;
|
private readonly ITransactionRepository _transactionRepository;
|
||||||
|
private readonly IProductRepository _productRepository;
|
||||||
|
|
||||||
public PdfController(IExpenseRepository expenseRepository, ITransactionRepository transactionRepository)
|
public PdfController(IExpenseRepository expenseRepository, ITransactionRepository transactionRepository, IProductRepository productRepository)
|
||||||
{
|
{
|
||||||
_expenseRepository = expenseRepository;
|
_expenseRepository = expenseRepository;
|
||||||
_transactionRepository = transactionRepository;
|
_transactionRepository = transactionRepository;
|
||||||
|
_productRepository = productRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("download")]
|
[HttpGet("download")]
|
||||||
@ -36,11 +55,9 @@ namespace FirmTracker_Server.Controllers
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Validate date inputs and set default values
|
|
||||||
DateTime start = startDate ?? DateTime.MinValue;
|
DateTime start = startDate ?? DateTime.MinValue;
|
||||||
DateTime end = endDate ?? DateTime.MaxValue;
|
DateTime end = endDate ?? DateTime.MaxValue;
|
||||||
|
|
||||||
// Validate report type
|
|
||||||
if (string.IsNullOrEmpty(reportType) ||
|
if (string.IsNullOrEmpty(reportType) ||
|
||||||
(reportType.ToLower() != "expenses" && reportType.ToLower() != "transactions"))
|
(reportType.ToLower() != "expenses" && reportType.ToLower() != "transactions"))
|
||||||
{
|
{
|
||||||
@ -108,33 +125,30 @@ namespace FirmTracker_Server.Controllers
|
|||||||
page.Margin(2, Unit.Centimetre);
|
page.Margin(2, Unit.Centimetre);
|
||||||
page.PageColor(Colors.White);
|
page.PageColor(Colors.White);
|
||||||
page.DefaultTextStyle(x => x.FontSize(12));
|
page.DefaultTextStyle(x => x.FontSize(12));
|
||||||
|
|
||||||
// Main header
|
|
||||||
page.Header()
|
page.Header()
|
||||||
.Text("Raport transakcji")
|
.Text("Raport transakcji")
|
||||||
.FontSize(20)
|
.FontSize(22)
|
||||||
.SemiBold()
|
.SemiBold()
|
||||||
|
.FontColor(Colors.Blue.Medium)
|
||||||
.AlignCenter();
|
.AlignCenter();
|
||||||
|
|
||||||
// Summary section
|
|
||||||
page.Content().PaddingVertical(1, Unit.Centimetre).Column(column =>
|
page.Content().PaddingVertical(1, Unit.Centimetre).Column(column =>
|
||||||
{
|
{
|
||||||
column.Spacing(10);
|
column.Spacing(10);
|
||||||
|
|
||||||
column.Item().Text($"Transakcje od ({startDate:yyyy-MM-dd} do {endDate:yyyy-MM-dd})")
|
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 =>
|
column.Item().Row(row =>
|
||||||
{
|
{
|
||||||
row.RelativeItem().Text("Data").SemiBold();
|
row.RelativeItem().Text("Data").SemiBold().FontColor(Colors.Blue.Darken1);
|
||||||
row.RelativeItem().Text("Typ płatności").SemiBold();
|
row.RelativeItem().Text("Typ płatności").SemiBold().FontColor(Colors.Blue.Darken1);
|
||||||
row.RelativeItem().Text("Kwota razem").SemiBold();
|
row.RelativeItem().Text("Kwota razem").SemiBold().FontColor(Colors.Blue.Darken1);
|
||||||
row.RelativeItem().Text("Rabat").SemiBold();
|
row.RelativeItem().Text("Rabat").SemiBold().FontColor(Colors.Blue.Darken1);
|
||||||
row.RelativeItem().Text("Opis").SemiBold();
|
row.RelativeItem().Text("Opis").SemiBold().FontColor(Colors.Blue.Darken1);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Populate table rows with transaction data
|
|
||||||
foreach (var transaction in transactions)
|
foreach (var transaction in transactions)
|
||||||
{
|
{
|
||||||
column.Item().Row(row =>
|
column.Item().Row(row =>
|
||||||
@ -145,34 +159,32 @@ namespace FirmTracker_Server.Controllers
|
|||||||
row.RelativeItem().Text(transaction.Discount.ToString("C"));
|
row.RelativeItem().Text(transaction.Discount.ToString("C"));
|
||||||
row.RelativeItem().Text(transaction.Description);
|
row.RelativeItem().Text(transaction.Description);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Fetch and display transaction products for this transaction
|
|
||||||
var products = transactionProducts
|
var products = transactionProducts
|
||||||
.Where(tp => tp.TransactionId == transaction.Id)
|
.Where(tp => tp.TransactionId == transaction.Id)
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
if (products.Any())
|
if (products.Any())
|
||||||
{
|
{
|
||||||
column.Item().Text("Produkty:").SemiBold();
|
column.Item().Text("Produkty:").SemiBold().FontColor(Colors.Blue.Medium);
|
||||||
foreach (var product in products)
|
foreach (var product in products)
|
||||||
{
|
{
|
||||||
|
var productQuery = _productRepository.GetProduct(product.Id);
|
||||||
column.Item().Row(productRow =>
|
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($"Ilość: {product.Quantity}");
|
||||||
|
productRow.RelativeItem().Text($"Cena 1 szt. bez rabatu: {productQuery.Price.ToString("F2")}");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Footer with generation date
|
|
||||||
page.Footer()
|
page.Footer()
|
||||||
.AlignCenter()
|
.AlignCenter()
|
||||||
.Text(text =>
|
.Text(text =>
|
||||||
{
|
{
|
||||||
text.Span("Wygenerowano przez automat FT: ");
|
text.Span("Wygenerowano przez automat FT: ").FontColor(Colors.Grey.Medium);
|
||||||
text.Span(DateTime.Now.ToString("yyyy-MM-dd")).SemiBold();
|
text.Span(DateTime.Now.ToString("yyyy-MM-dd")).SemiBold().FontColor(Colors.Grey.Medium);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}).GeneratePdf(ms);
|
}).GeneratePdf(ms);
|
||||||
@ -196,33 +208,32 @@ namespace FirmTracker_Server.Controllers
|
|||||||
page.Margin(2, Unit.Centimetre);
|
page.Margin(2, Unit.Centimetre);
|
||||||
page.PageColor(Colors.White);
|
page.PageColor(Colors.White);
|
||||||
page.DefaultTextStyle(x => x.FontSize(12));
|
page.DefaultTextStyle(x => x.FontSize(12));
|
||||||
|
|
||||||
// Main header
|
|
||||||
page.Header()
|
page.Header()
|
||||||
.Text("Raport wydatków")
|
.Text("Raport wydatków")
|
||||||
.FontSize(20)
|
.FontSize(22)
|
||||||
.SemiBold()
|
.SemiBold()
|
||||||
|
.FontColor(Colors.Green.Medium)
|
||||||
.AlignCenter();
|
.AlignCenter();
|
||||||
|
|
||||||
// Summary section
|
|
||||||
page.Content().PaddingVertical(1, Unit.Centimetre).Column(column =>
|
page.Content().PaddingVertical(1, Unit.Centimetre).Column(column =>
|
||||||
{
|
{
|
||||||
column.Spacing(10);
|
column.Spacing(10);
|
||||||
|
|
||||||
column.Item().Row(row =>
|
column.Item().Row(row =>
|
||||||
{
|
{
|
||||||
row.RelativeItem().Text($"Łączne wydatki: {totalExpenses: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();
|
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})")
|
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 =>
|
column.Item().Row(row =>
|
||||||
{
|
{
|
||||||
row.RelativeItem().Text("Data").SemiBold();
|
row.RelativeItem().Text("Data").SemiBold().FontColor(Colors.Green.Darken1);
|
||||||
row.RelativeItem().Text("Kwota").SemiBold();
|
row.RelativeItem().Text("Kwota").SemiBold().FontColor(Colors.Green.Darken1);
|
||||||
row.RelativeItem().Text("Opis").SemiBold();
|
row.RelativeItem().Text("Opis").SemiBold().FontColor(Colors.Green.Darken1);
|
||||||
});
|
});
|
||||||
|
|
||||||
foreach (var expense in expenses)
|
foreach (var expense in expenses)
|
||||||
@ -235,13 +246,12 @@ namespace FirmTracker_Server.Controllers
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
page.Footer()
|
page.Footer()
|
||||||
.AlignCenter()
|
.AlignCenter()
|
||||||
.Text(text =>
|
.Text(text =>
|
||||||
{
|
{
|
||||||
text.Span("Wygenerowano przez automat FT: ");
|
text.Span("Wygenerowano przez automat FT: ").FontColor(Colors.Grey.Medium);
|
||||||
text.Span(DateTime.Now.ToString("yyyy-MM-dd")).SemiBold();
|
text.Span(DateTime.Now.ToString("yyyy-MM-dd")).SemiBold().FontColor(Colors.Grey.Medium);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}).GeneratePdf(ms);
|
}).GeneratePdf(ms);
|
||||||
@ -249,5 +259,7 @@ namespace FirmTracker_Server.Controllers
|
|||||||
return ms.ToArray();
|
return ms.ToArray();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ namespace FirmTracker_Server.Controllers
|
|||||||
[HttpPost]
|
[HttpPost]
|
||||||
[ProducesResponseType(200)] // Created
|
[ProducesResponseType(200)] // Created
|
||||||
[ProducesResponseType(400)] // Bad Request
|
[ProducesResponseType(400)] // Bad Request
|
||||||
[Authorize(Roles = Roles.Admin)]
|
[Authorize(Roles = Roles.Admin + "," + Roles.User)]
|
||||||
public IActionResult CreateProduct([FromBody] Product product)
|
public IActionResult CreateProduct([FromBody] Product product)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@ -63,6 +63,11 @@ namespace FirmTracker_Server.Controllers
|
|||||||
{
|
{
|
||||||
throw new InvalidOperationException("Produkt nie może posiadać ujemnej ceny.");
|
throw new InvalidOperationException("Produkt nie może posiadać ujemnej ceny.");
|
||||||
}
|
}
|
||||||
|
var productByName = _productCrud.GetProductByName(product.Name);
|
||||||
|
if (productByName != null)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("Produkt o podanej nazwie już istnieje.");
|
||||||
|
}
|
||||||
|
|
||||||
_productCrud.AddProduct(product);
|
_productCrud.AddProduct(product);
|
||||||
return CreatedAtAction("GetProduct", new { id = product.Id }, product);
|
return CreatedAtAction("GetProduct", new { id = product.Id }, product);
|
||||||
@ -148,7 +153,7 @@ namespace FirmTracker_Server.Controllers
|
|||||||
[HttpDelete("{id}")]
|
[HttpDelete("{id}")]
|
||||||
[ProducesResponseType(200)] // Created
|
[ProducesResponseType(200)] // Created
|
||||||
[ProducesResponseType(400)] // Bad Request
|
[ProducesResponseType(400)] // Bad Request
|
||||||
[Authorize(Roles = Roles.Admin)]
|
[Authorize(Roles = Roles.Admin + "," + Roles.User)]
|
||||||
public IActionResult DeleteProduct(int id)
|
public IActionResult DeleteProduct(int id)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
@ -25,6 +25,8 @@ using FirmTracker_Server.nHibernate.Products;
|
|||||||
using FirmTracker_Server.nHibernate;
|
using FirmTracker_Server.nHibernate;
|
||||||
using Microsoft.AspNetCore.Http.HttpResults;
|
using Microsoft.AspNetCore.Http.HttpResults;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using FirmTracker_Server.Services;
|
||||||
|
using System.Security.Claims;
|
||||||
|
|
||||||
namespace FirmTracker_Server.Controllers
|
namespace FirmTracker_Server.Controllers
|
||||||
{
|
{
|
||||||
@ -35,11 +37,11 @@ namespace FirmTracker_Server.Controllers
|
|||||||
{
|
{
|
||||||
private readonly TransactionCRUD _transactionCRUD;
|
private readonly TransactionCRUD _transactionCRUD;
|
||||||
private readonly ProductCRUD _productCRUD;
|
private readonly ProductCRUD _productCRUD;
|
||||||
|
|
||||||
public TransactionController()
|
public TransactionController()
|
||||||
{
|
{
|
||||||
_transactionCRUD = new TransactionCRUD();
|
_transactionCRUD = new TransactionCRUD();
|
||||||
_productCRUD = new ProductCRUD();
|
_productCRUD = new ProductCRUD();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -55,7 +57,8 @@ namespace FirmTracker_Server.Controllers
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
var userId = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier)?.Value;
|
||||||
|
transaction.EmployeeId = int.Parse(userId);
|
||||||
foreach (var product in transaction.TransactionProducts)
|
foreach (var product in transaction.TransactionProducts)
|
||||||
{
|
{
|
||||||
// Validate if the product quantity is positive
|
// Validate if the product quantity is positive
|
||||||
@ -230,15 +233,15 @@ namespace FirmTracker_Server.Controllers
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
_transactionCRUD.DeleteTransactionProduct(transactionId, productId);
|
_transactionCRUD.DeleteTransactionProduct(transactionId, productId);
|
||||||
return NoContent(); // Successfully removed the product
|
return NoContent();
|
||||||
}
|
}
|
||||||
catch (InvalidOperationException ioe)
|
catch (InvalidOperationException ioe)
|
||||||
{
|
{
|
||||||
return BadRequest(ioe.Message); // If the transaction or product isn't found
|
return BadRequest(ioe.Message);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
return NotFound(ex.Message); // Other general errors
|
return NotFound(ex.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,20 @@
|
|||||||
using FirmTracker_Server.Models;
|
/*
|
||||||
|
* This file is part of FirmTracker - Server.
|
||||||
|
*
|
||||||
|
* FirmTracker - Server is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* FirmTracker - Server is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with FirmTracker - Server. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
using FirmTracker_Server.Models;
|
||||||
using FirmTracker_Server.Services;
|
using FirmTracker_Server.Services;
|
||||||
using FirmTracker_Server;
|
using FirmTracker_Server;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
@ -6,6 +22,9 @@ using Microsoft.AspNetCore.Mvc;
|
|||||||
using FirmTracker_Server.Entities;
|
using FirmTracker_Server.Entities;
|
||||||
using System.Security.Claims;
|
using System.Security.Claims;
|
||||||
|
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
namespace FirmTracker_Server.Controllers
|
namespace FirmTracker_Server.Controllers
|
||||||
{
|
{
|
||||||
[Route("api/user")]
|
[Route("api/user")]
|
||||||
@ -28,6 +47,12 @@ namespace FirmTracker_Server.Controllers
|
|||||||
{
|
{
|
||||||
return BadRequest("Nieprawidłowa wartość pola. /n" + ModelState);
|
return BadRequest("Nieprawidłowa wartość pola. /n" + ModelState);
|
||||||
}
|
}
|
||||||
|
if (!IsValidPassword(dto.Password))
|
||||||
|
{
|
||||||
|
return BadRequest("Hasło musi mieć co najmniej 8 znaków i nie może zawierać spacji, ani tabulatorów.");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
var id = UserService.AddUser(dto);
|
var id = UserService.AddUser(dto);
|
||||||
return Created($"/api/user/{id}", "User dodany poprawnie");
|
return Created($"/api/user/{id}", "User dodany poprawnie");
|
||||||
}
|
}
|
||||||
@ -50,6 +75,13 @@ namespace FirmTracker_Server.Controllers
|
|||||||
}
|
}
|
||||||
return Ok(roleClaim);
|
return Ok(roleClaim);
|
||||||
}
|
}
|
||||||
|
[HttpGet("UsersList")]
|
||||||
|
[Authorize(Roles = Roles.Admin)]
|
||||||
|
public ActionResult<IList<EmployeeDto>> GetAllUsers()
|
||||||
|
{
|
||||||
|
var users = UserService.GetAllUsers();
|
||||||
|
return Ok(users);
|
||||||
|
}
|
||||||
[HttpGet("emails")]
|
[HttpGet("emails")]
|
||||||
[Authorize(Roles = Roles.Admin)]
|
[Authorize(Roles = Roles.Admin)]
|
||||||
public ActionResult<IEnumerable<string>> GetAllUserEmails()
|
public ActionResult<IEnumerable<string>> GetAllUserEmails()
|
||||||
@ -62,6 +94,65 @@ namespace FirmTracker_Server.Controllers
|
|||||||
|
|
||||||
return Ok(emails);
|
return Ok(emails);
|
||||||
}
|
}
|
||||||
|
[HttpPost("ChangeUserPassword")]
|
||||||
|
[Authorize(Roles = Roles.Admin)]
|
||||||
|
public ActionResult ChangeUserPassword([FromBody] ChangeUserPasswordDto dto)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (!IsValidPassword(dto.password))
|
||||||
|
{
|
||||||
|
return BadRequest("Password must be at least 8 characters long and cannot contain spaces or tabs.");
|
||||||
|
}
|
||||||
|
|
||||||
|
var result = UserService.ChangeUserPassword(dto);
|
||||||
|
|
||||||
|
if (result)
|
||||||
|
{
|
||||||
|
return Ok("Password changed successfully.");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return BadRequest("Failed to change the password.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return BadRequest($"An error occurred: {ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[HttpPost("changePassword")]
|
||||||
|
[Authorize(Roles = Roles.Admin + "," + Roles.User)]
|
||||||
|
public ActionResult ChangePassword([FromBody] UpdatePasswordDto dto)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var result = UserService.UpdatePassword(dto);
|
||||||
|
if (result)
|
||||||
|
{
|
||||||
|
var loginDto = new LoginDto { Email = dto.email, Password = dto.newPassword };
|
||||||
|
var token = UserService.CreateTokenJwt(loginDto);
|
||||||
|
return Ok(new { Token = token });
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return BadRequest("Failed to change the password.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return BadRequest($"An error occurred: {ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private bool IsValidPassword(string password)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(password) || password.Length < 8 || password.Contains(" ") || password.Contains("\t"))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// New method to get all users
|
// New method to get all users
|
||||||
/* [HttpGet("all")]
|
/* [HttpGet("all")]
|
||||||
[AllowAnonymous]
|
[AllowAnonymous]
|
||||||
|
@ -47,13 +47,11 @@ namespace FirmTracker_Server.Controllers
|
|||||||
var userIdString = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier)?.Value;
|
var userIdString = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier)?.Value;
|
||||||
int userId = int.Parse(userIdString);
|
int userId = int.Parse(userIdString);
|
||||||
|
|
||||||
// Attempt to start a new workday
|
|
||||||
_workdayCRUD.StartWorkday(userId);
|
_workdayCRUD.StartWorkday(userId);
|
||||||
return Ok(new { status = "started", userId });
|
return Ok(new { status = "started", userId });
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
// If there's an error (like previous workday not stopped), handle it
|
|
||||||
return BadRequest(new { message = "An error occurred while starting the workday.", error = ex.Message });
|
return BadRequest(new { message = "An error occurred while starting the workday.", error = ex.Message });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -76,7 +74,22 @@ namespace FirmTracker_Server.Controllers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpGet("user/workdays")]
|
||||||
|
[Authorize(Roles = Roles.Admin + "," + Roles.User)]
|
||||||
|
public IActionResult GetWorkdaysLoggedUser()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var userId = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier)?.Value;
|
||||||
|
|
||||||
|
var workdays = _workdayCRUD.GetWorkdaysByLoggedUser(userId);
|
||||||
|
return Ok(workdays);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return BadRequest(new { message = "An error occurred while fetching workdays.", error = ex.Message });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Endpoint to get all workdays for a user
|
// Endpoint to get all workdays for a user
|
||||||
[HttpGet("user/{userMail}/workdays")]
|
[HttpGet("user/{userMail}/workdays")]
|
||||||
@ -104,7 +117,6 @@ namespace FirmTracker_Server.Controllers
|
|||||||
return BadRequest(new { message = "User email must be provided." });
|
return BadRequest(new { message = "User email must be provided." });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetch the userId based on the provided email
|
|
||||||
int userId;
|
int userId;
|
||||||
using (var session = SessionFactory.OpenSession())
|
using (var session = SessionFactory.OpenSession())
|
||||||
{
|
{
|
||||||
@ -116,7 +128,6 @@ namespace FirmTracker_Server.Controllers
|
|||||||
userId = user.UserId;
|
userId = user.UserId;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the absence for the retrieved userId
|
|
||||||
_workdayCRUD.AddAbsence(userId, dto.AbsenceType, dto.StartTime, dto.EndTime);
|
_workdayCRUD.AddAbsence(userId, dto.AbsenceType, dto.StartTime, dto.EndTime);
|
||||||
|
|
||||||
return Ok(new { status = "added", userId, dto.userEmail, absenceType = dto.AbsenceType });
|
return Ok(new { status = "added", userId, dto.userEmail, absenceType = dto.AbsenceType });
|
||||||
@ -127,6 +138,35 @@ namespace FirmTracker_Server.Controllers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpGet("user/{userMail}/day/info/{date}")]
|
||||||
|
[Authorize(Roles = Roles.Admin + "," + Roles.User)]
|
||||||
|
public IActionResult GetUserDayDetailsByMail(string userMail, DateTime date)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var dayDetails = _workdayCRUD.GetDayDetails(userMail, date);
|
||||||
|
return Ok(dayDetails);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return BadRequest(new { message = "An error occurred while fetching the day's details.", error = ex.Message });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[HttpGet("user/day/info/{date}")]
|
||||||
|
[Authorize(Roles = Roles.Admin + "," + Roles.User)]
|
||||||
|
public IActionResult GetUserDayDetails(DateTime date)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var userId = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier)?.Value;
|
||||||
|
|
||||||
|
var dayDetails = _workdayCRUD.GetDayDetailsForLoggedUser(int.Parse(userId), date);
|
||||||
|
return Ok(dayDetails);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return BadRequest(new { message = "An error occurred while fetching the day's details.", error = ex.Message });
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ COPY . .
|
|||||||
|
|
||||||
|
|
||||||
# Copy the szyfrowanie.dll into the build directory (to ensure it's available during the build)
|
# Copy the szyfrowanie.dll into the build directory (to ensure it's available during the build)
|
||||||
COPY ["szyfrowanie.dll", "./"]
|
#COPY ["szyfrowanie.dll", "./"]
|
||||||
|
|
||||||
# Build the app
|
# Build the app
|
||||||
RUN dotnet build "FirmTracker-Server.csproj" -c Release -o /app/build
|
RUN dotnet build "FirmTracker-Server.csproj" -c Release -o /app/build
|
||||||
@ -31,7 +31,7 @@ EXPOSE 443
|
|||||||
COPY --from=publish /app/publish .
|
COPY --from=publish /app/publish .
|
||||||
|
|
||||||
# Copy the szyfrowanie.dll to the final image (if needed at runtime)
|
# Copy the szyfrowanie.dll to the final image (if needed at runtime)
|
||||||
COPY ["szyfrowanie.dll", "./"]
|
#COPY ["szyfrowanie.dll", "./"]
|
||||||
|
|
||||||
# Set the entry point for the container
|
# Set the entry point for the container
|
||||||
ENTRYPOINT ["dotnet", "FirmTracker-Server.dll"]
|
ENTRYPOINT ["dotnet", "FirmTracker-Server.dll"]
|
||||||
|
@ -35,12 +35,6 @@
|
|||||||
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.1.2" />
|
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.1.2" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<Reference Include="szyfrowanie">
|
|
||||||
<HintPath>./szyfrowanie.dll</HintPath>
|
|
||||||
</Reference>
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Update="Properties\Resources.Designer.cs">
|
<Compile Update="Properties\Resources.Designer.cs">
|
||||||
<DesignTime>True</DesignTime>
|
<DesignTime>True</DesignTime>
|
||||||
|
25
JenkinsFile
25
JenkinsFile
@ -1,23 +1,26 @@
|
|||||||
pipeline {
|
pipeline {
|
||||||
agent any
|
agent any
|
||||||
|
environment {
|
||||||
|
IMG_NAME = 'firmtracker-server'
|
||||||
|
DOCKER_REPO = 'maciejm0101/firmtracker'
|
||||||
|
}
|
||||||
stages {
|
stages {
|
||||||
stage('Restore Dependencies') {
|
stage('build') {
|
||||||
steps {
|
steps {
|
||||||
echo 'Restoring dependencies...'
|
script {
|
||||||
sh 'dotnet restore'
|
sh 'docker build -t ${IMG_NAME} .'
|
||||||
|
sh 'docker tag ${IMG_NAME} ${DOCKER_REPO}:${IMG_NAME}'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
stage('Build') {
|
}
|
||||||
|
stage('push') {
|
||||||
steps {
|
steps {
|
||||||
echo 'Building the project...'
|
withCredentials([usernamePassword(credentialsId: 'DockerHub-LG', passwordVariable: 'PSWD', usernameVariable: 'LOGIN')]) {
|
||||||
sh 'dotnet build --configuration Release'
|
script {
|
||||||
|
sh 'echo ${PSWD} | docker login -u ${LOGIN} --password-stdin'
|
||||||
|
sh 'docker push ${DOCKER_REPO}:${IMG_NAME}'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stage('Publish') {
|
|
||||||
steps {
|
|
||||||
echo 'Publishing the project...'
|
|
||||||
sh 'dotnet publish --configuration Release --output ./publish'
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,25 @@
|
|||||||
namespace FirmTracker_Server.Models
|
/*
|
||||||
|
* This file is part of FirmTracker - Server.
|
||||||
|
*
|
||||||
|
* FirmTracker - Server is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* FirmTracker - Server is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with FirmTracker - Server. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
namespace FirmTracker_Server.Models
|
||||||
{
|
{
|
||||||
public class AddAbsenceDto
|
public class AddAbsenceDto
|
||||||
{
|
{
|
||||||
public string userEmail { get; set; }
|
public string userEmail { get; set; }
|
||||||
public string AbsenceType { get; set; } // e.g., "Sick", "Vacation", etc.
|
public string AbsenceType { get; set; }
|
||||||
public DateTime StartTime { get; set; }
|
public DateTime StartTime { get; set; }
|
||||||
public DateTime EndTime { get; set; }
|
public DateTime EndTime { get; set; }
|
||||||
|
|
||||||
|
24
Models/ChangeUserPasswordDto.cs
Normal file
24
Models/ChangeUserPasswordDto.cs
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of FirmTracker - Server.
|
||||||
|
*
|
||||||
|
* FirmTracker - Server is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* FirmTracker - Server is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with FirmTracker - Server. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
namespace FirmTracker_Server.Models
|
||||||
|
{
|
||||||
|
public class ChangeUserPasswordDto
|
||||||
|
{
|
||||||
|
public string email { get; set; }
|
||||||
|
public string password { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -1,11 +1,27 @@
|
|||||||
namespace FirmTracker_Server.Models
|
/*
|
||||||
|
* This file is part of FirmTracker - Server.
|
||||||
|
*
|
||||||
|
* FirmTracker - Server is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* FirmTracker - Server is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with FirmTracker - Server. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
namespace FirmTracker_Server.Models
|
||||||
{
|
{
|
||||||
public class CreateUserDto
|
public class CreateUserDto
|
||||||
{
|
{
|
||||||
public string Login { get; set; }
|
public required string Login { get; set; }
|
||||||
public string Password { get; set; }
|
public required string Password { get; set; }
|
||||||
public string Email { get; set; }
|
public required string Email { get; set; }
|
||||||
public string Role { get; set; }
|
public required string Role { get; set; }
|
||||||
public bool NewEncryption { get; set; } = true;
|
public bool NewEncryption { get; set; } = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
28
Models/DayDetailsDto.cs
Normal file
28
Models/DayDetailsDto.cs
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of FirmTracker - Server.
|
||||||
|
*
|
||||||
|
* FirmTracker - Server is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* FirmTracker - Server is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with FirmTracker - Server. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
using FirmTracker_Server.nHibernate;
|
||||||
|
|
||||||
|
namespace FirmTracker_Server.Models
|
||||||
|
{
|
||||||
|
public class DayDetailsDto
|
||||||
|
{
|
||||||
|
public required string Email { get; set; }
|
||||||
|
public DateTime Date { get; set; }
|
||||||
|
public required string TotalWorkedHours { get; set; }
|
||||||
|
public required List<Workday> WorkdayDetails { get; set; }
|
||||||
|
}
|
||||||
|
}
|
28
Models/DayDetailsLoggedUserDto.cs
Normal file
28
Models/DayDetailsLoggedUserDto.cs
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of FirmTracker - Server.
|
||||||
|
*
|
||||||
|
* FirmTracker - Server is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* FirmTracker - Server is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with FirmTracker - Server. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
using FirmTracker_Server.nHibernate;
|
||||||
|
|
||||||
|
namespace FirmTracker_Server.Models
|
||||||
|
{
|
||||||
|
public class DayDetailsLoggedUserDto
|
||||||
|
{
|
||||||
|
public int UserId { get; set; }
|
||||||
|
public DateTime Date { get; set; }
|
||||||
|
public string TotalWorkedHours { get; set; }
|
||||||
|
public List<Workday> WorkdayDetails { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,20 @@
|
|||||||
using FirmTracker_Server.Controllers;
|
/*
|
||||||
|
* This file is part of FirmTracker - Server.
|
||||||
|
*
|
||||||
|
* FirmTracker - Server is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* FirmTracker - Server is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with FirmTracker - Server. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
using FirmTracker_Server.Controllers;
|
||||||
|
|
||||||
namespace FirmTracker_Server.Models
|
namespace FirmTracker_Server.Models
|
||||||
{
|
{
|
||||||
|
@ -1,4 +1,20 @@
|
|||||||
namespace FirmTracker_Server.Models
|
/*
|
||||||
|
* This file is part of FirmTracker - Server.
|
||||||
|
*
|
||||||
|
* FirmTracker - Server is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* FirmTracker - Server is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with FirmTracker - Server. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
namespace FirmTracker_Server.Models
|
||||||
{
|
{
|
||||||
public class LoginDto
|
public class LoginDto
|
||||||
{
|
{
|
||||||
|
@ -1,4 +1,20 @@
|
|||||||
namespace FirmTracker_Server.Models
|
/*
|
||||||
|
* This file is part of FirmTracker - Server.
|
||||||
|
*
|
||||||
|
* FirmTracker - Server is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* FirmTracker - Server is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with FirmTracker - Server. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
namespace FirmTracker_Server.Models
|
||||||
{
|
{
|
||||||
public class UpdateAbsenceDto
|
public class UpdateAbsenceDto
|
||||||
{
|
{
|
||||||
|
27
Models/UpdatePasswordDto.cs
Normal file
27
Models/UpdatePasswordDto.cs
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of FirmTracker - Server.
|
||||||
|
*
|
||||||
|
* FirmTracker - Server is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* FirmTracker - Server is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with FirmTracker - Server. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
namespace FirmTracker_Server.Models
|
||||||
|
{
|
||||||
|
public class UpdatePasswordDto
|
||||||
|
{
|
||||||
|
public string email { get; set; }
|
||||||
|
public string oldPassword { get; set; }
|
||||||
|
public string newPassword { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,20 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
/*
|
||||||
|
* This file is part of FirmTracker - Server.
|
||||||
|
*
|
||||||
|
* FirmTracker - Server is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* FirmTracker - Server is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with FirmTracker - Server. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
namespace FirmTracker_Server.Models
|
namespace FirmTracker_Server.Models
|
||||||
{
|
{
|
||||||
|
@ -1,4 +1,20 @@
|
|||||||
using FirmTracker_Server.Entities;
|
/*
|
||||||
|
* This file is part of FirmTracker - Server.
|
||||||
|
*
|
||||||
|
* FirmTracker - Server is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* FirmTracker - Server is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with FirmTracker - Server. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
using FirmTracker_Server.Entities;
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace YourNamespace.Models
|
namespace YourNamespace.Models
|
||||||
|
34
Program.cs
34
Program.cs
@ -15,29 +15,20 @@
|
|||||||
* along with FirmTracker - Server. If not, see <https://www.gnu.org/licenses/>.
|
* along with FirmTracker - Server. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using NHibernate;
|
|
||||||
using NHibernate.Cfg;
|
using NHibernate.Cfg;
|
||||||
using NHibernate.Dialect;
|
|
||||||
using NHibernate.Driver;
|
|
||||||
using FirmTracker_Server.Controllers;
|
|
||||||
using FirmTracker_Server.nHibernate.Products;
|
|
||||||
using FirmTracker_Server.nHibernate;
|
using FirmTracker_Server.nHibernate;
|
||||||
using FirmTracker_Server.Utilities.Converters;
|
using FirmTracker_Server.Utilities.Converters;
|
||||||
using FirmTracker_Server.Utilities.Swagger;
|
using FirmTracker_Server.Utilities.Swagger;
|
||||||
using FluentValidation;
|
|
||||||
using Microsoft.AspNetCore.Authorization;
|
|
||||||
using Microsoft.AspNetCore.HttpOverrides;
|
|
||||||
using Microsoft.AspNetCore.Identity;
|
using Microsoft.AspNetCore.Identity;
|
||||||
using Microsoft.IdentityModel.Tokens;
|
using Microsoft.IdentityModel.Tokens;
|
||||||
using AutoMapper;
|
using AutoMapper;
|
||||||
using Microsoft.AspNetCore.Authentication;
|
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using FirmTracker_Server.Entities;
|
using FirmTracker_Server.Entities;
|
||||||
using FirmTracker_Server.Middleware;
|
using FirmTracker_Server.Middleware;
|
||||||
using FirmTracker_Server.Services;
|
using FirmTracker_Server.Services;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using FirmTracker_Server.Mappings;
|
using FirmTracker_Server.Mappings;
|
||||||
using NuGet.Packaging;
|
using Microsoft.AspNetCore.DataProtection;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -69,14 +60,18 @@ namespace FirmTracker_Server
|
|||||||
Console.WriteLine($"The configuration file '{configFilePath}' was not found.");
|
Console.WriteLine($"The configuration file '{configFilePath}' was not found.");
|
||||||
}
|
}
|
||||||
|
|
||||||
TestClass test = new TestClass();
|
//TestClass test = new TestClass();
|
||||||
test.AddTestProduct();
|
// test.AddTestProduct();
|
||||||
QuestPDF.Settings.License = QuestPDF.Infrastructure.LicenseType.Community;
|
QuestPDF.Settings.License = QuestPDF.Infrastructure.LicenseType.Community;
|
||||||
|
//builder.Services.AddDataProtection().DisableAutomaticKeyGeneration();
|
||||||
builder.Services.AddCors(options =>
|
builder.Services.AddCors(options =>
|
||||||
{
|
{
|
||||||
options.AddPolicy("AllowSpecificOrigin",
|
options.AddPolicy("AllowSpecificOrigin",
|
||||||
policy => policy.WithOrigins("http://localhost:3000")
|
policy => policy.WithOrigins(
|
||||||
|
"http://localhost:3000",
|
||||||
|
"https://firmtracker-server.onrender.com",
|
||||||
|
"https://firmtracker.netlify.app"
|
||||||
|
)
|
||||||
.AllowAnyHeader()
|
.AllowAnyHeader()
|
||||||
.AllowAnyMethod());
|
.AllowAnyMethod());
|
||||||
});
|
});
|
||||||
@ -106,9 +101,9 @@ namespace FirmTracker_Server
|
|||||||
|
|
||||||
|
|
||||||
var port = configSwagger.GetValue<int>("Port", 5075);
|
var port = configSwagger.GetValue<int>("Port", 5075);
|
||||||
var port2 = configSwagger.GetValue<int>("Port", 7039);
|
// var port2 = configSwagger.GetValue<int>("Port", 7039);
|
||||||
app.Urls.Add($"http://*:{port}");
|
app.Urls.Add($"http://*:{port}");
|
||||||
app.Urls.Add($"https://*:{port2}");
|
// app.Urls.Add($"https://*:{port2}");
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -119,14 +114,14 @@ namespace FirmTracker_Server
|
|||||||
c.RoutePrefix = "swagger";
|
c.RoutePrefix = "swagger";
|
||||||
});
|
});
|
||||||
Console.WriteLine("uruchomiono swaggera");
|
Console.WriteLine("uruchomiono swaggera");
|
||||||
app.UseHttpsRedirection();
|
// app.UseHttpsRedirection();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Nie uda³o siê uruchomiæ swaggera");
|
Console.WriteLine("Nie uda³o siê uruchomiæ swaggera");
|
||||||
}
|
}
|
||||||
|
|
||||||
app.UseHttpsRedirection();
|
// app.UseHttpsRedirection();
|
||||||
|
|
||||||
app.UseCors("AllowSpecificOrigin");
|
app.UseCors("AllowSpecificOrigin");
|
||||||
|
|
||||||
@ -179,6 +174,7 @@ namespace FirmTracker_Server
|
|||||||
services.AddScoped<IPasswordHasher<User>, PasswordHasher<User>>();
|
services.AddScoped<IPasswordHasher<User>, PasswordHasher<User>>();
|
||||||
services.AddScoped<IExpenseRepository, ExpenseRepository>();
|
services.AddScoped<IExpenseRepository, ExpenseRepository>();
|
||||||
services.AddScoped<ITransactionRepository, TransactionRepository>();
|
services.AddScoped<ITransactionRepository, TransactionRepository>();
|
||||||
|
services.AddScoped<IProductRepository, ProductRepository>();
|
||||||
// services.AddScoped<IWorkdayRepository, WorkdayRepository>();
|
// services.AddScoped<IWorkdayRepository, WorkdayRepository>();
|
||||||
services.AddMvc();
|
services.AddMvc();
|
||||||
}
|
}
|
||||||
|
@ -3,18 +3,17 @@ using FirmTracker_Server.Authentication;
|
|||||||
using FirmTracker_Server.Entities;
|
using FirmTracker_Server.Entities;
|
||||||
using FirmTracker_Server.Exceptions;
|
using FirmTracker_Server.Exceptions;
|
||||||
using FirmTracker_Server.Models;
|
using FirmTracker_Server.Models;
|
||||||
using FirmTracker_Server.Authentication;
|
|
||||||
using FirmTracker_Server.Exceptions;
|
|
||||||
using Microsoft.AspNetCore.Identity;
|
using Microsoft.AspNetCore.Identity;
|
||||||
using Microsoft.IdentityModel.Tokens;
|
using Microsoft.IdentityModel.Tokens;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.IdentityModel.Tokens.Jwt;
|
using System.IdentityModel.Tokens.Jwt;
|
||||||
using System.Security.Claims;
|
using System.Security.Claims;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using szyfrowanie;
|
|
||||||
using FirmTracker_Server.nHibernate;
|
using FirmTracker_Server.nHibernate;
|
||||||
using NHibernate;
|
using NHibernate;
|
||||||
using NHibernate.Criterion;
|
using NHibernate.Criterion;
|
||||||
|
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||||
|
using NHibernate.Type;
|
||||||
|
|
||||||
namespace FirmTracker_Server.Services
|
namespace FirmTracker_Server.Services
|
||||||
{
|
{
|
||||||
@ -24,31 +23,102 @@ namespace FirmTracker_Server.Services
|
|||||||
int AddUser(CreateUserDto dto);
|
int AddUser(CreateUserDto dto);
|
||||||
string CreateTokenJwt(LoginDto dto);
|
string CreateTokenJwt(LoginDto dto);
|
||||||
IEnumerable<string> GetAllUserEmails();
|
IEnumerable<string> GetAllUserEmails();
|
||||||
|
bool UpdatePassword(UpdatePasswordDto dto);
|
||||||
|
bool ChangeUserPassword(ChangeUserPasswordDto dto);
|
||||||
|
IList<EmployeeDto> GetAllUsers();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class UserService : IUserService
|
public class UserService : IUserService
|
||||||
{
|
{
|
||||||
// private readonly GeneralDbContext DbContext;
|
|
||||||
private readonly IMapper Mapper;
|
private readonly IMapper Mapper;
|
||||||
private readonly IPasswordHasher<User> PasswordHasher;
|
private readonly IPasswordHasher<User> PasswordHasher;
|
||||||
private readonly AuthenticationSettings AuthenticationSettings;
|
private readonly AuthenticationSettings AuthenticationSettings;
|
||||||
private readonly SimplerAES SimplerAES;
|
|
||||||
//private readonly SessionFactory sessionFactory;
|
|
||||||
|
|
||||||
public UserService( IMapper mapper, IPasswordHasher<User> passwordHasher, AuthenticationSettings authenticationSettings)
|
public UserService(IMapper mapper, IPasswordHasher<User> passwordHasher, AuthenticationSettings authenticationSettings)
|
||||||
{
|
{
|
||||||
// DbContext = dbContext;
|
|
||||||
Mapper = mapper;
|
Mapper = mapper;
|
||||||
PasswordHasher = passwordHasher;
|
PasswordHasher = passwordHasher;
|
||||||
AuthenticationSettings = authenticationSettings;
|
AuthenticationSettings = authenticationSettings;
|
||||||
SimplerAES = new SimplerAES();
|
|
||||||
//SessionFactory = sessionFactory;
|
}
|
||||||
|
public IList<EmployeeDto> GetAllUsers()
|
||||||
|
{
|
||||||
|
using (var session = SessionFactory.OpenSession())
|
||||||
|
{
|
||||||
|
var users = session.Query<User>()
|
||||||
|
.Select(u => new EmployeeDto
|
||||||
|
{
|
||||||
|
Id = u.UserId,
|
||||||
|
email = u.Email
|
||||||
|
})
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
return users;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public bool ChangeUserPassword(ChangeUserPasswordDto dto)
|
||||||
|
{
|
||||||
|
using (var session = SessionFactory.OpenSession())
|
||||||
|
using (var transaction = session.BeginTransaction())
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var user = session.Query<User>().FirstOrDefault(u => u.Email == dto.email);
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
throw new Exception("User not found.");
|
||||||
|
}
|
||||||
|
|
||||||
|
user.PassHash = PasswordHasher.HashPassword(user, dto.password);
|
||||||
|
session.Update(user);
|
||||||
|
transaction.Commit();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
transaction.Rollback();
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public bool UpdatePassword(UpdatePasswordDto dto)
|
||||||
|
{
|
||||||
|
using (var session = SessionFactory.OpenSession())
|
||||||
|
using (var transaction = session.BeginTransaction())
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var user = session.Query<User>().FirstOrDefault(u => u.Email == dto.email);
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
throw new Exception("User not found.");
|
||||||
|
}
|
||||||
|
|
||||||
|
var result = PasswordHasher.VerifyHashedPassword(user, user.PassHash, dto.oldPassword);
|
||||||
|
if (result != PasswordVerificationResult.Success)
|
||||||
|
{
|
||||||
|
throw new Exception("Invalid current password.");
|
||||||
|
}
|
||||||
|
|
||||||
|
user.PassHash = PasswordHasher.HashPassword(user, dto.newPassword);
|
||||||
|
session.Update(user);
|
||||||
|
transaction.Commit();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
transaction.Rollback();
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public IEnumerable<string> GetAllUserEmails()
|
public IEnumerable<string> GetAllUserEmails()
|
||||||
{
|
{
|
||||||
using (var session = SessionFactory.OpenSession())
|
using (var session = SessionFactory.OpenSession())
|
||||||
{
|
{
|
||||||
// Query the users and return a list of emails
|
|
||||||
var users = session.Query<User>().Select(u => u.Email).ToList();
|
var users = session.Query<User>().Select(u => u.Email).ToList();
|
||||||
return users;
|
return users;
|
||||||
}
|
}
|
||||||
@ -66,8 +136,7 @@ namespace FirmTracker_Server.Services
|
|||||||
{
|
{
|
||||||
var user = Mapper.Map<User>(dto);
|
var user = Mapper.Map<User>(dto);
|
||||||
|
|
||||||
// Encrypt or hash the password based on NewEncryption flag
|
user.PassHash = dto.NewEncryption ? PasswordHasher.HashPassword(user, dto.Password) : PasswordHasher.HashPassword(user, dto.Password);
|
||||||
user.PassHash = dto.NewEncryption ? SimplerAES.Encrypt(dto.Password) : PasswordHasher.HashPassword(user, dto.Password);
|
|
||||||
user.Role = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(dto.Role.ToLower());
|
user.Role = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(dto.Role.ToLower());
|
||||||
|
|
||||||
using (var session = SessionFactory.OpenSession())
|
using (var session = SessionFactory.OpenSession())
|
||||||
@ -107,14 +176,13 @@ namespace FirmTracker_Server.Services
|
|||||||
throw new WrongUserOrPasswordException("Nieprawidłowy login lub hasło.");
|
throw new WrongUserOrPasswordException("Nieprawidłowy login lub hasło.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Password verification logic
|
|
||||||
if (user.NewEncryption)
|
if (user.NewEncryption)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Console.WriteLine(SimplerAES.Decrypt(user.PassHash)+" "+SimplerAES.Decrypt(dto.Password));
|
Console.WriteLine(PasswordHasher.HashPassword(user, user.PassHash));
|
||||||
var ready = SimplerAES.Decrypt(user.PassHash) == SimplerAES.Decrypt(dto.Password);
|
var ready = PasswordHasher.VerifyHashedPassword(user, user.PassHash, dto.Password);
|
||||||
if (!ready)
|
if (ready == 0)
|
||||||
{
|
{
|
||||||
throw new WrongUserOrPasswordException("Nieprawidłowy login lub hasło.");
|
throw new WrongUserOrPasswordException("Nieprawidłowy login lub hasło.");
|
||||||
}
|
}
|
||||||
@ -127,14 +195,14 @@ namespace FirmTracker_Server.Services
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
var ready = PasswordVerificationResult.Failed;
|
var ready = PasswordVerificationResult.Failed;
|
||||||
if (SimplerAES.Decrypt(user.PassHash) == SimplerAES.Decrypt(dto.Password)) { ready = PasswordVerificationResult.Success; } //PasswordHasher.VerifyHashedPassword(user, user.PassHash, dto.Password);
|
if (PasswordHasher.VerifyHashedPassword(user, user.PassHash, dto.Password) == PasswordVerificationResult.Success) { ready = PasswordVerificationResult.Success; } //PasswordHasher.VerifyHashedPassword(user, user.PassHash, dto.Password);
|
||||||
if (ready == PasswordVerificationResult.Failed)
|
if (ready == PasswordVerificationResult.Failed)
|
||||||
{
|
{
|
||||||
throw new WrongUserOrPasswordException("Nieprawidłowy login lub hasło.");
|
throw new WrongUserOrPasswordException("Nieprawidłowy login lub hasło.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate JWT token
|
|
||||||
var claims = new List<Claim>() {
|
var claims = new List<Claim>() {
|
||||||
new(ClaimTypes.NameIdentifier, user.UserId.ToString()),
|
new(ClaimTypes.NameIdentifier, user.UserId.ToString()),
|
||||||
new(ClaimTypes.Role, user.Role)
|
new(ClaimTypes.Role, user.Role)
|
||||||
|
292
TestClass.cs
292
TestClass.cs
@ -1,292 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of FirmTracker - Server.
|
|
||||||
*
|
|
||||||
* FirmTracker - Server is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* FirmTracker - Server is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with FirmTracker - Server. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
using FirmTracker_Server.Controllers;
|
|
||||||
using FirmTracker_Server.nHibernate;
|
|
||||||
using FirmTracker_Server.nHibernate.Products;
|
|
||||||
using FirmTracker_Server.nHibernate.Transactions;
|
|
||||||
using FirmTracker_Server.nHibernate.Expenses;
|
|
||||||
using NHibernate;
|
|
||||||
using FirmTracker_Server.Entities;
|
|
||||||
using FirmTracker_Server.Services;
|
|
||||||
using AutoMapper;
|
|
||||||
using FirmTracker_Server.Authentication;
|
|
||||||
using Microsoft.AspNetCore.Identity;
|
|
||||||
using FirmTracker_Server.Models;
|
|
||||||
using System.Data.SqlClient;
|
|
||||||
|
|
||||||
namespace FirmTracker_Server
|
|
||||||
{
|
|
||||||
public class TestClass
|
|
||||||
{
|
|
||||||
public static Product CreateProduct(string name, string description, decimal price, int type, int availability)
|
|
||||||
{
|
|
||||||
return new Product
|
|
||||||
{
|
|
||||||
Name = name,
|
|
||||||
Description = description,
|
|
||||||
Price = price,
|
|
||||||
Type = type,
|
|
||||||
Availability = availability
|
|
||||||
};
|
|
||||||
}
|
|
||||||
public void AddTestProduct()
|
|
||||||
{
|
|
||||||
// SessionFactory.Init(ConnectionString);
|
|
||||||
|
|
||||||
|
|
||||||
var product2 = new nHibernate.Products.Product
|
|
||||||
{
|
|
||||||
Name = "Dostawa",
|
|
||||||
Description = "usługa dostawy",
|
|
||||||
Price = 7.50m,
|
|
||||||
Type = 0,
|
|
||||||
Availability = 0
|
|
||||||
};
|
|
||||||
|
|
||||||
var products = new List<Product>
|
|
||||||
{
|
|
||||||
CreateProduct("Tarta_truskawka", "produkt", 31.99m, 1, 10),
|
|
||||||
CreateProduct("Tarta_czekolada", "produkt", 30.99m, 1, 10),
|
|
||||||
CreateProduct("Tarta_agrest", "produkt", 32.90m, 1, 8),
|
|
||||||
CreateProduct("Tarta_pistacja", "produkt", 35.99m, 1, 12),
|
|
||||||
CreateProduct("Tarta_karmel", "produkt", 32.00m, 1, 12),
|
|
||||||
CreateProduct("Rolada_beza", "produkt", 21.00m, 1, 5),
|
|
||||||
CreateProduct("Rolada_róża", "produkt", 21.90m, 1, 10),
|
|
||||||
CreateProduct("Kostka_truskawka", "produkt", 12.00m, 1, 11),
|
|
||||||
CreateProduct("Kostka_lemonCurd", "produkt", 13.99m, 1, 13),
|
|
||||||
CreateProduct("Kostka_hiszpańska", "produkt", 11.99m, 1, 8),
|
|
||||||
CreateProduct("Kostka_wiosenna", "produkt", 11.99m, 1, 5),
|
|
||||||
CreateProduct("Kostka_jabłka", "produkt", 12.00m, 1, 5),
|
|
||||||
CreateProduct("Kostka_porzeczka", "produkt", 12.99m, 1, 5),
|
|
||||||
CreateProduct("Kostka_królewska", "produkt", 13.50m, 1, 5),
|
|
||||||
CreateProduct("Kostka_czekolada", "produkt", 14.50m, 1, 10),
|
|
||||||
CreateProduct("Kostka_wiśnia", "produkt", 12.50m, 1, 5),
|
|
||||||
CreateProduct("Kostka_beza", "produkt", 13.50m, 1, 20),
|
|
||||||
CreateProduct("Kostka_leśna", "produkt", 12.00m, 1, 20),
|
|
||||||
CreateProduct("Kostka_kawowa", "produkt", 12.00m, 1, 10),
|
|
||||||
CreateProduct("Kostka_galaretka", "produkt", 12.50m, 1, 25),
|
|
||||||
CreateProduct("Kostka_firmowa", "produkt", 12.50m, 1, 5),
|
|
||||||
CreateProduct("Sernik_wiśnia", "produkt", 33.00m, 1, 6),
|
|
||||||
CreateProduct("Sernik_truskawka", "produkt", 31.00m, 1, 5),
|
|
||||||
CreateProduct("Sernik_pistacja", "produkt", 38.90m, 1, 5),
|
|
||||||
CreateProduct("Sernik_fantazja", "produkt", 33.00m, 1, 7),
|
|
||||||
CreateProduct("Sernik_rafaello", "produkt", 33.00m, 1, 5),
|
|
||||||
CreateProduct("Sernik_nutella", "produkt", 35.50m, 1, 6),
|
|
||||||
CreateProduct("Sernik_mango", "produkt", 33.00m, 1, 5),
|
|
||||||
CreateProduct("Sernik_rabarbar", "produkt", 37.99m, 1, 5),
|
|
||||||
CreateProduct("Sernik_biszkopt", "produkt", 39.00m, 1, 11),
|
|
||||||
CreateProduct("Tartaletka", "produkt", 13.20m, 1, 30),
|
|
||||||
CreateProduct("Strudel_jabłko", "produkt", 29.00m, 1, 20),
|
|
||||||
CreateProduct("Placek_rabarbar", "produkt", 24.00m, 1, 18),
|
|
||||||
CreateProduct("Placek_jogurt", "produkt", 23.00m, 1, 13),
|
|
||||||
CreateProduct("Placek_śliwka", "produkt", 22.00m, 1, 14),
|
|
||||||
CreateProduct("Placek_maślany", "produkt", 18.00m, 1,11),
|
|
||||||
CreateProduct("Keks", "produkt", 22.00m, 1,11),
|
|
||||||
CreateProduct("Babka_drożdżowa", "produkt", 16.00m, 1,11),
|
|
||||||
CreateProduct("Pączek_pistacja", "produkt", 8.00m, 1,11),
|
|
||||||
CreateProduct("Pączek_marmolada", "produkt", 3.00m, 1,11),
|
|
||||||
CreateProduct("Pączek_nutella", "produkt", 4.50m, 1,11),
|
|
||||||
CreateProduct("Pączek_rafaello", "produkt", 4.50m, 1,11),
|
|
||||||
CreateProduct("Pączek_róża", "produkt", 4.00m, 1,11),
|
|
||||||
CreateProduct("Ekler", "produkt", 3.00m, 1,11),
|
|
||||||
CreateProduct("Ekler_słony_karmel", "produkt", 5.00m, 1,11),
|
|
||||||
CreateProduct("Ptyś", "produkt", 4.00m, 1,11),
|
|
||||||
CreateProduct("Drożdżówka_ser", "produkt", 4.00m, 1,11),
|
|
||||||
CreateProduct("Drożdżówka_rabarbar", "produkt", 5.00m, 1,11),
|
|
||||||
CreateProduct("Drożdżówka_żurawina", "produkt", 5.00m, 1,11),
|
|
||||||
CreateProduct("Drożdżówka_kruszonka", "produkt", 4.00m, 1,11),
|
|
||||||
CreateProduct("Drożdżówka_budyń", "produkt", 5.00m, 1,11),
|
|
||||||
CreateProduct("Jagodzianka", "produkt", 6.00m, 1,11),
|
|
||||||
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
var transaction1 = new Transaction
|
|
||||||
{
|
|
||||||
Date = DateTime.Now.AddDays(-2),
|
|
||||||
Description = "zamówienie telefon",
|
|
||||||
Discount = 5,
|
|
||||||
EmployeeId = 1,
|
|
||||||
PaymentType = "Karta kredytowa",
|
|
||||||
};
|
|
||||||
var transaction2 = new Transaction
|
|
||||||
{
|
|
||||||
Date = DateTime.Now.AddDays(-3),
|
|
||||||
Description = "sprzedaż - kasa",
|
|
||||||
Discount = 30,
|
|
||||||
EmployeeId = 2,
|
|
||||||
PaymentType = "Gotówka",
|
|
||||||
};
|
|
||||||
var transaction3 = new Transaction
|
|
||||||
{
|
|
||||||
Date = DateTime.Now,
|
|
||||||
Description = "sprzedaż - kasa",
|
|
||||||
Discount = 15,
|
|
||||||
EmployeeId = 1,
|
|
||||||
PaymentType = "BLIK",
|
|
||||||
};
|
|
||||||
var transaction4 = new Transaction
|
|
||||||
{
|
|
||||||
Date = DateTime.Now,
|
|
||||||
Description = "zamówienie",
|
|
||||||
Discount = 15,
|
|
||||||
EmployeeId = 1,
|
|
||||||
PaymentType = "BLIK",
|
|
||||||
};
|
|
||||||
|
|
||||||
var expense1 = new Expense
|
|
||||||
{
|
|
||||||
Date = DateTime.Now,
|
|
||||||
Value = 7999.9m,
|
|
||||||
Description = "zakup maszyny do lodów FZ/2/6/2024"
|
|
||||||
};
|
|
||||||
var expense2 = new Expense
|
|
||||||
{
|
|
||||||
Date = DateTime.Parse("2024-09-10 16:11:17.6232408"),
|
|
||||||
Value = 990.99m,
|
|
||||||
Description = "naprawa pieca - 25.05.2024"
|
|
||||||
};
|
|
||||||
var expense3 = new Expense
|
|
||||||
{
|
|
||||||
Date = DateTime.Now,
|
|
||||||
Value = 1800.00m,
|
|
||||||
Description = "zakup składników "
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
string appDirectory = Directory.GetCurrentDirectory();
|
|
||||||
string configFilePath = Path.Combine(appDirectory, "appsettings.json");
|
|
||||||
string connectionString = "";
|
|
||||||
if (File.Exists(configFilePath))
|
|
||||||
{
|
|
||||||
var config = new ConfigurationBuilder()
|
|
||||||
.AddJsonFile(configFilePath)
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
var connectionstringsection = config.GetSection("AppSettings:ConnectionString");
|
|
||||||
|
|
||||||
connectionString = connectionstringsection.Value;
|
|
||||||
|
|
||||||
//SessionFactory.Init(connectionString);
|
|
||||||
|
|
||||||
string queryUser = "insert into Users(Email,PassHash,Role) select '123@wp.pl', 'GOsGemJarMJu8btZKF6Rung27JLZkdO7Wfd4CwLhL1k=','User'";
|
|
||||||
string queryAdmin = "insert into Users(Email,PassHash,Role) select '321@wp.pl', 'GOsGemJarMJu8btZKF6Rung27JLZkdO7Wfd4CwLhL1k=','Admin'";
|
|
||||||
|
|
||||||
|
|
||||||
SqlConnection connection = new SqlConnection(connectionString);
|
|
||||||
connection.Open();
|
|
||||||
|
|
||||||
SqlCommand command = new SqlCommand(queryUser, connection);
|
|
||||||
command.CommandTimeout = 200;
|
|
||||||
command.ExecuteNonQuery();
|
|
||||||
connection.Close();
|
|
||||||
|
|
||||||
|
|
||||||
SqlConnection connection2 = new SqlConnection(connectionString);
|
|
||||||
connection.Open();
|
|
||||||
|
|
||||||
SqlCommand command2 = new SqlCommand(queryAdmin, connection);
|
|
||||||
command2.CommandTimeout = 200;
|
|
||||||
command2.ExecuteNonQuery();
|
|
||||||
connection2.Close();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
Console.WriteLine("Nie udało się dodać kont użytkowników " + e.Message);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
FirmTracker_Server.nHibernate.Products.ProductCRUD productCrud = new ProductCRUD();
|
|
||||||
FirmTracker_Server.nHibernate.Transactions.TransactionCRUD transactionCrud = new nHibernate.Transactions.TransactionCRUD();
|
|
||||||
|
|
||||||
ExpenseCRUD expenseCrud = new ExpenseCRUD();
|
|
||||||
// productCrud.AddProduct(product);
|
|
||||||
productCrud.AddProduct(product2);
|
|
||||||
// productCrud.AddProduct(product3);
|
|
||||||
foreach(var clientProduct in products)
|
|
||||||
{
|
|
||||||
productCrud.AddProduct(clientProduct);
|
|
||||||
}
|
|
||||||
transactionCrud.AddTransaction(transaction1);
|
|
||||||
transactionCrud.AddTransaction(transaction2);
|
|
||||||
transactionCrud.AddTransaction(transaction3);
|
|
||||||
transactionCrud.AddTransaction(transaction4);
|
|
||||||
expenseCrud.AddExpense(expense1);
|
|
||||||
expenseCrud.AddExpense(expense2);
|
|
||||||
expenseCrud.AddExpense(expense3);
|
|
||||||
|
|
||||||
List<TransactionProduct> testTransactionProducts = new List<TransactionProduct> {
|
|
||||||
new TransactionProduct { ProductID =17, Quantity = 3 },
|
|
||||||
new TransactionProduct { ProductID = 14, Quantity = 1 },
|
|
||||||
new TransactionProduct { ProductID = 1, Quantity = 1 },
|
|
||||||
};
|
|
||||||
foreach (var transactionProduct in testTransactionProducts)
|
|
||||||
{
|
|
||||||
transactionCrud.AddTransactionProductToTransaction(transaction1.Id, transactionProduct);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
List<TransactionProduct> testTransactionProducts2 = new List<TransactionProduct>
|
|
||||||
{
|
|
||||||
new TransactionProduct { ProductID = 28, Quantity=5},
|
|
||||||
new TransactionProduct { ProductID = 22, Quantity=5}
|
|
||||||
};
|
|
||||||
foreach (var transactionProduct in testTransactionProducts2)
|
|
||||||
{
|
|
||||||
transactionCrud.AddTransactionProductToTransaction(transaction2.Id, transactionProduct);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
List<TransactionProduct> testTransactionProducts3 = new List<TransactionProduct>
|
|
||||||
{
|
|
||||||
new TransactionProduct { ProductID = 3, Quantity=9},
|
|
||||||
new TransactionProduct { ProductID = 2, Quantity=1}
|
|
||||||
};
|
|
||||||
foreach (var transactionProduct in testTransactionProducts3)
|
|
||||||
{
|
|
||||||
transactionCrud.AddTransactionProductToTransaction(transaction3.Id, transactionProduct);
|
|
||||||
|
|
||||||
}
|
|
||||||
List<TransactionProduct> testTransactionProducts4 = new List<TransactionProduct>
|
|
||||||
{
|
|
||||||
new TransactionProduct { ProductID = 33, Quantity=12},
|
|
||||||
new TransactionProduct { ProductID = 12, Quantity=1}
|
|
||||||
};
|
|
||||||
foreach (var transactionProduct in testTransactionProducts4)
|
|
||||||
{
|
|
||||||
transactionCrud.AddTransactionProductToTransaction(transaction4.Id, transactionProduct);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
catch(Exception ex)
|
|
||||||
{
|
|
||||||
Console.WriteLine(ex.ToString());
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,28 +0,0 @@
|
|||||||
{
|
|
||||||
"AppSettings": {
|
|
||||||
"ConnectionString": "Server=localhost,1433;Initial Catalog=master;User Id=sa;Password=Rap45tro2;"
|
|
||||||
|
|
||||||
},
|
|
||||||
"TokenConfig": {
|
|
||||||
"JwtSecKey": "omgi5Rf4tqg351GQwefw1234567890123456",
|
|
||||||
"JwtExpireDays": 30,
|
|
||||||
"JwtIssuer": "http://api.graphcom.pl"
|
|
||||||
},
|
|
||||||
"profiles": {
|
|
||||||
"http": {
|
|
||||||
"commandName": "Project",
|
|
||||||
"dotnetRunMessages": true,
|
|
||||||
"launchBrowser": true,
|
|
||||||
"launchUrl": "swagger",
|
|
||||||
"applicationUrl": "http://localhost:5045"
|
|
||||||
|
|
||||||
},
|
|
||||||
|
|
||||||
"IIS Express": {
|
|
||||||
"commandName": "IISExpress",
|
|
||||||
"launchBrowser": true,
|
|
||||||
"launchUrl": "swagger"
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,11 +1,19 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Transactions;
|
||||||
using FirmTracker_Server.nHibernate.Expenses;
|
using FirmTracker_Server.nHibernate.Expenses;
|
||||||
|
using FirmTracker_Server.nHibernate.Products;
|
||||||
using FirmTracker_Server.nHibernate.Transactions;
|
using FirmTracker_Server.nHibernate.Transactions;
|
||||||
using NHibernate;
|
using NHibernate;
|
||||||
|
using Transaction = FirmTracker_Server.nHibernate.Transactions.Transaction;
|
||||||
|
|
||||||
namespace FirmTracker_Server.nHibernate
|
namespace FirmTracker_Server.nHibernate
|
||||||
{
|
{
|
||||||
|
public interface IProductRepository
|
||||||
|
{
|
||||||
|
Product GetProduct(int id);
|
||||||
|
}
|
||||||
|
|
||||||
public interface IExpenseRepository
|
public interface IExpenseRepository
|
||||||
{
|
{
|
||||||
List<Expense> GetAllExpenses();
|
List<Expense> GetAllExpenses();
|
||||||
@ -25,6 +33,17 @@ namespace FirmTracker_Server.nHibernate
|
|||||||
void DeleteTransaction(int transactionId);
|
void DeleteTransaction(int transactionId);
|
||||||
List<TransactionProduct> GetTransactionProductsForTransactions(List<int> transactionIds);
|
List<TransactionProduct> GetTransactionProductsForTransactions(List<int> transactionIds);
|
||||||
}
|
}
|
||||||
|
public class ProductRepository : IProductRepository
|
||||||
|
{
|
||||||
|
public Product GetProduct(int id)
|
||||||
|
{
|
||||||
|
using (var session = SessionFactory.OpenSession())
|
||||||
|
{
|
||||||
|
return session.Get<Product>(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public class TransactionRepository : ITransactionRepository
|
public class TransactionRepository : ITransactionRepository
|
||||||
{
|
{
|
||||||
// Retrieve all transactions
|
// Retrieve all transactions
|
||||||
|
@ -58,8 +58,8 @@ namespace FirmTracker_Server.nHibernate
|
|||||||
.AddFromAssemblyOf<UserMapping>()
|
.AddFromAssemblyOf<UserMapping>()
|
||||||
.AddFromAssemblyOf<WorkdayMapping>();
|
.AddFromAssemblyOf<WorkdayMapping>();
|
||||||
|
|
||||||
})
|
}) //SchemaExport .Create //żeby tworzyło za każdym razem
|
||||||
.ExposeConfiguration(cfg => new SchemaExport(cfg).Create(true, true)) //SchemaUpdate . Execute dla only update
|
.ExposeConfiguration(cfg => new SchemaUpdate(cfg).Execute(true, true)) //SchemaUpdate . Execute dla only update
|
||||||
.BuildSessionFactory();
|
.BuildSessionFactory();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,12 +5,12 @@ public class UserMapping : ClassMap<User>
|
|||||||
{
|
{
|
||||||
public UserMapping()
|
public UserMapping()
|
||||||
{
|
{
|
||||||
Table("Users"); // The name of your table in the database
|
Table("Users");
|
||||||
|
|
||||||
Id(x => x.UserId); // Mapping the Id property
|
Id(x => x.UserId);
|
||||||
Map(x => x.Email); // Mapping other properties
|
Map(x => x.Email);
|
||||||
Map(x => x.PassHash);
|
Map(x => x.PassHash);
|
||||||
Map(x => x.Role);
|
Map(x => x.Role);
|
||||||
// Add other mappings as needed
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
using FirmTracker_Server.Entities;
|
using FirmTracker_Server.Entities;
|
||||||
using FirmTracker_Server.nHibernate;
|
using FirmTracker_Server.nHibernate;
|
||||||
|
using static NHibernate.Engine.Query.CallableParser;
|
||||||
|
using FirmTracker_Server.Models;
|
||||||
|
|
||||||
public class WorkdayRepository
|
public class WorkdayRepository
|
||||||
{
|
{
|
||||||
@ -125,6 +127,131 @@ public class WorkdayRepository
|
|||||||
})
|
})
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
|
foreach (var workday in workdays)
|
||||||
|
{
|
||||||
|
if(workday.Absence!="")
|
||||||
|
{
|
||||||
|
workday.WorkedHours = TimeSpan.Zero;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return workdays;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
throw new Exception("An error occurred while fetching workdays", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public DayDetailsDto GetDayDetails(string mail, DateTime date)
|
||||||
|
{
|
||||||
|
using (var session = SessionFactory.OpenSession())
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Fetch workdays for the specified user on the given date
|
||||||
|
var startOfDay = date.Date;
|
||||||
|
var endOfDay = startOfDay.AddDays(1);
|
||||||
|
|
||||||
|
var workdays = session.Query<Workday>()
|
||||||
|
.Where(w => w.User.Email == mail && w.StartTime >= startOfDay && w.StartTime < endOfDay)
|
||||||
|
.Select(w => new Workday
|
||||||
|
{
|
||||||
|
StartTime = w.StartTime,
|
||||||
|
EndTime = w.EndTime ?? DateTime.Today.AddHours(17),
|
||||||
|
Absence = w.Absence,
|
||||||
|
})
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
TimeSpan totalWorkedHours = TimeSpan.Zero;
|
||||||
|
|
||||||
|
// Calculate total worked hours and adjust if there's an absence
|
||||||
|
foreach (var workday in workdays)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(workday.Absence))
|
||||||
|
{
|
||||||
|
totalWorkedHours += workday.WorkedHours;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new DayDetailsDto
|
||||||
|
{
|
||||||
|
Email = mail,
|
||||||
|
Date = date,
|
||||||
|
TotalWorkedHours = totalWorkedHours.ToString(@"hh\:mm\:ss"),
|
||||||
|
WorkdayDetails = workdays
|
||||||
|
};
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
throw new Exception("An error occurred while fetching the day's details", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public DayDetailsLoggedUserDto GetDayDetailsForLoggedUser(int userId, DateTime date)
|
||||||
|
{
|
||||||
|
using (var session = SessionFactory.OpenSession())
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Fetch workdays for the specified user on the given date
|
||||||
|
var startOfDay = date.Date;
|
||||||
|
var endOfDay = startOfDay.AddDays(1);
|
||||||
|
|
||||||
|
var workdays = session.Query<Workday>()
|
||||||
|
.Where(w => w.User.UserId == userId && w.StartTime >= startOfDay && w.StartTime < endOfDay)
|
||||||
|
.Select(w => new Workday
|
||||||
|
{
|
||||||
|
StartTime = w.StartTime,
|
||||||
|
EndTime = w.EndTime ?? DateTime.Today.AddHours(17),
|
||||||
|
Absence = w.Absence,
|
||||||
|
})
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
TimeSpan totalWorkedHours = TimeSpan.Zero;
|
||||||
|
|
||||||
|
// Calculate total worked hours and adjust if there's an absence
|
||||||
|
foreach (var workday in workdays)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(workday.Absence))
|
||||||
|
{
|
||||||
|
totalWorkedHours += workday.WorkedHours;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new DayDetailsLoggedUserDto
|
||||||
|
{
|
||||||
|
UserId = userId,
|
||||||
|
Date = date,
|
||||||
|
TotalWorkedHours = totalWorkedHours.ToString(@"hh\:mm\:ss"),
|
||||||
|
WorkdayDetails = workdays
|
||||||
|
};
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
throw new Exception("An error occurred while fetching the day's details", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public List<Workday> GetWorkdaysByLoggedUser(string userId)
|
||||||
|
{
|
||||||
|
using (var session = SessionFactory.OpenSession())
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
int parsedUserId = Int32.Parse(userId);
|
||||||
|
var workdays = session.Query<Workday>()
|
||||||
|
.Where(w => w.User.UserId == parsedUserId)
|
||||||
|
.Select(w => new Workday
|
||||||
|
{
|
||||||
|
Id = w.Id,
|
||||||
|
StartTime = w.StartTime,
|
||||||
|
EndTime = w.EndTime ?? DateTime.Today.AddHours(17),
|
||||||
|
WorkedHours = (w.EndTime ?? DateTime.Today.AddHours(17)) - w.StartTime,
|
||||||
|
Absence = w.Absence,
|
||||||
|
})
|
||||||
|
.ToList();
|
||||||
|
|
||||||
return workdays;
|
return workdays;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
@ -253,7 +253,7 @@ namespace FirmTracker_Server.nHibernate.Transactions
|
|||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
transaction.Rollback();
|
transaction.Rollback();
|
||||||
throw ex;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user