diff --git a/Marechai.Server/Controllers/BookScansController.cs b/Marechai.Server/Controllers/BookScansController.cs index 148e5f8f..18034e93 100644 --- a/Marechai.Server/Controllers/BookScansController.cs +++ b/Marechai.Server/Controllers/BookScansController.cs @@ -80,14 +80,14 @@ public class BookScansController(MarechaiContext context) : ControllerBase [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task UpdateAsync(BookScanDto dto) + public async Task UpdateAsync(BookScanDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return; + if(userId is null) return Unauthorized(); BookScan model = await context.BookScans.FindAsync(dto.Id); - if(model is null) return; + if(model is null) return NotFound(); model.Author = dto.Author; model.ColorSpace = dto.ColorSpace; @@ -104,17 +104,19 @@ public class BookScansController(MarechaiContext context) : ControllerBase model.VerticalResolution = dto.VerticalResolution; await context.SaveChangesWithUserAsync(userId); + + return Ok(); } [HttpPost] [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task CreateAsync(BookScanDto dto) + public async Task> CreateAsync(BookScanDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return null; + if(userId is null) return Unauthorized(); var model = new BookScan { @@ -148,17 +150,19 @@ public class BookScansController(MarechaiContext context) : ControllerBase [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task DeleteAsync(Guid id) + public async Task DeleteAsync(Guid id) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return; + if(userId is null) return Unauthorized(); BookScan item = await context.BookScans.FindAsync(id); - if(item is null) return; + if(item is null) return NotFound(); context.BookScans.Remove(item); await context.SaveChangesWithUserAsync(userId); + + return Ok(); } } \ No newline at end of file diff --git a/Marechai.Server/Controllers/BooksController.cs b/Marechai.Server/Controllers/BooksController.cs index d58bafe8..72031bc0 100644 --- a/Marechai.Server/Controllers/BooksController.cs +++ b/Marechai.Server/Controllers/BooksController.cs @@ -90,14 +90,14 @@ public class BooksController(MarechaiContext context) : ControllerBase [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task UpdateAsync(BookDto dto) + public async Task UpdateAsync(BookDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return; + if(userId is null) return Unauthorized(); Book model = await context.Books.FindAsync(dto.Id); - if(model is null) return; + if(model is null) return NotFound(); model.Title = dto.Title; model.NativeTitle = dto.NativeTitle; @@ -110,6 +110,8 @@ public class BooksController(MarechaiContext context) : ControllerBase model.PreviousId = dto.PreviousId; model.SourceId = dto.SourceId; await context.SaveChangesWithUserAsync(userId); + + return Ok(); } [HttpPost] @@ -153,17 +155,19 @@ public class BooksController(MarechaiContext context) : ControllerBase [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task DeleteAsync(long id) + public async Task DeleteAsync(long id) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return; + if(userId is null) return Unauthorized(); Book item = await context.Books.FindAsync(id); - if(item is null) return; + if(item is null) return NotFound(); context.Books.Remove(item); await context.SaveChangesWithUserAsync(userId); + + return Ok(); } } \ No newline at end of file diff --git a/Marechai.Server/Controllers/CompaniesByBookController.cs b/Marechai.Server/Controllers/CompaniesByBookController.cs index 1621fda4..cdbb3166 100644 --- a/Marechai.Server/Controllers/CompaniesByBookController.cs +++ b/Marechai.Server/Controllers/CompaniesByBookController.cs @@ -63,29 +63,31 @@ public class CompaniesByBookController(MarechaiContext context) : ControllerBase [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task DeleteAsync(long id) + public async Task DeleteAsync(long id) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return; + if(userId is null) return Unauthorized(); CompaniesByBook item = await context.CompaniesByBooks.FindAsync(id); - if(item is null) return; + if(item is null) return NotFound(); context.CompaniesByBooks.Remove(item); await context.SaveChangesWithUserAsync(userId); + + return Ok(); } [HttpPost] [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task CreateAsync(int companyId, long bookId, string roleId) + public async Task> CreateAsync(int companyId, long bookId, string roleId) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return 0; + if(userId is null) return Unauthorized(); var item = new CompaniesByBook { diff --git a/Marechai.Server/Controllers/CompaniesByDocumentController.cs b/Marechai.Server/Controllers/CompaniesByDocumentController.cs index de7a23d2..17fa0398 100644 --- a/Marechai.Server/Controllers/CompaniesByDocumentController.cs +++ b/Marechai.Server/Controllers/CompaniesByDocumentController.cs @@ -63,29 +63,31 @@ public class CompaniesByDocumentController(MarechaiContext context) : Controller [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task DeleteAsync(long id) + public async Task DeleteAsync(long id) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return; + if(userId is null) return Unauthorized(); CompaniesByDocument item = await context.CompaniesByDocuments.FindAsync(id); - if(item is null) return; + if(item is null) return NotFound(); context.CompaniesByDocuments.Remove(item); await context.SaveChangesWithUserAsync(userId); + + return Ok(); } [HttpPost] [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task CreateAsync(int companyId, long documentId, string roleId) + public async Task> CreateAsync(int companyId, long documentId, string roleId) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return 0; + if(userId is null) return Unauthorized(); var item = new CompaniesByDocument { diff --git a/Marechai.Server/Controllers/CompaniesByMagazineController.cs b/Marechai.Server/Controllers/CompaniesByMagazineController.cs index b65867e0..ab4e3dc6 100644 --- a/Marechai.Server/Controllers/CompaniesByMagazineController.cs +++ b/Marechai.Server/Controllers/CompaniesByMagazineController.cs @@ -63,29 +63,31 @@ public class CompaniesByMagazineController(MarechaiContext context) : Controller [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task DeleteAsync(long id) + public async Task DeleteAsync(long id) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return; + if(userId is null) return Unauthorized(); CompaniesByMagazine item = await context.CompaniesByMagazines.FindAsync(id); - if(item is null) return; + if(item is null) return NotFound(); context.CompaniesByMagazines.Remove(item); await context.SaveChangesWithUserAsync(userId); + + return Ok(); } [HttpPost] [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task CreateAsync(int companyId, long magazineId, string roleId) + public async Task> CreateAsync(int companyId, long magazineId, string roleId) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return 0; + if(userId is null) return Unauthorized(); var item = new CompaniesByMagazine { diff --git a/Marechai.Server/Controllers/CompaniesBySoftwareFamilyController.cs b/Marechai.Server/Controllers/CompaniesBySoftwareFamilyController.cs index 6de57941..44b8da4e 100644 --- a/Marechai.Server/Controllers/CompaniesBySoftwareFamilyController.cs +++ b/Marechai.Server/Controllers/CompaniesBySoftwareFamilyController.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,46 +44,51 @@ public class CompaniesBySoftwareFamilyController(MarechaiContext context) : Cont [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task> GetBySoftwareFamily(ulong softwareFamilyId) => - await context.CompaniesBySoftwareFamilies.Where(p => p.SoftwareFamilyId == softwareFamilyId) - .Select(p => new CompanyBySoftwareFamilyDto - { - Id = p.Id, - Company = p.Company.Name, - CompanyId = p.CompanyId, - RoleId = p.RoleId, - Role = p.Role.Name, - SoftwareFamilyId = p.SoftwareFamilyId - }) - .OrderBy(p => p.Company) - .ThenBy(p => p.Role) - .ToListAsync(); + public async Task> GetBySoftwareFamily(ulong softwareFamilyId) => await context + .CompaniesBySoftwareFamilies.Where(p => p.SoftwareFamilyId == softwareFamilyId) + .Select(p => new CompanyBySoftwareFamilyDto + { + Id = p.Id, + Company = p.Company.Name, + CompanyId = p.CompanyId, + RoleId = p.RoleId, + Role = p.Role.Name, + SoftwareFamilyId = p.SoftwareFamilyId + }) + .OrderBy(p => p.Company) + .ThenBy(p => p.Role) + .ToListAsync(); [HttpDelete] [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task DeleteAsync(ulong id) + public async Task DeleteAsync(ulong id) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return; + + if(userId is null) return Unauthorized(); CompaniesBySoftwareFamily item = await context.CompaniesBySoftwareFamilies.FindAsync(id); - if(item is null) return; + if(item is null) return NotFound(); context.CompaniesBySoftwareFamilies.Remove(item); await context.SaveChangesWithUserAsync(userId); + + return Ok(); } [HttpPost] [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task CreateAsync(int companyId, ulong softwareFamilyId, string roleId) + public async Task> CreateAsync(int companyId, ulong softwareFamilyId, string roleId) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return null; + + if(userId is null) return Unauthorized(); + var item = new CompaniesBySoftwareFamily { CompanyId = companyId, @@ -98,4 +101,4 @@ public class CompaniesBySoftwareFamilyController(MarechaiContext context) : Cont return item.Id; } -} +} \ No newline at end of file diff --git a/Marechai.Server/Controllers/CompaniesBySoftwareVariantController.cs b/Marechai.Server/Controllers/CompaniesBySoftwareVariantController.cs index 76178313..06f317eb 100644 --- a/Marechai.Server/Controllers/CompaniesBySoftwareVariantController.cs +++ b/Marechai.Server/Controllers/CompaniesBySoftwareVariantController.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,46 +44,51 @@ public class CompaniesBySoftwareVariantController(MarechaiContext context) : Con [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task> GetBySoftwareVariant(ulong softwareVariantId) => - await context.CompaniesBySoftwareVariants.Where(p => p.SoftwareVariantId == softwareVariantId) - .Select(p => new CompanyBySoftwareVariantDto - { - Id = p.Id, - Company = p.Company.Name, - CompanyId = p.CompanyId, - RoleId = p.RoleId, - Role = p.Role.Name, - SoftwareVariantId = p.SoftwareVariantId - }) - .OrderBy(p => p.Company) - .ThenBy(p => p.Role) - .ToListAsync(); + public async Task> GetBySoftwareVariant(ulong softwareVariantId) => await context + .CompaniesBySoftwareVariants.Where(p => p.SoftwareVariantId == softwareVariantId) + .Select(p => new CompanyBySoftwareVariantDto + { + Id = p.Id, + Company = p.Company.Name, + CompanyId = p.CompanyId, + RoleId = p.RoleId, + Role = p.Role.Name, + SoftwareVariantId = p.SoftwareVariantId + }) + .OrderBy(p => p.Company) + .ThenBy(p => p.Role) + .ToListAsync(); [HttpDelete] [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task DeleteAsync(ulong id) + public async Task DeleteAsync(ulong id) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return; + + if(userId is null) return Unauthorized(); CompaniesBySoftwareVariant item = await context.CompaniesBySoftwareVariants.FindAsync(id); - if(item is null) return; + if(item is null) return NotFound(); context.CompaniesBySoftwareVariants.Remove(item); await context.SaveChangesWithUserAsync(userId); + + return Ok(); } [HttpPost] [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task CreateAsync(int companyId, ulong softwareVariantId, string roleId) + public async Task> CreateAsync(int companyId, ulong softwareVariantId, string roleId) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return null; + + if(userId is null) return Unauthorized(); + var item = new CompaniesBySoftwareVariant { CompanyId = companyId, @@ -98,4 +101,4 @@ public class CompaniesBySoftwareVariantController(MarechaiContext context) : Con return item.Id; } -} +} \ No newline at end of file diff --git a/Marechai.Server/Controllers/CompaniesBySoftwareVersionController.cs b/Marechai.Server/Controllers/CompaniesBySoftwareVersionController.cs index cd600631..d64550b8 100644 --- a/Marechai.Server/Controllers/CompaniesBySoftwareVersionController.cs +++ b/Marechai.Server/Controllers/CompaniesBySoftwareVersionController.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,46 +44,51 @@ public class CompaniesBySoftwareVersionController(MarechaiContext context) : Con [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task> GetBySoftwareVersion(ulong softwareVersionId) => - await context.CompaniesBySoftwareVersions.Where(p => p.SoftwareVersionId == softwareVersionId) - .Select(p => new CompanyBySoftwareVersionDto - { - Id = p.Id, - Company = p.Company.Name, - CompanyId = p.CompanyId, - RoleId = p.RoleId, - Role = p.Role.Name, - SoftwareVersionId = p.SoftwareVersionId - }) - .OrderBy(p => p.Company) - .ThenBy(p => p.Role) - .ToListAsync(); + public async Task> GetBySoftwareVersion(ulong softwareVersionId) => await context + .CompaniesBySoftwareVersions.Where(p => p.SoftwareVersionId == softwareVersionId) + .Select(p => new CompanyBySoftwareVersionDto + { + Id = p.Id, + Company = p.Company.Name, + CompanyId = p.CompanyId, + RoleId = p.RoleId, + Role = p.Role.Name, + SoftwareVersionId = p.SoftwareVersionId + }) + .OrderBy(p => p.Company) + .ThenBy(p => p.Role) + .ToListAsync(); [HttpDelete] [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task DeleteAsync(ulong id) + public async Task DeleteAsync(ulong id) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return; + + if(userId is null) return Unauthorized(); CompaniesBySoftwareVersion item = await context.CompaniesBySoftwareVersions.FindAsync(id); - if(item is null) return; + if(item is null) return NotFound(); context.CompaniesBySoftwareVersions.Remove(item); await context.SaveChangesWithUserAsync(userId); + + return Ok(); } [HttpPost] [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task CreateAsync(int companyId, ulong softwareVersionId, string roleId) + public async Task> CreateAsync(int companyId, ulong softwareVersionId, string roleId) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return null; + + if(userId is null) return Unauthorized(); + var item = new CompaniesBySoftwareVersion { CompanyId = companyId, @@ -98,4 +101,4 @@ public class CompaniesBySoftwareVersionController(MarechaiContext context) : Con return item.Id; } -} +} \ No newline at end of file diff --git a/Marechai.Server/Controllers/CompaniesController.cs b/Marechai.Server/Controllers/CompaniesController.cs index 59da002c..81715ab6 100644 --- a/Marechai.Server/Controllers/CompaniesController.cs +++ b/Marechai.Server/Controllers/CompaniesController.cs @@ -33,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; @@ -114,14 +113,14 @@ public class CompaniesController(MarechaiContext context) : ControllerBase [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task UpdateAsync(CompanyDto dto) + public async Task UpdateAsync(CompanyDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return; + if(userId is null) return Unauthorized(); Company model = await context.Companies.FindAsync(dto.Id); - if(model is null) return; + if(model is null) return NotFound(); model.Name = dto.Name; model.Founded = dto.Founded; @@ -142,17 +141,19 @@ public class CompaniesController(MarechaiContext context) : ControllerBase model.SoldMonthIsUnknown = dto.SoldMonthIsUnknown; model.LegalName = dto.LegalName; await context.SaveChangesWithUserAsync(userId); + + return Ok(); } [HttpPost] [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task CreateAsync(CompanyDto dto) + public async Task> CreateAsync(CompanyDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return 0; + if(userId is null) return Unauthorized(); var model = new Company { @@ -259,18 +260,20 @@ public class CompaniesController(MarechaiContext context) : ControllerBase [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task DeleteAsync(int id) + public async Task DeleteAsync(int id) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return; + if(userId is null) return Unauthorized(); Company item = await context.Companies.FindAsync(id); - if(item is null) return; + if(item is null) return NotFound(); context.Companies.Remove(item); await context.SaveChangesWithUserAsync(userId); + + return Ok(); } [HttpGet] @@ -292,11 +295,11 @@ public class CompaniesController(MarechaiContext context) : ControllerBase [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; + if(userId is null) return Unauthorized(); CompanyDescription current = await context.CompanyDescriptions.FirstOrDefaultAsync(d => d.CompanyId == id); if(current is null) diff --git a/Marechai.Server/Controllers/CompanyLogosController.cs b/Marechai.Server/Controllers/CompanyLogosController.cs index 20e5571e..bd22ef37 100644 --- a/Marechai.Server/Controllers/CompanyLogosController.cs +++ b/Marechai.Server/Controllers/CompanyLogosController.cs @@ -25,16 +25,16 @@ using System; using System.Collections.Generic; +using System.IO; 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.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Localization; namespace Marechai.Server.Controllers; @@ -53,18 +53,19 @@ public class CompanyLogosController(MarechaiContext context, IWebHostEnvironment [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task DeleteAsync(int id) + public async Task DeleteAsync(int id) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return; + + if(userId is null) return Unauthorized(); CompanyLogo logo = await context.CompanyLogos.Where(l => l.Id == id).FirstOrDefaultAsync(); - if(logo is null) return; + if(logo is null) return NotFound(); context.CompanyLogos.Remove(logo); await context.SaveChangesWithUserAsync(userId); - if(File.Exists(Path.Combine(_webRootPath, "assets/logos", logo.Guid + ".svg"))) + if(System.IO.File.Exists(Path.Combine(_webRootPath, "assets/logos", logo.Guid + ".svg"))) File.Delete(Path.Combine(_webRootPath, "assets/logos", logo.Guid + ".svg")); if(File.Exists(Path.Combine(_webRootPath, "assets/logos/webp/1x", logo.Guid + ".webp"))) @@ -108,26 +109,31 @@ public class CompanyLogosController(MarechaiContext context, IWebHostEnvironment [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task ChangeYearAsync(int id, int? year) + public async Task ChangeYearAsync(int id, int? year) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return; + + if(userId is null) return Unauthorized(); CompanyLogo logo = await context.CompanyLogos.Where(l => l.Id == id).FirstOrDefaultAsync(); - if(logo is null) return; + if(logo is null) return NotFound(); logo.Year = year; await context.SaveChangesWithUserAsync(userId); + + return Ok(); } [HttpPost] [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task CreateAsync(int companyId, Guid guid, int? year) + public async Task> CreateAsync(int companyId, Guid guid, int? year) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return 0; + + if(userId is null) return Unauthorized(); + var logo = new CompanyLogo { Guid = guid, @@ -140,4 +146,4 @@ public class CompanyLogosController(MarechaiContext context, IWebHostEnvironment return logo.Id; } -} +} \ No newline at end of file diff --git a/Marechai.Server/Controllers/ComputersController.cs b/Marechai.Server/Controllers/ComputersController.cs index 622e3ab9..a490c5f7 100644 --- a/Marechai.Server/Controllers/ComputersController.cs +++ b/Marechai.Server/Controllers/ComputersController.cs @@ -24,8 +24,10 @@ *******************************************************************************/ using System.Collections.Generic; +using System.Linq; using System.Threading.Tasks; using Marechai.Data.Dtos; +using Marechai.Database; using Marechai.Database.Models; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; diff --git a/Marechai.Server/Controllers/ConsolesController.cs b/Marechai.Server/Controllers/ConsolesController.cs index 4d8aec5a..b68945bf 100644 --- a/Marechai.Server/Controllers/ConsolesController.cs +++ b/Marechai.Server/Controllers/ConsolesController.cs @@ -24,8 +24,10 @@ *******************************************************************************/ using System.Collections.Generic; +using System.Linq; using System.Threading.Tasks; using Marechai.Data.Dtos; +using Marechai.Database; using Marechai.Database.Models; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; diff --git a/Marechai.Server/Controllers/CurrencyInflationController.cs b/Marechai.Server/Controllers/CurrencyInflationController.cs index 3bcbae5c..ba020698 100644 --- a/Marechai.Server/Controllers/CurrencyInflationController.cs +++ b/Marechai.Server/Controllers/CurrencyInflationController.cs @@ -75,30 +75,32 @@ public class CurrencyInflationController(MarechaiContext context) : ControllerBa [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task UpdateAsync(CurrencyInflationDto dto) + public async Task UpdateAsync(CurrencyInflationDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return; + if(userId is null) return Unauthorized(); CurrencyInflation model = await context.CurrenciesInflation.FindAsync(dto.Id); - if(model is null) return; + if(model is null) return NotFound(); model.CurrencyCode = dto.CurrencyCode; model.Year = dto.Year; model.Inflation = dto.Inflation; await context.SaveChangesWithUserAsync(userId); + + return Ok(); } [HttpPost] [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task CreateAsync(CurrencyInflationDto dto) + public async Task> CreateAsync(CurrencyInflationDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return 0; + if(userId is null) return Unauthorized(); var model = new CurrencyInflation { @@ -117,17 +119,19 @@ public class CurrencyInflationController(MarechaiContext context) : ControllerBa [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task DeleteAsync(int id) + public async Task DeleteAsync(int id) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return; + if(userId is null) return Unauthorized(); CurrencyInflation item = await context.CurrenciesInflation.FindAsync(id); - if(item is null) return; + if(item is null) return NotFound(); context.CurrenciesInflation.Remove(item); await context.SaveChangesWithUserAsync(userId); + + return Ok(); } } \ No newline at end of file diff --git a/Marechai.Server/Controllers/CurrencyPeggingController.cs b/Marechai.Server/Controllers/CurrencyPeggingController.cs index 62e15e5d..0407f1f6 100644 --- a/Marechai.Server/Controllers/CurrencyPeggingController.cs +++ b/Marechai.Server/Controllers/CurrencyPeggingController.cs @@ -83,14 +83,14 @@ public class CurrencyPeggingController(MarechaiContext context) : ControllerBase [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task UpdateAsync(CurrencyPeggingDto dto) + public async Task UpdateAsync(CurrencyPeggingDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return; + if(userId is null) return Unauthorized(); CurrencyPegging model = await context.CurrenciesPegging.FindAsync(dto.Id); - if(model is null) return; + if(model is null) return NotFound(); model.SourceCode = dto.SourceCode; model.DestinationCode = dto.DestinationCode; @@ -98,17 +98,19 @@ public class CurrencyPeggingController(MarechaiContext context) : ControllerBase model.Start = dto.Start; model.End = dto.End; await context.SaveChangesWithUserAsync(userId); + + return Ok(); } [HttpPost] [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task CreateAsync(CurrencyPeggingDto dto) + public async Task> CreateAsync(CurrencyPeggingDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return 0; + if(userId is null) return Unauthorized(); var model = new CurrencyPegging { @@ -129,17 +131,19 @@ public class CurrencyPeggingController(MarechaiContext context) : ControllerBase [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task DeleteAsync(int id) + public async Task DeleteAsync(int id) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return; + if(userId is null) return Unauthorized(); CurrencyPegging item = await context.CurrenciesPegging.FindAsync(id); - if(item is null) return; + if(item is null) return NotFound(); context.CurrenciesPegging.Remove(item); await context.SaveChangesWithUserAsync(userId); + + return Ok(); } } \ No newline at end of file diff --git a/Marechai.Server/Controllers/DocumentCompaniesController.cs b/Marechai.Server/Controllers/DocumentCompaniesController.cs index 12e79b53..824e6ca3 100644 --- a/Marechai.Server/Controllers/DocumentCompaniesController.cs +++ b/Marechai.Server/Controllers/DocumentCompaniesController.cs @@ -71,30 +71,32 @@ public class DocumentCompaniesController(MarechaiContext context) : ControllerBa [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task UpdateAsync(DocumentCompanyDto dto) + public async Task UpdateAsync(DocumentCompanyDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return; + if(userId is null) return Unauthorized(); DocumentCompany model = await context.DocumentCompanies.FindAsync(dto.Id); - if(model is null) return; + if(model is null) return NotFound(); model.CompanyId = dto.CompanyId; model.Name = dto.Name; await context.SaveChangesWithUserAsync(userId); + + return Ok(); } [HttpPost] [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task CreateAsync(DocumentCompanyDto dto) + public async Task> CreateAsync(DocumentCompanyDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return 0; + if(userId is null) return Unauthorized(); var model = new DocumentCompany { @@ -112,17 +114,19 @@ public class DocumentCompaniesController(MarechaiContext context) : ControllerBa [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task DeleteAsync(int id) + public async Task DeleteAsync(int id) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return; + if(userId is null) return Unauthorized(); DocumentCompany item = await context.DocumentCompanies.FindAsync(id); - if(item is null) return; + if(item is null) return NotFound(); context.DocumentCompanies.Remove(item); await context.SaveChangesWithUserAsync(userId); + + return Ok(); } } \ No newline at end of file diff --git a/Marechai.Server/Controllers/DocumentPeopleController.cs b/Marechai.Server/Controllers/DocumentPeopleController.cs index 4085601d..ca0e3fad 100644 --- a/Marechai.Server/Controllers/DocumentPeopleController.cs +++ b/Marechai.Server/Controllers/DocumentPeopleController.cs @@ -77,14 +77,14 @@ public class DocumentPeopleController(MarechaiContext context) : ControllerBase [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task UpdateAsync(DocumentPersonDto dto) + public async Task UpdateAsync(DocumentPersonDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return; + if(userId is null) return Unauthorized(); DocumentPerson model = await context.DocumentPeople.FindAsync(dto.Id); - if(model is null) return; + if(model is null) return NotFound(); model.Alias = dto.Alias; model.Name = dto.Name; @@ -93,17 +93,19 @@ public class DocumentPeopleController(MarechaiContext context) : ControllerBase model.PersonId = dto.PersonId; await context.SaveChangesWithUserAsync(userId); + + return Ok(); } [HttpPost] [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task CreateAsync(DocumentPersonDto dto) + public async Task> CreateAsync(DocumentPersonDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return 0; + if(userId is null) return Unauthorized(); var model = new DocumentPerson { @@ -124,17 +126,19 @@ public class DocumentPeopleController(MarechaiContext context) : ControllerBase [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task DeleteAsync(int id) + public async Task DeleteAsync(int id) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return; + if(userId is null) return Unauthorized(); DocumentPerson item = await context.DocumentPeople.FindAsync(id); - if(item is null) return; + if(item is null) return NotFound(); context.DocumentPeople.Remove(item); await context.SaveChangesWithUserAsync(userId); + + return Ok(); } } \ No newline at end of file diff --git a/Marechai.Server/Controllers/DocumentScansController.cs b/Marechai.Server/Controllers/DocumentScansController.cs index ae307710..a1fd3be9 100644 --- a/Marechai.Server/Controllers/DocumentScansController.cs +++ b/Marechai.Server/Controllers/DocumentScansController.cs @@ -80,14 +80,14 @@ public class DocumentScansController(MarechaiContext context) : ControllerBase [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task UpdateAsync(DocumentScanDto dto) + public async Task UpdateAsync(DocumentScanDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return; + if(userId is null) return Unauthorized(); DocumentScan model = await context.DocumentScans.FindAsync(dto.Id); - if(model is null) return; + if(model is null) return NotFound(); model.Author = dto.Author; model.ColorSpace = dto.ColorSpace; @@ -104,17 +104,19 @@ public class DocumentScansController(MarechaiContext context) : ControllerBase model.VerticalResolution = dto.VerticalResolution; await context.SaveChangesWithUserAsync(userId); + + return Ok(); } [HttpPost] [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task CreateAsync(DocumentScanDto dto) + public async Task> CreateAsync(DocumentScanDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return null; + if(userId is null) return Unauthorized(); var model = new DocumentScan { @@ -148,17 +150,19 @@ public class DocumentScansController(MarechaiContext context) : ControllerBase [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task DeleteAsync(Guid id) + public async Task DeleteAsync(Guid id) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return; + if(userId is null) return Unauthorized(); DocumentScan item = await context.DocumentScans.FindAsync(id); - if(item is null) return; + if(item is null) return NotFound(); context.DocumentScans.Remove(item); await context.SaveChangesWithUserAsync(userId); + + return Ok(); } } \ No newline at end of file diff --git a/Marechai.Server/Controllers/DocumentsByMachineController.cs b/Marechai.Server/Controllers/DocumentsByMachineController.cs index 13572c08..95c89629 100644 --- a/Marechai.Server/Controllers/DocumentsByMachineController.cs +++ b/Marechai.Server/Controllers/DocumentsByMachineController.cs @@ -60,29 +60,31 @@ public class DocumentsByMachineController(MarechaiContext context) : ControllerB [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task DeleteAsync(long id) + public async Task DeleteAsync(long id) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return; + if(userId is null) return Unauthorized(); DocumentsByMachine item = await context.DocumentsByMachines.FindAsync(id); - if(item is null) return; + if(item is null) return NotFound(); context.DocumentsByMachines.Remove(item); await context.SaveChangesWithUserAsync(userId); + + return Ok(); } [HttpPost] [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task CreateAsync(int machineId, long bookId) + public async Task> CreateAsync(int machineId, long bookId) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return 0; + if(userId is null) return Unauthorized(); var item = new DocumentsByMachine { diff --git a/Marechai.Server/Controllers/DocumentsByMachineFamilyController.cs b/Marechai.Server/Controllers/DocumentsByMachineFamilyController.cs index d17f732f..0207d834 100644 --- a/Marechai.Server/Controllers/DocumentsByMachineFamilyController.cs +++ b/Marechai.Server/Controllers/DocumentsByMachineFamilyController.cs @@ -60,29 +60,31 @@ public class DocumentsByMachineFamilyController(MarechaiContext context) : Contr [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task DeleteAsync(long id) + public async Task DeleteAsync(long id) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return; + if(userId is null) return Unauthorized(); DocumentsByMachineFamily item = await context.DocumentsByMachineFamilies.FindAsync(id); - if(item is null) return; + if(item is null) return NotFound(); context.DocumentsByMachineFamilies.Remove(item); await context.SaveChangesWithUserAsync(userId); + + return Ok(); } [HttpPost] [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task CreateAsync(int machineFamilyId, long bookId) + public async Task> CreateAsync(int machineFamilyId, long bookId) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return 0; + if(userId is null) return Unauthorized(); var item = new DocumentsByMachineFamily { diff --git a/Marechai.Server/Controllers/DocumentsController.cs b/Marechai.Server/Controllers/DocumentsController.cs index 0b9c237f..e4de4d3c 100644 --- a/Marechai.Server/Controllers/DocumentsController.cs +++ b/Marechai.Server/Controllers/DocumentsController.cs @@ -80,14 +80,14 @@ public class DocumentsController(MarechaiContext context) : ControllerBase [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task UpdateAsync(DocumentDto dto) + public async Task UpdateAsync(DocumentDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return; + if(userId is null) return Unauthorized(); Document model = await context.Documents.FindAsync(dto.Id); - if(model is null) return; + if(model is null) return NotFound(); model.Title = dto.Title; model.NativeTitle = dto.NativeTitle; @@ -95,17 +95,19 @@ public class DocumentsController(MarechaiContext context) : ControllerBase model.Synopsis = dto.Synopsis; model.CountryId = dto.CountryId; await context.SaveChangesWithUserAsync(userId); + + return Ok(); } [HttpPost] [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task CreateAsync(DocumentDto dto) + public async Task> CreateAsync(DocumentDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return 0; + if(userId is null) return Unauthorized(); var model = new Document { @@ -133,17 +135,19 @@ public class DocumentsController(MarechaiContext context) : ControllerBase [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task DeleteAsync(long id) + public async Task DeleteAsync(long id) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return; + if(userId is null) return Unauthorized(); Document item = await context.Documents.FindAsync(id); - if(item is null) return; + if(item is null) return NotFound(); context.Documents.Remove(item); await context.SaveChangesWithUserAsync(userId); + + return Ok(); } } \ No newline at end of file diff --git a/Marechai.Server/Controllers/DumpsController.cs b/Marechai.Server/Controllers/DumpsController.cs index 3de6caa8..b9832e99 100644 --- a/Marechai.Server/Controllers/DumpsController.cs +++ b/Marechai.Server/Controllers/DumpsController.cs @@ -85,14 +85,14 @@ public class DumpsController(MarechaiContext context) : ControllerBase [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task UpdateAsync(DumpDto dto) + public async Task UpdateAsync(DumpDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return; + if(userId is null) return Unauthorized(); Dump model = await context.Dumps.FindAsync(dto.Id); - if(model is null) return; + if(model is null) return NotFound(); model.Dumper = dto.Dumper; model.UserId = dto.UserId; @@ -101,17 +101,19 @@ public class DumpsController(MarechaiContext context) : ControllerBase model.MediaId = dto.MediaId; model.MediaDumpId = dto.MediaDumpId; await context.SaveChangesWithUserAsync(userId); + + return Ok(); } [HttpPost] [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task CreateAsync(DumpDto dto) + public async Task> CreateAsync(DumpDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return null; + if(userId is null) return Unauthorized(); var model = new Dump { @@ -133,17 +135,19 @@ public class DumpsController(MarechaiContext context) : ControllerBase [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task DeleteAsync(ulong id) + public async Task DeleteAsync(ulong id) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return; + if(userId is null) return Unauthorized(); Dump item = await context.Dumps.FindAsync(id); - if(item is null) return; + if(item is null) return NotFound(); context.Dumps.Remove(item); await context.SaveChangesWithUserAsync(userId); + + return Ok(); } } \ No newline at end of file diff --git a/Marechai.Server/Controllers/GpusByMachineController.cs b/Marechai.Server/Controllers/GpusByMachineController.cs index f2bf1439..27f38aca 100644 --- a/Marechai.Server/Controllers/GpusByMachineController.cs +++ b/Marechai.Server/Controllers/GpusByMachineController.cs @@ -62,29 +62,31 @@ public class GpusByMachineController(MarechaiContext context) : ControllerBase [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task DeleteAsync(long id) + public async Task DeleteAsync(long id) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return; + if(userId is null) return Unauthorized(); GpusByMachine item = await context.GpusByMachine.FindAsync(id); - if(item is null) return; + if(item is null) return NotFound(); context.GpusByMachine.Remove(item); await context.SaveChangesWithUserAsync(userId); + + return Ok(); } [HttpPost] [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task CreateAsync(int gpuId, int machineId) + public async Task> CreateAsync(int gpuId, int machineId) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return 0; + if(userId is null) return Unauthorized(); var item = new GpusByMachine { diff --git a/Marechai.Server/Controllers/GpusController.cs b/Marechai.Server/Controllers/GpusController.cs index e2b1f005..7b66c347 100644 --- a/Marechai.Server/Controllers/GpusController.cs +++ b/Marechai.Server/Controllers/GpusController.cs @@ -106,14 +106,14 @@ public class GpusController(MarechaiContext context) : ControllerBase [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task UpdateAsync(GpuDto dto) + public async Task UpdateAsync(GpuDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return; + if(userId is null) return Unauthorized(); Gpu model = await context.Gpus.FindAsync(dto.Id); - if(model is null) return; + if(model is null) return NotFound(); model.Name = dto.Name; model.CompanyId = dto.CompanyId; @@ -126,17 +126,19 @@ public class GpusController(MarechaiContext context) : ControllerBase model.Transistors = dto.Transistors; await context.SaveChangesWithUserAsync(userId); + + return Ok(); } [HttpPost] [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task CreateAsync(GpuDto dto) + public async Task> CreateAsync(GpuDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return 0; + if(userId is null) return Unauthorized(); var model = new Gpu { @@ -161,17 +163,19 @@ public class GpusController(MarechaiContext context) : ControllerBase [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task DeleteAsync(int id) + public async Task DeleteAsync(int id) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return; + if(userId is null) return Unauthorized(); Gpu item = await context.Gpus.FindAsync(id); - if(item is null) return; + if(item is null) return NotFound(); context.Gpus.Remove(item); await context.SaveChangesWithUserAsync(userId); + + return Ok(); } } \ No newline at end of file diff --git a/Marechai.Server/Controllers/InstructionSetExtensionsByProcessorController.cs b/Marechai.Server/Controllers/InstructionSetExtensionsByProcessorController.cs index 96e34694..6a105ea6 100644 --- a/Marechai.Server/Controllers/InstructionSetExtensionsByProcessorController.cs +++ b/Marechai.Server/Controllers/InstructionSetExtensionsByProcessorController.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,44 +44,49 @@ public class InstructionSetExtensionsByProcessorController(MarechaiContext conte [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task> GetByProcessor(int processorId) => - await context.InstructionSetExtensionsByProcessor.Where(e => e.ProcessorId == processorId) - .Select(e => new InstructionSetExtensionByProcessorDto - { - Id = e.Id, - Extension = e.Extension.Extension, - Processor = e.Processor.Name, - ProcessorId = e.ProcessorId, - ExtensionId = e.ExtensionId - }) - .OrderBy(e => e.Extension) - .ToListAsync(); + public async Task> GetByProcessor(int processorId) => await context + .InstructionSetExtensionsByProcessor.Where(e => e.ProcessorId == processorId) + .Select(e => new InstructionSetExtensionByProcessorDto + { + Id = e.Id, + Extension = e.Extension.Extension, + Processor = e.Processor.Name, + ProcessorId = e.ProcessorId, + ExtensionId = e.ExtensionId + }) + .OrderBy(e => e.Extension) + .ToListAsync(); [HttpDelete] [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task DeleteAsync(int id) + public async Task DeleteAsync(int id) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return; + + if(userId is null) return Unauthorized(); InstructionSetExtensionsByProcessor item = await context.InstructionSetExtensionsByProcessor.FindAsync(id); - if(item is null) return; + if(item is null) return NotFound(); context.InstructionSetExtensionsByProcessor.Remove(item); await context.SaveChangesWithUserAsync(userId); + + return Ok(); } [HttpPost] [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task CreateAsync(int processorId, int extensionId) + public async Task> CreateAsync(int processorId, int extensionId) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return 0; + + if(userId is null) return Unauthorized(); + var item = new InstructionSetExtensionsByProcessor { ProcessorId = processorId, @@ -95,4 +98,4 @@ public class InstructionSetExtensionsByProcessorController(MarechaiContext conte return item.Id; } -} +} \ No newline at end of file diff --git a/Marechai.Server/Controllers/InstructionSetExtensionsController.cs b/Marechai.Server/Controllers/InstructionSetExtensionsController.cs index 4011682f..30d8511f 100644 --- a/Marechai.Server/Controllers/InstructionSetExtensionsController.cs +++ b/Marechai.Server/Controllers/InstructionSetExtensionsController.cs @@ -68,29 +68,31 @@ public class InstructionSetExtensionsController(MarechaiContext context) : Contr [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task UpdateAsync(InstructionSetExtension viewModel) + public async Task UpdateAsync(InstructionSetExtension viewModel) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return; + if(userId is null) return Unauthorized(); InstructionSetExtension model = await context.InstructionSetExtensions.FindAsync(viewModel.Id); - if(model is null) return; + if(model is null) return NotFound(); model.Extension = viewModel.Extension; await context.SaveChangesWithUserAsync(userId); + + return Ok(); } [HttpPost] [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task CreateAsync(InstructionSetExtension viewModel) + public async Task> CreateAsync(InstructionSetExtension viewModel) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return 0; + if(userId is null) return Unauthorized(); var model = new InstructionSetExtension { @@ -107,18 +109,20 @@ public class InstructionSetExtensionsController(MarechaiContext context) : Contr [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task DeleteAsync(int id) + public async Task DeleteAsync(int id) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return; + if(userId is null) return Unauthorized(); InstructionSetExtension item = await context.InstructionSetExtensions.FindAsync(id); - if(item is null) return; + if(item is null) return NotFound(); context.InstructionSetExtensions.Remove(item); await context.SaveChangesWithUserAsync(userId); + + return Ok(); } [HttpGet] diff --git a/Marechai.Server/Controllers/InstructionSetsController.cs b/Marechai.Server/Controllers/InstructionSetsController.cs index 86397c33..57ba4c18 100644 --- a/Marechai.Server/Controllers/InstructionSetsController.cs +++ b/Marechai.Server/Controllers/InstructionSetsController.cs @@ -68,29 +68,31 @@ public class InstructionSetsController(MarechaiContext context) : ControllerBase [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task UpdateAsync(InstructionSet viewModel) + public async Task UpdateAsync(InstructionSet viewModel) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return; + if(userId is null) return Unauthorized(); InstructionSet model = await context.InstructionSets.FindAsync(viewModel.Id); - if(model is null) return; + if(model is null) return NotFound(); model.Name = viewModel.Name; await context.SaveChangesWithUserAsync(userId); + + return Ok(); } [HttpPost] [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task CreateAsync(InstructionSet viewModel) + public async Task> CreateAsync(InstructionSet viewModel) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return 0; + if(userId is null) return Unauthorized(); var model = new InstructionSet { @@ -107,18 +109,20 @@ public class InstructionSetsController(MarechaiContext context) : ControllerBase [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task DeleteAsync(int id) + public async Task DeleteAsync(int id) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return; + if(userId is null) return Unauthorized(); InstructionSet item = await context.InstructionSets.FindAsync(id); - if(item is null) return; + if(item is null) return NotFound(); context.InstructionSets.Remove(item); await context.SaveChangesWithUserAsync(userId); + + return Ok(); } [HttpGet] diff --git a/Marechai.Server/Controllers/LicensesController.cs b/Marechai.Server/Controllers/LicensesController.cs index fcb8beae..6bafb978 100644 --- a/Marechai.Server/Controllers/LicensesController.cs +++ b/Marechai.Server/Controllers/LicensesController.cs @@ -76,14 +76,14 @@ public class LicensesController(MarechaiContext context) : ControllerBase [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task UpdateAsync(License viewModel) + public async Task UpdateAsync(License viewModel) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return; + if(userId is null) return Unauthorized(); License model = await context.Licenses.FindAsync(viewModel.Id); - if(model is null) return; + if(model is null) return NotFound(); model.FsfApproved = viewModel.FsfApproved; model.Link = viewModel.Link; @@ -93,17 +93,19 @@ public class LicensesController(MarechaiContext context) : ControllerBase model.Text = viewModel.Text; await context.SaveChangesWithUserAsync(userId); + + return Ok(); } [HttpPost] [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task CreateAsync(License viewModel) + public async Task> CreateAsync(License viewModel) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return 0; + if(userId is null) return Unauthorized(); var model = new License { @@ -125,17 +127,19 @@ public class LicensesController(MarechaiContext context) : ControllerBase [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task DeleteAsync(int id) + public async Task DeleteAsync(int id) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return; + if(userId is null) return Unauthorized(); License item = await context.Licenses.FindAsync(id); - if(item is null) return; + if(item is null) return NotFound(); context.Licenses.Remove(item); await context.SaveChangesWithUserAsync(userId); + + return Ok(); } } \ No newline at end of file diff --git a/Marechai.Server/Controllers/MachineFamiliesController.cs b/Marechai.Server/Controllers/MachineFamiliesController.cs index 78b4a107..32bc8e06 100644 --- a/Marechai.Server/Controllers/MachineFamiliesController.cs +++ b/Marechai.Server/Controllers/MachineFamiliesController.cs @@ -72,30 +72,32 @@ public class MachineFamiliesController(MarechaiContext context) : ControllerBase [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task UpdateAsync(MachineFamilyDto dto) + public async Task UpdateAsync(MachineFamilyDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return; + if(userId is null) return Unauthorized(); MachineFamily model = await context.MachineFamilies.FindAsync(dto.Id); - if(model is null) return; + if(model is null) return NotFound(); model.Name = dto.Name; model.CompanyId = dto.CompanyId; await context.SaveChangesWithUserAsync(userId); + + return Ok(); } [HttpPost] [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task CreateAsync(MachineFamilyDto dto) + public async Task> CreateAsync(MachineFamilyDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return 0; + if(userId is null) return Unauthorized(); var model = new MachineFamily { @@ -113,17 +115,19 @@ public class MachineFamiliesController(MarechaiContext context) : ControllerBase [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task DeleteAsync(int id) + public async Task DeleteAsync(int id) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return; + if(userId is null) return Unauthorized(); MachineFamily item = await context.MachineFamilies.FindAsync(id); - if(item is null) return; + if(item is null) return NotFound(); context.MachineFamilies.Remove(item); await context.SaveChangesWithUserAsync(userId); + + return Ok(); } } \ No newline at end of file diff --git a/Marechai.Server/Controllers/MachinePhotosController.cs b/Marechai.Server/Controllers/MachinePhotosController.cs index 7851cc78..51da5745 100644 --- a/Marechai.Server/Controllers/MachinePhotosController.cs +++ b/Marechai.Server/Controllers/MachinePhotosController.cs @@ -104,14 +104,14 @@ public class MachinePhotosController(MarechaiContext context) : ControllerBase [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task UpdateAsync(MachinePhotoDto dto) + public async Task UpdateAsync(MachinePhotoDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return; + if(userId is null) return Unauthorized(); MachinePhoto model = await context.MachinePhotos.FindAsync(dto.Id); - if(model is null) return; + if(model is null) return NotFound(); model.Aperture = dto.Aperture; model.Author = dto.Author; @@ -149,17 +149,19 @@ public class MachinePhotosController(MarechaiContext context) : ControllerBase model.WhiteBalance = dto.WhiteBalance; await context.SaveChangesWithUserAsync(userId); + + return Ok(); } [HttpPost] [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task CreateAsync(MachinePhotoDto dto) + public async Task> CreateAsync(MachinePhotoDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return null; + if(userId is null) return Unauthorized(); var model = new MachinePhoto { diff --git a/Marechai.Server/Controllers/MachinesController.cs b/Marechai.Server/Controllers/MachinesController.cs index 04be65c0..06b2532b 100644 --- a/Marechai.Server/Controllers/MachinesController.cs +++ b/Marechai.Server/Controllers/MachinesController.cs @@ -29,6 +29,7 @@ using System.Linq; using System.Security.Claims; using System.Threading.Tasks; using Marechai.Data.Dtos; +using Marechai.Database; using Marechai.Database.Models; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; @@ -90,14 +91,14 @@ public class MachinesController [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task UpdateAsync(MachineDto dto) + public async Task UpdateAsync(MachineDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return; + if(userId is null) return Unauthorized(); Machine model = await context.Machines.FindAsync(dto.Id); - if(model is null) return; + if(model is null) return NotFound(); model.CompanyId = dto.CompanyId; model.Name = dto.Name; @@ -131,17 +132,19 @@ public class MachinesController if(news != null) await context.News.AddAsync(news); await context.SaveChangesWithUserAsync(userId); + + return Ok(); } [HttpPost] [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task CreateAsync(MachineDto dto) + public async Task> CreateAsync(MachineDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return 0; + if(userId is null) return Unauthorized(); var model = new Machine { @@ -260,17 +263,19 @@ public class MachinesController [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task DeleteAsync(int id) + public async Task DeleteAsync(int id) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return; + if(userId is null) return Unauthorized(); Machine item = await context.Machines.FindAsync(id); - if(item is null) return; + if(item is null) return NotFound(); context.Machines.Remove(item); await context.SaveChangesWithUserAsync(userId); + + return Ok(); } } \ No newline at end of file diff --git a/Marechai.Server/Controllers/MagazineIssuesController.cs b/Marechai.Server/Controllers/MagazineIssuesController.cs index 933cf1ec..4be3ba89 100644 --- a/Marechai.Server/Controllers/MagazineIssuesController.cs +++ b/Marechai.Server/Controllers/MagazineIssuesController.cs @@ -84,14 +84,14 @@ public class MagazineIssuesController(MarechaiContext context) : ControllerBase [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task UpdateAsync(MagazineIssueDto dto) + public async Task UpdateAsync(MagazineIssueDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return; + if(userId is null) return Unauthorized(); MagazineIssue model = await context.MagazineIssues.FindAsync(dto.Id); - if(model is null) return; + if(model is null) return NotFound(); model.MagazineId = dto.MagazineId; model.Caption = dto.Caption; @@ -101,17 +101,19 @@ public class MagazineIssuesController(MarechaiContext context) : ControllerBase model.Pages = dto.Pages; model.IssueNumber = dto.IssueNumber; await context.SaveChangesWithUserAsync(userId); + + return Ok(); } [HttpPost] [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task CreateAsync(MagazineIssueDto dto) + public async Task> CreateAsync(MagazineIssueDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return 0; + if(userId is null) return Unauthorized(); var model = new MagazineIssue { @@ -134,17 +136,19 @@ public class MagazineIssuesController(MarechaiContext context) : ControllerBase [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task DeleteAsync(long id) + public async Task DeleteAsync(long id) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return; + if(userId is null) return Unauthorized(); MagazineIssue item = await context.MagazineIssues.FindAsync(id); - if(item is null) return; + if(item is null) return NotFound(); context.MagazineIssues.Remove(item); await context.SaveChangesWithUserAsync(userId); + + return Ok(); } } \ No newline at end of file diff --git a/Marechai.Server/Controllers/MagazineScansController.cs b/Marechai.Server/Controllers/MagazineScansController.cs index 4d514478..dcf8da52 100644 --- a/Marechai.Server/Controllers/MagazineScansController.cs +++ b/Marechai.Server/Controllers/MagazineScansController.cs @@ -80,14 +80,14 @@ public class MagazineScansController(MarechaiContext context) : ControllerBase [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task UpdateAsync(MagazineScanDto dto) + public async Task UpdateAsync(MagazineScanDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return; + if(userId is null) return Unauthorized(); MagazineScan model = await context.MagazineScans.FindAsync(dto.Id); - if(model is null) return; + if(model is null) return NotFound(); model.Author = dto.Author; model.ColorSpace = dto.ColorSpace; @@ -104,17 +104,19 @@ public class MagazineScansController(MarechaiContext context) : ControllerBase model.VerticalResolution = dto.VerticalResolution; await context.SaveChangesWithUserAsync(userId); + + return Ok(); } [HttpPost] [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task CreateAsync(MagazineScanDto dto) + public async Task> CreateAsync(MagazineScanDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return null; + if(userId is null) return Unauthorized(); var model = new MagazineScan { @@ -148,17 +150,19 @@ public class MagazineScansController(MarechaiContext context) : ControllerBase [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task DeleteAsync(Guid id) + public async Task DeleteAsync(Guid id) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return; + if(userId is null) return Unauthorized(); MagazineScan item = await context.MagazineScans.FindAsync(id); - if(item is null) return; + if(item is null) return NotFound(); context.MagazineScans.Remove(item); await context.SaveChangesWithUserAsync(userId); + + return Ok(); } } \ No newline at end of file diff --git a/Marechai.Server/Controllers/MagazinesByMachineController.cs b/Marechai.Server/Controllers/MagazinesByMachineController.cs index e6d5e3af..9473fafc 100644 --- a/Marechai.Server/Controllers/MagazinesByMachineController.cs +++ b/Marechai.Server/Controllers/MagazinesByMachineController.cs @@ -60,29 +60,31 @@ public class MagazinesByMachineController(MarechaiContext context) : ControllerB [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task DeleteAsync(long id) + public async Task DeleteAsync(long id) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return; + if(userId is null) return Unauthorized(); MagazinesByMachine item = await context.MagazinesByMachines.FindAsync(id); - if(item is null) return; + if(item is null) return NotFound(); context.MagazinesByMachines.Remove(item); await context.SaveChangesWithUserAsync(userId); + + return Ok(); } [HttpPost] [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task CreateAsync(int machineId, long bookId) + public async Task> CreateAsync(int machineId, long bookId) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return 0; + if(userId is null) return Unauthorized(); var item = new MagazinesByMachine { diff --git a/Marechai.Server/Controllers/MagazinesByMachineFamilyController.cs b/Marechai.Server/Controllers/MagazinesByMachineFamilyController.cs index 0a0cd4d7..1e872f68 100644 --- a/Marechai.Server/Controllers/MagazinesByMachineFamilyController.cs +++ b/Marechai.Server/Controllers/MagazinesByMachineFamilyController.cs @@ -60,29 +60,31 @@ public class MagazinesByMachineFamilyController(MarechaiContext context) : Contr [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task DeleteAsync(long id) + public async Task DeleteAsync(long id) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return; + if(userId is null) return Unauthorized(); MagazinesByMachineFamily item = await context.MagazinesByMachinesFamilies.FindAsync(id); - if(item is null) return; + if(item is null) return NotFound(); context.MagazinesByMachinesFamilies.Remove(item); await context.SaveChangesWithUserAsync(userId); + + return Ok(); } [HttpPost] [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task CreateAsync(int machineFamilyId, long bookId) + public async Task> CreateAsync(int machineFamilyId, long bookId) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return 0; + if(userId is null) return Unauthorized(); var item = new MagazinesByMachineFamily { diff --git a/Marechai.Server/Controllers/MagazinesController.cs b/Marechai.Server/Controllers/MagazinesController.cs index 6f70b19a..d4d80d51 100644 --- a/Marechai.Server/Controllers/MagazinesController.cs +++ b/Marechai.Server/Controllers/MagazinesController.cs @@ -95,14 +95,14 @@ public class MagazinesController(MarechaiContext context) : ControllerBase [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task UpdateAsync(MagazineDto dto) + public async Task UpdateAsync(MagazineDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return; + if(userId is null) return Unauthorized(); Magazine model = await context.Magazines.FindAsync(dto.Id); - if(model is null) return; + if(model is null) return NotFound(); model.Title = dto.Title; model.NativeTitle = dto.NativeTitle; @@ -111,17 +111,19 @@ public class MagazinesController(MarechaiContext context) : ControllerBase model.CountryId = dto.CountryId; model.Issn = dto.Issn; await context.SaveChangesWithUserAsync(userId); + + return Ok(); } [HttpPost] [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task CreateAsync(MagazineDto dto) + public async Task> CreateAsync(MagazineDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return 0; + if(userId is null) return Unauthorized(); var model = new Magazine { @@ -150,17 +152,19 @@ public class MagazinesController(MarechaiContext context) : ControllerBase [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task DeleteAsync(long id) + public async Task DeleteAsync(long id) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return; + if(userId is null) return Unauthorized(); Magazine item = await context.Magazines.FindAsync(id); - if(item is null) return; + if(item is null) return NotFound(); context.Magazines.Remove(item); await context.SaveChangesWithUserAsync(userId); + + return Ok(); } } \ No newline at end of file diff --git a/Marechai.Server/Controllers/MediaController.cs b/Marechai.Server/Controllers/MediaController.cs index 12f54a60..ca6d61a8 100644 --- a/Marechai.Server/Controllers/MediaController.cs +++ b/Marechai.Server/Controllers/MediaController.cs @@ -128,14 +128,14 @@ public class MediaController(MarechaiContext context) : ControllerBase [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task UpdateAsync(MediaDto dto) + public async Task UpdateAsync(MediaDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return; + if(userId is null) return Unauthorized(); Media model = await context.Media.FindAsync(dto.Id); - if(model is null) return; + if(model is null) return NotFound(); model.Title = dto.Title; model.Sequence = dto.Sequence; @@ -163,17 +163,19 @@ public class MediaController(MarechaiContext context) : ControllerBase model.StorageInterface = dto.StorageInterface; model.TableOfContents = dto.TableOfContents; await context.SaveChangesWithUserAsync(userId); + + return Ok(); } [HttpPost] [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task CreateAsync(MediaDto dto) + public async Task> CreateAsync(MediaDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return null; + if(userId is null) return Unauthorized(); var model = new Media { @@ -214,17 +216,19 @@ public class MediaController(MarechaiContext context) : ControllerBase [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task DeleteAsync(ulong id) + public async Task DeleteAsync(ulong id) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return; + if(userId is null) return Unauthorized(); Media item = await context.Media.FindAsync(id); - if(item is null) return; + if(item is null) return NotFound(); context.Media.Remove(item); await context.SaveChangesWithUserAsync(userId); + + return Ok(); } } \ No newline at end of file diff --git a/Marechai.Server/Controllers/MemoriesByMachineController.cs b/Marechai.Server/Controllers/MemoriesByMachineController.cs index a4170015..6d683fbd 100644 --- a/Marechai.Server/Controllers/MemoriesByMachineController.cs +++ b/Marechai.Server/Controllers/MemoriesByMachineController.cs @@ -28,6 +28,7 @@ using System.Linq; using System.Security.Claims; using System.Threading.Tasks; using Marechai.Data.Dtos; +using Marechai.Database; using Marechai.Database.Models; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; @@ -65,29 +66,32 @@ public class MemoriesByMachineController(MarechaiContext context) : ControllerBa [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task DeleteAsync(long id) + public async Task DeleteAsync(long id) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return; + if(userId is null) return Unauthorized(); MemoryByMachine item = await context.MemoryByMachine.FindAsync(id); - if(item is null) return; + if(item is null) return NotFound(); context.MemoryByMachine.Remove(item); await context.SaveChangesWithUserAsync(userId); + + return Ok(); } [HttpPost] [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; + if(userId is null) return Unauthorized(); var item = new MemoryByMachine { diff --git a/Marechai.Server/Controllers/NewsController.cs b/Marechai.Server/Controllers/NewsController.cs index 09cefe05..96ccd781 100644 --- a/Marechai.Server/Controllers/NewsController.cs +++ b/Marechai.Server/Controllers/NewsController.cs @@ -28,12 +28,12 @@ using System.Linq; using System.Security.Claims; using System.Threading.Tasks; using Marechai.Data.Dtos; +using Marechai.Database; 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; @@ -158,17 +158,19 @@ public class NewsController(MarechaiContext context) : ControllerBase [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task DeleteAsync(int id) + public async Task DeleteAsync(int id) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return; + if(userId is null) return Unauthorized(); News item = await context.News.FindAsync(id); - if(item is null) return; + if(item is null) return NotFound(); context.News.Remove(item); await context.SaveChangesWithUserAsync(userId); + + return Ok(); } } \ No newline at end of file diff --git a/Marechai.Server/Controllers/PeopleByBookController.cs b/Marechai.Server/Controllers/PeopleByBookController.cs index 46a3be36..2a700ff3 100644 --- a/Marechai.Server/Controllers/PeopleByBookController.cs +++ b/Marechai.Server/Controllers/PeopleByBookController.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,50 +45,53 @@ public class PeopleByBookController(MarechaiContext context) : ControllerBase [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] public async Task> GetByBook(long bookId) => (await context.PeopleByBooks - .Where(p => p.BookId == bookId) - .Select(p => new PersonByBookDto - { - Id = p.Id, - Name = p.Person.Name, - Surname = p.Person.Surname, - Alias = p.Person.Alias, - DisplayName = - p.Person.DisplayName, - PersonId = p.PersonId, - RoleId = p.RoleId, - Role = p.Role.Name, - BookId = p.BookId - }) - .ToListAsync()) - .OrderBy(p => p.FullName) - .ThenBy(p => p.Role) - .ToList(); + .Where(p => p.BookId == bookId) + .Select(p => new PersonByBookDto + { + Id = p.Id, + Name = p.Person.Name, + Surname = p.Person.Surname, + Alias = p.Person.Alias, + DisplayName = p.Person.DisplayName, + PersonId = p.PersonId, + RoleId = p.RoleId, + Role = p.Role.Name, + BookId = p.BookId + }) + .ToListAsync()).OrderBy(p => p.FullName) + .ThenBy(p => p.Role) + .ToList(); [HttpDelete] [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task DeleteAsync(long id) + public async Task DeleteAsync(long id) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return; + + if(userId is null) return Unauthorized(); PeopleByBook item = await context.PeopleByBooks.FindAsync(id); - if(item is null) return; + if(item is null) return NotFound(); context.PeopleByBooks.Remove(item); await context.SaveChangesWithUserAsync(userId); + + return Ok(); } [HttpPost] [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task CreateAsync(int personId, long bookId, string roleId) + public async Task> CreateAsync(int personId, long bookId, string roleId) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return 0; + + if(userId is null) return Unauthorized(); + var item = new PeopleByBook { PersonId = personId, @@ -103,4 +104,4 @@ public class PeopleByBookController(MarechaiContext context) : ControllerBase return item.Id; } -} +} \ No newline at end of file diff --git a/Marechai.Server/Controllers/PeopleByDocumentController.cs b/Marechai.Server/Controllers/PeopleByDocumentController.cs index e4240bcd..53cec814 100644 --- a/Marechai.Server/Controllers/PeopleByDocumentController.cs +++ b/Marechai.Server/Controllers/PeopleByDocumentController.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,49 +44,54 @@ public class PeopleByDocumentController(MarechaiContext context) : ControllerBas [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task> GetByDocument(long documentId) => (await context - .PeopleByDocuments.Where(p => p.DocumentId == documentId) - .Select(p => new PersonByDocumentDto - { - Id = p.Id, - Name = p.Person.Name, - Surname = p.Person.Surname, - Alias = p.Person.Alias, - DisplayName = p.Person.DisplayName, - PersonId = p.PersonId, - RoleId = p.RoleId, - Role = p.Role.Name, - DocumentId = p.DocumentId - }) - .ToListAsync()).OrderBy(p => p.FullName) - .ThenBy(p => p.Role) - .ToList(); + public async Task> GetByDocument(long documentId) => (await context.PeopleByDocuments + .Where(p => p.DocumentId == documentId) + .Select(p => new PersonByDocumentDto + { + Id = p.Id, + Name = p.Person.Name, + Surname = p.Person.Surname, + Alias = p.Person.Alias, + DisplayName = p.Person.DisplayName, + PersonId = p.PersonId, + RoleId = p.RoleId, + Role = p.Role.Name, + DocumentId = p.DocumentId + }) + .ToListAsync()).OrderBy(p => p.FullName) + .ThenBy(p => p.Role) + .ToList(); [HttpDelete] [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task DeleteAsync(long id) + public async Task DeleteAsync(long id) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return; + + if(userId is null) return Unauthorized(); PeopleByDocument item = await context.PeopleByDocuments.FindAsync(id); - if(item is null) return; + if(item is null) return NotFound(); context.PeopleByDocuments.Remove(item); await context.SaveChangesWithUserAsync(userId); + + return Ok(); } [HttpPost] [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task CreateAsync(int personId, long documentId, string roleId) + public async Task> CreateAsync(int personId, long documentId, string roleId) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return 0; + + if(userId is null) return Unauthorized(); + var item = new PeopleByDocument { PersonId = personId, @@ -101,4 +104,4 @@ public class PeopleByDocumentController(MarechaiContext context) : ControllerBas return item.Id; } -} +} \ No newline at end of file diff --git a/Marechai.Server/Controllers/PeopleByMagazineController.cs b/Marechai.Server/Controllers/PeopleByMagazineController.cs index bab8a67b..b0480ac5 100644 --- a/Marechai.Server/Controllers/PeopleByMagazineController.cs +++ b/Marechai.Server/Controllers/PeopleByMagazineController.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,49 +44,54 @@ public class PeopleByMagazineController(MarechaiContext context) : ControllerBas [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task> GetByMagazine(long magazineId) => (await context - .PeopleByMagazines.Where(p => p.MagazineId == magazineId) - .Select(p => new PersonByMagazineDto - { - Id = p.Id, - Name = p.Person.Name, - Surname = p.Person.Surname, - Alias = p.Person.Alias, - DisplayName = p.Person.DisplayName, - PersonId = p.PersonId, - RoleId = p.RoleId, - Role = p.Role.Name, - MagazineId = p.MagazineId - }) - .ToListAsync()).OrderBy(p => p.FullName) - .ThenBy(p => p.Role) - .ToList(); + public async Task> GetByMagazine(long magazineId) => (await context.PeopleByMagazines + .Where(p => p.MagazineId == magazineId) + .Select(p => new PersonByMagazineDto + { + Id = p.Id, + Name = p.Person.Name, + Surname = p.Person.Surname, + Alias = p.Person.Alias, + DisplayName = p.Person.DisplayName, + PersonId = p.PersonId, + RoleId = p.RoleId, + Role = p.Role.Name, + MagazineId = p.MagazineId + }) + .ToListAsync()).OrderBy(p => p.FullName) + .ThenBy(p => p.Role) + .ToList(); [HttpDelete] [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task DeleteAsync(long id) + public async Task DeleteAsync(long id) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return; + + if(userId is null) return Unauthorized(); PeopleByMagazine item = await context.PeopleByMagazines.FindAsync(id); - if(item is null) return; + if(item is null) return NotFound(); context.PeopleByMagazines.Remove(item); await context.SaveChangesWithUserAsync(userId); + + return Ok(); } [HttpPost] [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task CreateAsync(int personId, long magazineId, string roleId) + public async Task> CreateAsync(int personId, long magazineId, string roleId) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return 0; + + if(userId is null) return Unauthorized(); + var item = new PeopleByMagazine { PersonId = personId, @@ -101,4 +104,4 @@ public class PeopleByMagazineController(MarechaiContext context) : ControllerBas return item.Id; } -} +} \ No newline at end of file diff --git a/Marechai.Server/Controllers/PeopleController.cs b/Marechai.Server/Controllers/PeopleController.cs index 67d52caa..711ea938 100644 --- a/Marechai.Server/Controllers/PeopleController.cs +++ b/Marechai.Server/Controllers/PeopleController.cs @@ -91,14 +91,14 @@ public class PeopleController(MarechaiContext context) : ControllerBase [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task UpdateAsync(PersonDto dto) + public async Task UpdateAsync(PersonDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return; + if(userId is null) return Unauthorized(); Person model = await context.People.FindAsync(dto.Id); - if(model is null) return; + if(model is null) return NotFound(); model.Name = dto.Name; model.Surname = dto.Surname; @@ -113,17 +113,19 @@ public class PeopleController(MarechaiContext context) : ControllerBase model.DisplayName = dto.DisplayName; await context.SaveChangesWithUserAsync(userId); + + return Ok(); } [HttpPost] [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task CreateAsync(PersonDto dto) + public async Task> CreateAsync(PersonDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return 0; + if(userId is null) return Unauthorized(); var model = new Person { @@ -150,17 +152,19 @@ public class PeopleController(MarechaiContext context) : ControllerBase [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task DeleteAsync(int id) + public async Task DeleteAsync(int id) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return; + if(userId is null) return Unauthorized(); Person item = await context.People.FindAsync(id); - if(item is null) return; + if(item is null) return NotFound(); context.People.Remove(item); await context.SaveChangesWithUserAsync(userId); + + return Ok(); } } \ No newline at end of file diff --git a/Marechai.Server/Controllers/ProcessorsByMachineController.cs b/Marechai.Server/Controllers/ProcessorsByMachineController.cs index 083349c2..ec1c13b9 100644 --- a/Marechai.Server/Controllers/ProcessorsByMachineController.cs +++ b/Marechai.Server/Controllers/ProcessorsByMachineController.cs @@ -63,29 +63,31 @@ public class ProcessorsByMachineController(MarechaiContext context) : Controller [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task DeleteAsync(long id) + public async Task DeleteAsync(long id) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return; + if(userId is null) return Unauthorized(); ProcessorsByMachine item = await context.ProcessorsByMachine.FindAsync(id); - if(item is null) return; + if(item is null) return NotFound(); context.ProcessorsByMachine.Remove(item); await context.SaveChangesWithUserAsync(userId); + + return Ok(); } [HttpPost] [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task CreateAsync(int processorId, int machineId, float? speed) + public async Task> CreateAsync(int processorId, int machineId, float? speed) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return 0; + if(userId is null) return Unauthorized(); var item = new ProcessorsByMachine { diff --git a/Marechai.Server/Controllers/ProcessorsController.cs b/Marechai.Server/Controllers/ProcessorsController.cs index c707b2ff..e01e0cba 100644 --- a/Marechai.Server/Controllers/ProcessorsController.cs +++ b/Marechai.Server/Controllers/ProcessorsController.cs @@ -163,14 +163,14 @@ public class ProcessorsController(MarechaiContext context) : ControllerBase [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task UpdateAsync(ProcessorDto dto) + public async Task UpdateAsync(ProcessorDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return; + if(userId is null) return Unauthorized(); Processor model = await context.Processors.FindAsync(dto.Id); - if(model is null) return; + if(model is null) return NotFound(); model.AddrBus = dto.AddrBus; model.CompanyId = dto.CompanyId; @@ -199,17 +199,19 @@ public class ProcessorsController(MarechaiContext context) : ControllerBase model.Transistors = dto.Transistors; await context.SaveChangesWithUserAsync(userId); + + return Ok(); } [HttpPost] [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task CreateAsync(ProcessorDto dto) + public async Task> CreateAsync(ProcessorDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return 0; + if(userId is null) return Unauthorized(); var model = new Processor { @@ -250,17 +252,19 @@ public class ProcessorsController(MarechaiContext context) : ControllerBase [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task DeleteAsync(int id) + public async Task DeleteAsync(int id) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return; + if(userId is null) return Unauthorized(); Processor item = await context.Processors.FindAsync(id); - if(item is null) return; + if(item is null) return NotFound(); context.Processors.Remove(item); await context.SaveChangesWithUserAsync(userId); + + return Ok(); } } \ No newline at end of file diff --git a/Marechai.Server/Controllers/ResolutionsByGpuController.cs b/Marechai.Server/Controllers/ResolutionsByGpuController.cs index ff201d34..10bebd4f 100644 --- a/Marechai.Server/Controllers/ResolutionsByGpuController.cs +++ b/Marechai.Server/Controllers/ResolutionsByGpuController.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,56 +45,65 @@ public class ResolutionsByGpuController(MarechaiContext context) : ControllerBas [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] public async Task> GetByGpu(int resolutionId) => (await context.ResolutionsByGpu - .Where(r => r.ResolutionId == resolutionId) - .Select(r => new ResolutionByGpuDto - { - Id = r.Id, - GpuId = r.GpuId, - Resolution = new ResolutionDto - { - Id = r.Resolution.Id, - Width = r.Resolution.Width, - Height = r.Resolution.Height, - Colors = r.Resolution.Colors, - Palette = r.Resolution.Palette, - Chars = r.Resolution.Chars, - Grayscale = r.Resolution.Grayscale - }, - ResolutionId = r.ResolutionId - }) - .ToListAsync()).OrderBy(r => r.Resolution.Width) - .ThenBy(r => r.Resolution.Height) - .ThenBy(r => r.Resolution.Chars) - .ThenBy(r => r.Resolution.Grayscale) - .ThenBy(r => r.Resolution.Colors) - .ThenBy(r => r.Resolution.Palette) - .ToList(); + .Where(r => r.ResolutionId == + resolutionId) + .Select(r => new ResolutionByGpuDto + { + Id = r.Id, + GpuId = r.GpuId, + Resolution = new ResolutionDto + { + Id = r.Resolution.Id, + Width = r.Resolution.Width, + Height = r.Resolution.Height, + Colors = r.Resolution.Colors, + Palette = r.Resolution + .Palette, + Chars = r.Resolution.Chars, + Grayscale = r.Resolution + .Grayscale + }, + ResolutionId = r.ResolutionId + }) + .ToListAsync()) + .OrderBy(r => r.Resolution.Width) + .ThenBy(r => r.Resolution.Height) + .ThenBy(r => r.Resolution.Chars) + .ThenBy(r => r.Resolution.Grayscale) + .ThenBy(r => r.Resolution.Colors) + .ThenBy(r => r.Resolution.Palette) + .ToList(); [HttpDelete] [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task DeleteAsync(long id) + public async Task DeleteAsync(long id) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return; + + if(userId is null) return Unauthorized(); ResolutionsByGpu item = await context.ResolutionsByGpu.FindAsync(id); - if(item is null) return; + if(item is null) return NotFound(); context.ResolutionsByGpu.Remove(item); await context.SaveChangesWithUserAsync(userId); + + return Ok(); } [HttpPost] [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task CreateAsync(int resolutionId, int gpuId) + public async Task> CreateAsync(int resolutionId, int gpuId) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return 0; + + if(userId is null) return Unauthorized(); + var item = new ResolutionsByGpu { GpuId = gpuId, @@ -108,4 +115,4 @@ public class ResolutionsByGpuController(MarechaiContext context) : ControllerBas return item.Id; } -} +} \ No newline at end of file diff --git a/Marechai.Server/Controllers/ResolutionsByScreenController.cs b/Marechai.Server/Controllers/ResolutionsByScreenController.cs index 0e0b3322..f35c5dad 100644 --- a/Marechai.Server/Controllers/ResolutionsByScreenController.cs +++ b/Marechai.Server/Controllers/ResolutionsByScreenController.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,57 +44,62 @@ public class ResolutionsByScreenController(MarechaiContext context) : Controller [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task> GetByScreen(int resolutionId) => (await context - .ResolutionsByScreen.Where(r => r.ResolutionId == resolutionId) - .Select(r => new ResolutionByScreenDto - { - Id = r.Id, - ScreenId = r.ScreenId, - Resolution = new ResolutionDto - { - Id = r.Resolution.Id, - Width = r.Resolution.Width, - Height = r.Resolution.Height, - Colors = r.Resolution.Colors, - Palette = r.Resolution.Palette, - Chars = r.Resolution.Chars, - Grayscale = r.Resolution.Grayscale - }, - ResolutionId = r.ResolutionId - }) - .ToListAsync()).OrderBy(r => r.Resolution.Width) - .ThenBy(r => r.Resolution.Height) - .ThenBy(r => r.Resolution.Chars) - .ThenBy(r => r.Resolution.Grayscale) - .ThenBy(r => r.Resolution.Colors) - .ThenBy(r => r.Resolution.Palette) - .ToList(); + public async Task> GetByScreen(int resolutionId) => (await context.ResolutionsByScreen + .Where(r => r.ResolutionId == resolutionId) + .Select(r => new ResolutionByScreenDto + { + Id = r.Id, + ScreenId = r.ScreenId, + Resolution = new ResolutionDto + { + Id = r.Resolution.Id, + Width = r.Resolution.Width, + Height = r.Resolution.Height, + Colors = r.Resolution.Colors, + Palette = r.Resolution.Palette, + Chars = r.Resolution.Chars, + Grayscale = r.Resolution.Grayscale + }, + ResolutionId = r.ResolutionId + }) + .ToListAsync()).OrderBy(r => r.Resolution.Width) + .ThenBy(r => r.Resolution.Height) + .ThenBy(r => r.Resolution.Chars) + .ThenBy(r => r.Resolution.Grayscale) + .ThenBy(r => r.Resolution.Colors) + .ThenBy(r => r.Resolution.Palette) + .ToList(); [HttpDelete] [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task DeleteAsync(long id) + public async Task DeleteAsync(long id) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return; + + if(userId is null) return Unauthorized(); ResolutionsByScreen item = await context.ResolutionsByScreen.FindAsync(id); - if(item is null) return; + if(item is null) return NotFound(); context.ResolutionsByScreen.Remove(item); await context.SaveChangesWithUserAsync(userId); + + return Ok(); } [HttpPost] [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task CreateAsync(int resolutionId, int screenId) + public async Task> CreateAsync(int resolutionId, int screenId) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return 0; + + if(userId is null) return Unauthorized(); + var item = new ResolutionsByScreen { ScreenId = screenId, @@ -108,4 +111,4 @@ public class ResolutionsByScreenController(MarechaiContext context) : Controller return item.Id; } -} +} \ No newline at end of file diff --git a/Marechai.Server/Controllers/ResolutionsController.cs b/Marechai.Server/Controllers/ResolutionsController.cs index 5a0648bc..4c1feafc 100644 --- a/Marechai.Server/Controllers/ResolutionsController.cs +++ b/Marechai.Server/Controllers/ResolutionsController.cs @@ -83,14 +83,14 @@ public class ResolutionsController(MarechaiContext context) : ControllerBase [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task UpdateAsync(ResolutionDto dto) + public async Task UpdateAsync(ResolutionDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return; + if(userId is null) return Unauthorized(); Resolution model = await context.Resolutions.FindAsync(dto.Id); - if(model is null) return; + if(model is null) return NotFound(); model.Chars = dto.Chars; model.Colors = dto.Colors; @@ -100,17 +100,19 @@ public class ResolutionsController(MarechaiContext context) : ControllerBase model.Width = dto.Width; await context.SaveChangesWithUserAsync(userId); + + return Ok(); } [HttpPost] [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task CreateAsync(ResolutionDto dto) + public async Task> CreateAsync(ResolutionDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return 0; + if(userId is null) return Unauthorized(); var model = new Resolution { @@ -132,17 +134,19 @@ public class ResolutionsController(MarechaiContext context) : ControllerBase [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task DeleteAsync(int id) + public async Task DeleteAsync(int id) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return; + if(userId is null) return Unauthorized(); Resolution item = await context.Resolutions.FindAsync(id); - if(item is null) return; + if(item is null) return NotFound(); context.Resolutions.Remove(item); await context.SaveChangesWithUserAsync(userId); + + return Ok(); } } \ No newline at end of file diff --git a/Marechai.Server/Controllers/ScreensByMachineController.cs b/Marechai.Server/Controllers/ScreensByMachineController.cs index fd7738a9..069a7275 100644 --- a/Marechai.Server/Controllers/ScreensByMachineController.cs +++ b/Marechai.Server/Controllers/ScreensByMachineController.cs @@ -78,29 +78,31 @@ public class ScreensByMachineController(MarechaiContext context) : ControllerBas [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task DeleteAsync(long id) + public async Task DeleteAsync(long id) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return; + if(userId is null) return Unauthorized(); ScreensByMachine item = await context.ScreensByMachine.FindAsync(id); - if(item is null) return; + if(item is null) return NotFound(); context.ScreensByMachine.Remove(item); await context.SaveChangesWithUserAsync(userId); + + return Ok(); } [HttpPost] [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task CreateAsync(int machineId, int screenId) + public async Task> CreateAsync(int machineId, int screenId) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return 0; + if(userId is null) return Unauthorized(); if(context.ScreensByMachine.Any(s => s.MachineId == machineId && s.ScreenId == screenId)) return 0; var item = new ScreensByMachine diff --git a/Marechai.Server/Controllers/ScreensController.cs b/Marechai.Server/Controllers/ScreensController.cs index 91603dbb..1fdb0cb1 100644 --- a/Marechai.Server/Controllers/ScreensController.cs +++ b/Marechai.Server/Controllers/ScreensController.cs @@ -102,18 +102,18 @@ public class ScreensController(MarechaiContext context) : ControllerBase [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task UpdateAsync(ScreenDto dto) + public async Task UpdateAsync(ScreenDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return; + if(userId is null) return Unauthorized(); Screen model = await context.Screens.FindAsync(dto.Id); - if(model is null) return; + if(model is null) return NotFound(); Resolution nativeResolution = await context.Resolutions.FindAsync(dto.NativeResolutionId); - if(nativeResolution is null) return; + if(nativeResolution is null) return NotFound(); model.Diagonal = dto.Diagonal; model.EffectiveColors = dto.EffectiveColors; @@ -123,17 +123,19 @@ public class ScreensController(MarechaiContext context) : ControllerBase model.Width = dto.Width; await context.SaveChangesWithUserAsync(userId); + + return Ok(); } [HttpPost] [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task CreateAsync(ScreenDto dto) + public async Task> CreateAsync(ScreenDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return 0; + if(userId is null) return Unauthorized(); var model = new Screen { @@ -155,17 +157,19 @@ public class ScreensController(MarechaiContext context) : ControllerBase [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task DeleteAsync(int id) + public async Task DeleteAsync(int id) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return; + if(userId is null) return Unauthorized(); Screen item = await context.Screens.FindAsync(id); - if(item is null) return; + if(item is null) return NotFound(); context.Screens.Remove(item); await context.SaveChangesWithUserAsync(userId); + + return Ok(); } } \ No newline at end of file diff --git a/Marechai.Server/Controllers/SoftwareFamiliesController.cs b/Marechai.Server/Controllers/SoftwareFamiliesController.cs index 5062f922..db60c7b7 100644 --- a/Marechai.Server/Controllers/SoftwareFamiliesController.cs +++ b/Marechai.Server/Controllers/SoftwareFamiliesController.cs @@ -74,30 +74,32 @@ public class SoftwareFamiliesController(MarechaiContext context) : ControllerBas [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task UpdateAsync(SoftwareFamilyDto dto) + public async Task UpdateAsync(SoftwareFamilyDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return; + if(userId is null) return Unauthorized(); SoftwareFamily model = await context.SoftwareFamilies.FindAsync(dto.Id); - if(model is null) return; + if(model is null) return NotFound(); model.Name = dto.Name; model.ParentId = dto.ParentId; model.Introduced = dto.Introduced; await context.SaveChangesWithUserAsync(userId); + + return Ok(); } [HttpPost] [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task CreateAsync(SoftwareFamilyDto dto) + public async Task> CreateAsync(SoftwareFamilyDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return null; + if(userId is null) return Unauthorized(); var model = new SoftwareFamily { @@ -116,17 +118,19 @@ public class SoftwareFamiliesController(MarechaiContext context) : ControllerBas [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task DeleteAsync(ulong id) + public async Task DeleteAsync(ulong id) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return; + if(userId is null) return Unauthorized(); SoftwareFamily item = await context.SoftwareFamilies.FindAsync(id); - if(item is null) return; + if(item is null) return NotFound(); context.SoftwareFamilies.Remove(item); await context.SaveChangesWithUserAsync(userId); + + return Ok(); } } \ No newline at end of file diff --git a/Marechai.Server/Controllers/SoftwareVariantsController.cs b/Marechai.Server/Controllers/SoftwareVariantsController.cs index 7a8fc4ce..b75d9fea 100644 --- a/Marechai.Server/Controllers/SoftwareVariantsController.cs +++ b/Marechai.Server/Controllers/SoftwareVariantsController.cs @@ -105,14 +105,14 @@ public class SoftwareVariantsController(MarechaiContext context) : ControllerBas [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task UpdateAsync(SoftwareVariantDto dto) + public async Task UpdateAsync(SoftwareVariantDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return; + if(userId is null) return Unauthorized(); SoftwareVariant model = await context.SoftwareVariants.FindAsync(dto.Id); - if(model is null) return; + if(model is null) return NotFound(); model.Name = dto.Name; model.Version = dto.Version; @@ -129,17 +129,19 @@ public class SoftwareVariantsController(MarechaiContext context) : ControllerBas model.DistributionMode = dto.DistributionMode; await context.SaveChangesWithUserAsync(userId); + + return Ok(); } [HttpPost] [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task CreateAsync(SoftwareVariantDto dto) + public async Task> CreateAsync(SoftwareVariantDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return null; + if(userId is null) return Unauthorized(); var model = new SoftwareVariant { @@ -168,17 +170,19 @@ public class SoftwareVariantsController(MarechaiContext context) : ControllerBas [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task DeleteAsync(ulong id) + public async Task DeleteAsync(ulong id) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return; + if(userId is null) return Unauthorized(); SoftwareVariant item = await context.SoftwareVariants.FindAsync(id); - if(item is null) return; + if(item is null) return NotFound(); context.SoftwareVariants.Remove(item); await context.SaveChangesWithUserAsync(userId); + + return Ok(); } } \ No newline at end of file diff --git a/Marechai.Server/Controllers/SoftwareVersionsController.cs b/Marechai.Server/Controllers/SoftwareVersionsController.cs index ae79c943..f68461dc 100644 --- a/Marechai.Server/Controllers/SoftwareVersionsController.cs +++ b/Marechai.Server/Controllers/SoftwareVersionsController.cs @@ -88,14 +88,14 @@ public class SoftwareVersionsController(MarechaiContext context) : ControllerBas [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task UpdateAsync(SoftwareVersionDto dto) + public async Task UpdateAsync(SoftwareVersionDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return; + if(userId is null) return Unauthorized(); SoftwareVersion model = await context.SoftwareVersions.FindAsync(dto.Id); - if(model is null) return; + if(model is null) return NotFound(); model.Name = dto.Name; model.Codename = dto.Codename; @@ -105,17 +105,19 @@ public class SoftwareVersionsController(MarechaiContext context) : ControllerBas model.LicenseId = dto.LicenseId; model.PreviousId = dto.PreviousId; await context.SaveChangesWithUserAsync(userId); + + return Ok(); } [HttpPost] [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task CreateAsync(SoftwareVersionDto dto) + public async Task> CreateAsync(SoftwareVersionDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return null; + if(userId is null) return Unauthorized(); var model = new SoftwareVersion { @@ -138,17 +140,19 @@ public class SoftwareVersionsController(MarechaiContext context) : ControllerBas [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task DeleteAsync(ulong id) + public async Task DeleteAsync(ulong id) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return; + if(userId is null) return Unauthorized(); SoftwareVersion item = await context.SoftwareVersions.FindAsync(id); - if(item is null) return; + if(item is null) return NotFound(); context.SoftwareVersions.Remove(item); await context.SaveChangesWithUserAsync(userId); + + return Ok(); } } \ No newline at end of file diff --git a/Marechai.Server/Controllers/SoundSynthsByMachineController.cs b/Marechai.Server/Controllers/SoundSynthsByMachineController.cs index 22518222..5ae4050d 100644 --- a/Marechai.Server/Controllers/SoundSynthsByMachineController.cs +++ b/Marechai.Server/Controllers/SoundSynthsByMachineController.cs @@ -62,29 +62,31 @@ public class SoundSynthsByMachineController(MarechaiContext context) : Controlle [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task DeleteAsync(long id) + public async Task DeleteAsync(long id) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return; + if(userId is null) return Unauthorized(); SoundByMachine item = await context.SoundByMachine.FindAsync(id); - if(item is null) return; + if(item is null) return NotFound(); context.SoundByMachine.Remove(item); await context.SaveChangesWithUserAsync(userId); + + return Ok(); } [HttpPost] [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task CreateAsync(int soundSynthId, int machineId) + public async Task> CreateAsync(int soundSynthId, int machineId) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return 0; + if(userId is null) return Unauthorized(); var item = new SoundByMachine { diff --git a/Marechai.Server/Controllers/SoundSynthsController.cs b/Marechai.Server/Controllers/SoundSynthsController.cs index 6749b363..f06e4535 100644 --- a/Marechai.Server/Controllers/SoundSynthsController.cs +++ b/Marechai.Server/Controllers/SoundSynthsController.cs @@ -117,14 +117,14 @@ public class SoundSynthsController(MarechaiContext context) : ControllerBase [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task UpdateAsync(SoundSynthDto dto) + public async Task UpdateAsync(SoundSynthDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return; + if(userId is null) return Unauthorized(); SoundSynth model = await context.SoundSynths.FindAsync(dto.Id); - if(model is null) return; + if(model is null) return NotFound(); model.Depth = dto.Depth; model.Frequency = dto.Frequency; @@ -138,17 +138,19 @@ public class SoundSynthsController(MarechaiContext context) : ControllerBase model.WhiteNoise = dto.WhiteNoise; await context.SaveChangesWithUserAsync(userId); + + return Ok(); } [HttpPost] [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task CreateAsync(SoundSynthDto dto) + public async Task> CreateAsync(SoundSynthDto dto) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return 0; + if(userId is null) return Unauthorized(); var model = new SoundSynth { @@ -174,17 +176,19 @@ public class SoundSynthsController(MarechaiContext context) : ControllerBase [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task DeleteAsync(int id) + public async Task DeleteAsync(int id) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return; + if(userId is null) return Unauthorized(); SoundSynth item = await context.SoundSynths.FindAsync(id); - if(item is null) return; + if(item is null) return NotFound(); context.SoundSynths.Remove(item); await context.SaveChangesWithUserAsync(userId); + + return Ok(); } } \ No newline at end of file diff --git a/Marechai.Server/Controllers/StorageByMachineController.cs b/Marechai.Server/Controllers/StorageByMachineController.cs index b85815c6..24aadc68 100644 --- a/Marechai.Server/Controllers/StorageByMachineController.cs +++ b/Marechai.Server/Controllers/StorageByMachineController.cs @@ -28,6 +28,7 @@ using System.Linq; using System.Security.Claims; using System.Threading.Tasks; using Marechai.Data.Dtos; +using Marechai.Database; using Marechai.Database.Models; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; @@ -63,29 +64,32 @@ public class StorageByMachineController(MarechaiContext context) : ControllerBas [Authorize(Roles = "Admin,UberAdmin")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task DeleteAsync(long id) + public async Task DeleteAsync(long id) { string userId = User.FindFirstValue(ClaimTypes.Sid); - if(userId is null) return; + if(userId is null) return Unauthorized(); StorageByMachine item = await context.StorageByMachine.FindAsync(id); - if(item is null) return; + if(item is null) return NotFound(); context.StorageByMachine.Remove(item); await context.SaveChangesWithUserAsync(userId); + + return Ok(); } [HttpPost] [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; + if(userId is null) return Unauthorized(); var item = new StorageByMachine {