diff --git a/Marechai.Server/Controllers/BookScansController.cs b/Marechai.Server/Controllers/BookScansController.cs index d0ca0911..148e5f8f 100644 --- a/Marechai.Server/Controllers/BookScansController.cs +++ b/Marechai.Server/Controllers/BookScansController.cs @@ -34,7 +34,6 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Localization; namespace Marechai.Server.Controllers; @@ -53,34 +52,29 @@ public class BookScansController(MarechaiContext context) : ControllerBase [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task GetAsync(Guid id) => await context.BookScans.Where(p => p.Id == id) - .Select(p => new BookScanDto - { - Author = p.Author, - BookId = p.Book.Id, - ColorSpace = p.ColorSpace, - Comments = p.Comments, - CreationDate = p.CreationDate, - ExifVersion = p.ExifVersion, - HorizontalResolution = - p.HorizontalResolution, - Id = p.Id, - ResolutionUnit = - p.ResolutionUnit, - Page = p.Page, - ScannerManufacturer = - p.ScannerManufacturer, - ScannerModel = p.ScannerModel, - SoftwareUsed = p.SoftwareUsed, - Type = p.Type, - UploadDate = p.UploadDate, - UserId = p.UserId, - VerticalResolution = - p.VerticalResolution, - OriginalExtension = - p.OriginalExtension - }) - .FirstOrDefaultAsync(); + public Task GetAsync(Guid id) => context.BookScans.Where(p => p.Id == id) + .Select(p => new BookScanDto + { + Author = p.Author, + BookId = p.Book.Id, + ColorSpace = p.ColorSpace, + Comments = p.Comments, + CreationDate = p.CreationDate, + ExifVersion = p.ExifVersion, + HorizontalResolution = p.HorizontalResolution, + Id = p.Id, + ResolutionUnit = p.ResolutionUnit, + Page = p.Page, + ScannerManufacturer = p.ScannerManufacturer, + ScannerModel = p.ScannerModel, + SoftwareUsed = p.SoftwareUsed, + Type = p.Type, + UploadDate = p.UploadDate, + UserId = p.UserId, + VerticalResolution = p.VerticalResolution, + OriginalExtension = p.OriginalExtension + }) + .FirstOrDefaultAsync(); [HttpPost] [Authorize(Roles = "Admin,UberAdmin")] @@ -89,6 +83,7 @@ public class BookScansController(MarechaiContext context) : ControllerBase public async Task UpdateAsync(BookScanDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return; BookScan model = await context.BookScans.FindAsync(dto.Id); @@ -118,7 +113,9 @@ public class BookScansController(MarechaiContext context) : ControllerBase public async Task CreateAsync(BookScanDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return null; + var model = new BookScan { Author = dto.Author, @@ -154,6 +151,7 @@ public class BookScansController(MarechaiContext context) : ControllerBase public async Task DeleteAsync(Guid id) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return; BookScan item = await context.BookScans.FindAsync(id); @@ -163,4 +161,4 @@ public class BookScansController(MarechaiContext context) : ControllerBase await context.SaveChangesWithUserAsync(userId); } -} +} \ No newline at end of file diff --git a/Marechai.Server/Controllers/BooksController.cs b/Marechai.Server/Controllers/BooksController.cs index be815097..d58bafe8 100644 --- a/Marechai.Server/Controllers/BooksController.cs +++ b/Marechai.Server/Controllers/BooksController.cs @@ -23,7 +23,6 @@ // Copyright © 2003-2025 Natalia Portillo *******************************************************************************/ -using System; using System.Collections.Generic; using System.Linq; using System.Security.Claims; @@ -34,7 +33,6 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Localization; namespace Marechai.Server.Controllers; @@ -46,47 +44,47 @@ public class BooksController(MarechaiContext context) : ControllerBase [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task> GetAsync() => await context.Books.OrderBy(b => b.NativeTitle) - .ThenBy(b => b.Published) - .ThenBy(b => b.Title) - .Select(b => new BookDto - { - Id = b.Id, - Title = b.Title, - NativeTitle = b.NativeTitle, - Published = b.Published, - Synopsis = b.Synopsis, - Isbn = b.Isbn, - CountryId = b.CountryId, - Pages = b.Pages, - Edition = b.Edition, - PreviousId = b.PreviousId, - SourceId = b.SourceId, - Country = b.Country.Name - }) - .ToListAsync(); + public Task> GetAsync() => context.Books.OrderBy(b => b.NativeTitle) + .ThenBy(b => b.Published) + .ThenBy(b => b.Title) + .Select(b => new BookDto + { + Id = b.Id, + Title = b.Title, + NativeTitle = b.NativeTitle, + Published = b.Published, + Synopsis = b.Synopsis, + Isbn = b.Isbn, + CountryId = b.CountryId, + Pages = b.Pages, + Edition = b.Edition, + PreviousId = b.PreviousId, + SourceId = b.SourceId, + Country = b.Country.Name + }) + .ToListAsync(); [HttpGet] [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task GetAsync(long id) => await context.Books.Where(b => b.Id == id) - .Select(b => new BookDto - { - Id = b.Id, - Title = b.Title, - NativeTitle = b.NativeTitle, - Published = b.Published, - Synopsis = b.Synopsis, - Isbn = b.Isbn, - CountryId = b.CountryId, - Pages = b.Pages, - Edition = b.Edition, - PreviousId = b.PreviousId, - SourceId = b.SourceId, - Country = b.Country.Name - }) - .FirstOrDefaultAsync(); + public Task GetAsync(long id) => context.Books.Where(b => b.Id == id) + .Select(b => new BookDto + { + Id = b.Id, + Title = b.Title, + NativeTitle = b.NativeTitle, + Published = b.Published, + Synopsis = b.Synopsis, + Isbn = b.Isbn, + CountryId = b.CountryId, + Pages = b.Pages, + Edition = b.Edition, + PreviousId = b.PreviousId, + SourceId = b.SourceId, + Country = b.Country.Name + }) + .FirstOrDefaultAsync(); [HttpPost] [Authorize(Roles = "Admin,UberAdmin")] @@ -95,6 +93,7 @@ public class BooksController(MarechaiContext context) : ControllerBase public async Task UpdateAsync(BookDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return; Book model = await context.Books.FindAsync(dto.Id); @@ -120,7 +119,9 @@ public class BooksController(MarechaiContext context) : ControllerBase public async Task CreateAsync(BookDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return 0; + var model = new Book { Title = dto.Title, @@ -155,6 +156,7 @@ public class BooksController(MarechaiContext context) : ControllerBase public async Task DeleteAsync(long id) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return; Book item = await context.Books.FindAsync(id); @@ -164,4 +166,4 @@ public class BooksController(MarechaiContext context) : ControllerBase await context.SaveChangesWithUserAsync(userId); } -} +} \ No newline at end of file diff --git a/Marechai.Server/Controllers/CompaniesByBookController.cs b/Marechai.Server/Controllers/CompaniesByBookController.cs index 6de79100..1621fda4 100644 --- a/Marechai.Server/Controllers/CompaniesByBookController.cs +++ b/Marechai.Server/Controllers/CompaniesByBookController.cs @@ -23,7 +23,6 @@ // Copyright © 2003-2025 Natalia Portillo *******************************************************************************/ -using System; using System.Collections.Generic; using System.Linq; using System.Security.Claims; @@ -34,7 +33,6 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Localization; namespace Marechai.Server.Controllers; @@ -46,20 +44,20 @@ public class CompaniesByBookController(MarechaiContext context) : ControllerBase [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task> GetByBook(long bookId) => await context.CompaniesByBooks - .Where(p => p.BookId == bookId) - .Select(p => new CompanyByBookDto - { - Id = p.Id, - Company = p.Company.Name, - CompanyId = p.CompanyId, - RoleId = p.RoleId, - Role = p.Role.Name, - BookId = p.BookId - }) - .OrderBy(p => p.Company) - .ThenBy(p => p.Role) - .ToListAsync(); + public Task> GetByBook(long bookId) => context.CompaniesByBooks + .Where(p => p.BookId == bookId) + .Select(p => new CompanyByBookDto + { + Id = p.Id, + Company = p.Company.Name, + CompanyId = p.CompanyId, + RoleId = p.RoleId, + Role = p.Role.Name, + BookId = p.BookId + }) + .OrderBy(p => p.Company) + .ThenBy(p => p.Role) + .ToListAsync(); [HttpDelete] [Authorize(Roles = "Admin,UberAdmin")] @@ -68,6 +66,7 @@ public class CompaniesByBookController(MarechaiContext context) : ControllerBase public async Task DeleteAsync(long id) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return; CompaniesByBook item = await context.CompaniesByBooks.FindAsync(id); @@ -85,7 +84,9 @@ public class CompaniesByBookController(MarechaiContext context) : ControllerBase public async Task CreateAsync(int companyId, long bookId, string roleId) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return 0; + var item = new CompaniesByBook { CompanyId = companyId, @@ -98,4 +99,4 @@ public class CompaniesByBookController(MarechaiContext context) : ControllerBase return item.Id; } -} +} \ No newline at end of file diff --git a/Marechai.Server/Controllers/CompaniesByDocumentController.cs b/Marechai.Server/Controllers/CompaniesByDocumentController.cs index 4684d027..de7a23d2 100644 --- a/Marechai.Server/Controllers/CompaniesByDocumentController.cs +++ b/Marechai.Server/Controllers/CompaniesByDocumentController.cs @@ -23,7 +23,6 @@ // Copyright © 2003-2025 Natalia Portillo *******************************************************************************/ -using System; using System.Collections.Generic; using System.Linq; using System.Security.Claims; @@ -34,7 +33,6 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Localization; namespace Marechai.Server.Controllers; @@ -46,20 +44,20 @@ public class CompaniesByDocumentController(MarechaiContext context) : Controller [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task> GetByDocument(long documentId) => await context - .CompaniesByDocuments.Where(p => p.DocumentId == documentId) - .Select(p => new CompanyByDocumentDto - { - Id = p.Id, - Company = p.Company.Name, - CompanyId = p.CompanyId, - RoleId = p.RoleId, - Role = p.Role.Name, - DocumentId = p.DocumentId - }) - .OrderBy(p => p.Company) - .ThenBy(p => p.Role) - .ToListAsync(); + public Task> GetByDocument(long documentId) => context.CompaniesByDocuments + .Where(p => p.DocumentId == documentId) + .Select(p => new CompanyByDocumentDto + { + Id = p.Id, + Company = p.Company.Name, + CompanyId = p.CompanyId, + RoleId = p.RoleId, + Role = p.Role.Name, + DocumentId = p.DocumentId + }) + .OrderBy(p => p.Company) + .ThenBy(p => p.Role) + .ToListAsync(); [HttpDelete] [Authorize(Roles = "Admin,UberAdmin")] @@ -68,6 +66,7 @@ public class CompaniesByDocumentController(MarechaiContext context) : Controller public async Task DeleteAsync(long id) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return; CompaniesByDocument item = await context.CompaniesByDocuments.FindAsync(id); @@ -85,7 +84,9 @@ public class CompaniesByDocumentController(MarechaiContext context) : Controller public async Task CreateAsync(int companyId, long documentId, string roleId) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return 0; + var item = new CompaniesByDocument { CompanyId = companyId, @@ -98,4 +99,4 @@ public class CompaniesByDocumentController(MarechaiContext context) : Controller return item.Id; } -} +} \ No newline at end of file diff --git a/Marechai.Server/Controllers/CompaniesByMagazineController.cs b/Marechai.Server/Controllers/CompaniesByMagazineController.cs index 05c12686..b65867e0 100644 --- a/Marechai.Server/Controllers/CompaniesByMagazineController.cs +++ b/Marechai.Server/Controllers/CompaniesByMagazineController.cs @@ -23,7 +23,6 @@ // Copyright © 2003-2025 Natalia Portillo *******************************************************************************/ -using System; using System.Collections.Generic; using System.Linq; using System.Security.Claims; @@ -34,7 +33,6 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Localization; namespace Marechai.Server.Controllers; @@ -46,20 +44,20 @@ public class CompaniesByMagazineController(MarechaiContext context) : Controller [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task> GetByMagazine(long magazineId) => await context - .CompaniesByMagazines.Where(p => p.MagazineId == magazineId) - .Select(p => new CompanyByMagazineDto - { - Id = p.Id, - Company = p.Company.Name, - CompanyId = p.CompanyId, - RoleId = p.RoleId, - Role = p.Role.Name, - MagazineId = p.MagazineId - }) - .OrderBy(p => p.Company) - .ThenBy(p => p.Role) - .ToListAsync(); + public Task> GetByMagazine(long magazineId) => context.CompaniesByMagazines + .Where(p => p.MagazineId == magazineId) + .Select(p => new CompanyByMagazineDto + { + Id = p.Id, + Company = p.Company.Name, + CompanyId = p.CompanyId, + RoleId = p.RoleId, + Role = p.Role.Name, + MagazineId = p.MagazineId + }) + .OrderBy(p => p.Company) + .ThenBy(p => p.Role) + .ToListAsync(); [HttpDelete] [Authorize(Roles = "Admin,UberAdmin")] @@ -68,6 +66,7 @@ public class CompaniesByMagazineController(MarechaiContext context) : Controller public async Task DeleteAsync(long id) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return; CompaniesByMagazine item = await context.CompaniesByMagazines.FindAsync(id); @@ -85,7 +84,9 @@ public class CompaniesByMagazineController(MarechaiContext context) : Controller public async Task CreateAsync(int companyId, long magazineId, string roleId) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return 0; + var item = new CompaniesByMagazine { CompanyId = companyId, @@ -98,4 +99,4 @@ public class CompaniesByMagazineController(MarechaiContext context) : Controller return item.Id; } -} +} \ No newline at end of file diff --git a/Marechai.Server/Controllers/CompaniesController.cs b/Marechai.Server/Controllers/CompaniesController.cs index c642e0d6..d47a4a8d 100644 --- a/Marechai.Server/Controllers/CompaniesController.cs +++ b/Marechai.Server/Controllers/CompaniesController.cs @@ -23,7 +23,6 @@ // Copyright © 2003-2025 Natalia Portillo *******************************************************************************/ -using System; using System.Collections.Generic; using System.Linq; using System.Security.Claims; @@ -46,80 +45,70 @@ public class CompaniesController(MarechaiContext context, IStringLocalizer> GetAsync() => await context.Companies.Include(c => c.Logos) - .OrderBy(c => c.Name) - .Select(c => new CompanyDto - { - Id = c.Id, - LastLogo = - c.Logos - .OrderByDescending(l => l.Year) - .FirstOrDefault() - .Guid, - Name = c.Name, - Founded = c.Founded, - Sold = c.Sold, - SoldToId = c.SoldToId, - CountryId = c.CountryId, - Status = c.Status, - Website = c.Website, - Twitter = c.Twitter, - Facebook = c.Facebook, - Address = c.Address, - City = c.City, - Province = c.Province, - PostalCode = c.PostalCode, - Country = c.Country.Name, - FoundedDayIsUnknown = - c.FoundedDayIsUnknown, - FoundedMonthIsUnknown = - c.FoundedMonthIsUnknown, - SoldDayIsUnknown = - c.SoldDayIsUnknown, - SoldMonthIsUnknown = - c.SoldMonthIsUnknown, - LegalName = c.LegalName - }) - .ToListAsync(); + public Task> GetAsync() => context.Companies.Include(c => c.Logos) + .OrderBy(c => c.Name) + .Select(c => new CompanyDto + { + Id = c.Id, + LastLogo = + c.Logos.OrderByDescending(l => l.Year) + .FirstOrDefault() + .Guid, + Name = c.Name, + Founded = c.Founded, + Sold = c.Sold, + SoldToId = c.SoldToId, + CountryId = c.CountryId, + Status = c.Status, + Website = c.Website, + Twitter = c.Twitter, + Facebook = c.Facebook, + Address = c.Address, + City = c.City, + Province = c.Province, + PostalCode = c.PostalCode, + Country = c.Country.Name, + FoundedDayIsUnknown = c.FoundedDayIsUnknown, + FoundedMonthIsUnknown = c.FoundedMonthIsUnknown, + SoldDayIsUnknown = c.SoldDayIsUnknown, + SoldMonthIsUnknown = c.SoldMonthIsUnknown, + LegalName = c.LegalName + }) + .ToListAsync(); [HttpGet] [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task GetAsync(int id) => await context.Companies.Where(c => c.Id == id) - .Select(c => new CompanyDto - { - Id = c.Id, - LastLogo = - c.Logos - .OrderByDescending(l => l.Year) - .FirstOrDefault() - .Guid, - Name = c.Name, - Founded = c.Founded, - Sold = c.Sold, - SoldToId = c.SoldToId, - CountryId = c.CountryId, - Status = c.Status, - Website = c.Website, - Twitter = c.Twitter, - Facebook = c.Facebook, - Address = c.Address, - City = c.City, - Province = c.Province, - PostalCode = c.PostalCode, - Country = c.Country.Name, - FoundedDayIsUnknown = - c.FoundedDayIsUnknown, - FoundedMonthIsUnknown = - c.FoundedMonthIsUnknown, - SoldDayIsUnknown = - c.SoldDayIsUnknown, - SoldMonthIsUnknown = - c.SoldMonthIsUnknown, - LegalName = c.LegalName - }) - .FirstOrDefaultAsync(); + public Task GetAsync(int id) => context.Companies.Where(c => c.Id == id) + .Select(c => new CompanyDto + { + Id = c.Id, + LastLogo = + c.Logos.OrderByDescending(l => l.Year) + .FirstOrDefault() + .Guid, + Name = c.Name, + Founded = c.Founded, + Sold = c.Sold, + SoldToId = c.SoldToId, + CountryId = c.CountryId, + Status = c.Status, + Website = c.Website, + Twitter = c.Twitter, + Facebook = c.Facebook, + Address = c.Address, + City = c.City, + Province = c.Province, + PostalCode = c.PostalCode, + Country = c.Country.Name, + FoundedDayIsUnknown = c.FoundedDayIsUnknown, + FoundedMonthIsUnknown = c.FoundedMonthIsUnknown, + SoldDayIsUnknown = c.SoldDayIsUnknown, + SoldMonthIsUnknown = c.SoldMonthIsUnknown, + LegalName = c.LegalName + }) + .FirstOrDefaultAsync(); [HttpPost] [Authorize(Roles = "Admin,UberAdmin")] @@ -128,6 +117,7 @@ public class CompaniesController(MarechaiContext context, IStringLocalizer CreateAsync(CompanyDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return 0; + var model = new Company { Name = dto.Name, @@ -194,15 +186,15 @@ public class CompaniesController(MarechaiContext context, IStringLocalizer> GetMachinesAsync(int id) => await context.Machines.Where(m => m.CompanyId == id) - .OrderBy(m => m.Name) - .Select(m => new Machine - { - Id = m.Id, - Name = m.Name, - Type = m.Type - }) - .ToListAsync(); + public Task> GetMachinesAsync(int id) => context.Machines.Where(m => m.CompanyId == id) + .OrderBy(m => m.Name) + .Select(m => new Machine + { + Id = m.Id, + Name = m.Name, + Type = m.Type + }) + .ToListAsync(); [HttpGet] [AllowAnonymous] @@ -219,12 +211,12 @@ public class CompaniesController(MarechaiContext context, IStringLocalizer GetSoldToAsync(int? id) => await context.Companies.Select(c => new Company - { - Id = c.Id, - Name = c.Name - }) - .FirstOrDefaultAsync(c => c.Id == id); + public Task GetSoldToAsync(int? id) => context.Companies.Select(c => new Company + { + Id = c.Id, + Name = c.Name + }) + .FirstOrDefaultAsync(c => c.Id == id); [HttpGet] [AllowAnonymous] @@ -237,8 +229,7 @@ public class CompaniesController(MarechaiContext context, IStringLocalizer> GetCompaniesByCountryAsync(int countryId) => context.Companies - .Include(c => c.Logos) + public Task> GetCompaniesByCountryAsync(int countryId) => context.Companies.Include(c => c.Logos) .Where(c => c.CountryId == countryId) .OrderBy(c => c.Name) .Select(c => new CompanyDto @@ -271,6 +262,7 @@ public class CompaniesController(MarechaiContext context, IStringLocalizer GetDescriptionAsync(int id) => await context.CompanyDescriptions - .Where(d => d.CompanyId == id) - .Select(d => new CompanyDescriptionDto - { - Id = d.Id, - CompanyId = d.CompanyId, - Html = d.Html, - Markdown = d.Text - }) - .FirstOrDefaultAsync(); + public Task GetDescriptionAsync(int id) => context.CompanyDescriptions + .Where(d => d.CompanyId == id) + .Select(d => new CompanyDescriptionDto + { + Id = d.Id, + CompanyId = d.CompanyId, + Html = d.Html, + Markdown = d.Text + }) + .FirstOrDefaultAsync(); [HttpPost] [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task CreateOrUpdateDescriptionAsync(int id, CompanyDescriptionDto description) + public async Task CreateOrUpdateDescriptionAsync(int id, CompanyDescriptionDto description) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return 0; CompanyDescription current = await context.CompanyDescriptions.FirstOrDefaultAsync(d => d.CompanyId == id); @@ -327,4 +320,4 @@ public class CompaniesController(MarechaiContext context, IStringLocalizer GetMinimumYearAsync() => context.Machines - .Where(t => t.Type == MachineType.Computer && - t.Introduced.HasValue && - t.Introduced.Value.Year > 1000) - .MinAsync(t => t.Introduced.Value.Year); + .Where(t => t.Type == MachineType.Computer && + t.Introduced.HasValue && + t.Introduced.Value.Year > 1000) + .MinAsync(t => t.Introduced.Value.Year); [HttpGet] [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] public Task GetMaximumYearAsync() => context.Machines - .Where(t => t.Type == MachineType.Computer && - t.Introduced.HasValue && - t.Introduced.Value.Year > 1000) - .MaxAsync(t => t.Introduced.Value.Year); + .Where(t => t.Type == MachineType.Computer && + t.Introduced.HasValue && + t.Introduced.Value.Year > 1000) + .MaxAsync(t => t.Introduced.Value.Year); [HttpGet] [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task> GetComputersByLetterAsync(char c) => await context.Machines - .Include(m => m.Company) - .Where(m => m.Type == MachineType.Computer && EF.Functions.Like(m.Name, $"{c}%")) - .OrderBy(m => m.Company.Name) - .ThenBy(m => m.Name) - .Select(m => new MachineDto - { - Id = m.Id, - Name = m.Name, - Company = m.Company.Name - }) - .ToListAsync(); + public Task> GetComputersByLetterAsync(char c) => context.Machines.Include(m => m.Company) + .Where(m => + m.Type == MachineType.Computer && + EF.Functions.Like(m.Name, $"{c}%")) + .OrderBy(m => m.Company.Name) + .ThenBy(m => m.Name) + .Select(m => new MachineDto + { + Id = m.Id, + Name = m.Name, + Company = m.Company.Name + }) + .ToListAsync(); [HttpGet] [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task> GetComputersByYearAsync(int year) => await context.Machines - .Include(m => m.Company) - .Where(m => m.Type == MachineType.Computer && m.Introduced != null && m.Introduced.Value.Year == year) - .OrderBy(m => m.Company.Name) - .ThenBy(m => m.Name) - .Select(m => new MachineDto - { - Id = m.Id, - Name = m.Name, - Company = m.Company.Name - }) - .ToListAsync(); + public Task> GetComputersByYearAsync(int year) => context.Machines.Include(m => m.Company) + .Where(m => + m.Type == MachineType.Computer && + m.Introduced != null && + m.Introduced.Value.Year == year) + .OrderBy(m => m.Company.Name) + .ThenBy(m => m.Name) + .Select(m => new MachineDto + { + Id = m.Id, + Name = m.Name, + Company = m.Company.Name + }) + .ToListAsync(); [HttpGet] [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task> GetComputersAsync() => await context.Machines.Include(m => m.Company) - .Where(m => m.Type == MachineType.Computer) - .OrderBy(m => m.Company.Name) - .ThenBy(m => m.Name) - .Select(m => new MachineDto - { - Id = m.Id, - Name = m.Name, - Company = m.Company.Name - }) - .ToListAsync(); -} + public Task> GetComputersAsync() => context.Machines.Include(m => m.Company) + .Where(m => m.Type == MachineType.Computer) + .OrderBy(m => m.Company.Name) + .ThenBy(m => m.Name) + .Select(m => new MachineDto + { + Id = m.Id, + Name = m.Name, + Company = m.Company.Name + }) + .ToListAsync(); +} \ No newline at end of file diff --git a/Marechai.Server/Controllers/ConsolesController.cs b/Marechai.Server/Controllers/ConsolesController.cs index 76a024bd..4d8aec5a 100644 --- a/Marechai.Server/Controllers/ConsolesController.cs +++ b/Marechai.Server/Controllers/ConsolesController.cs @@ -23,10 +23,7 @@ // Copyright © 2003-2025 Natalia Portillo *******************************************************************************/ -using System; using System.Collections.Generic; -using System.Linq; -using System.Security.Claims; using System.Threading.Tasks; using Marechai.Data.Dtos; using Marechai.Database.Models; @@ -34,7 +31,6 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Localization; namespace Marechai.Server.Controllers; @@ -54,68 +50,71 @@ public class ConsolesController(MarechaiContext context) : ControllerBase [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] public Task GetMinimumYearAsync() => context.Machines - .Where(t => t.Type == MachineType.Console && - t.Introduced.HasValue && - t.Introduced.Value.Year > 1000) - .MinAsync(t => t.Introduced.Value.Year); + .Where(t => t.Type == MachineType.Console && + t.Introduced.HasValue && + t.Introduced.Value.Year > 1000) + .MinAsync(t => t.Introduced.Value.Year); [HttpGet] [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] public Task GetMaximumYearAsync() => context.Machines - .Where(t => t.Type == MachineType.Console && - t.Introduced.HasValue && - t.Introduced.Value.Year > 1000) - .MaxAsync(t => t.Introduced.Value.Year); + .Where(t => t.Type == MachineType.Console && + t.Introduced.HasValue && + t.Introduced.Value.Year > 1000) + .MaxAsync(t => t.Introduced.Value.Year); [HttpGet] [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task> GetConsolesByLetterAsync(char c) => await context.Machines - .Include(m => m.Company) - .Where(m => m.Type == MachineType.Console && EF.Functions.Like(m.Name, $"{c}%")) - .OrderBy(m => m.Company.Name) - .ThenBy(m => m.Name) - .Select(m => new MachineDto - { - Id = m.Id, - Name = m.Name, - Company = m.Company.Name - }) - .ToListAsync(); + public Task> GetConsolesByLetterAsync(char c) => context.Machines.Include(m => m.Company) + .Where(m => + m.Type == MachineType.Console && + EF.Functions.Like(m.Name, $"{c}%")) + .OrderBy(m => m.Company.Name) + .ThenBy(m => m.Name) + .Select(m => new MachineDto + { + Id = m.Id, + Name = m.Name, + Company = m.Company.Name + }) + .ToListAsync(); [HttpGet] [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task> GetConsolesByYearAsync(int year) => await context.Machines - .Include(m => m.Company) - .Where(m => m.Type == MachineType.Console && m.Introduced != null && m.Introduced.Value.Year == year) - .OrderBy(m => m.Company.Name) - .ThenBy(m => m.Name) - .Select(m => new MachineDto - { - Id = m.Id, - Name = m.Name, - Company = m.Company.Name - }) - .ToListAsync(); + public Task> GetConsolesByYearAsync(int year) => context.Machines.Include(m => m.Company) + .Where(m => + m.Type == MachineType.Console && + m.Introduced != null && + m.Introduced.Value.Year == year) + .OrderBy(m => m.Company.Name) + .ThenBy(m => m.Name) + .Select(m => new MachineDto + { + Id = m.Id, + Name = m.Name, + Company = m.Company.Name + }) + .ToListAsync(); [HttpGet] [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task> GetConsolesAsync() => await context.Machines.Include(m => m.Company) - .Where(m => m.Type == MachineType.Console) - .OrderBy(m => m.Company.Name) - .ThenBy(m => m.Name) - .Select(m => new MachineDto - { - Id = m.Id, - Name = m.Name, - Company = m.Company.Name - }) - .ToListAsync(); -} + public Task> GetConsolesAsync() => context.Machines.Include(m => m.Company) + .Where(m => m.Type == MachineType.Console) + .OrderBy(m => m.Company.Name) + .ThenBy(m => m.Name) + .Select(m => new MachineDto + { + Id = m.Id, + Name = m.Name, + Company = m.Company.Name + }) + .ToListAsync(); +} \ No newline at end of file diff --git a/Marechai.Server/Controllers/CurrencyInflationController.cs b/Marechai.Server/Controllers/CurrencyInflationController.cs index e4af14f9..3bcbae5c 100644 --- a/Marechai.Server/Controllers/CurrencyInflationController.cs +++ b/Marechai.Server/Controllers/CurrencyInflationController.cs @@ -23,7 +23,6 @@ // Copyright © 2003-2025 Natalia Portillo *******************************************************************************/ -using System; using System.Collections.Generic; using System.Linq; using System.Security.Claims; @@ -34,7 +33,6 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Localization; namespace Marechai.Server.Controllers; @@ -46,34 +44,32 @@ public class CurrencyInflationController(MarechaiContext context) : ControllerBa [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task> GetAsync() => await context.CurrenciesInflation - .OrderBy(i => i.Currency.Name) - .ThenBy(i => i.Year) - .Select(i => new CurrencyInflationDto - { - Id = i.Id, - CurrencyCode = i.Currency.Code, - CurrencyName = i.Currency.Name, - Year = i.Year, - Inflation = i.Inflation - }) - .ToListAsync(); + public Task> GetAsync() => context.CurrenciesInflation.OrderBy(i => i.Currency.Name) + .ThenBy(i => i.Year) + .Select(i => new CurrencyInflationDto + { + Id = i.Id, + CurrencyCode = i.Currency.Code, + CurrencyName = i.Currency.Name, + Year = i.Year, + Inflation = i.Inflation + }) + .ToListAsync(); [HttpGet] [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task GetAsync(int id) => await context.CurrenciesInflation - .Where(b => b.Id == id) - .Select(i => new CurrencyInflationDto - { - Id = i.Id, - CurrencyCode = i.Currency.Code, - CurrencyName = i.Currency.Name, - Year = i.Year, - Inflation = i.Inflation - }) - .FirstOrDefaultAsync(); + public Task GetAsync(int id) => context.CurrenciesInflation.Where(b => b.Id == id) + .Select(i => new CurrencyInflationDto + { + Id = i.Id, + CurrencyCode = i.Currency.Code, + CurrencyName = i.Currency.Name, + Year = i.Year, + Inflation = i.Inflation + }) + .FirstOrDefaultAsync(); [HttpPost] [Authorize(Roles = "Admin,UberAdmin")] @@ -82,6 +78,7 @@ public class CurrencyInflationController(MarechaiContext context) : ControllerBa public async Task UpdateAsync(CurrencyInflationDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return; CurrencyInflation model = await context.CurrenciesInflation.FindAsync(dto.Id); @@ -100,7 +97,9 @@ public class CurrencyInflationController(MarechaiContext context) : ControllerBa public async Task CreateAsync(CurrencyInflationDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return 0; + var model = new CurrencyInflation { CurrencyCode = dto.CurrencyCode, @@ -121,6 +120,7 @@ public class CurrencyInflationController(MarechaiContext context) : ControllerBa public async Task DeleteAsync(int id) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return; CurrencyInflation item = await context.CurrenciesInflation.FindAsync(id); @@ -130,4 +130,4 @@ public class CurrencyInflationController(MarechaiContext context) : ControllerBa await context.SaveChangesWithUserAsync(userId); } -} +} \ No newline at end of file diff --git a/Marechai.Server/Controllers/CurrencyPeggingController.cs b/Marechai.Server/Controllers/CurrencyPeggingController.cs index 01d21373..62e15e5d 100644 --- a/Marechai.Server/Controllers/CurrencyPeggingController.cs +++ b/Marechai.Server/Controllers/CurrencyPeggingController.cs @@ -23,7 +23,6 @@ // Copyright © 2003-2025 Natalia Portillo *******************************************************************************/ -using System; using System.Collections.Generic; using System.Linq; using System.Security.Claims; @@ -34,7 +33,6 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Localization; namespace Marechai.Server.Controllers; @@ -46,42 +44,40 @@ public class CurrencyPeggingController(MarechaiContext context) : ControllerBase [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task> GetAsync() => await context.CurrenciesPegging - .OrderBy(i => i.Source.Name) - .ThenBy(i => i.Destination.Name) - .ThenBy(i => i.Start) - .ThenBy(i => i.End) - .Select(i => new CurrencyPeggingDto - { - Id = i.Id, - SourceCode = i.Source.Code, - SourceName = i.Source.Name, - DestinationCode = i.Source.Code, - DestinationName = i.Source.Name, - Ratio = i.Ratio, - Start = i.Start, - End = i.End - }) - .ToListAsync(); + public Task> GetAsync() => context.CurrenciesPegging.OrderBy(i => i.Source.Name) + .ThenBy(i => i.Destination.Name) + .ThenBy(i => i.Start) + .ThenBy(i => i.End) + .Select(i => new CurrencyPeggingDto + { + Id = i.Id, + SourceCode = i.Source.Code, + SourceName = i.Source.Name, + DestinationCode = i.Source.Code, + DestinationName = i.Source.Name, + Ratio = i.Ratio, + Start = i.Start, + End = i.End + }) + .ToListAsync(); [HttpGet] [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task GetAsync(int id) => await context.CurrenciesPegging - .Where(b => b.Id == id) - .Select(i => new CurrencyPeggingDto - { - Id = i.Id, - SourceCode = i.Source.Code, - SourceName = i.Source.Name, - DestinationCode = i.Destination.Code, - DestinationName = i.Destination.Name, - Ratio = i.Ratio, - Start = i.Start, - End = i.End - }) - .FirstOrDefaultAsync(); + public Task GetAsync(int id) => context.CurrenciesPegging.Where(b => b.Id == id) + .Select(i => new CurrencyPeggingDto + { + Id = i.Id, + SourceCode = i.Source.Code, + SourceName = i.Source.Name, + DestinationCode = i.Destination.Code, + DestinationName = i.Destination.Name, + Ratio = i.Ratio, + Start = i.Start, + End = i.End + }) + .FirstOrDefaultAsync(); [HttpPost] [Authorize(Roles = "Admin,UberAdmin")] @@ -90,6 +86,7 @@ public class CurrencyPeggingController(MarechaiContext context) : ControllerBase public async Task UpdateAsync(CurrencyPeggingDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return; CurrencyPegging model = await context.CurrenciesPegging.FindAsync(dto.Id); @@ -110,7 +107,9 @@ public class CurrencyPeggingController(MarechaiContext context) : ControllerBase public async Task CreateAsync(CurrencyPeggingDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return 0; + var model = new CurrencyPegging { SourceCode = dto.SourceCode, @@ -133,6 +132,7 @@ public class CurrencyPeggingController(MarechaiContext context) : ControllerBase public async Task DeleteAsync(int id) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return; CurrencyPegging item = await context.CurrenciesPegging.FindAsync(id); @@ -142,4 +142,4 @@ public class CurrencyPeggingController(MarechaiContext context) : ControllerBase await context.SaveChangesWithUserAsync(userId); } -} +} \ No newline at end of file diff --git a/Marechai.Server/Controllers/DocumentCompaniesController.cs b/Marechai.Server/Controllers/DocumentCompaniesController.cs index a8b897cb..12e79b53 100644 --- a/Marechai.Server/Controllers/DocumentCompaniesController.cs +++ b/Marechai.Server/Controllers/DocumentCompaniesController.cs @@ -23,7 +23,6 @@ // Copyright © 2003-2025 Natalia Portillo *******************************************************************************/ -using System; using System.Collections.Generic; using System.Linq; using System.Security.Claims; @@ -34,7 +33,6 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Localization; namespace Marechai.Server.Controllers; @@ -46,30 +44,28 @@ public class DocumentCompaniesController(MarechaiContext context) : ControllerBa [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task> GetAsync() => await context.DocumentCompanies - .OrderBy(c => c.Name) - .Select(d => new DocumentCompanyDto - { - Id = d.Id, - Name = d.Name, - Company = d.Company.Name, - CompanyId = d.CompanyId - }) - .ToListAsync(); + public Task> GetAsync() => context.DocumentCompanies.OrderBy(c => c.Name) + .Select(d => new DocumentCompanyDto + { + Id = d.Id, + Name = d.Name, + Company = d.Company.Name, + CompanyId = d.CompanyId + }) + .ToListAsync(); [HttpGet] [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task GetAsync(int id) => await context.DocumentCompanies - .Where(d => d.Id == id) - .Select(d => new DocumentCompanyDto - { - Id = d.Id, - Name = d.Name, - CompanyId = d.CompanyId - }) - .FirstOrDefaultAsync(); + public Task GetAsync(int id) => context.DocumentCompanies.Where(d => d.Id == id) + .Select(d => new DocumentCompanyDto + { + Id = d.Id, + Name = d.Name, + CompanyId = d.CompanyId + }) + .FirstOrDefaultAsync(); [HttpPost] [Authorize(Roles = "Admin,UberAdmin")] @@ -78,6 +74,7 @@ public class DocumentCompaniesController(MarechaiContext context) : ControllerBa public async Task UpdateAsync(DocumentCompanyDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return; DocumentCompany model = await context.DocumentCompanies.FindAsync(dto.Id); @@ -96,7 +93,9 @@ public class DocumentCompaniesController(MarechaiContext context) : ControllerBa public async Task CreateAsync(DocumentCompanyDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return 0; + var model = new DocumentCompany { CompanyId = dto.CompanyId, @@ -116,6 +115,7 @@ public class DocumentCompaniesController(MarechaiContext context) : ControllerBa public async Task DeleteAsync(int id) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return; DocumentCompany item = await context.DocumentCompanies.FindAsync(id); @@ -125,4 +125,4 @@ public class DocumentCompaniesController(MarechaiContext context) : ControllerBa await context.SaveChangesWithUserAsync(userId); } -} +} \ No newline at end of file diff --git a/Marechai.Server/Controllers/DocumentPeopleController.cs b/Marechai.Server/Controllers/DocumentPeopleController.cs index 8b66ffe5..4085601d 100644 --- a/Marechai.Server/Controllers/DocumentPeopleController.cs +++ b/Marechai.Server/Controllers/DocumentPeopleController.cs @@ -23,7 +23,6 @@ // Copyright © 2003-2025 Natalia Portillo *******************************************************************************/ -using System; using System.Collections.Generic; using System.Linq; using System.Security.Claims; @@ -34,7 +33,6 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Localization; namespace Marechai.Server.Controllers; @@ -46,35 +44,34 @@ public class DocumentPeopleController(MarechaiContext context) : ControllerBase [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task> GetAsync() => await context.DocumentPeople - .OrderBy(d => d.DisplayName) - .ThenBy(d => d.Alias) - .ThenBy(d => d.Name) - .ThenBy(d => d.Surname) - .Select(d => new DocumentPersonDto - { - Id = d.Id, - Name = d.FullName, - Person = d.Person.FullName, - PersonId = d.PersonId - }) - .ToListAsync(); + public Task> GetAsync() => context.DocumentPeople.OrderBy(d => d.DisplayName) + .ThenBy(d => d.Alias) + .ThenBy(d => d.Name) + .ThenBy(d => d.Surname) + .Select(d => new DocumentPersonDto + { + Id = d.Id, + Name = d.FullName, + Person = d.Person.FullName, + PersonId = d.PersonId + }) + .ToListAsync(); [HttpGet] [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task GetAsync(int id) => await context.DocumentPeople.Where(p => p.Id == id) - .Select(d => new DocumentPersonDto - { - Id = d.Id, - Alias = d.Alias, - Name = d.Name, - Surname = d.Surname, - DisplayName = d.DisplayName, - PersonId = d.PersonId - }) - .FirstOrDefaultAsync(); + public Task GetAsync(int id) => context.DocumentPeople.Where(p => p.Id == id) + .Select(d => new DocumentPersonDto + { + Id = d.Id, + Alias = d.Alias, + Name = d.Name, + Surname = d.Surname, + DisplayName = d.DisplayName, + PersonId = d.PersonId + }) + .FirstOrDefaultAsync(); [HttpPost] [Authorize(Roles = "Admin,UberAdmin")] @@ -83,6 +80,7 @@ public class DocumentPeopleController(MarechaiContext context) : ControllerBase public async Task UpdateAsync(DocumentPersonDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return; DocumentPerson model = await context.DocumentPeople.FindAsync(dto.Id); @@ -104,7 +102,9 @@ public class DocumentPeopleController(MarechaiContext context) : ControllerBase public async Task CreateAsync(DocumentPersonDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return 0; + var model = new DocumentPerson { Alias = dto.Alias, @@ -127,6 +127,7 @@ public class DocumentPeopleController(MarechaiContext context) : ControllerBase public async Task DeleteAsync(int id) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return; DocumentPerson item = await context.DocumentPeople.FindAsync(id); @@ -136,4 +137,4 @@ public class DocumentPeopleController(MarechaiContext context) : ControllerBase await context.SaveChangesWithUserAsync(userId); } -} +} \ No newline at end of file diff --git a/Marechai.Server/Controllers/DocumentRolesController.cs b/Marechai.Server/Controllers/DocumentRolesController.cs index 6309b6af..f9c5907c 100644 --- a/Marechai.Server/Controllers/DocumentRolesController.cs +++ b/Marechai.Server/Controllers/DocumentRolesController.cs @@ -23,10 +23,8 @@ // Copyright © 2003-2025 Natalia Portillo *******************************************************************************/ -using System; using System.Collections.Generic; using System.Linq; -using System.Security.Claims; using System.Threading.Tasks; using Marechai.Data.Dtos; using Marechai.Database.Models; @@ -34,7 +32,6 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Localization; namespace Marechai.Server.Controllers; @@ -46,40 +43,39 @@ public class DocumentRolesController(MarechaiContext context) : ControllerBase [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task> GetAsync() => await context.DocumentRoles.OrderBy(c => c.Name) - .Select(c => new DocumentRoleDto - { - Id = c.Id, - Name = c.Name, - Enabled = c.Enabled - }) - .ToListAsync(); + public Task> GetAsync() => context.DocumentRoles.OrderBy(c => c.Name) + .Select(c => new DocumentRoleDto + { + Id = c.Id, + Name = c.Name, + Enabled = c.Enabled + }) + .ToListAsync(); [HttpGet] [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task> GetEnabledAsync() => await context.DocumentRoles - .Where(c => c.Enabled) - .OrderBy(c => c.Name) - .Select(c => new DocumentRoleDto - { - Id = c.Id, - Name = c.Name, - Enabled = c.Enabled - }) - .ToListAsync(); + public Task> GetEnabledAsync() => context.DocumentRoles.Where(c => c.Enabled) + .OrderBy(c => c.Name) + .Select(c => new DocumentRoleDto + { + Id = c.Id, + Name = c.Name, + Enabled = c.Enabled + }) + .ToListAsync(); [HttpGet] [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task GetAsync(string id) => await context.DocumentRoles.Where(c => c.Id == id) - .Select(c => new DocumentRoleDto - { - Id = c.Id, - Name = c.Name, - Enabled = c.Enabled - }) - .FirstOrDefaultAsync(); -} + public Task GetAsync(string id) => context.DocumentRoles.Where(c => c.Id == id) + .Select(c => new DocumentRoleDto + { + Id = c.Id, + Name = c.Name, + Enabled = c.Enabled + }) + .FirstOrDefaultAsync(); +} \ No newline at end of file diff --git a/Marechai.Server/Controllers/DocumentScansController.cs b/Marechai.Server/Controllers/DocumentScansController.cs index 4af8f7a5..ae307710 100644 --- a/Marechai.Server/Controllers/DocumentScansController.cs +++ b/Marechai.Server/Controllers/DocumentScansController.cs @@ -34,7 +34,6 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Localization; namespace Marechai.Server.Controllers; @@ -53,29 +52,29 @@ public class DocumentScansController(MarechaiContext context) : ControllerBase [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task GetAsync(Guid id) => await context.DocumentScans.Where(p => p.Id == id) - .Select(p => new DocumentScanDto - { - Author = p.Author, - DocumentId = p.Document.Id, - ColorSpace = p.ColorSpace, - Comments = p.Comments, - CreationDate = p.CreationDate, - ExifVersion = p.ExifVersion, - HorizontalResolution = p.HorizontalResolution, - Id = p.Id, - ResolutionUnit = p.ResolutionUnit, - Page = p.Page, - ScannerManufacturer = p.ScannerManufacturer, - ScannerModel = p.ScannerModel, - SoftwareUsed = p.SoftwareUsed, - Type = p.Type, - UploadDate = p.UploadDate, - UserId = p.UserId, - VerticalResolution = p.VerticalResolution, - OriginalExtension = p.OriginalExtension - }) - .FirstOrDefaultAsync(); + public Task GetAsync(Guid id) => context.DocumentScans.Where(p => p.Id == id) + .Select(p => new DocumentScanDto + { + Author = p.Author, + DocumentId = p.Document.Id, + ColorSpace = p.ColorSpace, + Comments = p.Comments, + CreationDate = p.CreationDate, + ExifVersion = p.ExifVersion, + HorizontalResolution = p.HorizontalResolution, + Id = p.Id, + ResolutionUnit = p.ResolutionUnit, + Page = p.Page, + ScannerManufacturer = p.ScannerManufacturer, + ScannerModel = p.ScannerModel, + SoftwareUsed = p.SoftwareUsed, + Type = p.Type, + UploadDate = p.UploadDate, + UserId = p.UserId, + VerticalResolution = p.VerticalResolution, + OriginalExtension = p.OriginalExtension + }) + .FirstOrDefaultAsync(); [HttpPost] [Authorize(Roles = "Admin,UberAdmin")] @@ -84,6 +83,7 @@ public class DocumentScansController(MarechaiContext context) : ControllerBase public async Task UpdateAsync(DocumentScanDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return; DocumentScan model = await context.DocumentScans.FindAsync(dto.Id); @@ -113,7 +113,9 @@ public class DocumentScansController(MarechaiContext context) : ControllerBase public async Task CreateAsync(DocumentScanDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return null; + var model = new DocumentScan { Author = dto.Author, @@ -149,6 +151,7 @@ public class DocumentScansController(MarechaiContext context) : ControllerBase public async Task DeleteAsync(Guid id) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return; DocumentScan item = await context.DocumentScans.FindAsync(id); @@ -158,4 +161,4 @@ public class DocumentScansController(MarechaiContext context) : ControllerBase await context.SaveChangesWithUserAsync(userId); } -} +} \ No newline at end of file diff --git a/Marechai.Server/Controllers/DocumentsByMachineController.cs b/Marechai.Server/Controllers/DocumentsByMachineController.cs index b58994b8..13572c08 100644 --- a/Marechai.Server/Controllers/DocumentsByMachineController.cs +++ b/Marechai.Server/Controllers/DocumentsByMachineController.cs @@ -23,7 +23,6 @@ // Copyright © 2003-2025 Natalia Portillo *******************************************************************************/ -using System; using System.Collections.Generic; using System.Linq; using System.Security.Claims; @@ -34,7 +33,6 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Localization; namespace Marechai.Server.Controllers; @@ -46,17 +44,17 @@ public class DocumentsByMachineController(MarechaiContext context) : ControllerB [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task> GetByDocument(long bookId) => await context.DocumentsByMachines - .Where(p => p.DocumentId == bookId) - .Select(p => new DocumentByMachineDto - { - Id = p.Id, - DocumentId = p.DocumentId, - MachineId = p.MachineId, - Machine = p.Machine.Name - }) - .OrderBy(p => p.Machine) - .ToListAsync(); + public Task> GetByDocument(long bookId) => context.DocumentsByMachines + .Where(p => p.DocumentId == bookId) + .Select(p => new DocumentByMachineDto + { + Id = p.Id, + DocumentId = p.DocumentId, + MachineId = p.MachineId, + Machine = p.Machine.Name + }) + .OrderBy(p => p.Machine) + .ToListAsync(); [HttpDelete] [Authorize(Roles = "Admin,UberAdmin")] @@ -65,6 +63,7 @@ public class DocumentsByMachineController(MarechaiContext context) : ControllerB public async Task DeleteAsync(long id) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return; DocumentsByMachine item = await context.DocumentsByMachines.FindAsync(id); @@ -82,7 +81,9 @@ public class DocumentsByMachineController(MarechaiContext context) : ControllerB public async Task CreateAsync(int machineId, long bookId) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return 0; + var item = new DocumentsByMachine { MachineId = machineId, @@ -94,4 +95,4 @@ public class DocumentsByMachineController(MarechaiContext context) : ControllerB return item.Id; } -} +} \ No newline at end of file diff --git a/Marechai.Server/Controllers/DocumentsByMachineFamilyController.cs b/Marechai.Server/Controllers/DocumentsByMachineFamilyController.cs index ed9ab6d4..d17f732f 100644 --- a/Marechai.Server/Controllers/DocumentsByMachineFamilyController.cs +++ b/Marechai.Server/Controllers/DocumentsByMachineFamilyController.cs @@ -23,7 +23,6 @@ // Copyright © 2003-2025 Natalia Portillo *******************************************************************************/ -using System; using System.Collections.Generic; using System.Linq; using System.Security.Claims; @@ -34,7 +33,6 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Localization; namespace Marechai.Server.Controllers; @@ -46,17 +44,17 @@ public class DocumentsByMachineFamilyController(MarechaiContext context) : Contr [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task> GetByDocument(long bookId) => await context - .DocumentsByMachineFamilies.Where(p => p.DocumentId == bookId) - .Select(p => new DocumentByMachineFamilyDto - { - Id = p.Id, - DocumentId = p.DocumentId, - MachineFamilyId = p.MachineFamilyId, - MachineFamily = p.MachineFamily.Name - }) - .OrderBy(p => p.MachineFamily) - .ToListAsync(); + public Task> GetByDocument(long bookId) => context.DocumentsByMachineFamilies + .Where(p => p.DocumentId == bookId) + .Select(p => new DocumentByMachineFamilyDto + { + Id = p.Id, + DocumentId = p.DocumentId, + MachineFamilyId = p.MachineFamilyId, + MachineFamily = p.MachineFamily.Name + }) + .OrderBy(p => p.MachineFamily) + .ToListAsync(); [HttpDelete] [Authorize(Roles = "Admin,UberAdmin")] @@ -65,6 +63,7 @@ public class DocumentsByMachineFamilyController(MarechaiContext context) : Contr public async Task DeleteAsync(long id) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return; DocumentsByMachineFamily item = await context.DocumentsByMachineFamilies.FindAsync(id); @@ -82,7 +81,9 @@ public class DocumentsByMachineFamilyController(MarechaiContext context) : Contr public async Task CreateAsync(int machineFamilyId, long bookId) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return 0; + var item = new DocumentsByMachineFamily { MachineFamilyId = machineFamilyId, @@ -94,4 +95,4 @@ public class DocumentsByMachineFamilyController(MarechaiContext context) : Contr return item.Id; } -} +} \ No newline at end of file diff --git a/Marechai.Server/Controllers/DocumentsController.cs b/Marechai.Server/Controllers/DocumentsController.cs index 64ac0c38..0b9c237f 100644 --- a/Marechai.Server/Controllers/DocumentsController.cs +++ b/Marechai.Server/Controllers/DocumentsController.cs @@ -23,7 +23,6 @@ // Copyright © 2003-2025 Natalia Portillo *******************************************************************************/ -using System; using System.Collections.Generic; using System.Linq; using System.Security.Claims; @@ -34,7 +33,6 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Localization; namespace Marechai.Server.Controllers; @@ -46,37 +44,37 @@ public class DocumentsController(MarechaiContext context) : ControllerBase [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task> GetAsync() => await context.Documents.OrderBy(b => b.NativeTitle) - .ThenBy(b => b.Published) - .ThenBy(b => b.Title) - .Select(b => new DocumentDto - { - Id = b.Id, - Title = b.Title, - NativeTitle = b.NativeTitle, - Published = b.Published, - Synopsis = b.Synopsis, - CountryId = b.CountryId, - Country = b.Country.Name - }) - .ToListAsync(); + public Task> GetAsync() => context.Documents.OrderBy(b => b.NativeTitle) + .ThenBy(b => b.Published) + .ThenBy(b => b.Title) + .Select(b => new DocumentDto + { + Id = b.Id, + Title = b.Title, + NativeTitle = b.NativeTitle, + Published = b.Published, + Synopsis = b.Synopsis, + CountryId = b.CountryId, + Country = b.Country.Name + }) + .ToListAsync(); [HttpGet] [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task GetAsync(long id) => await context.Documents.Where(b => b.Id == id) - .Select(b => new DocumentDto - { - Id = b.Id, - Title = b.Title, - NativeTitle = b.NativeTitle, - Published = b.Published, - Synopsis = b.Synopsis, - CountryId = b.CountryId, - Country = b.Country.Name - }) - .FirstOrDefaultAsync(); + public Task GetAsync(long id) => context.Documents.Where(b => b.Id == id) + .Select(b => new DocumentDto + { + Id = b.Id, + Title = b.Title, + NativeTitle = b.NativeTitle, + Published = b.Published, + Synopsis = b.Synopsis, + CountryId = b.CountryId, + Country = b.Country.Name + }) + .FirstOrDefaultAsync(); [HttpPost] [Authorize(Roles = "Admin,UberAdmin")] @@ -85,6 +83,7 @@ public class DocumentsController(MarechaiContext context) : ControllerBase public async Task UpdateAsync(DocumentDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return; Document model = await context.Documents.FindAsync(dto.Id); @@ -105,7 +104,9 @@ public class DocumentsController(MarechaiContext context) : ControllerBase public async Task CreateAsync(DocumentDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return 0; + var model = new Document { Title = dto.Title, @@ -135,6 +136,7 @@ public class DocumentsController(MarechaiContext context) : ControllerBase public async Task DeleteAsync(long id) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return; Document item = await context.Documents.FindAsync(id); @@ -144,4 +146,4 @@ public class DocumentsController(MarechaiContext context) : ControllerBase await context.SaveChangesWithUserAsync(userId); } -} +} \ No newline at end of file diff --git a/Marechai.Server/Controllers/DumpsController.cs b/Marechai.Server/Controllers/DumpsController.cs index ca97462f..3de6caa8 100644 --- a/Marechai.Server/Controllers/DumpsController.cs +++ b/Marechai.Server/Controllers/DumpsController.cs @@ -23,7 +23,6 @@ // Copyright © 2003-2025 Natalia Portillo *******************************************************************************/ -using System; using System.Collections.Generic; using System.Linq; using System.Security.Claims; @@ -34,7 +33,6 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Localization; namespace Marechai.Server.Controllers; @@ -46,42 +44,42 @@ public class DumpsController(MarechaiContext context) : ControllerBase [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task> GetAsync() => await context.Dumps.OrderBy(d => d.Dumper) - .ThenBy(d => d.DumpingGroup) - .ThenBy(b => b.Media.Title) - .ThenBy(d => d.DumpDate) - .Select(d => new DumpDto - { - Id = d.Id, - Dumper = d.Dumper, - UserId = d.UserId, - DumpingGroup = d.DumpingGroup, - DumpDate = d.DumpDate, - UserName = d.User.UserName, - MediaId = d.MediaId, - MediaTitle = d.Media.Title, - MediaDumpId = d.MediaDumpId - }) - .ToListAsync(); + public Task> GetAsync() => context.Dumps.OrderBy(d => d.Dumper) + .ThenBy(d => d.DumpingGroup) + .ThenBy(b => b.Media.Title) + .ThenBy(d => d.DumpDate) + .Select(d => new DumpDto + { + Id = d.Id, + Dumper = d.Dumper, + UserId = d.UserId, + DumpingGroup = d.DumpingGroup, + DumpDate = d.DumpDate, + UserName = d.User.UserName, + MediaId = d.MediaId, + MediaTitle = d.Media.Title, + MediaDumpId = d.MediaDumpId + }) + .ToListAsync(); [HttpGet] [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task GetAsync(ulong id) => await context.Dumps.Where(d => d.Id == id) - .Select(d => new DumpDto - { - Id = d.Id, - Dumper = d.Dumper, - UserId = d.User.Id, - DumpingGroup = d.DumpingGroup, - DumpDate = d.DumpDate, - UserName = d.User.UserName, - MediaId = d.MediaId, - MediaTitle = d.Media.Title, - MediaDumpId = d.MediaDumpId - }) - .FirstOrDefaultAsync(); + public Task GetAsync(ulong id) => context.Dumps.Where(d => d.Id == id) + .Select(d => new DumpDto + { + Id = d.Id, + Dumper = d.Dumper, + UserId = d.User.Id, + DumpingGroup = d.DumpingGroup, + DumpDate = d.DumpDate, + UserName = d.User.UserName, + MediaId = d.MediaId, + MediaTitle = d.Media.Title, + MediaDumpId = d.MediaDumpId + }) + .FirstOrDefaultAsync(); [HttpPost] [Authorize(Roles = "Admin,UberAdmin")] @@ -90,6 +88,7 @@ public class DumpsController(MarechaiContext context) : ControllerBase public async Task UpdateAsync(DumpDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return; Dump model = await context.Dumps.FindAsync(dto.Id); @@ -111,7 +110,9 @@ public class DumpsController(MarechaiContext context) : ControllerBase public async Task CreateAsync(DumpDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return null; + var model = new Dump { Dumper = dto.Dumper, @@ -135,6 +136,7 @@ public class DumpsController(MarechaiContext context) : ControllerBase public async Task DeleteAsync(ulong id) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return; Dump item = await context.Dumps.FindAsync(id); @@ -144,4 +146,4 @@ public class DumpsController(MarechaiContext context) : ControllerBase await context.SaveChangesWithUserAsync(userId); } -} +} \ No newline at end of file diff --git a/Marechai.Server/Controllers/GpusByMachineController.cs b/Marechai.Server/Controllers/GpusByMachineController.cs index 8d0bef96..f2bf1439 100644 --- a/Marechai.Server/Controllers/GpusByMachineController.cs +++ b/Marechai.Server/Controllers/GpusByMachineController.cs @@ -23,7 +23,6 @@ // Copyright © 2003-2025 Natalia Portillo *******************************************************************************/ -using System; using System.Collections.Generic; using System.Linq; using System.Security.Claims; @@ -34,7 +33,6 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Localization; namespace Marechai.Server.Controllers; @@ -46,19 +44,19 @@ public class GpusByMachineController(MarechaiContext context) : ControllerBase [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task> GetByMachine(int machineId) => await context.GpusByMachine - .Where(g => g.MachineId == machineId) - .Select(g => new GpuByMachineDto - { - Id = g.Id, - Name = g.Gpu.Name, - CompanyName = g.Gpu.Company.Name, - GpuId = g.GpuId, - MachineId = g.MachineId - }) - .OrderBy(g => g.CompanyName) - .ThenBy(g => g.Name) - .ToListAsync(); + public Task> GetByMachine(int machineId) => context.GpusByMachine + .Where(g => g.MachineId == machineId) + .Select(g => new GpuByMachineDto + { + Id = g.Id, + Name = g.Gpu.Name, + CompanyName = g.Gpu.Company.Name, + GpuId = g.GpuId, + MachineId = g.MachineId + }) + .OrderBy(g => g.CompanyName) + .ThenBy(g => g.Name) + .ToListAsync(); [HttpDelete] [Authorize(Roles = "Admin,UberAdmin")] @@ -67,6 +65,7 @@ public class GpusByMachineController(MarechaiContext context) : ControllerBase public async Task DeleteAsync(long id) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return; GpusByMachine item = await context.GpusByMachine.FindAsync(id); @@ -84,7 +83,9 @@ public class GpusByMachineController(MarechaiContext context) : ControllerBase public async Task CreateAsync(int gpuId, int machineId) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return 0; + var item = new GpusByMachine { GpuId = gpuId, @@ -96,4 +97,4 @@ public class GpusByMachineController(MarechaiContext context) : ControllerBase return item.Id; } -} +} \ No newline at end of file diff --git a/Marechai.Server/Controllers/GpusController.cs b/Marechai.Server/Controllers/GpusController.cs index 1916b67d..e2b1f005 100644 --- a/Marechai.Server/Controllers/GpusController.cs +++ b/Marechai.Server/Controllers/GpusController.cs @@ -23,7 +23,6 @@ // Copyright © 2003-2025 Natalia Portillo *******************************************************************************/ -using System; using System.Collections.Generic; using System.Linq; using System.Security.Claims; @@ -34,7 +33,6 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Localization; namespace Marechai.Server.Controllers; @@ -46,63 +44,63 @@ public class GpusController(MarechaiContext context) : ControllerBase [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task> GetAsync() => await context.Gpus.OrderBy(g => g.Company.Name) - .ThenBy(g => g.Name) - .ThenBy(g => g.Introduced) - .Select(g => new GpuDto - { - Id = g.Id, - Company = g.Company.Name, - Introduced = g.Introduced, - ModelCode = g.ModelCode, - Name = g.Name - }) - .ToListAsync(); + public Task> GetAsync() => context.Gpus.OrderBy(g => g.Company.Name) + .ThenBy(g => g.Name) + .ThenBy(g => g.Introduced) + .Select(g => new GpuDto + { + Id = g.Id, + Company = g.Company.Name, + Introduced = g.Introduced, + ModelCode = g.ModelCode, + Name = g.Name + }) + .ToListAsync(); [HttpGet] [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task> GetByMachineAsync(int machineId) => await context.GpusByMachine - .Where(g => g.MachineId == machineId) - .Select(g => g.Gpu) - .OrderBy(g => g.Company.Name) - .ThenBy(g => g.Name) - .Select(g => new GpuDto - { - Id = g.Id, - Name = g.Name, - Company = g.Company.Name, - CompanyId = g.Company.Id, - ModelCode = g.ModelCode, - Introduced = g.Introduced, - Package = g.Package, - Process = g.Process, - ProcessNm = g.ProcessNm, - DieSize = g.DieSize, - Transistors = g.Transistors - }) - .ToListAsync(); + public Task> GetByMachineAsync(int machineId) => context.GpusByMachine + .Where(g => g.MachineId == machineId) + .Select(g => g.Gpu) + .OrderBy(g => g.Company.Name) + .ThenBy(g => g.Name) + .Select(g => new GpuDto + { + Id = g.Id, + Name = g.Name, + Company = g.Company.Name, + CompanyId = g.Company.Id, + ModelCode = g.ModelCode, + Introduced = g.Introduced, + Package = g.Package, + Process = g.Process, + ProcessNm = g.ProcessNm, + DieSize = g.DieSize, + Transistors = g.Transistors + }) + .ToListAsync(); [HttpGet] [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task GetAsync(int id) => await context.Gpus.Where(g => g.Id == id) - .Select(g => new GpuDto - { - Id = g.Id, - Name = g.Name, - CompanyId = g.Company.Id, - ModelCode = g.ModelCode, - Introduced = g.Introduced, - Package = g.Package, - Process = g.Process, - ProcessNm = g.ProcessNm, - DieSize = g.DieSize, - Transistors = g.Transistors - }) - .FirstOrDefaultAsync(); + public Task GetAsync(int id) => context.Gpus.Where(g => g.Id == id) + .Select(g => new GpuDto + { + Id = g.Id, + Name = g.Name, + CompanyId = g.Company.Id, + ModelCode = g.ModelCode, + Introduced = g.Introduced, + Package = g.Package, + Process = g.Process, + ProcessNm = g.ProcessNm, + DieSize = g.DieSize, + Transistors = g.Transistors + }) + .FirstOrDefaultAsync(); [HttpPost] [Authorize(Roles = "Admin,UberAdmin")] @@ -111,6 +109,7 @@ public class GpusController(MarechaiContext context) : ControllerBase public async Task UpdateAsync(GpuDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return; Gpu model = await context.Gpus.FindAsync(dto.Id); @@ -136,7 +135,9 @@ public class GpusController(MarechaiContext context) : ControllerBase public async Task CreateAsync(GpuDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return 0; + var model = new Gpu { Name = dto.Name, @@ -163,6 +164,7 @@ public class GpusController(MarechaiContext context) : ControllerBase public async Task DeleteAsync(int id) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return; Gpu item = await context.Gpus.FindAsync(id); @@ -172,4 +174,4 @@ public class GpusController(MarechaiContext context) : ControllerBase await context.SaveChangesWithUserAsync(userId); } -} +} \ No newline at end of file diff --git a/Marechai.Server/Controllers/InstructionSetExtensionsController.cs b/Marechai.Server/Controllers/InstructionSetExtensionsController.cs index bfa64283..4011682f 100644 --- a/Marechai.Server/Controllers/InstructionSetExtensionsController.cs +++ b/Marechai.Server/Controllers/InstructionSetExtensionsController.cs @@ -28,13 +28,11 @@ using System.Collections.Generic; using System.Linq; using System.Security.Claims; using System.Threading.Tasks; -using Marechai.Data.Dtos; using Marechai.Database.Models; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Localization; namespace Marechai.Server.Controllers; @@ -46,27 +44,25 @@ public class InstructionSetExtensionsController(MarechaiContext context) : Contr [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task> GetAsync() => await context.InstructionSetExtensions - .OrderBy(e => e.Extension) - .Select(e => new InstructionSetExtension - { - Extension = e.Extension, - Id = e.Id - }) - .ToListAsync(); + public Task> GetAsync() => context.InstructionSetExtensions.OrderBy(e => e.Extension) + .Select(e => new InstructionSetExtension + { + Extension = e.Extension, + Id = e.Id + }) + .ToListAsync(); [HttpGet] [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task GetAsync(int id) => await context.InstructionSetExtensions - .Where(e => e.Id == id) - .Select(e => new InstructionSetExtension - { - Extension = e.Extension, - Id = e.Id - }) - .FirstOrDefaultAsync(); + public Task GetAsync(int id) => context.InstructionSetExtensions.Where(e => e.Id == id) + .Select(e => new InstructionSetExtension + { + Extension = e.Extension, + Id = e.Id + }) + .FirstOrDefaultAsync(); [HttpPost] [Authorize(Roles = "Admin,UberAdmin")] @@ -75,6 +71,7 @@ public class InstructionSetExtensionsController(MarechaiContext context) : Contr public async Task UpdateAsync(InstructionSetExtension viewModel) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return; InstructionSetExtension model = await context.InstructionSetExtensions.FindAsync(viewModel.Id); @@ -92,7 +89,9 @@ public class InstructionSetExtensionsController(MarechaiContext context) : Contr public async Task CreateAsync(InstructionSetExtension viewModel) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return 0; + var model = new InstructionSetExtension { Extension = viewModel.Extension @@ -111,6 +110,7 @@ public class InstructionSetExtensionsController(MarechaiContext context) : Contr public async Task DeleteAsync(int id) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return; InstructionSetExtension item = await context.InstructionSetExtensions.FindAsync(id); @@ -127,6 +127,6 @@ public class InstructionSetExtensionsController(MarechaiContext context) : Contr [ProducesResponseType(StatusCodes.Status400BadRequest)] public bool VerifyUnique(string extension) => !context.InstructionSetExtensions.Any(i => string.Equals(i.Extension, - extension, - StringComparison.InvariantCultureIgnoreCase)); -} + extension, + StringComparison.InvariantCultureIgnoreCase)); +} \ No newline at end of file diff --git a/Marechai.Server/Controllers/InstructionSetsController.cs b/Marechai.Server/Controllers/InstructionSetsController.cs index d5259bb5..86397c33 100644 --- a/Marechai.Server/Controllers/InstructionSetsController.cs +++ b/Marechai.Server/Controllers/InstructionSetsController.cs @@ -28,13 +28,11 @@ using System.Collections.Generic; using System.Linq; using System.Security.Claims; using System.Threading.Tasks; -using Marechai.Data.Dtos; using Marechai.Database.Models; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Localization; namespace Marechai.Server.Controllers; @@ -46,25 +44,25 @@ public class InstructionSetsController(MarechaiContext context) : ControllerBase [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task> GetAsync() => await context.InstructionSets.OrderBy(e => e.Name) - .Select(e => new InstructionSet - { - Name = e.Name, - Id = e.Id - }) - .ToListAsync(); + public Task> GetAsync() => context.InstructionSets.OrderBy(e => e.Name) + .Select(e => new InstructionSet + { + Name = e.Name, + Id = e.Id + }) + .ToListAsync(); [HttpGet] [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task GetAsync(int id) => await context.InstructionSets.Where(e => e.Id == id) - .Select(e => new InstructionSet - { - Name = e.Name, - Id = e.Id - }) - .FirstOrDefaultAsync(); + public Task GetAsync(int id) => context.InstructionSets.Where(e => e.Id == id) + .Select(e => new InstructionSet + { + Name = e.Name, + Id = e.Id + }) + .FirstOrDefaultAsync(); [HttpPost] [Authorize(Roles = "Admin,UberAdmin")] @@ -73,6 +71,7 @@ public class InstructionSetsController(MarechaiContext context) : ControllerBase public async Task UpdateAsync(InstructionSet viewModel) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return; InstructionSet model = await context.InstructionSets.FindAsync(viewModel.Id); @@ -90,7 +89,9 @@ public class InstructionSetsController(MarechaiContext context) : ControllerBase public async Task CreateAsync(InstructionSet viewModel) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return 0; + var model = new InstructionSet { Name = viewModel.Name @@ -109,6 +110,7 @@ public class InstructionSetsController(MarechaiContext context) : ControllerBase public async Task DeleteAsync(int id) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return; InstructionSet item = await context.InstructionSets.FindAsync(id); @@ -125,4 +127,4 @@ public class InstructionSetsController(MarechaiContext context) : ControllerBase [ProducesResponseType(StatusCodes.Status400BadRequest)] public bool VerifyUnique(string name) => !context.InstructionSets.Any(i => string.Equals(i.Name, name, StringComparison.InvariantCultureIgnoreCase)); -} +} \ No newline at end of file diff --git a/Marechai.Server/Controllers/Iso4217Controller.cs b/Marechai.Server/Controllers/Iso4217Controller.cs index c76022f1..28b219e5 100644 --- a/Marechai.Server/Controllers/Iso4217Controller.cs +++ b/Marechai.Server/Controllers/Iso4217Controller.cs @@ -23,18 +23,14 @@ // Copyright © 2003-2025 Natalia Portillo *******************************************************************************/ -using System; using System.Collections.Generic; using System.Linq; -using System.Security.Claims; using System.Threading.Tasks; -using Marechai.Data.Dtos; using Marechai.Database.Models; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Localization; namespace Marechai.Server.Controllers; @@ -46,5 +42,5 @@ public class Iso4217Controller(MarechaiContext context) : ControllerBase [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task> GetAsync() => await context.Iso4217.OrderBy(c => c.Name).ToListAsync(); -} + public Task> GetAsync() => context.Iso4217.OrderBy(c => c.Name).ToListAsync(); +} \ No newline at end of file diff --git a/Marechai.Server/Controllers/LicensesController.cs b/Marechai.Server/Controllers/LicensesController.cs index 01eb7db7..fcb8beae 100644 --- a/Marechai.Server/Controllers/LicensesController.cs +++ b/Marechai.Server/Controllers/LicensesController.cs @@ -23,18 +23,15 @@ // Copyright © 2003-2025 Natalia Portillo *******************************************************************************/ -using System; using System.Collections.Generic; using System.Linq; using System.Security.Claims; using System.Threading.Tasks; -using Marechai.Data.Dtos; using Marechai.Database.Models; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Localization; namespace Marechai.Server.Controllers; @@ -46,34 +43,34 @@ public class LicensesController(MarechaiContext context) : ControllerBase [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task> GetAsync() => await context.Licenses.OrderBy(l => l.Name) - .Select(l => new License - { - FsfApproved = l.FsfApproved, - Id = l.Id, - Link = l.Link, - Name = l.Name, - OsiApproved = l.OsiApproved, - SPDX = l.SPDX - }) - .ToListAsync(); + public Task> GetAsync() => context.Licenses.OrderBy(l => l.Name) + .Select(l => new License + { + FsfApproved = l.FsfApproved, + Id = l.Id, + Link = l.Link, + Name = l.Name, + OsiApproved = l.OsiApproved, + SPDX = l.SPDX + }) + .ToListAsync(); [HttpGet] [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task GetAsync(int id) => await context.Licenses.Where(l => l.Id == id) - .Select(l => new License - { - FsfApproved = l.FsfApproved, - Id = l.Id, - Link = l.Link, - Name = l.Name, - OsiApproved = l.OsiApproved, - SPDX = l.SPDX, - Text = l.Text - }) - .FirstOrDefaultAsync(); + public Task GetAsync(int id) => context.Licenses.Where(l => l.Id == id) + .Select(l => new License + { + FsfApproved = l.FsfApproved, + Id = l.Id, + Link = l.Link, + Name = l.Name, + OsiApproved = l.OsiApproved, + SPDX = l.SPDX, + Text = l.Text + }) + .FirstOrDefaultAsync(); [HttpPost] [Authorize(Roles = "Admin,UberAdmin")] @@ -82,6 +79,7 @@ public class LicensesController(MarechaiContext context) : ControllerBase public async Task UpdateAsync(License viewModel) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return; License model = await context.Licenses.FindAsync(viewModel.Id); @@ -104,7 +102,9 @@ public class LicensesController(MarechaiContext context) : ControllerBase public async Task CreateAsync(License viewModel) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return 0; + var model = new License { FsfApproved = viewModel.FsfApproved, @@ -128,6 +128,7 @@ public class LicensesController(MarechaiContext context) : ControllerBase public async Task DeleteAsync(int id) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return; License item = await context.Licenses.FindAsync(id); @@ -137,4 +138,4 @@ public class LicensesController(MarechaiContext context) : ControllerBase await context.SaveChangesWithUserAsync(userId); } -} +} \ No newline at end of file diff --git a/Marechai.Server/Controllers/MachineFamiliesController.cs b/Marechai.Server/Controllers/MachineFamiliesController.cs index b3c1ca90..78b4a107 100644 --- a/Marechai.Server/Controllers/MachineFamiliesController.cs +++ b/Marechai.Server/Controllers/MachineFamiliesController.cs @@ -23,7 +23,6 @@ // Copyright © 2003-2025 Natalia Portillo *******************************************************************************/ -using System; using System.Collections.Generic; using System.Linq; using System.Security.Claims; @@ -34,7 +33,6 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Localization; namespace Marechai.Server.Controllers; @@ -46,30 +44,29 @@ public class MachineFamiliesController(MarechaiContext context) : ControllerBase [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task> GetAsync() => await context.MachineFamilies - .OrderBy(m => m.Company.Name) - .ThenBy(m => m.Name) - .Select(m => new MachineFamilyDto - { - Id = m.Id, - Company = m.Company.Name, - Name = m.Name - }) - .OrderBy(m => m.Name) - .ToListAsync(); + public Task> GetAsync() => context.MachineFamilies.OrderBy(m => m.Company.Name) + .ThenBy(m => m.Name) + .Select(m => new MachineFamilyDto + { + Id = m.Id, + Company = m.Company.Name, + Name = m.Name + }) + .OrderBy(m => m.Name) + .ToListAsync(); [HttpGet] [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task GetAsync(int id) => await context.MachineFamilies.Where(f => f.Id == id) - .Select(m => new MachineFamilyDto - { - Id = m.Id, - CompanyId = m.CompanyId, - Name = m.Name - }) - .FirstOrDefaultAsync(); + public Task GetAsync(int id) => context.MachineFamilies.Where(f => f.Id == id) + .Select(m => new MachineFamilyDto + { + Id = m.Id, + CompanyId = m.CompanyId, + Name = m.Name + }) + .FirstOrDefaultAsync(); [HttpPost] [Authorize(Roles = "Admin,UberAdmin")] @@ -78,6 +75,7 @@ public class MachineFamiliesController(MarechaiContext context) : ControllerBase public async Task UpdateAsync(MachineFamilyDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return; MachineFamily model = await context.MachineFamilies.FindAsync(dto.Id); @@ -96,7 +94,9 @@ public class MachineFamiliesController(MarechaiContext context) : ControllerBase public async Task CreateAsync(MachineFamilyDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return 0; + var model = new MachineFamily { Name = dto.Name, @@ -116,6 +116,7 @@ public class MachineFamiliesController(MarechaiContext context) : ControllerBase public async Task DeleteAsync(int id) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return; MachineFamily item = await context.MachineFamilies.FindAsync(id); @@ -125,4 +126,4 @@ public class MachineFamiliesController(MarechaiContext context) : ControllerBase await context.SaveChangesWithUserAsync(userId); } -} +} \ No newline at end of file diff --git a/Marechai.Server/Controllers/MachinePhotosController.cs b/Marechai.Server/Controllers/MachinePhotosController.cs index 16aac1ba..7851cc78 100644 --- a/Marechai.Server/Controllers/MachinePhotosController.cs +++ b/Marechai.Server/Controllers/MachinePhotosController.cs @@ -34,7 +34,6 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Localization; namespace Marechai.Server.Controllers; @@ -53,57 +52,53 @@ public class MachinePhotosController(MarechaiContext context) : ControllerBase [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task GetAsync(Guid id) => await context.MachinePhotos.Where(p => p.Id == id) - .Select(p => new MachinePhotoDto - { - Aperture = p.Aperture, - Author = p.Author, - CameraManufacturer = p.CameraManufacturer, - CameraModel = p.CameraModel, - ColorSpace = p.ColorSpace, - Comments = p.Comments, - Contrast = p.Contrast, - CreationDate = p.CreationDate, - DigitalZoomRatio = p.DigitalZoomRatio, - ExifVersion = p.ExifVersion, - ExposureTime = p.ExposureTime, - ExposureMethod = p.ExposureMethod, - ExposureProgram = p.ExposureProgram, - Flash = p.Flash, - Focal = p.Focal, - FocalLength = p.FocalLength, - FocalLengthEquivalent = - p.FocalLengthEquivalent, - HorizontalResolution = - p.HorizontalResolution, - Id = p.Id, - IsoRating = p.IsoRating, - Lens = p.Lens, - LicenseId = p.LicenseId, - LicenseName = p.License.Name, - LightSource = p.LightSource, - MachineCompanyName = - p.Machine.Company.Name, - MachineId = p.MachineId, - MachineName = p.Machine.Name, - MeteringMode = p.MeteringMode, - ResolutionUnit = p.ResolutionUnit, - Orientation = p.Orientation, - Saturation = p.Saturation, - SceneCaptureType = p.SceneCaptureType, - SensingMethod = p.SensingMethod, - Sharpness = p.Sharpness, - SoftwareUsed = p.SoftwareUsed, - Source = p.Source, - SubjectDistanceRange = - p.SubjectDistanceRange, - UploadDate = p.UploadDate, - UserId = p.UserId, - VerticalResolution = p.VerticalResolution, - WhiteBalance = p.WhiteBalance, - OriginalExtension = p.OriginalExtension - }) - .FirstOrDefaultAsync(); + public Task GetAsync(Guid id) => context.MachinePhotos.Where(p => p.Id == id) + .Select(p => new MachinePhotoDto + { + Aperture = p.Aperture, + Author = p.Author, + CameraManufacturer = p.CameraManufacturer, + CameraModel = p.CameraModel, + ColorSpace = p.ColorSpace, + Comments = p.Comments, + Contrast = p.Contrast, + CreationDate = p.CreationDate, + DigitalZoomRatio = p.DigitalZoomRatio, + ExifVersion = p.ExifVersion, + ExposureTime = p.ExposureTime, + ExposureMethod = p.ExposureMethod, + ExposureProgram = p.ExposureProgram, + Flash = p.Flash, + Focal = p.Focal, + FocalLength = p.FocalLength, + FocalLengthEquivalent = p.FocalLengthEquivalent, + HorizontalResolution = p.HorizontalResolution, + Id = p.Id, + IsoRating = p.IsoRating, + Lens = p.Lens, + LicenseId = p.LicenseId, + LicenseName = p.License.Name, + LightSource = p.LightSource, + MachineCompanyName = p.Machine.Company.Name, + MachineId = p.MachineId, + MachineName = p.Machine.Name, + MeteringMode = p.MeteringMode, + ResolutionUnit = p.ResolutionUnit, + Orientation = p.Orientation, + Saturation = p.Saturation, + SceneCaptureType = p.SceneCaptureType, + SensingMethod = p.SensingMethod, + Sharpness = p.Sharpness, + SoftwareUsed = p.SoftwareUsed, + Source = p.Source, + SubjectDistanceRange = p.SubjectDistanceRange, + UploadDate = p.UploadDate, + UserId = p.UserId, + VerticalResolution = p.VerticalResolution, + WhiteBalance = p.WhiteBalance, + OriginalExtension = p.OriginalExtension + }) + .FirstOrDefaultAsync(); [HttpPost] [Authorize(Roles = "Admin,UberAdmin")] @@ -112,6 +107,7 @@ public class MachinePhotosController(MarechaiContext context) : ControllerBase public async Task UpdateAsync(MachinePhotoDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return; MachinePhoto model = await context.MachinePhotos.FindAsync(dto.Id); @@ -162,7 +158,9 @@ public class MachinePhotosController(MarechaiContext context) : ControllerBase public async Task CreateAsync(MachinePhotoDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return null; + var model = new MachinePhoto { Aperture = dto.Aperture, @@ -211,4 +209,4 @@ public class MachinePhotosController(MarechaiContext context) : ControllerBase return model.Id; } -} +} \ No newline at end of file diff --git a/Marechai.Server/Controllers/MachinesController.cs b/Marechai.Server/Controllers/MachinesController.cs index c09e7619..04be65c0 100644 --- a/Marechai.Server/Controllers/MachinesController.cs +++ b/Marechai.Server/Controllers/MachinesController.cs @@ -40,48 +40,51 @@ namespace Marechai.Server.Controllers; [Route("/machines")] [ApiController] -public class MachinesController(MarechaiContext context, +public class MachinesController +( + MarechaiContext context, IStringLocalizer localizer, GpusService gpusService, ProcessorsService processorsService, - SoundSynthsService soundSynthsService) : ControllerBase + SoundSynthsService soundSynthsService +) : ControllerBase { [HttpGet] [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task> GetAsync() => await context.Machines.OrderBy(m => m.Company.Name) - .ThenBy(m => m.Name) - .ThenBy(m => m.Family.Name) - .Select(m => new MachineDto - { - Id = m.Id, - Company = m.Company.Name, - Name = m.Name, - Model = m.Model, - Introduced = m.Introduced, - Type = m.Type, - Family = m.Family.Name - }) - .ToListAsync(); + public Task> GetAsync() => context.Machines.OrderBy(m => m.Company.Name) + .ThenBy(m => m.Name) + .ThenBy(m => m.Family.Name) + .Select(m => new MachineDto + { + Id = m.Id, + Company = m.Company.Name, + Name = m.Name, + Model = m.Model, + Introduced = m.Introduced, + Type = m.Type, + Family = m.Family.Name + }) + .ToListAsync(); [HttpGet] [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task GetAsync(int id) => await context.Machines.Where(m => m.Id == id) - .Select(m => new MachineDto - { - Id = m.Id, - Company = m.Company.Name, - CompanyId = m.CompanyId, - Name = m.Name, - Model = m.Model, - Introduced = m.Introduced, - Type = m.Type, - FamilyId = m.FamilyId - }) - .FirstOrDefaultAsync(); + public Task GetAsync(int id) => context.Machines.Where(m => m.Id == id) + .Select(m => new MachineDto + { + Id = m.Id, + Company = m.Company.Name, + CompanyId = m.CompanyId, + Name = m.Name, + Model = m.Model, + Introduced = m.Introduced, + Type = m.Type, + FamilyId = m.FamilyId + }) + .FirstOrDefaultAsync(); [HttpPost] [Authorize(Roles = "Admin,UberAdmin")] @@ -90,6 +93,7 @@ public class MachinesController(MarechaiContext context, public async Task UpdateAsync(MachineDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return; Machine model = await context.Machines.FindAsync(dto.Id); @@ -136,7 +140,9 @@ public class MachinesController(MarechaiContext context, public async Task CreateAsync(MachineDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return 0; + var model = new Machine { CompanyId = dto.CompanyId, @@ -209,9 +215,7 @@ public class MachinesController(MarechaiContext context, IQueryable logos = context.CompanyLogos.Where(l => l.CompanyId == company.Id); if(model.Introduced.HasValue) - { model.CompanyLogo = (await logos.FirstOrDefaultAsync(l => l.Year >= model.Introduced.Value.Year))?.Guid; - } if(model.CompanyLogo is null && logos.Any()) model.CompanyLogo = (await logos.FirstAsync())?.Guid; } @@ -227,27 +231,27 @@ public class MachinesController(MarechaiContext context, model.Gpus = await gpusService.GetByMachineAsync(machine.Id); model.Memory = await context.MemoryByMachine.Where(m => m.MachineId == machine.Id) - .Select(m => new MemoryDto - { - Type = m.Type, - Usage = m.Usage, - Size = m.Size, - Speed = m.Speed - }) - .ToListAsync(); + .Select(m => new MemoryDto + { + Type = m.Type, + Usage = m.Usage, + Size = m.Size, + Speed = m.Speed + }) + .ToListAsync(); model.Processors = await processorsService.GetByMachineAsync(machine.Id); model.SoundSynthesizers = await soundSynthsService.GetByMachineAsync(machine.Id); model.Storage = await context.StorageByMachine.Where(s => s.MachineId == machine.Id) - .Select(s => new StorageDto - { - Type = s.Type, - Interface = s.Interface, - Capacity = s.Capacity - }) - .ToListAsync(); + .Select(s => new StorageDto + { + Type = s.Type, + Interface = s.Interface, + Capacity = s.Capacity + }) + .ToListAsync(); return model; } @@ -259,6 +263,7 @@ public class MachinesController(MarechaiContext context, public async Task DeleteAsync(int id) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return; Machine item = await context.Machines.FindAsync(id); @@ -268,4 +273,4 @@ public class MachinesController(MarechaiContext context, await context.SaveChangesWithUserAsync(userId); } -} +} \ No newline at end of file diff --git a/Marechai.Server/Controllers/MagazineIssuesController.cs b/Marechai.Server/Controllers/MagazineIssuesController.cs index 9e19a1dc..933cf1ec 100644 --- a/Marechai.Server/Controllers/MagazineIssuesController.cs +++ b/Marechai.Server/Controllers/MagazineIssuesController.cs @@ -23,7 +23,6 @@ // Copyright © 2003-2025 Natalia Portillo *******************************************************************************/ -using System; using System.Collections.Generic; using System.Linq; using System.Security.Claims; @@ -34,7 +33,6 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Localization; namespace Marechai.Server.Controllers; @@ -46,42 +44,41 @@ public class MagazineIssuesController(MarechaiContext context) : ControllerBase [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task> GetAsync() => await context.MagazineIssues - .OrderBy(b => b.Magazine.Title) - .ThenBy(b => b.Published) - .ThenBy(b => b.Caption) - .Select(b => new MagazineIssueDto - { - Id = b.Id, - MagazineId = b.MagazineId, - MagazineTitle = b.Magazine.Title, - Caption = b.Caption, - NativeCaption = b.NativeCaption, - Published = b.Published, - ProductCode = b.ProductCode, - Pages = b.Pages, - IssueNumber = b.IssueNumber - }) - .ToListAsync(); + public Task> GetAsync() => context.MagazineIssues.OrderBy(b => b.Magazine.Title) + .ThenBy(b => b.Published) + .ThenBy(b => b.Caption) + .Select(b => new MagazineIssueDto + { + Id = b.Id, + MagazineId = b.MagazineId, + MagazineTitle = b.Magazine.Title, + Caption = b.Caption, + NativeCaption = b.NativeCaption, + Published = b.Published, + ProductCode = b.ProductCode, + Pages = b.Pages, + IssueNumber = b.IssueNumber + }) + .ToListAsync(); [HttpGet] [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task GetAsync(long id) => await context.MagazineIssues.Where(b => b.Id == id) - .Select(b => new MagazineIssueDto - { - Id = b.Id, - MagazineId = b.MagazineId, - MagazineTitle = b.Magazine.Title, - Caption = b.Caption, - NativeCaption = b.NativeCaption, - Published = b.Published, - ProductCode = b.ProductCode, - Pages = b.Pages, - IssueNumber = b.IssueNumber - }) - .FirstOrDefaultAsync(); + public Task GetAsync(long id) => context.MagazineIssues.Where(b => b.Id == id) + .Select(b => new MagazineIssueDto + { + Id = b.Id, + MagazineId = b.MagazineId, + MagazineTitle = b.Magazine.Title, + Caption = b.Caption, + NativeCaption = b.NativeCaption, + Published = b.Published, + ProductCode = b.ProductCode, + Pages = b.Pages, + IssueNumber = b.IssueNumber + }) + .FirstOrDefaultAsync(); [HttpPost] [Authorize(Roles = "Admin,UberAdmin")] @@ -90,6 +87,7 @@ public class MagazineIssuesController(MarechaiContext context) : ControllerBase public async Task UpdateAsync(MagazineIssueDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return; MagazineIssue model = await context.MagazineIssues.FindAsync(dto.Id); @@ -112,7 +110,9 @@ public class MagazineIssuesController(MarechaiContext context) : ControllerBase public async Task CreateAsync(MagazineIssueDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return 0; + var model = new MagazineIssue { MagazineId = dto.MagazineId, @@ -137,6 +137,7 @@ public class MagazineIssuesController(MarechaiContext context) : ControllerBase public async Task DeleteAsync(long id) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return; MagazineIssue item = await context.MagazineIssues.FindAsync(id); @@ -146,4 +147,4 @@ public class MagazineIssuesController(MarechaiContext context) : ControllerBase await context.SaveChangesWithUserAsync(userId); } -} +} \ No newline at end of file diff --git a/Marechai.Server/Controllers/MagazineScansController.cs b/Marechai.Server/Controllers/MagazineScansController.cs index 43505ddb..4d514478 100644 --- a/Marechai.Server/Controllers/MagazineScansController.cs +++ b/Marechai.Server/Controllers/MagazineScansController.cs @@ -34,7 +34,6 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Localization; namespace Marechai.Server.Controllers; @@ -53,29 +52,29 @@ public class MagazineScansController(MarechaiContext context) : ControllerBase [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task GetAsync(Guid id) => await context.MagazineScans.Where(p => p.Id == id) - .Select(p => new MagazineScanDto - { - Author = p.Author, - MagazineId = p.Magazine.Id, - ColorSpace = p.ColorSpace, - Comments = p.Comments, - CreationDate = p.CreationDate, - ExifVersion = p.ExifVersion, - HorizontalResolution = p.HorizontalResolution, - Id = p.Id, - ResolutionUnit = p.ResolutionUnit, - Page = p.Page, - ScannerManufacturer = p.ScannerManufacturer, - ScannerModel = p.ScannerModel, - SoftwareUsed = p.SoftwareUsed, - Type = p.Type, - UploadDate = p.UploadDate, - UserId = p.UserId, - VerticalResolution = p.VerticalResolution, - OriginalExtension = p.OriginalExtension - }) - .FirstOrDefaultAsync(); + public Task GetAsync(Guid id) => context.MagazineScans.Where(p => p.Id == id) + .Select(p => new MagazineScanDto + { + Author = p.Author, + MagazineId = p.Magazine.Id, + ColorSpace = p.ColorSpace, + Comments = p.Comments, + CreationDate = p.CreationDate, + ExifVersion = p.ExifVersion, + HorizontalResolution = p.HorizontalResolution, + Id = p.Id, + ResolutionUnit = p.ResolutionUnit, + Page = p.Page, + ScannerManufacturer = p.ScannerManufacturer, + ScannerModel = p.ScannerModel, + SoftwareUsed = p.SoftwareUsed, + Type = p.Type, + UploadDate = p.UploadDate, + UserId = p.UserId, + VerticalResolution = p.VerticalResolution, + OriginalExtension = p.OriginalExtension + }) + .FirstOrDefaultAsync(); [HttpPost] [Authorize(Roles = "Admin,UberAdmin")] @@ -84,6 +83,7 @@ public class MagazineScansController(MarechaiContext context) : ControllerBase public async Task UpdateAsync(MagazineScanDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return; MagazineScan model = await context.MagazineScans.FindAsync(dto.Id); @@ -113,7 +113,9 @@ public class MagazineScansController(MarechaiContext context) : ControllerBase public async Task CreateAsync(MagazineScanDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return null; + var model = new MagazineScan { Author = dto.Author, @@ -149,6 +151,7 @@ public class MagazineScansController(MarechaiContext context) : ControllerBase public async Task DeleteAsync(Guid id) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return; MagazineScan item = await context.MagazineScans.FindAsync(id); @@ -158,4 +161,4 @@ public class MagazineScansController(MarechaiContext context) : ControllerBase await context.SaveChangesWithUserAsync(userId); } -} +} \ No newline at end of file diff --git a/Marechai.Server/Controllers/MagazinesByMachineController.cs b/Marechai.Server/Controllers/MagazinesByMachineController.cs index 3d4a7833..e6d5e3af 100644 --- a/Marechai.Server/Controllers/MagazinesByMachineController.cs +++ b/Marechai.Server/Controllers/MagazinesByMachineController.cs @@ -23,7 +23,6 @@ // Copyright © 2003-2025 Natalia Portillo *******************************************************************************/ -using System; using System.Collections.Generic; using System.Linq; using System.Security.Claims; @@ -34,7 +33,6 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Localization; namespace Marechai.Server.Controllers; @@ -46,17 +44,17 @@ public class MagazinesByMachineController(MarechaiContext context) : ControllerB [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task> GetByMagazine(long bookId) => await context.MagazinesByMachines - .Where(p => p.MagazineId == bookId) - .Select(p => new MagazineByMachineDto - { - Id = p.Id, - MagazineId = p.MagazineId, - MachineId = p.MachineId, - Machine = p.Machine.Name - }) - .OrderBy(p => p.Machine) - .ToListAsync(); + public Task> GetByMagazine(long bookId) => context.MagazinesByMachines + .Where(p => p.MagazineId == bookId) + .Select(p => new MagazineByMachineDto + { + Id = p.Id, + MagazineId = p.MagazineId, + MachineId = p.MachineId, + Machine = p.Machine.Name + }) + .OrderBy(p => p.Machine) + .ToListAsync(); [HttpDelete] [Authorize(Roles = "Admin,UberAdmin")] @@ -65,6 +63,7 @@ public class MagazinesByMachineController(MarechaiContext context) : ControllerB public async Task DeleteAsync(long id) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return; MagazinesByMachine item = await context.MagazinesByMachines.FindAsync(id); @@ -82,7 +81,9 @@ public class MagazinesByMachineController(MarechaiContext context) : ControllerB public async Task CreateAsync(int machineId, long bookId) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return 0; + var item = new MagazinesByMachine { MachineId = machineId, @@ -94,4 +95,4 @@ public class MagazinesByMachineController(MarechaiContext context) : ControllerB return item.Id; } -} +} \ No newline at end of file diff --git a/Marechai.Server/Controllers/MagazinesByMachineFamilyController.cs b/Marechai.Server/Controllers/MagazinesByMachineFamilyController.cs index 3b59eb07..0a0cd4d7 100644 --- a/Marechai.Server/Controllers/MagazinesByMachineFamilyController.cs +++ b/Marechai.Server/Controllers/MagazinesByMachineFamilyController.cs @@ -23,7 +23,6 @@ // Copyright © 2003-2025 Natalia Portillo *******************************************************************************/ -using System; using System.Collections.Generic; using System.Linq; using System.Security.Claims; @@ -34,7 +33,6 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Localization; namespace Marechai.Server.Controllers; @@ -46,17 +44,17 @@ public class MagazinesByMachineFamilyController(MarechaiContext context) : Contr [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task> GetByMagazine(long bookId) => await context - .MagazinesByMachinesFamilies.Where(p => p.MagazineId == bookId) - .Select(p => new MagazineByMachineFamilyDto - { - Id = p.Id, - MagazineId = p.MagazineId, - MachineFamilyId = p.MachineFamilyId, - MachineFamily = p.MachineFamily.Name - }) - .OrderBy(p => p.MachineFamily) - .ToListAsync(); + public Task> GetByMagazine(long bookId) => context.MagazinesByMachinesFamilies + .Where(p => p.MagazineId == bookId) + .Select(p => new MagazineByMachineFamilyDto + { + Id = p.Id, + MagazineId = p.MagazineId, + MachineFamilyId = p.MachineFamilyId, + MachineFamily = p.MachineFamily.Name + }) + .OrderBy(p => p.MachineFamily) + .ToListAsync(); [HttpDelete] [Authorize(Roles = "Admin,UberAdmin")] @@ -65,6 +63,7 @@ public class MagazinesByMachineFamilyController(MarechaiContext context) : Contr public async Task DeleteAsync(long id) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return; MagazinesByMachineFamily item = await context.MagazinesByMachinesFamilies.FindAsync(id); @@ -82,7 +81,9 @@ public class MagazinesByMachineFamilyController(MarechaiContext context) : Contr public async Task CreateAsync(int machineFamilyId, long bookId) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return 0; + var item = new MagazinesByMachineFamily { MachineFamilyId = machineFamilyId, @@ -94,4 +95,4 @@ public class MagazinesByMachineFamilyController(MarechaiContext context) : Contr return item.Id; } -} +} \ No newline at end of file diff --git a/Marechai.Server/Controllers/MagazinesController.cs b/Marechai.Server/Controllers/MagazinesController.cs index e08d3317..6f70b19a 100644 --- a/Marechai.Server/Controllers/MagazinesController.cs +++ b/Marechai.Server/Controllers/MagazinesController.cs @@ -23,7 +23,6 @@ // Copyright © 2003-2025 Natalia Portillo *******************************************************************************/ -using System; using System.Collections.Generic; using System.Linq; using System.Security.Claims; @@ -34,7 +33,6 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Localization; namespace Marechai.Server.Controllers; @@ -46,52 +44,52 @@ public class MagazinesController(MarechaiContext context) : ControllerBase [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task> GetAsync() => await context.Magazines.OrderBy(b => b.NativeTitle) - .ThenBy(b => b.FirstPublication) - .ThenBy(b => b.Title) - .Select(b => new MagazineDto - { - Id = b.Id, - Title = b.Title, - NativeTitle = b.NativeTitle, - FirstPublication = b.FirstPublication, - Synopsis = b.Synopsis, - Issn = b.Issn, - CountryId = b.CountryId, - Country = b.Country.Name - }) - .ToListAsync(); + public Task> GetAsync() => context.Magazines.OrderBy(b => b.NativeTitle) + .ThenBy(b => b.FirstPublication) + .ThenBy(b => b.Title) + .Select(b => new MagazineDto + { + Id = b.Id, + Title = b.Title, + NativeTitle = b.NativeTitle, + FirstPublication = b.FirstPublication, + Synopsis = b.Synopsis, + Issn = b.Issn, + CountryId = b.CountryId, + Country = b.Country.Name + }) + .ToListAsync(); [HttpGet] [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task> GetTitlesAsync() => await context.Magazines.OrderBy(b => b.Title) - .ThenBy(b => b.FirstPublication) - .Select(b => new MagazineDto - { - Id = b.Id, - Title = $"{b.Title} ({b.Country.Name}" - }) - .ToListAsync(); + public Task> GetTitlesAsync() => context.Magazines.OrderBy(b => b.Title) + .ThenBy(b => b.FirstPublication) + .Select(b => new MagazineDto + { + Id = b.Id, + Title = $"{b.Title} ({b.Country.Name}" + }) + .ToListAsync(); [HttpGet] [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task GetAsync(long id) => await context.Magazines.Where(b => b.Id == id) - .Select(b => new MagazineDto - { - Id = b.Id, - Title = b.Title, - NativeTitle = b.NativeTitle, - FirstPublication = b.FirstPublication, - Synopsis = b.Synopsis, - Issn = b.Issn, - CountryId = b.CountryId, - Country = b.Country.Name - }) - .FirstOrDefaultAsync(); + public Task GetAsync(long id) => context.Magazines.Where(b => b.Id == id) + .Select(b => new MagazineDto + { + Id = b.Id, + Title = b.Title, + NativeTitle = b.NativeTitle, + FirstPublication = b.FirstPublication, + Synopsis = b.Synopsis, + Issn = b.Issn, + CountryId = b.CountryId, + Country = b.Country.Name + }) + .FirstOrDefaultAsync(); [HttpPost] [Authorize(Roles = "Admin,UberAdmin")] @@ -100,6 +98,7 @@ public class MagazinesController(MarechaiContext context) : ControllerBase public async Task UpdateAsync(MagazineDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return; Magazine model = await context.Magazines.FindAsync(dto.Id); @@ -121,7 +120,9 @@ public class MagazinesController(MarechaiContext context) : ControllerBase public async Task CreateAsync(MagazineDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return 0; + var model = new Magazine { Title = dto.Title, @@ -152,6 +153,7 @@ public class MagazinesController(MarechaiContext context) : ControllerBase public async Task DeleteAsync(long id) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return; Magazine item = await context.Magazines.FindAsync(id); @@ -161,4 +163,4 @@ public class MagazinesController(MarechaiContext context) : ControllerBase await context.SaveChangesWithUserAsync(userId); } -} +} \ No newline at end of file diff --git a/Marechai.Server/Controllers/MediaController.cs b/Marechai.Server/Controllers/MediaController.cs index 90a6444a..12f54a60 100644 --- a/Marechai.Server/Controllers/MediaController.cs +++ b/Marechai.Server/Controllers/MediaController.cs @@ -23,7 +23,6 @@ // Copyright © 2003-2025 Natalia Portillo *******************************************************************************/ -using System; using System.Collections.Generic; using System.Linq; using System.Security.Claims; @@ -34,7 +33,6 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Localization; namespace Marechai.Server.Controllers; @@ -46,85 +44,85 @@ public class MediaController(MarechaiContext context) : ControllerBase [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task> GetAsync() => await context.Media.OrderBy(d => d.Title) - .Select(d => new MediaDto - { - Id = d.Id, - Title = d.Title, - Sequence = d.Sequence, - LastSequence = d.LastSequence, - Type = d.Type, - WriteOffset = d.WriteOffset, - Sides = d.Sides, - Layers = d.Layers, - Sessions = d.Sessions, - Tracks = d.Tracks, - Sectors = d.Sectors, - Size = d.Size, - CopyProtection = d.CopyProtection, - PartNumber = d.PartNumber, - SerialNumber = d.SerialNumber, - Barcode = d.Barcode, - CatalogueNumber = d.CatalogueNumber, - Manufacturer = d.Manufacturer, - Model = d.Model, - Revision = d.Revision, - Firmware = d.Firmware, - PhysicalBlockSize = d.PhysicalBlockSize, - LogicalBlockSize = d.LogicalBlockSize, - BlockSizes = d.BlockSizes, - StorageInterface = d.StorageInterface, - TableOfContents = d.TableOfContents - }) - .ToListAsync(); + public Task> GetAsync() => context.Media.OrderBy(d => d.Title) + .Select(d => new MediaDto + { + Id = d.Id, + Title = d.Title, + Sequence = d.Sequence, + LastSequence = d.LastSequence, + Type = d.Type, + WriteOffset = d.WriteOffset, + Sides = d.Sides, + Layers = d.Layers, + Sessions = d.Sessions, + Tracks = d.Tracks, + Sectors = d.Sectors, + Size = d.Size, + CopyProtection = d.CopyProtection, + PartNumber = d.PartNumber, + SerialNumber = d.SerialNumber, + Barcode = d.Barcode, + CatalogueNumber = d.CatalogueNumber, + Manufacturer = d.Manufacturer, + Model = d.Model, + Revision = d.Revision, + Firmware = d.Firmware, + PhysicalBlockSize = d.PhysicalBlockSize, + LogicalBlockSize = d.LogicalBlockSize, + BlockSizes = d.BlockSizes, + StorageInterface = d.StorageInterface, + TableOfContents = d.TableOfContents + }) + .ToListAsync(); [HttpGet] [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task> GetTitlesAsync() => await context.Media.OrderBy(d => d.Title) - .Select(d => new MediaDto - { - Id = d.Id, - Title = d.Title - }) - .ToListAsync(); + public Task> GetTitlesAsync() => context.Media.OrderBy(d => d.Title) + .Select(d => new MediaDto + { + Id = d.Id, + Title = d.Title + }) + .ToListAsync(); [HttpGet] [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task GetAsync(ulong id) => await context.Media.Where(d => d.Id == id) - .Select(d => new MediaDto - { - Id = d.Id, - Title = d.Title, - Sequence = d.Sequence, - LastSequence = d.LastSequence, - Type = d.Type, - WriteOffset = d.WriteOffset, - Sides = d.Sides, - Layers = d.Layers, - Sessions = d.Sessions, - Tracks = d.Tracks, - Sectors = d.Sectors, - Size = d.Size, - CopyProtection = d.CopyProtection, - PartNumber = d.PartNumber, - SerialNumber = d.SerialNumber, - Barcode = d.Barcode, - CatalogueNumber = d.CatalogueNumber, - Manufacturer = d.Manufacturer, - Model = d.Model, - Revision = d.Revision, - Firmware = d.Firmware, - PhysicalBlockSize = d.PhysicalBlockSize, - LogicalBlockSize = d.LogicalBlockSize, - BlockSizes = d.BlockSizes, - StorageInterface = d.StorageInterface, - TableOfContents = d.TableOfContents - }) - .FirstOrDefaultAsync(); + public Task GetAsync(ulong id) => context.Media.Where(d => d.Id == id) + .Select(d => new MediaDto + { + Id = d.Id, + Title = d.Title, + Sequence = d.Sequence, + LastSequence = d.LastSequence, + Type = d.Type, + WriteOffset = d.WriteOffset, + Sides = d.Sides, + Layers = d.Layers, + Sessions = d.Sessions, + Tracks = d.Tracks, + Sectors = d.Sectors, + Size = d.Size, + CopyProtection = d.CopyProtection, + PartNumber = d.PartNumber, + SerialNumber = d.SerialNumber, + Barcode = d.Barcode, + CatalogueNumber = d.CatalogueNumber, + Manufacturer = d.Manufacturer, + Model = d.Model, + Revision = d.Revision, + Firmware = d.Firmware, + PhysicalBlockSize = d.PhysicalBlockSize, + LogicalBlockSize = d.LogicalBlockSize, + BlockSizes = d.BlockSizes, + StorageInterface = d.StorageInterface, + TableOfContents = d.TableOfContents + }) + .FirstOrDefaultAsync(); [HttpPost] [Authorize(Roles = "Admin,UberAdmin")] @@ -133,6 +131,7 @@ public class MediaController(MarechaiContext context) : ControllerBase public async Task UpdateAsync(MediaDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return; Media model = await context.Media.FindAsync(dto.Id); @@ -173,7 +172,9 @@ public class MediaController(MarechaiContext context) : ControllerBase public async Task CreateAsync(MediaDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return null; + var model = new Media { Title = dto.Title, @@ -216,6 +217,7 @@ public class MediaController(MarechaiContext context) : ControllerBase public async Task DeleteAsync(ulong id) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return; Media item = await context.Media.FindAsync(id); @@ -225,4 +227,4 @@ public class MediaController(MarechaiContext context) : ControllerBase await context.SaveChangesWithUserAsync(userId); } -} +} \ No newline at end of file diff --git a/Marechai.Server/Controllers/MemoriesByMachineController.cs b/Marechai.Server/Controllers/MemoriesByMachineController.cs index 5914cb7d..a4170015 100644 --- a/Marechai.Server/Controllers/MemoriesByMachineController.cs +++ b/Marechai.Server/Controllers/MemoriesByMachineController.cs @@ -23,7 +23,6 @@ // Copyright © 2003-2025 Natalia Portillo *******************************************************************************/ -using System; using System.Collections.Generic; using System.Linq; using System.Security.Claims; @@ -34,7 +33,6 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Localization; namespace Marechai.Server.Controllers; @@ -46,22 +44,22 @@ public class MemoriesByMachineController(MarechaiContext context) : ControllerBa [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task> GetByMachine(int machineId) => await context.MemoryByMachine - .Where(m => m.MachineId == machineId) - .Select(m => new MemoryByMachineDto - { - Id = m.Id, - Type = m.Type, - Usage = m.Usage, - Size = m.Size, - Speed = m.Speed, - MachineId = m.MachineId - }) - .OrderBy(m => m.Type) - .ThenBy(m => m.Usage) - .ThenBy(m => m.Size) - .ThenBy(m => m.Speed) - .ToListAsync(); + public Task> GetByMachine(int machineId) => context.MemoryByMachine + .Where(m => m.MachineId == machineId) + .Select(m => new MemoryByMachineDto + { + Id = m.Id, + Type = m.Type, + Usage = m.Usage, + Size = m.Size, + Speed = m.Speed, + MachineId = m.MachineId + }) + .OrderBy(m => m.Type) + .ThenBy(m => m.Usage) + .ThenBy(m => m.Size) + .ThenBy(m => m.Speed) + .ToListAsync(); [HttpDelete] [Authorize(Roles = "Admin,UberAdmin")] @@ -70,6 +68,7 @@ public class MemoriesByMachineController(MarechaiContext context) : ControllerBa public async Task DeleteAsync(long id) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return; MemoryByMachine item = await context.MemoryByMachine.FindAsync(id); @@ -84,10 +83,12 @@ public class MemoriesByMachineController(MarechaiContext context) : ControllerBa [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task CreateAsync(int machineId, MemoryType type, MemoryUsage usage, long? size, double? speed) + public async Task CreateAsync(int machineId, MemoryType type, MemoryUsage usage, long? size, double? speed) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return 0; + var item = new MemoryByMachine { MachineId = machineId, @@ -102,4 +103,4 @@ public class MemoriesByMachineController(MarechaiContext context) : ControllerBa return item.Id; } -} +} \ No newline at end of file diff --git a/Marechai.Server/Controllers/NewsController.cs b/Marechai.Server/Controllers/NewsController.cs index ec29e5fa..399b0355 100644 --- a/Marechai.Server/Controllers/NewsController.cs +++ b/Marechai.Server/Controllers/NewsController.cs @@ -23,7 +23,6 @@ // Copyright © 2003-2025 Natalia Portillo *******************************************************************************/ -using System; using System.Collections.Generic; using System.Linq; using System.Security.Claims; @@ -46,15 +45,15 @@ public class NewsController(MarechaiContext context, IStringLocalizer> GetAsync() => await context.News.OrderByDescending(n => n.Date) - .Select(n => new NewsDto - { - Id = n.Id, - Timestamp = n.Date, - Type = n.Type, - AffectedId = n.AddedId - }) - .ToListAsync(); + public Task> GetAsync() => context.News.OrderByDescending(n => n.Date) + .Select(n => new NewsDto + { + Id = n.Id, + Timestamp = n.Date, + Type = n.Type, + AffectedId = n.AddedId + }) + .ToListAsync(); [HttpGet] [AllowAnonymous] @@ -74,72 +73,72 @@ public class NewsController(MarechaiContext context, IStringLocalizer> GetAsync() => await context.People.OrderBy(p => p.DisplayName) - .ThenBy(p => p.Alias) - .ThenBy(p => p.Name) - .ThenBy(p => p.Surname) - .Select(p => new PersonDto - { - Id = p.Id, - Name = p.Name, - Surname = p.Surname, - CountryOfBirth = p.CountryOfBirth.Name, - BirthDate = p.BirthDate, - DeathDate = p.DeathDate, - Webpage = p.Webpage, - Twitter = p.Twitter, - Facebook = p.Facebook, - Photo = p.Photo, - Alias = p.Alias, - DisplayName = p.DisplayName - }) - .ToListAsync(); + public Task> GetAsync() => context.People.OrderBy(p => p.DisplayName) + .ThenBy(p => p.Alias) + .ThenBy(p => p.Name) + .ThenBy(p => p.Surname) + .Select(p => new PersonDto + { + Id = p.Id, + Name = p.Name, + Surname = p.Surname, + CountryOfBirth = p.CountryOfBirth.Name, + BirthDate = p.BirthDate, + DeathDate = p.DeathDate, + Webpage = p.Webpage, + Twitter = p.Twitter, + Facebook = p.Facebook, + Photo = p.Photo, + Alias = p.Alias, + DisplayName = p.DisplayName + }) + .ToListAsync(); [HttpGet] [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task GetAsync(int id) => await context.People.Where(p => p.Id == id) - .Select(p => new PersonDto - { - Id = p.Id, - Name = p.Name, - Surname = p.Surname, - CountryOfBirthId = p.CountryOfBirthId, - BirthDate = p.BirthDate, - DeathDate = p.DeathDate, - Webpage = p.Webpage, - Twitter = p.Twitter, - Facebook = p.Facebook, - Photo = p.Photo, - Alias = p.Alias, - DisplayName = p.DisplayName - }) - .FirstOrDefaultAsync(); + public Task GetAsync(int id) => context.People.Where(p => p.Id == id) + .Select(p => new PersonDto + { + Id = p.Id, + Name = p.Name, + Surname = p.Surname, + CountryOfBirthId = p.CountryOfBirthId, + BirthDate = p.BirthDate, + DeathDate = p.DeathDate, + Webpage = p.Webpage, + Twitter = p.Twitter, + Facebook = p.Facebook, + Photo = p.Photo, + Alias = p.Alias, + DisplayName = p.DisplayName + }) + .FirstOrDefaultAsync(); [HttpPost] [Authorize(Roles = "Admin,UberAdmin")] @@ -96,6 +94,7 @@ public class PeopleController(MarechaiContext context) : ControllerBase public async Task UpdateAsync(PersonDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return; Person model = await context.People.FindAsync(dto.Id); @@ -123,7 +122,9 @@ public class PeopleController(MarechaiContext context) : ControllerBase public async Task CreateAsync(PersonDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return 0; + var model = new Person { Name = dto.Name, @@ -152,6 +153,7 @@ public class PeopleController(MarechaiContext context) : ControllerBase public async Task DeleteAsync(int id) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return; Person item = await context.People.FindAsync(id); @@ -161,4 +163,4 @@ public class PeopleController(MarechaiContext context) : ControllerBase await context.SaveChangesWithUserAsync(userId); } -} +} \ No newline at end of file diff --git a/Marechai.Server/Controllers/ProcessorsByMachineController.cs b/Marechai.Server/Controllers/ProcessorsByMachineController.cs index 54252cc8..083349c2 100644 --- a/Marechai.Server/Controllers/ProcessorsByMachineController.cs +++ b/Marechai.Server/Controllers/ProcessorsByMachineController.cs @@ -23,7 +23,6 @@ // Copyright © 2003-2025 Natalia Portillo *******************************************************************************/ -using System; using System.Collections.Generic; using System.Linq; using System.Security.Claims; @@ -34,7 +33,6 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Localization; namespace Marechai.Server.Controllers; @@ -46,20 +44,20 @@ public class ProcessorsByMachineController(MarechaiContext context) : Controller [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task> GetByMachine(int machineId) => await context - .ProcessorsByMachine.Where(p => p.MachineId == machineId) - .Select(p => new ProcessorByMachineDto - { - Id = p.Id, - Name = p.Processor.Name, - CompanyName = p.Processor.Company.Name, - ProcessorId = p.ProcessorId, - MachineId = p.MachineId, - Speed = p.Speed - }) - .OrderBy(p => p.CompanyName) - .ThenBy(p => p.Name) - .ToListAsync(); + public Task> GetByMachine(int machineId) => context.ProcessorsByMachine + .Where(p => p.MachineId == machineId) + .Select(p => new ProcessorByMachineDto + { + Id = p.Id, + Name = p.Processor.Name, + CompanyName = p.Processor.Company.Name, + ProcessorId = p.ProcessorId, + MachineId = p.MachineId, + Speed = p.Speed + }) + .OrderBy(p => p.CompanyName) + .ThenBy(p => p.Name) + .ToListAsync(); [HttpDelete] [Authorize(Roles = "Admin,UberAdmin")] @@ -68,6 +66,7 @@ public class ProcessorsByMachineController(MarechaiContext context) : Controller public async Task DeleteAsync(long id) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return; ProcessorsByMachine item = await context.ProcessorsByMachine.FindAsync(id); @@ -85,7 +84,9 @@ public class ProcessorsByMachineController(MarechaiContext context) : Controller public async Task CreateAsync(int processorId, int machineId, float? speed) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return 0; + var item = new ProcessorsByMachine { ProcessorId = processorId, @@ -98,4 +99,4 @@ public class ProcessorsByMachineController(MarechaiContext context) : Controller return item.Id; } -} +} \ No newline at end of file diff --git a/Marechai.Server/Controllers/ProcessorsController.cs b/Marechai.Server/Controllers/ProcessorsController.cs index a3956588..c707b2ff 100644 --- a/Marechai.Server/Controllers/ProcessorsController.cs +++ b/Marechai.Server/Controllers/ProcessorsController.cs @@ -23,7 +23,6 @@ // Copyright © 2003-2025 Natalia Portillo *******************************************************************************/ -using System; using System.Collections.Generic; using System.Linq; using System.Security.Claims; @@ -34,7 +33,6 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Localization; namespace Marechai.Server.Controllers; @@ -46,83 +44,79 @@ public class ProcessorsController(MarechaiContext context) : ControllerBase [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task> GetAsync() => await context.Processors - .Select(p => new ProcessorDto - { - Name = p.Name, - CompanyName = p.Company.Name, - CompanyId = p.Company.Id, - ModelCode = p.ModelCode, - Introduced = p.Introduced, - Speed = p.Speed, - Package = p.Package, - Gprs = p.Gprs, - GprSize = p.GprSize, - Fprs = p.Fprs, - FprSize = p.FprSize, - Cores = p.Cores, - ThreadsPerCore = p.ThreadsPerCore, - Process = p.Process, - ProcessNm = p.ProcessNm, - DieSize = p.DieSize, - Transistors = p.Transistors, - DataBus = p.DataBus, - AddrBus = p.AddrBus, - SimdRegisters = p.SimdRegisters, - SimdSize = p.SimdSize, - L1Instruction = p.L1Instruction, - L1Data = p.L1Data, - L2 = p.L2, - L3 = p.L3, - InstructionSet = p.InstructionSet.Name, - Id = p.Id, - InstructionSetExtensions = - p.InstructionSetExtensions - .Select(e => e.Extension - .Extension) - .ToList() - }) - .OrderBy(p => p.CompanyName) - .ThenBy(p => p.Name) - .ToListAsync(); + public Task> GetAsync() => context.Processors.Select(p => new ProcessorDto + { + Name = p.Name, + CompanyName = p.Company.Name, + CompanyId = p.Company.Id, + ModelCode = p.ModelCode, + Introduced = p.Introduced, + Speed = p.Speed, + Package = p.Package, + Gprs = p.Gprs, + GprSize = p.GprSize, + Fprs = p.Fprs, + FprSize = p.FprSize, + Cores = p.Cores, + ThreadsPerCore = p.ThreadsPerCore, + Process = p.Process, + ProcessNm = p.ProcessNm, + DieSize = p.DieSize, + Transistors = p.Transistors, + DataBus = p.DataBus, + AddrBus = p.AddrBus, + SimdRegisters = p.SimdRegisters, + SimdSize = p.SimdSize, + L1Instruction = p.L1Instruction, + L1Data = p.L1Data, + L2 = p.L2, + L3 = p.L3, + InstructionSet = p.InstructionSet.Name, + Id = p.Id, + InstructionSetExtensions = p.InstructionSetExtensions + .Select(e => e.Extension.Extension) + .ToList() + }) + .OrderBy(p => p.CompanyName) + .ThenBy(p => p.Name) + .ToListAsync(); [HttpGet] [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task> GetByMachineAsync(int machineId) => await context.ProcessorsByMachine + public Task> GetByMachineAsync(int machineId) => context.ProcessorsByMachine .Where(p => p.MachineId == machineId) .Select(p => new ProcessorDto { - Name = p.Processor.Name, - CompanyName = p.Processor.Company.Name, - CompanyId = p.Processor.Company.Id, - ModelCode = p.Processor.ModelCode, - Introduced = p.Processor.Introduced, - Speed = p.Speed, - Package = p.Processor.Package, - Gprs = p.Processor.Gprs, - GprSize = p.Processor.GprSize, - Fprs = p.Processor.Fprs, - FprSize = p.Processor.FprSize, - Cores = p.Processor.Cores, - ThreadsPerCore = p.Processor.ThreadsPerCore, - Process = p.Processor.Process, - ProcessNm = p.Processor.ProcessNm, - DieSize = p.Processor.DieSize, - Transistors = p.Processor.Transistors, - DataBus = p.Processor.DataBus, - AddrBus = p.Processor.AddrBus, - SimdRegisters = p.Processor.SimdRegisters, - SimdSize = p.Processor.SimdSize, - L1Instruction = p.Processor.L1Instruction, - L1Data = p.Processor.L1Data, - L2 = p.Processor.L2, - L3 = p.Processor.L3, - InstructionSet = p.Processor.InstructionSet.Name, - Id = p.Processor.Id, - InstructionSetExtensions = - p.Processor.InstructionSetExtensions.Select(e => e.Extension.Extension).ToList() + Name = p.Processor.Name, + CompanyName = p.Processor.Company.Name, + CompanyId = p.Processor.Company.Id, + ModelCode = p.Processor.ModelCode, + Introduced = p.Processor.Introduced, + Speed = p.Speed, + Package = p.Processor.Package, + Gprs = p.Processor.Gprs, + GprSize = p.Processor.GprSize, + Fprs = p.Processor.Fprs, + FprSize = p.Processor.FprSize, + Cores = p.Processor.Cores, + ThreadsPerCore = p.Processor.ThreadsPerCore, + Process = p.Processor.Process, + ProcessNm = p.Processor.ProcessNm, + DieSize = p.Processor.DieSize, + Transistors = p.Processor.Transistors, + DataBus = p.Processor.DataBus, + AddrBus = p.Processor.AddrBus, + SimdRegisters = p.Processor.SimdRegisters, + SimdSize = p.Processor.SimdSize, + L1Instruction = p.Processor.L1Instruction, + L1Data = p.Processor.L1Data, + L2 = p.Processor.L2, + L3 = p.Processor.L3, + InstructionSet = p.Processor.InstructionSet.Name, + Id = p.Processor.Id, + InstructionSetExtensions = p.Processor.InstructionSetExtensions.Select(e => e.Extension.Extension).ToList() }) .OrderBy(p => p.CompanyName) .ThenBy(p => p.Name) @@ -132,39 +126,38 @@ public class ProcessorsController(MarechaiContext context) : ControllerBase [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task GetAsync(int id) => await context.Processors.Where(p => p.Id == id) - .Select(p => new ProcessorDto - { - Name = p.Name, - CompanyName = p.Company.Name, - CompanyId = p.Company.Id, - ModelCode = p.ModelCode, - Introduced = p.Introduced, - Speed = p.Speed, - Package = p.Package, - Gprs = p.Gprs, - GprSize = p.GprSize, - Fprs = p.Fprs, - FprSize = p.FprSize, - Cores = p.Cores, - ThreadsPerCore = p.ThreadsPerCore, - Process = p.Process, - ProcessNm = p.ProcessNm, - DieSize = p.DieSize, - Transistors = p.Transistors, - DataBus = p.DataBus, - AddrBus = p.AddrBus, - SimdRegisters = p.SimdRegisters, - SimdSize = p.SimdSize, - L1Instruction = p.L1Instruction, - L1Data = p.L1Data, - L2 = p.L2, - L3 = p.L3, - InstructionSet = - p.InstructionSet.Name, - InstructionSetId = p.InstructionSetId - }) - .FirstOrDefaultAsync(); + public Task GetAsync(int id) => context.Processors.Where(p => p.Id == id) + .Select(p => new ProcessorDto + { + Name = p.Name, + CompanyName = p.Company.Name, + CompanyId = p.Company.Id, + ModelCode = p.ModelCode, + Introduced = p.Introduced, + Speed = p.Speed, + Package = p.Package, + Gprs = p.Gprs, + GprSize = p.GprSize, + Fprs = p.Fprs, + FprSize = p.FprSize, + Cores = p.Cores, + ThreadsPerCore = p.ThreadsPerCore, + Process = p.Process, + ProcessNm = p.ProcessNm, + DieSize = p.DieSize, + Transistors = p.Transistors, + DataBus = p.DataBus, + AddrBus = p.AddrBus, + SimdRegisters = p.SimdRegisters, + SimdSize = p.SimdSize, + L1Instruction = p.L1Instruction, + L1Data = p.L1Data, + L2 = p.L2, + L3 = p.L3, + InstructionSet = p.InstructionSet.Name, + InstructionSetId = p.InstructionSetId + }) + .FirstOrDefaultAsync(); [HttpPost] [Authorize(Roles = "Admin,UberAdmin")] @@ -173,6 +166,7 @@ public class ProcessorsController(MarechaiContext context) : ControllerBase public async Task UpdateAsync(ProcessorDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return; Processor model = await context.Processors.FindAsync(dto.Id); @@ -214,7 +208,9 @@ public class ProcessorsController(MarechaiContext context) : ControllerBase public async Task CreateAsync(ProcessorDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return 0; + var model = new Processor { AddrBus = dto.AddrBus, @@ -257,6 +253,7 @@ public class ProcessorsController(MarechaiContext context) : ControllerBase public async Task DeleteAsync(int id) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return; Processor item = await context.Processors.FindAsync(id); @@ -266,4 +263,4 @@ public class ProcessorsController(MarechaiContext context) : ControllerBase await context.SaveChangesWithUserAsync(userId); } -} +} \ No newline at end of file diff --git a/Marechai.Server/Controllers/ResolutionsController.cs b/Marechai.Server/Controllers/ResolutionsController.cs index 5974f6fb..5a0648bc 100644 --- a/Marechai.Server/Controllers/ResolutionsController.cs +++ b/Marechai.Server/Controllers/ResolutionsController.cs @@ -23,7 +23,6 @@ // Copyright © 2003-2025 Natalia Portillo *******************************************************************************/ -using System; using System.Collections.Generic; using System.Linq; using System.Security.Claims; @@ -34,7 +33,6 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Localization; namespace Marechai.Server.Controllers; @@ -46,41 +44,40 @@ public class ResolutionsController(MarechaiContext context) : ControllerBase [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task> GetAsync() => await context.Resolutions - .Select(r => new ResolutionDto - { - Id = r.Id, - Width = r.Width, - Height = r.Height, - Colors = r.Colors, - Palette = r.Palette, - Chars = r.Chars, - Grayscale = r.Grayscale - }) - .OrderBy(r => r.Width) - .ThenBy(r => r.Height) - .ThenBy(r => r.Chars) - .ThenBy(r => r.Grayscale) - .ThenBy(r => r.Colors) - .ThenBy(r => r.Palette) - .ToListAsync(); + public Task> GetAsync() => context.Resolutions.Select(r => new ResolutionDto + { + Id = r.Id, + Width = r.Width, + Height = r.Height, + Colors = r.Colors, + Palette = r.Palette, + Chars = r.Chars, + Grayscale = r.Grayscale + }) + .OrderBy(r => r.Width) + .ThenBy(r => r.Height) + .ThenBy(r => r.Chars) + .ThenBy(r => r.Grayscale) + .ThenBy(r => r.Colors) + .ThenBy(r => r.Palette) + .ToListAsync(); [HttpGet] [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task GetAsync(int id) => await context.Resolutions.Where(r => r.Id == id) - .Select(r => new ResolutionDto - { - Id = r.Id, - Width = r.Width, - Height = r.Height, - Colors = r.Colors, - Palette = r.Palette, - Chars = r.Chars, - Grayscale = r.Grayscale - }) - .FirstOrDefaultAsync(); + public Task GetAsync(int id) => context.Resolutions.Where(r => r.Id == id) + .Select(r => new ResolutionDto + { + Id = r.Id, + Width = r.Width, + Height = r.Height, + Colors = r.Colors, + Palette = r.Palette, + Chars = r.Chars, + Grayscale = r.Grayscale + }) + .FirstOrDefaultAsync(); [HttpPost] [Authorize(Roles = "Admin,UberAdmin")] @@ -89,6 +86,7 @@ public class ResolutionsController(MarechaiContext context) : ControllerBase public async Task UpdateAsync(ResolutionDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return; Resolution model = await context.Resolutions.FindAsync(dto.Id); @@ -111,7 +109,9 @@ public class ResolutionsController(MarechaiContext context) : ControllerBase public async Task CreateAsync(ResolutionDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return 0; + var model = new Resolution { Chars = dto.Chars, @@ -135,6 +135,7 @@ public class ResolutionsController(MarechaiContext context) : ControllerBase public async Task DeleteAsync(int id) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return; Resolution item = await context.Resolutions.FindAsync(id); @@ -144,4 +145,4 @@ public class ResolutionsController(MarechaiContext context) : ControllerBase await context.SaveChangesWithUserAsync(userId); } -} +} \ No newline at end of file diff --git a/Marechai.Server/Controllers/ScreensByMachineController.cs b/Marechai.Server/Controllers/ScreensByMachineController.cs index fba2fd3b..fd7738a9 100644 --- a/Marechai.Server/Controllers/ScreensByMachineController.cs +++ b/Marechai.Server/Controllers/ScreensByMachineController.cs @@ -23,7 +23,6 @@ // Copyright © 2003-2025 Natalia Portillo *******************************************************************************/ -using System; using System.Collections.Generic; using System.Linq; using System.Security.Claims; @@ -34,7 +33,6 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Localization; namespace Marechai.Server.Controllers; @@ -46,35 +44,35 @@ public class ScreensByMachineController(MarechaiContext context) : ControllerBas [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task> GetByMachine(int machineId) => await context.ScreensByMachine - .Where(s => s.MachineId == machineId) - .Select(s => new ScreenByMachineDto - { - Id = s.Id, - ScreenId = s.ScreenId, - MachineId = s.MachineId, - Screen = new ScreenDto - { - Diagonal = s.Screen.Diagonal, - EffectiveColors = s.Screen.EffectiveColors, - Height = s.Screen.Height, - Id = s.Screen.Id, - NativeResolution = new ResolutionDto - { - Chars = s.Screen.NativeResolution.Chars, - Colors = s.Screen.NativeResolution.Colors, - Grayscale = s.Screen.NativeResolution.Grayscale, - Height = s.Screen.NativeResolution.Height, - Id = s.Screen.NativeResolutionId, - Palette = s.Screen.NativeResolution.Palette, - Width = s.Screen.NativeResolution.Width - }, - NativeResolutionId = s.Screen.NativeResolutionId, - Type = s.Screen.Type, - Width = s.Screen.Width - } - }) - .ToListAsync(); + public Task> GetByMachine(int machineId) => context.ScreensByMachine + .Where(s => s.MachineId == machineId) + .Select(s => new ScreenByMachineDto + { + Id = s.Id, + ScreenId = s.ScreenId, + MachineId = s.MachineId, + Screen = new ScreenDto + { + Diagonal = s.Screen.Diagonal, + EffectiveColors = s.Screen.EffectiveColors, + Height = s.Screen.Height, + Id = s.Screen.Id, + NativeResolution = new ResolutionDto + { + Chars = s.Screen.NativeResolution.Chars, + Colors = s.Screen.NativeResolution.Colors, + Grayscale = s.Screen.NativeResolution.Grayscale, + Height = s.Screen.NativeResolution.Height, + Id = s.Screen.NativeResolutionId, + Palette = s.Screen.NativeResolution.Palette, + Width = s.Screen.NativeResolution.Width + }, + NativeResolutionId = s.Screen.NativeResolutionId, + Type = s.Screen.Type, + Width = s.Screen.Width + } + }) + .ToListAsync(); [HttpDelete] [Authorize(Roles = "Admin,UberAdmin")] @@ -83,6 +81,7 @@ public class ScreensByMachineController(MarechaiContext context) : ControllerBas public async Task DeleteAsync(long id) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return; ScreensByMachine item = await context.ScreensByMachine.FindAsync(id); @@ -100,6 +99,7 @@ public class ScreensByMachineController(MarechaiContext context) : ControllerBas public async Task CreateAsync(int machineId, int screenId) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return 0; if(context.ScreensByMachine.Any(s => s.MachineId == machineId && s.ScreenId == screenId)) return 0; @@ -114,4 +114,4 @@ public class ScreensByMachineController(MarechaiContext context) : ControllerBas return item.Id; } -} +} \ No newline at end of file diff --git a/Marechai.Server/Controllers/ScreensController.cs b/Marechai.Server/Controllers/ScreensController.cs index 70895f82..91603dbb 100644 --- a/Marechai.Server/Controllers/ScreensController.cs +++ b/Marechai.Server/Controllers/ScreensController.cs @@ -23,7 +23,6 @@ // Copyright © 2003-2025 Natalia Portillo *******************************************************************************/ -using System; using System.Collections.Generic; using System.Linq; using System.Security.Claims; @@ -34,7 +33,6 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Localization; namespace Marechai.Server.Controllers; @@ -47,69 +45,58 @@ public class ScreensController(MarechaiContext context) : ControllerBase [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] public async Task> GetAsync() => (await context.Screens.Select(s => new ScreenDto - { - Diagonal = s.Diagonal, - EffectiveColors = s.EffectiveColors, - Height = s.Height, - Id = s.Id, - Type = s.Type, - Width = s.Width, - NativeResolutionId = - s.NativeResolutionId, - NativeResolution = - new ResolutionDto - { - Chars = s.NativeResolution - .Chars, - Colors = s.NativeResolution - .Colors, - Grayscale = s.NativeResolution - .Grayscale, - Height = s.NativeResolution - .Height, - Id = - s.NativeResolution.Id, - Palette = s.NativeResolution - .Palette, - Width = s.NativeResolution - .Width - } - }) - .ToListAsync()).OrderBy(s => s.Diagonal) - .ThenBy(s => s.EffectiveColors) - .ThenBy(s => s.NativeResolution.ToString()) - .ThenBy(s => s.Type) - .ThenBy(s => s.Size) - .ToList(); + { + Diagonal = s.Diagonal, + EffectiveColors = s.EffectiveColors, + Height = s.Height, + Id = s.Id, + Type = s.Type, + Width = s.Width, + NativeResolutionId = s.NativeResolutionId, + NativeResolution = new ResolutionDto + { + Chars = s.NativeResolution.Chars, + Colors = s.NativeResolution.Colors, + Grayscale = s.NativeResolution.Grayscale, + Height = s.NativeResolution.Height, + Id = s.NativeResolution.Id, + Palette = s.NativeResolution.Palette, + Width = s.NativeResolution.Width + } + }) + .ToListAsync()).OrderBy(s => s.Diagonal) + .ThenBy(s => s.EffectiveColors) + .ThenBy(s => s.NativeResolution.ToString()) + .ThenBy(s => s.Type) + .ThenBy(s => s.Size) + .ToList(); [HttpGet] [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task GetAsync(int id) => await context.Screens.Where(s => s.Id == id) - .Select(s => new ScreenDto - { - Diagonal = s.Diagonal, - EffectiveColors = s.EffectiveColors, - Height = s.Height, - Id = s.Id, - NativeResolution = new ResolutionDto - { - Chars = s.NativeResolution.Chars, - Colors = s.NativeResolution.Colors, - Grayscale = s.NativeResolution - .Grayscale, - Height = s.NativeResolution.Height, - Id = s.NativeResolution.Id, - Palette = - s.NativeResolution.Palette, - Width = s.NativeResolution.Width - }, - NativeResolutionId = s.NativeResolutionId, - Type = s.Type, - Width = s.Width - }) - .FirstOrDefaultAsync(); + public Task GetAsync(int id) => context.Screens.Where(s => s.Id == id) + .Select(s => new ScreenDto + { + Diagonal = s.Diagonal, + EffectiveColors = s.EffectiveColors, + Height = s.Height, + Id = s.Id, + NativeResolution = new ResolutionDto + { + Chars = s.NativeResolution.Chars, + Colors = s.NativeResolution.Colors, + Grayscale = s.NativeResolution.Grayscale, + Height = s.NativeResolution.Height, + Id = s.NativeResolution.Id, + Palette = s.NativeResolution.Palette, + Width = s.NativeResolution.Width + }, + NativeResolutionId = s.NativeResolutionId, + Type = s.Type, + Width = s.Width + }) + .FirstOrDefaultAsync(); [HttpPost] [Authorize(Roles = "Admin,UberAdmin")] @@ -118,6 +105,7 @@ public class ScreensController(MarechaiContext context) : ControllerBase public async Task UpdateAsync(ScreenDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return; Screen model = await context.Screens.FindAsync(dto.Id); @@ -144,7 +132,9 @@ public class ScreensController(MarechaiContext context) : ControllerBase public async Task CreateAsync(ScreenDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return 0; + var model = new Screen { Diagonal = dto.Diagonal, @@ -168,6 +158,7 @@ public class ScreensController(MarechaiContext context) : ControllerBase public async Task DeleteAsync(int id) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return; Screen item = await context.Screens.FindAsync(id); @@ -177,4 +168,4 @@ public class ScreensController(MarechaiContext context) : ControllerBase await context.SaveChangesWithUserAsync(userId); } -} +} \ No newline at end of file diff --git a/Marechai.Server/Controllers/SoftwareFamiliesController.cs b/Marechai.Server/Controllers/SoftwareFamiliesController.cs index 024c6495..5062f922 100644 --- a/Marechai.Server/Controllers/SoftwareFamiliesController.cs +++ b/Marechai.Server/Controllers/SoftwareFamiliesController.cs @@ -23,7 +23,6 @@ // Copyright © 2003-2025 Natalia Portillo *******************************************************************************/ -using System; using System.Collections.Generic; using System.Linq; using System.Security.Claims; @@ -34,7 +33,6 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Localization; namespace Marechai.Server.Controllers; @@ -46,32 +44,31 @@ public class SoftwareFamiliesController(MarechaiContext context) : ControllerBas [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task> GetAsync() => await context.SoftwareFamilies.OrderBy(b => b.Name) - .Select(b => new SoftwareFamilyDto - { - Id = b.Id, - Name = b.Name, - Parent = b.Parent.Name, - Introduced = b.Introduced, - ParentId = b.ParentId - }) - .ToListAsync(); + public Task> GetAsync() => context.SoftwareFamilies.OrderBy(b => b.Name) + .Select(b => new SoftwareFamilyDto + { + Id = b.Id, + Name = b.Name, + Parent = b.Parent.Name, + Introduced = b.Introduced, + ParentId = b.ParentId + }) + .ToListAsync(); [HttpGet] [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task GetAsync(ulong id) => await context.SoftwareFamilies - .Where(b => b.Id == id) - .Select(b => new SoftwareFamilyDto - { - Id = b.Id, - Name = b.Name, - Parent = b.Parent.Name, - Introduced = b.Introduced, - ParentId = b.ParentId - }) - .FirstOrDefaultAsync(); + public Task GetAsync(ulong id) => context.SoftwareFamilies.Where(b => b.Id == id) + .Select(b => new SoftwareFamilyDto + { + Id = b.Id, + Name = b.Name, + Parent = b.Parent.Name, + Introduced = b.Introduced, + ParentId = b.ParentId + }) + .FirstOrDefaultAsync(); [HttpPost] [Authorize(Roles = "Admin,UberAdmin")] @@ -80,6 +77,7 @@ public class SoftwareFamiliesController(MarechaiContext context) : ControllerBas public async Task UpdateAsync(SoftwareFamilyDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return; SoftwareFamily model = await context.SoftwareFamilies.FindAsync(dto.Id); @@ -98,7 +96,9 @@ public class SoftwareFamiliesController(MarechaiContext context) : ControllerBas public async Task CreateAsync(SoftwareFamilyDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return null; + var model = new SoftwareFamily { Name = dto.Name, @@ -119,6 +119,7 @@ public class SoftwareFamiliesController(MarechaiContext context) : ControllerBas public async Task DeleteAsync(ulong id) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return; SoftwareFamily item = await context.SoftwareFamilies.FindAsync(id); @@ -128,4 +129,4 @@ public class SoftwareFamiliesController(MarechaiContext context) : ControllerBas await context.SaveChangesWithUserAsync(userId); } -} +} \ No newline at end of file diff --git a/Marechai.Server/Controllers/SoftwareVariantsController.cs b/Marechai.Server/Controllers/SoftwareVariantsController.cs index 15f258d5..7a8fc4ce 100644 --- a/Marechai.Server/Controllers/SoftwareVariantsController.cs +++ b/Marechai.Server/Controllers/SoftwareVariantsController.cs @@ -23,7 +23,6 @@ // Copyright © 2003-2025 Natalia Portillo *******************************************************************************/ -using System; using System.Collections.Generic; using System.Linq; using System.Security.Claims; @@ -34,7 +33,6 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Localization; namespace Marechai.Server.Controllers; @@ -46,64 +44,62 @@ public class SoftwareVariantsController(MarechaiContext context) : ControllerBas [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task> GetAsync() => await context.SoftwareVariants - .OrderBy(b => b.SoftwareVersion.Family.Name) - .ThenBy(b => b.SoftwareVersion.Version) - .ThenBy(b => b.Name) - .ThenBy(b => b.Version) - .ThenBy(b => b.Introduced) - .Select(b => new SoftwareVariantDto - { - Id = b.Id, - Name = b.Name, - Version = b.Version, - Introduced = b.Introduced, - ParentId = b.ParentId, - Parent = b.Parent.Name ?? b.Parent.Version, - SoftwareVersionId = b.SoftwareVersionId, - SoftwareVersion = - b.SoftwareVersion.Name ?? - b.SoftwareVersion.Version, - MinimumMemory = b.MinimumMemory, - RecommendedMemory = b.RecommendedMemory, - RequiredStorage = b.RequiredStorage, - PartNumber = b.PartNumber, - SerialNumber = b.SerialNumber, - ProductCode = b.ProductCode, - CatalogueNumber = b.CatalogueNumber, - DistributionMode = b.DistributionMode - }) - .ToListAsync(); + public Task> GetAsync() => context.SoftwareVariants + .OrderBy(b => b.SoftwareVersion.Family.Name) + .ThenBy(b => b.SoftwareVersion.Version) + .ThenBy(b => b.Name) + .ThenBy(b => b.Version) + .ThenBy(b => b.Introduced) + .Select(b => new SoftwareVariantDto + { + Id = b.Id, + Name = b.Name, + Version = b.Version, + Introduced = b.Introduced, + ParentId = b.ParentId, + Parent = b.Parent.Name ?? b.Parent.Version, + SoftwareVersionId = b.SoftwareVersionId, + SoftwareVersion = + b.SoftwareVersion.Name ?? + b.SoftwareVersion.Version, + MinimumMemory = b.MinimumMemory, + RecommendedMemory = b.RecommendedMemory, + RequiredStorage = b.RequiredStorage, + PartNumber = b.PartNumber, + SerialNumber = b.SerialNumber, + ProductCode = b.ProductCode, + CatalogueNumber = b.CatalogueNumber, + DistributionMode = b.DistributionMode + }) + .ToListAsync(); [HttpGet] [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task GetAsync(ulong id) => await context.SoftwareVariants - .Where(b => b.Id == id) - .Select(b => new SoftwareVariantDto - { - Id = b.Id, - Name = b.Name, - Version = b.Version, - Introduced = b.Introduced, - ParentId = b.ParentId, - Parent = - b.Parent.Name ?? b.Parent.Version, - SoftwareVersionId = b.SoftwareVersionId, - SoftwareVersion = - b.SoftwareVersion.Name ?? - b.SoftwareVersion.Version, - MinimumMemory = b.MinimumMemory, - RecommendedMemory = b.RecommendedMemory, - RequiredStorage = b.RequiredStorage, - PartNumber = b.PartNumber, - SerialNumber = b.SerialNumber, - ProductCode = b.ProductCode, - CatalogueNumber = b.CatalogueNumber, - DistributionMode = b.DistributionMode - }) - .FirstOrDefaultAsync(); + public Task GetAsync(ulong id) => context.SoftwareVariants.Where(b => b.Id == id) + .Select(b => new SoftwareVariantDto + { + Id = b.Id, + Name = b.Name, + Version = b.Version, + Introduced = b.Introduced, + ParentId = b.ParentId, + Parent = + b.Parent.Name ?? b.Parent.Version, + SoftwareVersionId = b.SoftwareVersionId, + SoftwareVersion = b.SoftwareVersion.Name ?? + b.SoftwareVersion.Version, + MinimumMemory = b.MinimumMemory, + RecommendedMemory = b.RecommendedMemory, + RequiredStorage = b.RequiredStorage, + PartNumber = b.PartNumber, + SerialNumber = b.SerialNumber, + ProductCode = b.ProductCode, + CatalogueNumber = b.CatalogueNumber, + DistributionMode = b.DistributionMode + }) + .FirstOrDefaultAsync(); [HttpPost] [Authorize(Roles = "Admin,UberAdmin")] @@ -112,6 +108,7 @@ public class SoftwareVariantsController(MarechaiContext context) : ControllerBas public async Task UpdateAsync(SoftwareVariantDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return; SoftwareVariant model = await context.SoftwareVariants.FindAsync(dto.Id); @@ -141,7 +138,9 @@ public class SoftwareVariantsController(MarechaiContext context) : ControllerBas public async Task CreateAsync(SoftwareVariantDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return null; + var model = new SoftwareVariant { Name = dto.Name, @@ -172,6 +171,7 @@ public class SoftwareVariantsController(MarechaiContext context) : ControllerBas public async Task DeleteAsync(ulong id) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return; SoftwareVariant item = await context.SoftwareVariants.FindAsync(id); @@ -181,4 +181,4 @@ public class SoftwareVariantsController(MarechaiContext context) : ControllerBas await context.SaveChangesWithUserAsync(userId); } -} +} \ No newline at end of file diff --git a/Marechai.Server/Controllers/SoftwareVersionsController.cs b/Marechai.Server/Controllers/SoftwareVersionsController.cs index 446e80d9..ae79c943 100644 --- a/Marechai.Server/Controllers/SoftwareVersionsController.cs +++ b/Marechai.Server/Controllers/SoftwareVersionsController.cs @@ -23,7 +23,6 @@ // Copyright © 2003-2025 Natalia Portillo *******************************************************************************/ -using System; using System.Collections.Generic; using System.Linq; using System.Security.Claims; @@ -34,7 +33,6 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Localization; namespace Marechai.Server.Controllers; @@ -46,47 +44,45 @@ public class SoftwareVersionsController(MarechaiContext context) : ControllerBas [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task> GetAsync() => await context.SoftwareVersions - .OrderBy(b => b.Family.Name) - .ThenBy(b => b.Version) - .ThenBy(b => b.Introduced) - .Select(b => new SoftwareVersionDto - { - Id = b.Id, - Family = b.Family.Name, - Name = b.Name, - Codename = b.Codename, - Version = b.Version, - Introduced = b.Introduced, - Previous = b.Previous.Name, - License = b.License.Name, - FamilyId = b.FamilyId, - LicenseId = b.LicenseId, - PreviousId = b.PreviousId - }) - .ToListAsync(); + public Task> GetAsync() => context.SoftwareVersions.OrderBy(b => b.Family.Name) + .ThenBy(b => b.Version) + .ThenBy(b => b.Introduced) + .Select(b => new SoftwareVersionDto + { + Id = b.Id, + Family = b.Family.Name, + Name = b.Name, + Codename = b.Codename, + Version = b.Version, + Introduced = b.Introduced, + Previous = b.Previous.Name, + License = b.License.Name, + FamilyId = b.FamilyId, + LicenseId = b.LicenseId, + PreviousId = b.PreviousId + }) + .ToListAsync(); [HttpGet] [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task GetAsync(ulong id) => await context.SoftwareVersions - .Where(b => b.Id == id) - .Select(b => new SoftwareVersionDto - { - Id = b.Id, - Family = b.Family.Name, - Name = b.Name, - Codename = b.Codename, - Version = b.Version, - Introduced = b.Introduced, - Previous = b.Previous.Name, - License = b.License.Name, - FamilyId = b.FamilyId, - LicenseId = b.LicenseId, - PreviousId = b.PreviousId - }) - .FirstOrDefaultAsync(); + public Task GetAsync(ulong id) => context.SoftwareVersions.Where(b => b.Id == id) + .Select(b => new SoftwareVersionDto + { + Id = b.Id, + Family = b.Family.Name, + Name = b.Name, + Codename = b.Codename, + Version = b.Version, + Introduced = b.Introduced, + Previous = b.Previous.Name, + License = b.License.Name, + FamilyId = b.FamilyId, + LicenseId = b.LicenseId, + PreviousId = b.PreviousId + }) + .FirstOrDefaultAsync(); [HttpPost] [Authorize(Roles = "Admin,UberAdmin")] @@ -95,6 +91,7 @@ public class SoftwareVersionsController(MarechaiContext context) : ControllerBas public async Task UpdateAsync(SoftwareVersionDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return; SoftwareVersion model = await context.SoftwareVersions.FindAsync(dto.Id); @@ -117,7 +114,9 @@ public class SoftwareVersionsController(MarechaiContext context) : ControllerBas public async Task CreateAsync(SoftwareVersionDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return null; + var model = new SoftwareVersion { Name = dto.Name, @@ -142,6 +141,7 @@ public class SoftwareVersionsController(MarechaiContext context) : ControllerBas public async Task DeleteAsync(ulong id) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return; SoftwareVersion item = await context.SoftwareVersions.FindAsync(id); @@ -151,4 +151,4 @@ public class SoftwareVersionsController(MarechaiContext context) : ControllerBas await context.SaveChangesWithUserAsync(userId); } -} +} \ No newline at end of file diff --git a/Marechai.Server/Controllers/SoundSynthsByMachineController.cs b/Marechai.Server/Controllers/SoundSynthsByMachineController.cs index ed8652cb..22518222 100644 --- a/Marechai.Server/Controllers/SoundSynthsByMachineController.cs +++ b/Marechai.Server/Controllers/SoundSynthsByMachineController.cs @@ -23,7 +23,6 @@ // Copyright © 2003-2025 Natalia Portillo *******************************************************************************/ -using System; using System.Collections.Generic; using System.Linq; using System.Security.Claims; @@ -34,7 +33,6 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Localization; namespace Marechai.Server.Controllers; @@ -46,19 +44,19 @@ public class SoundSynthsByMachineController(MarechaiContext context) : Controlle [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task> GetByMachine(int machineId) => await context.SoundByMachine - .Where(g => g.MachineId == machineId) - .Select(g => new SoundSynthByMachineDto - { - Id = g.Id, - Name = g.SoundSynth.Name, - CompanyName = g.SoundSynth.Company.Name, - SoundSynthId = g.SoundSynthId, - MachineId = g.MachineId - }) - .OrderBy(g => g.CompanyName) - .ThenBy(g => g.Name) - .ToListAsync(); + public Task> GetByMachine(int machineId) => context.SoundByMachine + .Where(g => g.MachineId == machineId) + .Select(g => new SoundSynthByMachineDto + { + Id = g.Id, + Name = g.SoundSynth.Name, + CompanyName = g.SoundSynth.Company.Name, + SoundSynthId = g.SoundSynthId, + MachineId = g.MachineId + }) + .OrderBy(g => g.CompanyName) + .ThenBy(g => g.Name) + .ToListAsync(); [HttpDelete] [Authorize(Roles = "Admin,UberAdmin")] @@ -67,6 +65,7 @@ public class SoundSynthsByMachineController(MarechaiContext context) : Controlle public async Task DeleteAsync(long id) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return; SoundByMachine item = await context.SoundByMachine.FindAsync(id); @@ -84,7 +83,9 @@ public class SoundSynthsByMachineController(MarechaiContext context) : Controlle public async Task CreateAsync(int soundSynthId, int machineId) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return 0; + var item = new SoundByMachine { SoundSynthId = soundSynthId, @@ -96,4 +97,4 @@ public class SoundSynthsByMachineController(MarechaiContext context) : Controlle return item.Id; } -} +} \ No newline at end of file diff --git a/Marechai.Server/Controllers/SoundSynthsController.cs b/Marechai.Server/Controllers/SoundSynthsController.cs index 8fdacbf9..6749b363 100644 --- a/Marechai.Server/Controllers/SoundSynthsController.cs +++ b/Marechai.Server/Controllers/SoundSynthsController.cs @@ -23,7 +23,6 @@ // Copyright © 2003-2025 Natalia Portillo *******************************************************************************/ -using System; using System.Collections.Generic; using System.Linq; using System.Security.Claims; @@ -34,7 +33,6 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Localization; namespace Marechai.Server.Controllers; @@ -46,31 +44,31 @@ public class SoundSynthsController(MarechaiContext context) : ControllerBase [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task> GetAsync() => await context.SoundSynths.OrderBy(s => s.Company.Name) - .ThenBy(s => s.Name) - .ThenBy(s => s.ModelCode) - .Select(s => new SoundSynthDto - { - Id = s.Id, - Name = s.Name, - CompanyId = s.Company.Id, - CompanyName = s.Company.Name, - ModelCode = s.ModelCode, - Introduced = s.Introduced, - Voices = s.Voices, - Frequency = s.Frequency, - Depth = s.Depth, - SquareWave = s.SquareWave, - WhiteNoise = s.WhiteNoise, - Type = s.Type - }) - .ToListAsync(); + public Task> GetAsync() => context.SoundSynths.OrderBy(s => s.Company.Name) + .ThenBy(s => s.Name) + .ThenBy(s => s.ModelCode) + .Select(s => new SoundSynthDto + { + Id = s.Id, + Name = s.Name, + CompanyId = s.Company.Id, + CompanyName = s.Company.Name, + ModelCode = s.ModelCode, + Introduced = s.Introduced, + Voices = s.Voices, + Frequency = s.Frequency, + Depth = s.Depth, + SquareWave = s.SquareWave, + WhiteNoise = s.WhiteNoise, + Type = s.Type + }) + .ToListAsync(); [HttpGet] [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task> GetByMachineAsync(int machineId) => await context.SoundByMachine + public Task> GetByMachineAsync(int machineId) => context.SoundByMachine .Where(s => s.MachineId == machineId) .Select(s => s.SoundSynth) .OrderBy(s => s.Company.Name) @@ -97,23 +95,23 @@ public class SoundSynthsController(MarechaiContext context) : ControllerBase [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task GetAsync(int id) => await context.SoundSynths.Where(s => s.Id == id) - .Select(s => new SoundSynthDto - { - Id = s.Id, - Name = s.Name, - CompanyId = s.Company.Id, - CompanyName = s.Company.Name, - ModelCode = s.ModelCode, - Introduced = s.Introduced, - Voices = s.Voices, - Frequency = s.Frequency, - Depth = s.Depth, - SquareWave = s.SquareWave, - WhiteNoise = s.WhiteNoise, - Type = s.Type - }) - .FirstOrDefaultAsync(); + public Task GetAsync(int id) => context.SoundSynths.Where(s => s.Id == id) + .Select(s => new SoundSynthDto + { + Id = s.Id, + Name = s.Name, + CompanyId = s.Company.Id, + CompanyName = s.Company.Name, + ModelCode = s.ModelCode, + Introduced = s.Introduced, + Voices = s.Voices, + Frequency = s.Frequency, + Depth = s.Depth, + SquareWave = s.SquareWave, + WhiteNoise = s.WhiteNoise, + Type = s.Type + }) + .FirstOrDefaultAsync(); [HttpPost] [Authorize(Roles = "Admin,UberAdmin")] @@ -122,6 +120,7 @@ public class SoundSynthsController(MarechaiContext context) : ControllerBase public async Task UpdateAsync(SoundSynthDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return; SoundSynth model = await context.SoundSynths.FindAsync(dto.Id); @@ -148,7 +147,9 @@ public class SoundSynthsController(MarechaiContext context) : ControllerBase public async Task CreateAsync(SoundSynthDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return 0; + var model = new SoundSynth { Depth = dto.Depth, @@ -176,6 +177,7 @@ public class SoundSynthsController(MarechaiContext context) : ControllerBase public async Task DeleteAsync(int id) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return; SoundSynth item = await context.SoundSynths.FindAsync(id); @@ -185,4 +187,4 @@ public class SoundSynthsController(MarechaiContext context) : ControllerBase await context.SaveChangesWithUserAsync(userId); } -} +} \ No newline at end of file diff --git a/Marechai.Server/Controllers/StorageByMachineController.cs b/Marechai.Server/Controllers/StorageByMachineController.cs index 1c47acfc..b85815c6 100644 --- a/Marechai.Server/Controllers/StorageByMachineController.cs +++ b/Marechai.Server/Controllers/StorageByMachineController.cs @@ -23,7 +23,6 @@ // Copyright © 2003-2025 Natalia Portillo *******************************************************************************/ -using System; using System.Collections.Generic; using System.Linq; using System.Security.Claims; @@ -34,7 +33,6 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Localization; namespace Marechai.Server.Controllers; @@ -46,20 +44,20 @@ public class StorageByMachineController(MarechaiContext context) : ControllerBas [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task> GetByMachine(int machineId) => await context.StorageByMachine - .Where(s => s.MachineId == machineId) - .Select(s => new StorageByMachineDto - { - Id = s.Id, - Type = s.Type, - Interface = s.Interface, - Capacity = s.Capacity, - MachineId = s.MachineId - }) - .OrderBy(s => s.Type) - .ThenBy(s => s.Interface) - .ThenBy(s => s.Capacity) - .ToListAsync(); + public Task> GetByMachine(int machineId) => context.StorageByMachine + .Where(s => s.MachineId == machineId) + .Select(s => new StorageByMachineDto + { + Id = s.Id, + Type = s.Type, + Interface = s.Interface, + Capacity = s.Capacity, + MachineId = s.MachineId + }) + .OrderBy(s => s.Type) + .ThenBy(s => s.Interface) + .ThenBy(s => s.Capacity) + .ToListAsync(); [HttpDelete] [Authorize(Roles = "Admin,UberAdmin")] @@ -68,6 +66,7 @@ public class StorageByMachineController(MarechaiContext context) : ControllerBas public async Task DeleteAsync(long id) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return; StorageByMachine item = await context.StorageByMachine.FindAsync(id); @@ -82,10 +81,12 @@ public class StorageByMachineController(MarechaiContext context) : ControllerBas [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task CreateAsync(int machineId, StorageType type, StorageInterface @interface, long? capacity) + public async Task CreateAsync(int machineId, StorageType type, StorageInterface @interface, long? capacity) { string userId = User.FindFirstValue(ClaimTypes.Sid); + if(userId is null) return 0; + var item = new StorageByMachine { MachineId = machineId, @@ -99,4 +100,4 @@ public class StorageByMachineController(MarechaiContext context) : ControllerBas return item.Id; } -} +} \ No newline at end of file