Refactor controller methods to use synchronous Task return types for improved readability

This commit is contained in:
2025-11-13 18:27:00 +00:00
parent e4c2837ad9
commit a715d936eb
47 changed files with 1585 additions and 1571 deletions

View File

@@ -34,7 +34,6 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Localization;
namespace Marechai.Server.Controllers; namespace Marechai.Server.Controllers;
@@ -53,7 +52,7 @@ public class BookScansController(MarechaiContext context) : ControllerBase
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<BookScanDto> GetAsync(Guid id) => await context.BookScans.Where(p => p.Id == id) public Task<BookScanDto> GetAsync(Guid id) => context.BookScans.Where(p => p.Id == id)
.Select(p => new BookScanDto .Select(p => new BookScanDto
{ {
Author = p.Author, Author = p.Author,
@@ -62,23 +61,18 @@ public class BookScansController(MarechaiContext context) : ControllerBase
Comments = p.Comments, Comments = p.Comments,
CreationDate = p.CreationDate, CreationDate = p.CreationDate,
ExifVersion = p.ExifVersion, ExifVersion = p.ExifVersion,
HorizontalResolution = HorizontalResolution = p.HorizontalResolution,
p.HorizontalResolution,
Id = p.Id, Id = p.Id,
ResolutionUnit = ResolutionUnit = p.ResolutionUnit,
p.ResolutionUnit,
Page = p.Page, Page = p.Page,
ScannerManufacturer = ScannerManufacturer = p.ScannerManufacturer,
p.ScannerManufacturer,
ScannerModel = p.ScannerModel, ScannerModel = p.ScannerModel,
SoftwareUsed = p.SoftwareUsed, SoftwareUsed = p.SoftwareUsed,
Type = p.Type, Type = p.Type,
UploadDate = p.UploadDate, UploadDate = p.UploadDate,
UserId = p.UserId, UserId = p.UserId,
VerticalResolution = VerticalResolution = p.VerticalResolution,
p.VerticalResolution, OriginalExtension = p.OriginalExtension
OriginalExtension =
p.OriginalExtension
}) })
.FirstOrDefaultAsync(); .FirstOrDefaultAsync();
@@ -89,6 +83,7 @@ public class BookScansController(MarechaiContext context) : ControllerBase
public async Task UpdateAsync(BookScanDto dto) public async Task UpdateAsync(BookScanDto dto)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return; if(userId is null) return;
BookScan model = await context.BookScans.FindAsync(dto.Id); BookScan model = await context.BookScans.FindAsync(dto.Id);
@@ -118,7 +113,9 @@ public class BookScansController(MarechaiContext context) : ControllerBase
public async Task<Guid> CreateAsync(BookScanDto dto) public async Task<Guid> CreateAsync(BookScanDto dto)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return null; if(userId is null) return null;
var model = new BookScan var model = new BookScan
{ {
Author = dto.Author, Author = dto.Author,
@@ -154,6 +151,7 @@ public class BookScansController(MarechaiContext context) : ControllerBase
public async Task DeleteAsync(Guid id) public async Task DeleteAsync(Guid id)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return; if(userId is null) return;
BookScan item = await context.BookScans.FindAsync(id); BookScan item = await context.BookScans.FindAsync(id);

View File

@@ -23,7 +23,6 @@
// Copyright © 2003-2025 Natalia Portillo // Copyright © 2003-2025 Natalia Portillo
*******************************************************************************/ *******************************************************************************/
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Security.Claims; using System.Security.Claims;
@@ -34,7 +33,6 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Localization;
namespace Marechai.Server.Controllers; namespace Marechai.Server.Controllers;
@@ -46,7 +44,7 @@ public class BooksController(MarechaiContext context) : ControllerBase
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<List<BookDto>> GetAsync() => await context.Books.OrderBy(b => b.NativeTitle) public Task<List<BookDto>> GetAsync() => context.Books.OrderBy(b => b.NativeTitle)
.ThenBy(b => b.Published) .ThenBy(b => b.Published)
.ThenBy(b => b.Title) .ThenBy(b => b.Title)
.Select(b => new BookDto .Select(b => new BookDto
@@ -70,7 +68,7 @@ public class BooksController(MarechaiContext context) : ControllerBase
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<BookDto> GetAsync(long id) => await context.Books.Where(b => b.Id == id) public Task<BookDto> GetAsync(long id) => context.Books.Where(b => b.Id == id)
.Select(b => new BookDto .Select(b => new BookDto
{ {
Id = b.Id, Id = b.Id,
@@ -95,6 +93,7 @@ public class BooksController(MarechaiContext context) : ControllerBase
public async Task UpdateAsync(BookDto dto) public async Task UpdateAsync(BookDto dto)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return; if(userId is null) return;
Book model = await context.Books.FindAsync(dto.Id); Book model = await context.Books.FindAsync(dto.Id);
@@ -120,7 +119,9 @@ public class BooksController(MarechaiContext context) : ControllerBase
public async Task<long> CreateAsync(BookDto dto) public async Task<long> CreateAsync(BookDto dto)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return 0; if(userId is null) return 0;
var model = new Book var model = new Book
{ {
Title = dto.Title, Title = dto.Title,
@@ -155,6 +156,7 @@ public class BooksController(MarechaiContext context) : ControllerBase
public async Task DeleteAsync(long id) public async Task DeleteAsync(long id)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return; if(userId is null) return;
Book item = await context.Books.FindAsync(id); Book item = await context.Books.FindAsync(id);

View File

@@ -23,7 +23,6 @@
// Copyright © 2003-2025 Natalia Portillo // Copyright © 2003-2025 Natalia Portillo
*******************************************************************************/ *******************************************************************************/
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Security.Claims; using System.Security.Claims;
@@ -34,7 +33,6 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Localization;
namespace Marechai.Server.Controllers; namespace Marechai.Server.Controllers;
@@ -46,7 +44,7 @@ public class CompaniesByBookController(MarechaiContext context) : ControllerBase
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<List<CompanyByBookDto>> GetByBook(long bookId) => await context.CompaniesByBooks public Task<List<CompanyByBookDto>> GetByBook(long bookId) => context.CompaniesByBooks
.Where(p => p.BookId == bookId) .Where(p => p.BookId == bookId)
.Select(p => new CompanyByBookDto .Select(p => new CompanyByBookDto
{ {
@@ -68,6 +66,7 @@ public class CompaniesByBookController(MarechaiContext context) : ControllerBase
public async Task DeleteAsync(long id) public async Task DeleteAsync(long id)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return; if(userId is null) return;
CompaniesByBook item = await context.CompaniesByBooks.FindAsync(id); CompaniesByBook item = await context.CompaniesByBooks.FindAsync(id);
@@ -85,7 +84,9 @@ public class CompaniesByBookController(MarechaiContext context) : ControllerBase
public async Task<long> CreateAsync(int companyId, long bookId, string roleId) public async Task<long> CreateAsync(int companyId, long bookId, string roleId)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return 0; if(userId is null) return 0;
var item = new CompaniesByBook var item = new CompaniesByBook
{ {
CompanyId = companyId, CompanyId = companyId,

View File

@@ -23,7 +23,6 @@
// Copyright © 2003-2025 Natalia Portillo // Copyright © 2003-2025 Natalia Portillo
*******************************************************************************/ *******************************************************************************/
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Security.Claims; using System.Security.Claims;
@@ -34,7 +33,6 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Localization;
namespace Marechai.Server.Controllers; namespace Marechai.Server.Controllers;
@@ -46,8 +44,8 @@ public class CompaniesByDocumentController(MarechaiContext context) : Controller
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<List<CompanyByDocumentDto>> GetByDocument(long documentId) => await context public Task<List<CompanyByDocumentDto>> GetByDocument(long documentId) => context.CompaniesByDocuments
.CompaniesByDocuments.Where(p => p.DocumentId == documentId) .Where(p => p.DocumentId == documentId)
.Select(p => new CompanyByDocumentDto .Select(p => new CompanyByDocumentDto
{ {
Id = p.Id, Id = p.Id,
@@ -68,6 +66,7 @@ public class CompaniesByDocumentController(MarechaiContext context) : Controller
public async Task DeleteAsync(long id) public async Task DeleteAsync(long id)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return; if(userId is null) return;
CompaniesByDocument item = await context.CompaniesByDocuments.FindAsync(id); CompaniesByDocument item = await context.CompaniesByDocuments.FindAsync(id);
@@ -85,7 +84,9 @@ public class CompaniesByDocumentController(MarechaiContext context) : Controller
public async Task<long> CreateAsync(int companyId, long documentId, string roleId) public async Task<long> CreateAsync(int companyId, long documentId, string roleId)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return 0; if(userId is null) return 0;
var item = new CompaniesByDocument var item = new CompaniesByDocument
{ {
CompanyId = companyId, CompanyId = companyId,

View File

@@ -23,7 +23,6 @@
// Copyright © 2003-2025 Natalia Portillo // Copyright © 2003-2025 Natalia Portillo
*******************************************************************************/ *******************************************************************************/
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Security.Claims; using System.Security.Claims;
@@ -34,7 +33,6 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Localization;
namespace Marechai.Server.Controllers; namespace Marechai.Server.Controllers;
@@ -46,8 +44,8 @@ public class CompaniesByMagazineController(MarechaiContext context) : Controller
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<List<CompanyByMagazineDto>> GetByMagazine(long magazineId) => await context public Task<List<CompanyByMagazineDto>> GetByMagazine(long magazineId) => context.CompaniesByMagazines
.CompaniesByMagazines.Where(p => p.MagazineId == magazineId) .Where(p => p.MagazineId == magazineId)
.Select(p => new CompanyByMagazineDto .Select(p => new CompanyByMagazineDto
{ {
Id = p.Id, Id = p.Id,
@@ -68,6 +66,7 @@ public class CompaniesByMagazineController(MarechaiContext context) : Controller
public async Task DeleteAsync(long id) public async Task DeleteAsync(long id)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return; if(userId is null) return;
CompaniesByMagazine item = await context.CompaniesByMagazines.FindAsync(id); CompaniesByMagazine item = await context.CompaniesByMagazines.FindAsync(id);
@@ -85,7 +84,9 @@ public class CompaniesByMagazineController(MarechaiContext context) : Controller
public async Task<long> CreateAsync(int companyId, long magazineId, string roleId) public async Task<long> CreateAsync(int companyId, long magazineId, string roleId)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return 0; if(userId is null) return 0;
var item = new CompaniesByMagazine var item = new CompaniesByMagazine
{ {
CompanyId = companyId, CompanyId = companyId,

View File

@@ -23,7 +23,6 @@
// Copyright © 2003-2025 Natalia Portillo // Copyright © 2003-2025 Natalia Portillo
*******************************************************************************/ *******************************************************************************/
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Security.Claims; using System.Security.Claims;
@@ -46,14 +45,13 @@ public class CompaniesController(MarechaiContext context, IStringLocalizer<Compa
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<List<CompanyDto>> GetAsync() => await context.Companies.Include(c => c.Logos) public Task<List<CompanyDto>> GetAsync() => context.Companies.Include(c => c.Logos)
.OrderBy(c => c.Name) .OrderBy(c => c.Name)
.Select(c => new CompanyDto .Select(c => new CompanyDto
{ {
Id = c.Id, Id = c.Id,
LastLogo = LastLogo =
c.Logos c.Logos.OrderByDescending(l => l.Year)
.OrderByDescending(l => l.Year)
.FirstOrDefault() .FirstOrDefault()
.Guid, .Guid,
Name = c.Name, Name = c.Name,
@@ -70,14 +68,10 @@ public class CompaniesController(MarechaiContext context, IStringLocalizer<Compa
Province = c.Province, Province = c.Province,
PostalCode = c.PostalCode, PostalCode = c.PostalCode,
Country = c.Country.Name, Country = c.Country.Name,
FoundedDayIsUnknown = FoundedDayIsUnknown = c.FoundedDayIsUnknown,
c.FoundedDayIsUnknown, FoundedMonthIsUnknown = c.FoundedMonthIsUnknown,
FoundedMonthIsUnknown = SoldDayIsUnknown = c.SoldDayIsUnknown,
c.FoundedMonthIsUnknown, SoldMonthIsUnknown = c.SoldMonthIsUnknown,
SoldDayIsUnknown =
c.SoldDayIsUnknown,
SoldMonthIsUnknown =
c.SoldMonthIsUnknown,
LegalName = c.LegalName LegalName = c.LegalName
}) })
.ToListAsync(); .ToListAsync();
@@ -86,13 +80,12 @@ public class CompaniesController(MarechaiContext context, IStringLocalizer<Compa
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<CompanyDto> GetAsync(int id) => await context.Companies.Where(c => c.Id == id) public Task<CompanyDto> GetAsync(int id) => context.Companies.Where(c => c.Id == id)
.Select(c => new CompanyDto .Select(c => new CompanyDto
{ {
Id = c.Id, Id = c.Id,
LastLogo = LastLogo =
c.Logos c.Logos.OrderByDescending(l => l.Year)
.OrderByDescending(l => l.Year)
.FirstOrDefault() .FirstOrDefault()
.Guid, .Guid,
Name = c.Name, Name = c.Name,
@@ -109,14 +102,10 @@ public class CompaniesController(MarechaiContext context, IStringLocalizer<Compa
Province = c.Province, Province = c.Province,
PostalCode = c.PostalCode, PostalCode = c.PostalCode,
Country = c.Country.Name, Country = c.Country.Name,
FoundedDayIsUnknown = FoundedDayIsUnknown = c.FoundedDayIsUnknown,
c.FoundedDayIsUnknown, FoundedMonthIsUnknown = c.FoundedMonthIsUnknown,
FoundedMonthIsUnknown = SoldDayIsUnknown = c.SoldDayIsUnknown,
c.FoundedMonthIsUnknown, SoldMonthIsUnknown = c.SoldMonthIsUnknown,
SoldDayIsUnknown =
c.SoldDayIsUnknown,
SoldMonthIsUnknown =
c.SoldMonthIsUnknown,
LegalName = c.LegalName LegalName = c.LegalName
}) })
.FirstOrDefaultAsync(); .FirstOrDefaultAsync();
@@ -128,6 +117,7 @@ public class CompaniesController(MarechaiContext context, IStringLocalizer<Compa
public async Task UpdateAsync(CompanyDto dto) public async Task UpdateAsync(CompanyDto dto)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return; if(userId is null) return;
Company model = await context.Companies.FindAsync(dto.Id); Company model = await context.Companies.FindAsync(dto.Id);
@@ -161,7 +151,9 @@ public class CompaniesController(MarechaiContext context, IStringLocalizer<Compa
public async Task<int> CreateAsync(CompanyDto dto) public async Task<int> CreateAsync(CompanyDto dto)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return 0; if(userId is null) return 0;
var model = new Company var model = new Company
{ {
Name = dto.Name, Name = dto.Name,
@@ -194,7 +186,7 @@ public class CompaniesController(MarechaiContext context, IStringLocalizer<Compa
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<List<Machine>> GetMachinesAsync(int id) => await context.Machines.Where(m => m.CompanyId == id) public Task<List<Machine>> GetMachinesAsync(int id) => context.Machines.Where(m => m.CompanyId == id)
.OrderBy(m => m.Name) .OrderBy(m => m.Name)
.Select(m => new Machine .Select(m => new Machine
{ {
@@ -219,7 +211,7 @@ public class CompaniesController(MarechaiContext context, IStringLocalizer<Compa
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<Company> GetSoldToAsync(int? id) => await context.Companies.Select(c => new Company public Task<Company> GetSoldToAsync(int? id) => context.Companies.Select(c => new Company
{ {
Id = c.Id, Id = c.Id,
Name = c.Name Name = c.Name
@@ -237,8 +229,7 @@ public class CompaniesController(MarechaiContext context, IStringLocalizer<Compa
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public Task<List<CompanyDto>> GetCompaniesByCountryAsync(int countryId) => context.Companies public Task<List<CompanyDto>> GetCompaniesByCountryAsync(int countryId) => context.Companies.Include(c => c.Logos)
.Include(c => c.Logos)
.Where(c => c.CountryId == countryId) .Where(c => c.CountryId == countryId)
.OrderBy(c => c.Name) .OrderBy(c => c.Name)
.Select(c => new CompanyDto .Select(c => new CompanyDto
@@ -271,6 +262,7 @@ public class CompaniesController(MarechaiContext context, IStringLocalizer<Compa
public async Task DeleteAsync(int id) public async Task DeleteAsync(int id)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return; if(userId is null) return;
Company item = await context.Companies.FindAsync(id); Company item = await context.Companies.FindAsync(id);
@@ -285,7 +277,7 @@ public class CompaniesController(MarechaiContext context, IStringLocalizer<Compa
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<CompanyDescriptionDto> GetDescriptionAsync(int id) => await context.CompanyDescriptions public Task<CompanyDescriptionDto> GetDescriptionAsync(int id) => context.CompanyDescriptions
.Where(d => d.CompanyId == id) .Where(d => d.CompanyId == id)
.Select(d => new CompanyDescriptionDto .Select(d => new CompanyDescriptionDto
{ {
@@ -303,6 +295,7 @@ public class CompaniesController(MarechaiContext context, IStringLocalizer<Compa
public async Task<int> CreateOrUpdateDescriptionAsync(int id, CompanyDescriptionDto description) public async Task<int> CreateOrUpdateDescriptionAsync(int id, CompanyDescriptionDto description)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return 0; if(userId is null) return 0;
CompanyDescription current = await context.CompanyDescriptions.FirstOrDefaultAsync(d => d.CompanyId == id); CompanyDescription current = await context.CompanyDescriptions.FirstOrDefaultAsync(d => d.CompanyId == id);

View File

@@ -23,10 +23,7 @@
// Copyright © 2003-2025 Natalia Portillo // Copyright © 2003-2025 Natalia Portillo
*******************************************************************************/ *******************************************************************************/
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks; using System.Threading.Tasks;
using Marechai.Data.Dtos; using Marechai.Data.Dtos;
using Marechai.Database.Models; using Marechai.Database.Models;
@@ -34,7 +31,6 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Localization;
namespace Marechai.Server.Controllers; namespace Marechai.Server.Controllers;
@@ -73,9 +69,10 @@ public class ComputersController(MarechaiContext context) : ControllerBase
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<List<MachineDto>> GetComputersByLetterAsync(char c) => await context.Machines public Task<List<MachineDto>> GetComputersByLetterAsync(char c) => context.Machines.Include(m => m.Company)
.Include(m => m.Company) .Where(m =>
.Where(m => m.Type == MachineType.Computer && EF.Functions.Like(m.Name, $"{c}%")) m.Type == MachineType.Computer &&
EF.Functions.Like(m.Name, $"{c}%"))
.OrderBy(m => m.Company.Name) .OrderBy(m => m.Company.Name)
.ThenBy(m => m.Name) .ThenBy(m => m.Name)
.Select(m => new MachineDto .Select(m => new MachineDto
@@ -90,9 +87,11 @@ public class ComputersController(MarechaiContext context) : ControllerBase
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<List<MachineDto>> GetComputersByYearAsync(int year) => await context.Machines public Task<List<MachineDto>> GetComputersByYearAsync(int year) => context.Machines.Include(m => m.Company)
.Include(m => m.Company) .Where(m =>
.Where(m => m.Type == MachineType.Computer && m.Introduced != null && m.Introduced.Value.Year == year) m.Type == MachineType.Computer &&
m.Introduced != null &&
m.Introduced.Value.Year == year)
.OrderBy(m => m.Company.Name) .OrderBy(m => m.Company.Name)
.ThenBy(m => m.Name) .ThenBy(m => m.Name)
.Select(m => new MachineDto .Select(m => new MachineDto
@@ -107,7 +106,7 @@ public class ComputersController(MarechaiContext context) : ControllerBase
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<List<MachineDto>> GetComputersAsync() => await context.Machines.Include(m => m.Company) public Task<List<MachineDto>> GetComputersAsync() => context.Machines.Include(m => m.Company)
.Where(m => m.Type == MachineType.Computer) .Where(m => m.Type == MachineType.Computer)
.OrderBy(m => m.Company.Name) .OrderBy(m => m.Company.Name)
.ThenBy(m => m.Name) .ThenBy(m => m.Name)

View File

@@ -23,10 +23,7 @@
// Copyright © 2003-2025 Natalia Portillo // Copyright © 2003-2025 Natalia Portillo
*******************************************************************************/ *******************************************************************************/
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks; using System.Threading.Tasks;
using Marechai.Data.Dtos; using Marechai.Data.Dtos;
using Marechai.Database.Models; using Marechai.Database.Models;
@@ -34,7 +31,6 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Localization;
namespace Marechai.Server.Controllers; namespace Marechai.Server.Controllers;
@@ -73,9 +69,10 @@ public class ConsolesController(MarechaiContext context) : ControllerBase
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<List<MachineDto>> GetConsolesByLetterAsync(char c) => await context.Machines public Task<List<MachineDto>> GetConsolesByLetterAsync(char c) => context.Machines.Include(m => m.Company)
.Include(m => m.Company) .Where(m =>
.Where(m => m.Type == MachineType.Console && EF.Functions.Like(m.Name, $"{c}%")) m.Type == MachineType.Console &&
EF.Functions.Like(m.Name, $"{c}%"))
.OrderBy(m => m.Company.Name) .OrderBy(m => m.Company.Name)
.ThenBy(m => m.Name) .ThenBy(m => m.Name)
.Select(m => new MachineDto .Select(m => new MachineDto
@@ -90,9 +87,11 @@ public class ConsolesController(MarechaiContext context) : ControllerBase
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<List<MachineDto>> GetConsolesByYearAsync(int year) => await context.Machines public Task<List<MachineDto>> GetConsolesByYearAsync(int year) => context.Machines.Include(m => m.Company)
.Include(m => m.Company) .Where(m =>
.Where(m => m.Type == MachineType.Console && m.Introduced != null && m.Introduced.Value.Year == year) m.Type == MachineType.Console &&
m.Introduced != null &&
m.Introduced.Value.Year == year)
.OrderBy(m => m.Company.Name) .OrderBy(m => m.Company.Name)
.ThenBy(m => m.Name) .ThenBy(m => m.Name)
.Select(m => new MachineDto .Select(m => new MachineDto
@@ -107,7 +106,7 @@ public class ConsolesController(MarechaiContext context) : ControllerBase
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<List<MachineDto>> GetConsolesAsync() => await context.Machines.Include(m => m.Company) public Task<List<MachineDto>> GetConsolesAsync() => context.Machines.Include(m => m.Company)
.Where(m => m.Type == MachineType.Console) .Where(m => m.Type == MachineType.Console)
.OrderBy(m => m.Company.Name) .OrderBy(m => m.Company.Name)
.ThenBy(m => m.Name) .ThenBy(m => m.Name)

View File

@@ -23,7 +23,6 @@
// Copyright © 2003-2025 Natalia Portillo // Copyright © 2003-2025 Natalia Portillo
*******************************************************************************/ *******************************************************************************/
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Security.Claims; using System.Security.Claims;
@@ -34,7 +33,6 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Localization;
namespace Marechai.Server.Controllers; namespace Marechai.Server.Controllers;
@@ -46,8 +44,7 @@ public class CurrencyInflationController(MarechaiContext context) : ControllerBa
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<List<CurrencyInflationDto>> GetAsync() => await context.CurrenciesInflation public Task<List<CurrencyInflationDto>> GetAsync() => context.CurrenciesInflation.OrderBy(i => i.Currency.Name)
.OrderBy(i => i.Currency.Name)
.ThenBy(i => i.Year) .ThenBy(i => i.Year)
.Select(i => new CurrencyInflationDto .Select(i => new CurrencyInflationDto
{ {
@@ -63,8 +60,7 @@ public class CurrencyInflationController(MarechaiContext context) : ControllerBa
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<CurrencyInflationDto> GetAsync(int id) => await context.CurrenciesInflation public Task<CurrencyInflationDto> GetAsync(int id) => context.CurrenciesInflation.Where(b => b.Id == id)
.Where(b => b.Id == id)
.Select(i => new CurrencyInflationDto .Select(i => new CurrencyInflationDto
{ {
Id = i.Id, Id = i.Id,
@@ -82,6 +78,7 @@ public class CurrencyInflationController(MarechaiContext context) : ControllerBa
public async Task UpdateAsync(CurrencyInflationDto dto) public async Task UpdateAsync(CurrencyInflationDto dto)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return; if(userId is null) return;
CurrencyInflation model = await context.CurrenciesInflation.FindAsync(dto.Id); CurrencyInflation model = await context.CurrenciesInflation.FindAsync(dto.Id);
@@ -100,7 +97,9 @@ public class CurrencyInflationController(MarechaiContext context) : ControllerBa
public async Task<int> CreateAsync(CurrencyInflationDto dto) public async Task<int> CreateAsync(CurrencyInflationDto dto)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return 0; if(userId is null) return 0;
var model = new CurrencyInflation var model = new CurrencyInflation
{ {
CurrencyCode = dto.CurrencyCode, CurrencyCode = dto.CurrencyCode,
@@ -121,6 +120,7 @@ public class CurrencyInflationController(MarechaiContext context) : ControllerBa
public async Task DeleteAsync(int id) public async Task DeleteAsync(int id)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return; if(userId is null) return;
CurrencyInflation item = await context.CurrenciesInflation.FindAsync(id); CurrencyInflation item = await context.CurrenciesInflation.FindAsync(id);

View File

@@ -23,7 +23,6 @@
// Copyright © 2003-2025 Natalia Portillo // Copyright © 2003-2025 Natalia Portillo
*******************************************************************************/ *******************************************************************************/
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Security.Claims; using System.Security.Claims;
@@ -34,7 +33,6 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Localization;
namespace Marechai.Server.Controllers; namespace Marechai.Server.Controllers;
@@ -46,8 +44,7 @@ public class CurrencyPeggingController(MarechaiContext context) : ControllerBase
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<List<CurrencyPeggingDto>> GetAsync() => await context.CurrenciesPegging public Task<List<CurrencyPeggingDto>> GetAsync() => context.CurrenciesPegging.OrderBy(i => i.Source.Name)
.OrderBy(i => i.Source.Name)
.ThenBy(i => i.Destination.Name) .ThenBy(i => i.Destination.Name)
.ThenBy(i => i.Start) .ThenBy(i => i.Start)
.ThenBy(i => i.End) .ThenBy(i => i.End)
@@ -68,8 +65,7 @@ public class CurrencyPeggingController(MarechaiContext context) : ControllerBase
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<CurrencyPeggingDto> GetAsync(int id) => await context.CurrenciesPegging public Task<CurrencyPeggingDto> GetAsync(int id) => context.CurrenciesPegging.Where(b => b.Id == id)
.Where(b => b.Id == id)
.Select(i => new CurrencyPeggingDto .Select(i => new CurrencyPeggingDto
{ {
Id = i.Id, Id = i.Id,
@@ -90,6 +86,7 @@ public class CurrencyPeggingController(MarechaiContext context) : ControllerBase
public async Task UpdateAsync(CurrencyPeggingDto dto) public async Task UpdateAsync(CurrencyPeggingDto dto)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return; if(userId is null) return;
CurrencyPegging model = await context.CurrenciesPegging.FindAsync(dto.Id); CurrencyPegging model = await context.CurrenciesPegging.FindAsync(dto.Id);
@@ -110,7 +107,9 @@ public class CurrencyPeggingController(MarechaiContext context) : ControllerBase
public async Task<int> CreateAsync(CurrencyPeggingDto dto) public async Task<int> CreateAsync(CurrencyPeggingDto dto)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return 0; if(userId is null) return 0;
var model = new CurrencyPegging var model = new CurrencyPegging
{ {
SourceCode = dto.SourceCode, SourceCode = dto.SourceCode,
@@ -133,6 +132,7 @@ public class CurrencyPeggingController(MarechaiContext context) : ControllerBase
public async Task DeleteAsync(int id) public async Task DeleteAsync(int id)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return; if(userId is null) return;
CurrencyPegging item = await context.CurrenciesPegging.FindAsync(id); CurrencyPegging item = await context.CurrenciesPegging.FindAsync(id);

View File

@@ -23,7 +23,6 @@
// Copyright © 2003-2025 Natalia Portillo // Copyright © 2003-2025 Natalia Portillo
*******************************************************************************/ *******************************************************************************/
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Security.Claims; using System.Security.Claims;
@@ -34,7 +33,6 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Localization;
namespace Marechai.Server.Controllers; namespace Marechai.Server.Controllers;
@@ -46,8 +44,7 @@ public class DocumentCompaniesController(MarechaiContext context) : ControllerBa
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<List<DocumentCompanyDto>> GetAsync() => await context.DocumentCompanies public Task<List<DocumentCompanyDto>> GetAsync() => context.DocumentCompanies.OrderBy(c => c.Name)
.OrderBy(c => c.Name)
.Select(d => new DocumentCompanyDto .Select(d => new DocumentCompanyDto
{ {
Id = d.Id, Id = d.Id,
@@ -61,8 +58,7 @@ public class DocumentCompaniesController(MarechaiContext context) : ControllerBa
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<DocumentCompanyDto> GetAsync(int id) => await context.DocumentCompanies public Task<DocumentCompanyDto> GetAsync(int id) => context.DocumentCompanies.Where(d => d.Id == id)
.Where(d => d.Id == id)
.Select(d => new DocumentCompanyDto .Select(d => new DocumentCompanyDto
{ {
Id = d.Id, Id = d.Id,
@@ -78,6 +74,7 @@ public class DocumentCompaniesController(MarechaiContext context) : ControllerBa
public async Task UpdateAsync(DocumentCompanyDto dto) public async Task UpdateAsync(DocumentCompanyDto dto)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return; if(userId is null) return;
DocumentCompany model = await context.DocumentCompanies.FindAsync(dto.Id); DocumentCompany model = await context.DocumentCompanies.FindAsync(dto.Id);
@@ -96,7 +93,9 @@ public class DocumentCompaniesController(MarechaiContext context) : ControllerBa
public async Task<int> CreateAsync(DocumentCompanyDto dto) public async Task<int> CreateAsync(DocumentCompanyDto dto)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return 0; if(userId is null) return 0;
var model = new DocumentCompany var model = new DocumentCompany
{ {
CompanyId = dto.CompanyId, CompanyId = dto.CompanyId,
@@ -116,6 +115,7 @@ public class DocumentCompaniesController(MarechaiContext context) : ControllerBa
public async Task DeleteAsync(int id) public async Task DeleteAsync(int id)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return; if(userId is null) return;
DocumentCompany item = await context.DocumentCompanies.FindAsync(id); DocumentCompany item = await context.DocumentCompanies.FindAsync(id);

View File

@@ -23,7 +23,6 @@
// Copyright © 2003-2025 Natalia Portillo // Copyright © 2003-2025 Natalia Portillo
*******************************************************************************/ *******************************************************************************/
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Security.Claims; using System.Security.Claims;
@@ -34,7 +33,6 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Localization;
namespace Marechai.Server.Controllers; namespace Marechai.Server.Controllers;
@@ -46,8 +44,7 @@ public class DocumentPeopleController(MarechaiContext context) : ControllerBase
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<List<DocumentPersonDto>> GetAsync() => await context.DocumentPeople public Task<List<DocumentPersonDto>> GetAsync() => context.DocumentPeople.OrderBy(d => d.DisplayName)
.OrderBy(d => d.DisplayName)
.ThenBy(d => d.Alias) .ThenBy(d => d.Alias)
.ThenBy(d => d.Name) .ThenBy(d => d.Name)
.ThenBy(d => d.Surname) .ThenBy(d => d.Surname)
@@ -64,7 +61,7 @@ public class DocumentPeopleController(MarechaiContext context) : ControllerBase
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<DocumentPersonDto> GetAsync(int id) => await context.DocumentPeople.Where(p => p.Id == id) public Task<DocumentPersonDto> GetAsync(int id) => context.DocumentPeople.Where(p => p.Id == id)
.Select(d => new DocumentPersonDto .Select(d => new DocumentPersonDto
{ {
Id = d.Id, Id = d.Id,
@@ -83,6 +80,7 @@ public class DocumentPeopleController(MarechaiContext context) : ControllerBase
public async Task UpdateAsync(DocumentPersonDto dto) public async Task UpdateAsync(DocumentPersonDto dto)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return; if(userId is null) return;
DocumentPerson model = await context.DocumentPeople.FindAsync(dto.Id); DocumentPerson model = await context.DocumentPeople.FindAsync(dto.Id);
@@ -104,7 +102,9 @@ public class DocumentPeopleController(MarechaiContext context) : ControllerBase
public async Task<int> CreateAsync(DocumentPersonDto dto) public async Task<int> CreateAsync(DocumentPersonDto dto)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return 0; if(userId is null) return 0;
var model = new DocumentPerson var model = new DocumentPerson
{ {
Alias = dto.Alias, Alias = dto.Alias,
@@ -127,6 +127,7 @@ public class DocumentPeopleController(MarechaiContext context) : ControllerBase
public async Task DeleteAsync(int id) public async Task DeleteAsync(int id)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return; if(userId is null) return;
DocumentPerson item = await context.DocumentPeople.FindAsync(id); DocumentPerson item = await context.DocumentPeople.FindAsync(id);

View File

@@ -23,10 +23,8 @@
// Copyright © 2003-2025 Natalia Portillo // Copyright © 2003-2025 Natalia Portillo
*******************************************************************************/ *******************************************************************************/
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks; using System.Threading.Tasks;
using Marechai.Data.Dtos; using Marechai.Data.Dtos;
using Marechai.Database.Models; using Marechai.Database.Models;
@@ -34,7 +32,6 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Localization;
namespace Marechai.Server.Controllers; namespace Marechai.Server.Controllers;
@@ -46,7 +43,7 @@ public class DocumentRolesController(MarechaiContext context) : ControllerBase
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<List<DocumentRoleDto>> GetAsync() => await context.DocumentRoles.OrderBy(c => c.Name) public Task<List<DocumentRoleDto>> GetAsync() => context.DocumentRoles.OrderBy(c => c.Name)
.Select(c => new DocumentRoleDto .Select(c => new DocumentRoleDto
{ {
Id = c.Id, Id = c.Id,
@@ -59,8 +56,7 @@ public class DocumentRolesController(MarechaiContext context) : ControllerBase
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<List<DocumentRoleDto>> GetEnabledAsync() => await context.DocumentRoles public Task<List<DocumentRoleDto>> GetEnabledAsync() => context.DocumentRoles.Where(c => c.Enabled)
.Where(c => c.Enabled)
.OrderBy(c => c.Name) .OrderBy(c => c.Name)
.Select(c => new DocumentRoleDto .Select(c => new DocumentRoleDto
{ {
@@ -74,7 +70,7 @@ public class DocumentRolesController(MarechaiContext context) : ControllerBase
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<DocumentRoleDto> GetAsync(string id) => await context.DocumentRoles.Where(c => c.Id == id) public Task<DocumentRoleDto> GetAsync(string id) => context.DocumentRoles.Where(c => c.Id == id)
.Select(c => new DocumentRoleDto .Select(c => new DocumentRoleDto
{ {
Id = c.Id, Id = c.Id,

View File

@@ -34,7 +34,6 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Localization;
namespace Marechai.Server.Controllers; namespace Marechai.Server.Controllers;
@@ -53,7 +52,7 @@ public class DocumentScansController(MarechaiContext context) : ControllerBase
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<DocumentScanDto> GetAsync(Guid id) => await context.DocumentScans.Where(p => p.Id == id) public Task<DocumentScanDto> GetAsync(Guid id) => context.DocumentScans.Where(p => p.Id == id)
.Select(p => new DocumentScanDto .Select(p => new DocumentScanDto
{ {
Author = p.Author, Author = p.Author,
@@ -84,6 +83,7 @@ public class DocumentScansController(MarechaiContext context) : ControllerBase
public async Task UpdateAsync(DocumentScanDto dto) public async Task UpdateAsync(DocumentScanDto dto)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return; if(userId is null) return;
DocumentScan model = await context.DocumentScans.FindAsync(dto.Id); DocumentScan model = await context.DocumentScans.FindAsync(dto.Id);
@@ -113,7 +113,9 @@ public class DocumentScansController(MarechaiContext context) : ControllerBase
public async Task<Guid> CreateAsync(DocumentScanDto dto) public async Task<Guid> CreateAsync(DocumentScanDto dto)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return null; if(userId is null) return null;
var model = new DocumentScan var model = new DocumentScan
{ {
Author = dto.Author, Author = dto.Author,
@@ -149,6 +151,7 @@ public class DocumentScansController(MarechaiContext context) : ControllerBase
public async Task DeleteAsync(Guid id) public async Task DeleteAsync(Guid id)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return; if(userId is null) return;
DocumentScan item = await context.DocumentScans.FindAsync(id); DocumentScan item = await context.DocumentScans.FindAsync(id);

View File

@@ -23,7 +23,6 @@
// Copyright © 2003-2025 Natalia Portillo // Copyright © 2003-2025 Natalia Portillo
*******************************************************************************/ *******************************************************************************/
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Security.Claims; using System.Security.Claims;
@@ -34,7 +33,6 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Localization;
namespace Marechai.Server.Controllers; namespace Marechai.Server.Controllers;
@@ -46,7 +44,7 @@ public class DocumentsByMachineController(MarechaiContext context) : ControllerB
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<List<DocumentByMachineDto>> GetByDocument(long bookId) => await context.DocumentsByMachines public Task<List<DocumentByMachineDto>> GetByDocument(long bookId) => context.DocumentsByMachines
.Where(p => p.DocumentId == bookId) .Where(p => p.DocumentId == bookId)
.Select(p => new DocumentByMachineDto .Select(p => new DocumentByMachineDto
{ {
@@ -65,6 +63,7 @@ public class DocumentsByMachineController(MarechaiContext context) : ControllerB
public async Task DeleteAsync(long id) public async Task DeleteAsync(long id)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return; if(userId is null) return;
DocumentsByMachine item = await context.DocumentsByMachines.FindAsync(id); DocumentsByMachine item = await context.DocumentsByMachines.FindAsync(id);
@@ -82,7 +81,9 @@ public class DocumentsByMachineController(MarechaiContext context) : ControllerB
public async Task<long> CreateAsync(int machineId, long bookId) public async Task<long> CreateAsync(int machineId, long bookId)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return 0; if(userId is null) return 0;
var item = new DocumentsByMachine var item = new DocumentsByMachine
{ {
MachineId = machineId, MachineId = machineId,

View File

@@ -23,7 +23,6 @@
// Copyright © 2003-2025 Natalia Portillo // Copyright © 2003-2025 Natalia Portillo
*******************************************************************************/ *******************************************************************************/
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Security.Claims; using System.Security.Claims;
@@ -34,7 +33,6 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Localization;
namespace Marechai.Server.Controllers; namespace Marechai.Server.Controllers;
@@ -46,8 +44,8 @@ public class DocumentsByMachineFamilyController(MarechaiContext context) : Contr
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<List<DocumentByMachineFamilyDto>> GetByDocument(long bookId) => await context public Task<List<DocumentByMachineFamilyDto>> GetByDocument(long bookId) => context.DocumentsByMachineFamilies
.DocumentsByMachineFamilies.Where(p => p.DocumentId == bookId) .Where(p => p.DocumentId == bookId)
.Select(p => new DocumentByMachineFamilyDto .Select(p => new DocumentByMachineFamilyDto
{ {
Id = p.Id, Id = p.Id,
@@ -65,6 +63,7 @@ public class DocumentsByMachineFamilyController(MarechaiContext context) : Contr
public async Task DeleteAsync(long id) public async Task DeleteAsync(long id)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return; if(userId is null) return;
DocumentsByMachineFamily item = await context.DocumentsByMachineFamilies.FindAsync(id); DocumentsByMachineFamily item = await context.DocumentsByMachineFamilies.FindAsync(id);
@@ -82,7 +81,9 @@ public class DocumentsByMachineFamilyController(MarechaiContext context) : Contr
public async Task<long> CreateAsync(int machineFamilyId, long bookId) public async Task<long> CreateAsync(int machineFamilyId, long bookId)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return 0; if(userId is null) return 0;
var item = new DocumentsByMachineFamily var item = new DocumentsByMachineFamily
{ {
MachineFamilyId = machineFamilyId, MachineFamilyId = machineFamilyId,

View File

@@ -23,7 +23,6 @@
// Copyright © 2003-2025 Natalia Portillo // Copyright © 2003-2025 Natalia Portillo
*******************************************************************************/ *******************************************************************************/
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Security.Claims; using System.Security.Claims;
@@ -34,7 +33,6 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Localization;
namespace Marechai.Server.Controllers; namespace Marechai.Server.Controllers;
@@ -46,7 +44,7 @@ public class DocumentsController(MarechaiContext context) : ControllerBase
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<List<DocumentDto>> GetAsync() => await context.Documents.OrderBy(b => b.NativeTitle) public Task<List<DocumentDto>> GetAsync() => context.Documents.OrderBy(b => b.NativeTitle)
.ThenBy(b => b.Published) .ThenBy(b => b.Published)
.ThenBy(b => b.Title) .ThenBy(b => b.Title)
.Select(b => new DocumentDto .Select(b => new DocumentDto
@@ -65,7 +63,7 @@ public class DocumentsController(MarechaiContext context) : ControllerBase
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<DocumentDto> GetAsync(long id) => await context.Documents.Where(b => b.Id == id) public Task<DocumentDto> GetAsync(long id) => context.Documents.Where(b => b.Id == id)
.Select(b => new DocumentDto .Select(b => new DocumentDto
{ {
Id = b.Id, Id = b.Id,
@@ -85,6 +83,7 @@ public class DocumentsController(MarechaiContext context) : ControllerBase
public async Task UpdateAsync(DocumentDto dto) public async Task UpdateAsync(DocumentDto dto)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return; if(userId is null) return;
Document model = await context.Documents.FindAsync(dto.Id); Document model = await context.Documents.FindAsync(dto.Id);
@@ -105,7 +104,9 @@ public class DocumentsController(MarechaiContext context) : ControllerBase
public async Task<long> CreateAsync(DocumentDto dto) public async Task<long> CreateAsync(DocumentDto dto)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return 0; if(userId is null) return 0;
var model = new Document var model = new Document
{ {
Title = dto.Title, Title = dto.Title,
@@ -135,6 +136,7 @@ public class DocumentsController(MarechaiContext context) : ControllerBase
public async Task DeleteAsync(long id) public async Task DeleteAsync(long id)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return; if(userId is null) return;
Document item = await context.Documents.FindAsync(id); Document item = await context.Documents.FindAsync(id);

View File

@@ -23,7 +23,6 @@
// Copyright © 2003-2025 Natalia Portillo // Copyright © 2003-2025 Natalia Portillo
*******************************************************************************/ *******************************************************************************/
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Security.Claims; using System.Security.Claims;
@@ -34,7 +33,6 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Localization;
namespace Marechai.Server.Controllers; namespace Marechai.Server.Controllers;
@@ -46,7 +44,7 @@ public class DumpsController(MarechaiContext context) : ControllerBase
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<List<DumpDto>> GetAsync() => await context.Dumps.OrderBy(d => d.Dumper) public Task<List<DumpDto>> GetAsync() => context.Dumps.OrderBy(d => d.Dumper)
.ThenBy(d => d.DumpingGroup) .ThenBy(d => d.DumpingGroup)
.ThenBy(b => b.Media.Title) .ThenBy(b => b.Media.Title)
.ThenBy(d => d.DumpDate) .ThenBy(d => d.DumpDate)
@@ -68,7 +66,7 @@ public class DumpsController(MarechaiContext context) : ControllerBase
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<DumpDto> GetAsync(ulong id) => await context.Dumps.Where(d => d.Id == id) public Task<DumpDto> GetAsync(ulong id) => context.Dumps.Where(d => d.Id == id)
.Select(d => new DumpDto .Select(d => new DumpDto
{ {
Id = d.Id, Id = d.Id,
@@ -90,6 +88,7 @@ public class DumpsController(MarechaiContext context) : ControllerBase
public async Task UpdateAsync(DumpDto dto) public async Task UpdateAsync(DumpDto dto)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return; if(userId is null) return;
Dump model = await context.Dumps.FindAsync(dto.Id); Dump model = await context.Dumps.FindAsync(dto.Id);
@@ -111,7 +110,9 @@ public class DumpsController(MarechaiContext context) : ControllerBase
public async Task<ulong> CreateAsync(DumpDto dto) public async Task<ulong> CreateAsync(DumpDto dto)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return null; if(userId is null) return null;
var model = new Dump var model = new Dump
{ {
Dumper = dto.Dumper, Dumper = dto.Dumper,
@@ -135,6 +136,7 @@ public class DumpsController(MarechaiContext context) : ControllerBase
public async Task DeleteAsync(ulong id) public async Task DeleteAsync(ulong id)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return; if(userId is null) return;
Dump item = await context.Dumps.FindAsync(id); Dump item = await context.Dumps.FindAsync(id);

View File

@@ -23,7 +23,6 @@
// Copyright © 2003-2025 Natalia Portillo // Copyright © 2003-2025 Natalia Portillo
*******************************************************************************/ *******************************************************************************/
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Security.Claims; using System.Security.Claims;
@@ -34,7 +33,6 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Localization;
namespace Marechai.Server.Controllers; namespace Marechai.Server.Controllers;
@@ -46,7 +44,7 @@ public class GpusByMachineController(MarechaiContext context) : ControllerBase
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<List<GpuByMachineDto>> GetByMachine(int machineId) => await context.GpusByMachine public Task<List<GpuByMachineDto>> GetByMachine(int machineId) => context.GpusByMachine
.Where(g => g.MachineId == machineId) .Where(g => g.MachineId == machineId)
.Select(g => new GpuByMachineDto .Select(g => new GpuByMachineDto
{ {
@@ -67,6 +65,7 @@ public class GpusByMachineController(MarechaiContext context) : ControllerBase
public async Task DeleteAsync(long id) public async Task DeleteAsync(long id)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return; if(userId is null) return;
GpusByMachine item = await context.GpusByMachine.FindAsync(id); GpusByMachine item = await context.GpusByMachine.FindAsync(id);
@@ -84,7 +83,9 @@ public class GpusByMachineController(MarechaiContext context) : ControllerBase
public async Task<long> CreateAsync(int gpuId, int machineId) public async Task<long> CreateAsync(int gpuId, int machineId)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return 0; if(userId is null) return 0;
var item = new GpusByMachine var item = new GpusByMachine
{ {
GpuId = gpuId, GpuId = gpuId,

View File

@@ -23,7 +23,6 @@
// Copyright © 2003-2025 Natalia Portillo // Copyright © 2003-2025 Natalia Portillo
*******************************************************************************/ *******************************************************************************/
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Security.Claims; using System.Security.Claims;
@@ -34,7 +33,6 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Localization;
namespace Marechai.Server.Controllers; namespace Marechai.Server.Controllers;
@@ -46,7 +44,7 @@ public class GpusController(MarechaiContext context) : ControllerBase
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<List<GpuDto>> GetAsync() => await context.Gpus.OrderBy(g => g.Company.Name) public Task<List<GpuDto>> GetAsync() => context.Gpus.OrderBy(g => g.Company.Name)
.ThenBy(g => g.Name) .ThenBy(g => g.Name)
.ThenBy(g => g.Introduced) .ThenBy(g => g.Introduced)
.Select(g => new GpuDto .Select(g => new GpuDto
@@ -63,7 +61,7 @@ public class GpusController(MarechaiContext context) : ControllerBase
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<List<GpuDto>> GetByMachineAsync(int machineId) => await context.GpusByMachine public Task<List<GpuDto>> GetByMachineAsync(int machineId) => context.GpusByMachine
.Where(g => g.MachineId == machineId) .Where(g => g.MachineId == machineId)
.Select(g => g.Gpu) .Select(g => g.Gpu)
.OrderBy(g => g.Company.Name) .OrderBy(g => g.Company.Name)
@@ -88,7 +86,7 @@ public class GpusController(MarechaiContext context) : ControllerBase
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<GpuDto> GetAsync(int id) => await context.Gpus.Where(g => g.Id == id) public Task<GpuDto> GetAsync(int id) => context.Gpus.Where(g => g.Id == id)
.Select(g => new GpuDto .Select(g => new GpuDto
{ {
Id = g.Id, Id = g.Id,
@@ -111,6 +109,7 @@ public class GpusController(MarechaiContext context) : ControllerBase
public async Task UpdateAsync(GpuDto dto) public async Task UpdateAsync(GpuDto dto)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return; if(userId is null) return;
Gpu model = await context.Gpus.FindAsync(dto.Id); Gpu model = await context.Gpus.FindAsync(dto.Id);
@@ -136,7 +135,9 @@ public class GpusController(MarechaiContext context) : ControllerBase
public async Task<int> CreateAsync(GpuDto dto) public async Task<int> CreateAsync(GpuDto dto)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return 0; if(userId is null) return 0;
var model = new Gpu var model = new Gpu
{ {
Name = dto.Name, Name = dto.Name,
@@ -163,6 +164,7 @@ public class GpusController(MarechaiContext context) : ControllerBase
public async Task DeleteAsync(int id) public async Task DeleteAsync(int id)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return; if(userId is null) return;
Gpu item = await context.Gpus.FindAsync(id); Gpu item = await context.Gpus.FindAsync(id);

View File

@@ -28,13 +28,11 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Security.Claims; using System.Security.Claims;
using System.Threading.Tasks; using System.Threading.Tasks;
using Marechai.Data.Dtos;
using Marechai.Database.Models; using Marechai.Database.Models;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Localization;
namespace Marechai.Server.Controllers; namespace Marechai.Server.Controllers;
@@ -46,8 +44,7 @@ public class InstructionSetExtensionsController(MarechaiContext context) : Contr
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<List<InstructionSetExtension>> GetAsync() => await context.InstructionSetExtensions public Task<List<InstructionSetExtension>> GetAsync() => context.InstructionSetExtensions.OrderBy(e => e.Extension)
.OrderBy(e => e.Extension)
.Select(e => new InstructionSetExtension .Select(e => new InstructionSetExtension
{ {
Extension = e.Extension, Extension = e.Extension,
@@ -59,8 +56,7 @@ public class InstructionSetExtensionsController(MarechaiContext context) : Contr
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<InstructionSetExtension> GetAsync(int id) => await context.InstructionSetExtensions public Task<InstructionSetExtension> GetAsync(int id) => context.InstructionSetExtensions.Where(e => e.Id == id)
.Where(e => e.Id == id)
.Select(e => new InstructionSetExtension .Select(e => new InstructionSetExtension
{ {
Extension = e.Extension, Extension = e.Extension,
@@ -75,6 +71,7 @@ public class InstructionSetExtensionsController(MarechaiContext context) : Contr
public async Task UpdateAsync(InstructionSetExtension viewModel) public async Task UpdateAsync(InstructionSetExtension viewModel)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return; if(userId is null) return;
InstructionSetExtension model = await context.InstructionSetExtensions.FindAsync(viewModel.Id); InstructionSetExtension model = await context.InstructionSetExtensions.FindAsync(viewModel.Id);
@@ -92,7 +89,9 @@ public class InstructionSetExtensionsController(MarechaiContext context) : Contr
public async Task<int> CreateAsync(InstructionSetExtension viewModel) public async Task<int> CreateAsync(InstructionSetExtension viewModel)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return 0; if(userId is null) return 0;
var model = new InstructionSetExtension var model = new InstructionSetExtension
{ {
Extension = viewModel.Extension Extension = viewModel.Extension
@@ -111,6 +110,7 @@ public class InstructionSetExtensionsController(MarechaiContext context) : Contr
public async Task DeleteAsync(int id) public async Task DeleteAsync(int id)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return; if(userId is null) return;
InstructionSetExtension item = await context.InstructionSetExtensions.FindAsync(id); InstructionSetExtension item = await context.InstructionSetExtensions.FindAsync(id);

View File

@@ -28,13 +28,11 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Security.Claims; using System.Security.Claims;
using System.Threading.Tasks; using System.Threading.Tasks;
using Marechai.Data.Dtos;
using Marechai.Database.Models; using Marechai.Database.Models;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Localization;
namespace Marechai.Server.Controllers; namespace Marechai.Server.Controllers;
@@ -46,7 +44,7 @@ public class InstructionSetsController(MarechaiContext context) : ControllerBase
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<List<InstructionSet>> GetAsync() => await context.InstructionSets.OrderBy(e => e.Name) public Task<List<InstructionSet>> GetAsync() => context.InstructionSets.OrderBy(e => e.Name)
.Select(e => new InstructionSet .Select(e => new InstructionSet
{ {
Name = e.Name, Name = e.Name,
@@ -58,7 +56,7 @@ public class InstructionSetsController(MarechaiContext context) : ControllerBase
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<InstructionSet> GetAsync(int id) => await context.InstructionSets.Where(e => e.Id == id) public Task<InstructionSet> GetAsync(int id) => context.InstructionSets.Where(e => e.Id == id)
.Select(e => new InstructionSet .Select(e => new InstructionSet
{ {
Name = e.Name, Name = e.Name,
@@ -73,6 +71,7 @@ public class InstructionSetsController(MarechaiContext context) : ControllerBase
public async Task UpdateAsync(InstructionSet viewModel) public async Task UpdateAsync(InstructionSet viewModel)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return; if(userId is null) return;
InstructionSet model = await context.InstructionSets.FindAsync(viewModel.Id); InstructionSet model = await context.InstructionSets.FindAsync(viewModel.Id);
@@ -90,7 +89,9 @@ public class InstructionSetsController(MarechaiContext context) : ControllerBase
public async Task<int> CreateAsync(InstructionSet viewModel) public async Task<int> CreateAsync(InstructionSet viewModel)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return 0; if(userId is null) return 0;
var model = new InstructionSet var model = new InstructionSet
{ {
Name = viewModel.Name Name = viewModel.Name
@@ -109,6 +110,7 @@ public class InstructionSetsController(MarechaiContext context) : ControllerBase
public async Task DeleteAsync(int id) public async Task DeleteAsync(int id)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return; if(userId is null) return;
InstructionSet item = await context.InstructionSets.FindAsync(id); InstructionSet item = await context.InstructionSets.FindAsync(id);

View File

@@ -23,18 +23,14 @@
// Copyright © 2003-2025 Natalia Portillo // Copyright © 2003-2025 Natalia Portillo
*******************************************************************************/ *******************************************************************************/
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks; using System.Threading.Tasks;
using Marechai.Data.Dtos;
using Marechai.Database.Models; using Marechai.Database.Models;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Localization;
namespace Marechai.Server.Controllers; namespace Marechai.Server.Controllers;
@@ -46,5 +42,5 @@ public class Iso4217Controller(MarechaiContext context) : ControllerBase
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<List<Iso4217>> GetAsync() => await context.Iso4217.OrderBy(c => c.Name).ToListAsync(); public Task<List<Iso4217>> GetAsync() => context.Iso4217.OrderBy(c => c.Name).ToListAsync();
} }

View File

@@ -23,18 +23,15 @@
// Copyright © 2003-2025 Natalia Portillo // Copyright © 2003-2025 Natalia Portillo
*******************************************************************************/ *******************************************************************************/
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Security.Claims; using System.Security.Claims;
using System.Threading.Tasks; using System.Threading.Tasks;
using Marechai.Data.Dtos;
using Marechai.Database.Models; using Marechai.Database.Models;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Localization;
namespace Marechai.Server.Controllers; namespace Marechai.Server.Controllers;
@@ -46,7 +43,7 @@ public class LicensesController(MarechaiContext context) : ControllerBase
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<List<License>> GetAsync() => await context.Licenses.OrderBy(l => l.Name) public Task<List<License>> GetAsync() => context.Licenses.OrderBy(l => l.Name)
.Select(l => new License .Select(l => new License
{ {
FsfApproved = l.FsfApproved, FsfApproved = l.FsfApproved,
@@ -62,7 +59,7 @@ public class LicensesController(MarechaiContext context) : ControllerBase
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<License> GetAsync(int id) => await context.Licenses.Where(l => l.Id == id) public Task<License> GetAsync(int id) => context.Licenses.Where(l => l.Id == id)
.Select(l => new License .Select(l => new License
{ {
FsfApproved = l.FsfApproved, FsfApproved = l.FsfApproved,
@@ -82,6 +79,7 @@ public class LicensesController(MarechaiContext context) : ControllerBase
public async Task UpdateAsync(License viewModel) public async Task UpdateAsync(License viewModel)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return; if(userId is null) return;
License model = await context.Licenses.FindAsync(viewModel.Id); License model = await context.Licenses.FindAsync(viewModel.Id);
@@ -104,7 +102,9 @@ public class LicensesController(MarechaiContext context) : ControllerBase
public async Task<int> CreateAsync(License viewModel) public async Task<int> CreateAsync(License viewModel)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return 0; if(userId is null) return 0;
var model = new License var model = new License
{ {
FsfApproved = viewModel.FsfApproved, FsfApproved = viewModel.FsfApproved,
@@ -128,6 +128,7 @@ public class LicensesController(MarechaiContext context) : ControllerBase
public async Task DeleteAsync(int id) public async Task DeleteAsync(int id)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return; if(userId is null) return;
License item = await context.Licenses.FindAsync(id); License item = await context.Licenses.FindAsync(id);

View File

@@ -23,7 +23,6 @@
// Copyright © 2003-2025 Natalia Portillo // Copyright © 2003-2025 Natalia Portillo
*******************************************************************************/ *******************************************************************************/
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Security.Claims; using System.Security.Claims;
@@ -34,7 +33,6 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Localization;
namespace Marechai.Server.Controllers; namespace Marechai.Server.Controllers;
@@ -46,8 +44,7 @@ public class MachineFamiliesController(MarechaiContext context) : ControllerBase
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<List<MachineFamilyDto>> GetAsync() => await context.MachineFamilies public Task<List<MachineFamilyDto>> GetAsync() => context.MachineFamilies.OrderBy(m => m.Company.Name)
.OrderBy(m => m.Company.Name)
.ThenBy(m => m.Name) .ThenBy(m => m.Name)
.Select(m => new MachineFamilyDto .Select(m => new MachineFamilyDto
{ {
@@ -62,7 +59,7 @@ public class MachineFamiliesController(MarechaiContext context) : ControllerBase
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<MachineFamilyDto> GetAsync(int id) => await context.MachineFamilies.Where(f => f.Id == id) public Task<MachineFamilyDto> GetAsync(int id) => context.MachineFamilies.Where(f => f.Id == id)
.Select(m => new MachineFamilyDto .Select(m => new MachineFamilyDto
{ {
Id = m.Id, Id = m.Id,
@@ -78,6 +75,7 @@ public class MachineFamiliesController(MarechaiContext context) : ControllerBase
public async Task UpdateAsync(MachineFamilyDto dto) public async Task UpdateAsync(MachineFamilyDto dto)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return; if(userId is null) return;
MachineFamily model = await context.MachineFamilies.FindAsync(dto.Id); MachineFamily model = await context.MachineFamilies.FindAsync(dto.Id);
@@ -96,7 +94,9 @@ public class MachineFamiliesController(MarechaiContext context) : ControllerBase
public async Task<int> CreateAsync(MachineFamilyDto dto) public async Task<int> CreateAsync(MachineFamilyDto dto)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return 0; if(userId is null) return 0;
var model = new MachineFamily var model = new MachineFamily
{ {
Name = dto.Name, Name = dto.Name,
@@ -116,6 +116,7 @@ public class MachineFamiliesController(MarechaiContext context) : ControllerBase
public async Task DeleteAsync(int id) public async Task DeleteAsync(int id)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return; if(userId is null) return;
MachineFamily item = await context.MachineFamilies.FindAsync(id); MachineFamily item = await context.MachineFamilies.FindAsync(id);

View File

@@ -34,7 +34,6 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Localization;
namespace Marechai.Server.Controllers; namespace Marechai.Server.Controllers;
@@ -53,7 +52,7 @@ public class MachinePhotosController(MarechaiContext context) : ControllerBase
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<MachinePhotoDto> GetAsync(Guid id) => await context.MachinePhotos.Where(p => p.Id == id) public Task<MachinePhotoDto> GetAsync(Guid id) => context.MachinePhotos.Where(p => p.Id == id)
.Select(p => new MachinePhotoDto .Select(p => new MachinePhotoDto
{ {
Aperture = p.Aperture, Aperture = p.Aperture,
@@ -72,18 +71,15 @@ public class MachinePhotosController(MarechaiContext context) : ControllerBase
Flash = p.Flash, Flash = p.Flash,
Focal = p.Focal, Focal = p.Focal,
FocalLength = p.FocalLength, FocalLength = p.FocalLength,
FocalLengthEquivalent = FocalLengthEquivalent = p.FocalLengthEquivalent,
p.FocalLengthEquivalent, HorizontalResolution = p.HorizontalResolution,
HorizontalResolution =
p.HorizontalResolution,
Id = p.Id, Id = p.Id,
IsoRating = p.IsoRating, IsoRating = p.IsoRating,
Lens = p.Lens, Lens = p.Lens,
LicenseId = p.LicenseId, LicenseId = p.LicenseId,
LicenseName = p.License.Name, LicenseName = p.License.Name,
LightSource = p.LightSource, LightSource = p.LightSource,
MachineCompanyName = MachineCompanyName = p.Machine.Company.Name,
p.Machine.Company.Name,
MachineId = p.MachineId, MachineId = p.MachineId,
MachineName = p.Machine.Name, MachineName = p.Machine.Name,
MeteringMode = p.MeteringMode, MeteringMode = p.MeteringMode,
@@ -95,8 +91,7 @@ public class MachinePhotosController(MarechaiContext context) : ControllerBase
Sharpness = p.Sharpness, Sharpness = p.Sharpness,
SoftwareUsed = p.SoftwareUsed, SoftwareUsed = p.SoftwareUsed,
Source = p.Source, Source = p.Source,
SubjectDistanceRange = SubjectDistanceRange = p.SubjectDistanceRange,
p.SubjectDistanceRange,
UploadDate = p.UploadDate, UploadDate = p.UploadDate,
UserId = p.UserId, UserId = p.UserId,
VerticalResolution = p.VerticalResolution, VerticalResolution = p.VerticalResolution,
@@ -112,6 +107,7 @@ public class MachinePhotosController(MarechaiContext context) : ControllerBase
public async Task UpdateAsync(MachinePhotoDto dto) public async Task UpdateAsync(MachinePhotoDto dto)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return; if(userId is null) return;
MachinePhoto model = await context.MachinePhotos.FindAsync(dto.Id); MachinePhoto model = await context.MachinePhotos.FindAsync(dto.Id);
@@ -162,7 +158,9 @@ public class MachinePhotosController(MarechaiContext context) : ControllerBase
public async Task<Guid> CreateAsync(MachinePhotoDto dto) public async Task<Guid> CreateAsync(MachinePhotoDto dto)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return null; if(userId is null) return null;
var model = new MachinePhoto var model = new MachinePhoto
{ {
Aperture = dto.Aperture, Aperture = dto.Aperture,

View File

@@ -40,17 +40,20 @@ namespace Marechai.Server.Controllers;
[Route("/machines")] [Route("/machines")]
[ApiController] [ApiController]
public class MachinesController(MarechaiContext context, public class MachinesController
(
MarechaiContext context,
IStringLocalizer<MachinesService> localizer, IStringLocalizer<MachinesService> localizer,
GpusService gpusService, GpusService gpusService,
ProcessorsService processorsService, ProcessorsService processorsService,
SoundSynthsService soundSynthsService) : ControllerBase SoundSynthsService soundSynthsService
) : ControllerBase
{ {
[HttpGet] [HttpGet]
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<List<MachineDto>> GetAsync() => await context.Machines.OrderBy(m => m.Company.Name) public Task<List<MachineDto>> GetAsync() => context.Machines.OrderBy(m => m.Company.Name)
.ThenBy(m => m.Name) .ThenBy(m => m.Name)
.ThenBy(m => m.Family.Name) .ThenBy(m => m.Family.Name)
.Select(m => new MachineDto .Select(m => new MachineDto
@@ -69,7 +72,7 @@ public class MachinesController(MarechaiContext context,
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<MachineDto> GetAsync(int id) => await context.Machines.Where(m => m.Id == id) public Task<MachineDto> GetAsync(int id) => context.Machines.Where(m => m.Id == id)
.Select(m => new MachineDto .Select(m => new MachineDto
{ {
Id = m.Id, Id = m.Id,
@@ -90,6 +93,7 @@ public class MachinesController(MarechaiContext context,
public async Task UpdateAsync(MachineDto dto) public async Task UpdateAsync(MachineDto dto)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return; if(userId is null) return;
Machine model = await context.Machines.FindAsync(dto.Id); Machine model = await context.Machines.FindAsync(dto.Id);
@@ -136,7 +140,9 @@ public class MachinesController(MarechaiContext context,
public async Task<int> CreateAsync(MachineDto dto) public async Task<int> CreateAsync(MachineDto dto)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return 0; if(userId is null) return 0;
var model = new Machine var model = new Machine
{ {
CompanyId = dto.CompanyId, CompanyId = dto.CompanyId,
@@ -209,9 +215,7 @@ public class MachinesController(MarechaiContext context,
IQueryable<CompanyLogo> logos = context.CompanyLogos.Where(l => l.CompanyId == company.Id); IQueryable<CompanyLogo> logos = context.CompanyLogos.Where(l => l.CompanyId == company.Id);
if(model.Introduced.HasValue) if(model.Introduced.HasValue)
{
model.CompanyLogo = (await logos.FirstOrDefaultAsync(l => l.Year >= model.Introduced.Value.Year))?.Guid; model.CompanyLogo = (await logos.FirstOrDefaultAsync(l => l.Year >= model.Introduced.Value.Year))?.Guid;
}
if(model.CompanyLogo is null && logos.Any()) model.CompanyLogo = (await logos.FirstAsync())?.Guid; if(model.CompanyLogo is null && logos.Any()) model.CompanyLogo = (await logos.FirstAsync())?.Guid;
} }
@@ -259,6 +263,7 @@ public class MachinesController(MarechaiContext context,
public async Task DeleteAsync(int id) public async Task DeleteAsync(int id)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return; if(userId is null) return;
Machine item = await context.Machines.FindAsync(id); Machine item = await context.Machines.FindAsync(id);

View File

@@ -23,7 +23,6 @@
// Copyright © 2003-2025 Natalia Portillo // Copyright © 2003-2025 Natalia Portillo
*******************************************************************************/ *******************************************************************************/
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Security.Claims; using System.Security.Claims;
@@ -34,7 +33,6 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Localization;
namespace Marechai.Server.Controllers; namespace Marechai.Server.Controllers;
@@ -46,8 +44,7 @@ public class MagazineIssuesController(MarechaiContext context) : ControllerBase
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<List<MagazineIssueDto>> GetAsync() => await context.MagazineIssues public Task<List<MagazineIssueDto>> GetAsync() => context.MagazineIssues.OrderBy(b => b.Magazine.Title)
.OrderBy(b => b.Magazine.Title)
.ThenBy(b => b.Published) .ThenBy(b => b.Published)
.ThenBy(b => b.Caption) .ThenBy(b => b.Caption)
.Select(b => new MagazineIssueDto .Select(b => new MagazineIssueDto
@@ -68,7 +65,7 @@ public class MagazineIssuesController(MarechaiContext context) : ControllerBase
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<MagazineIssueDto> GetAsync(long id) => await context.MagazineIssues.Where(b => b.Id == id) public Task<MagazineIssueDto> GetAsync(long id) => context.MagazineIssues.Where(b => b.Id == id)
.Select(b => new MagazineIssueDto .Select(b => new MagazineIssueDto
{ {
Id = b.Id, Id = b.Id,
@@ -90,6 +87,7 @@ public class MagazineIssuesController(MarechaiContext context) : ControllerBase
public async Task UpdateAsync(MagazineIssueDto dto) public async Task UpdateAsync(MagazineIssueDto dto)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return; if(userId is null) return;
MagazineIssue model = await context.MagazineIssues.FindAsync(dto.Id); MagazineIssue model = await context.MagazineIssues.FindAsync(dto.Id);
@@ -112,7 +110,9 @@ public class MagazineIssuesController(MarechaiContext context) : ControllerBase
public async Task<long> CreateAsync(MagazineIssueDto dto) public async Task<long> CreateAsync(MagazineIssueDto dto)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return 0; if(userId is null) return 0;
var model = new MagazineIssue var model = new MagazineIssue
{ {
MagazineId = dto.MagazineId, MagazineId = dto.MagazineId,
@@ -137,6 +137,7 @@ public class MagazineIssuesController(MarechaiContext context) : ControllerBase
public async Task DeleteAsync(long id) public async Task DeleteAsync(long id)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return; if(userId is null) return;
MagazineIssue item = await context.MagazineIssues.FindAsync(id); MagazineIssue item = await context.MagazineIssues.FindAsync(id);

View File

@@ -34,7 +34,6 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Localization;
namespace Marechai.Server.Controllers; namespace Marechai.Server.Controllers;
@@ -53,7 +52,7 @@ public class MagazineScansController(MarechaiContext context) : ControllerBase
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<MagazineScanDto> GetAsync(Guid id) => await context.MagazineScans.Where(p => p.Id == id) public Task<MagazineScanDto> GetAsync(Guid id) => context.MagazineScans.Where(p => p.Id == id)
.Select(p => new MagazineScanDto .Select(p => new MagazineScanDto
{ {
Author = p.Author, Author = p.Author,
@@ -84,6 +83,7 @@ public class MagazineScansController(MarechaiContext context) : ControllerBase
public async Task UpdateAsync(MagazineScanDto dto) public async Task UpdateAsync(MagazineScanDto dto)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return; if(userId is null) return;
MagazineScan model = await context.MagazineScans.FindAsync(dto.Id); MagazineScan model = await context.MagazineScans.FindAsync(dto.Id);
@@ -113,7 +113,9 @@ public class MagazineScansController(MarechaiContext context) : ControllerBase
public async Task<Guid> CreateAsync(MagazineScanDto dto) public async Task<Guid> CreateAsync(MagazineScanDto dto)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return null; if(userId is null) return null;
var model = new MagazineScan var model = new MagazineScan
{ {
Author = dto.Author, Author = dto.Author,
@@ -149,6 +151,7 @@ public class MagazineScansController(MarechaiContext context) : ControllerBase
public async Task DeleteAsync(Guid id) public async Task DeleteAsync(Guid id)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return; if(userId is null) return;
MagazineScan item = await context.MagazineScans.FindAsync(id); MagazineScan item = await context.MagazineScans.FindAsync(id);

View File

@@ -23,7 +23,6 @@
// Copyright © 2003-2025 Natalia Portillo // Copyright © 2003-2025 Natalia Portillo
*******************************************************************************/ *******************************************************************************/
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Security.Claims; using System.Security.Claims;
@@ -34,7 +33,6 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Localization;
namespace Marechai.Server.Controllers; namespace Marechai.Server.Controllers;
@@ -46,7 +44,7 @@ public class MagazinesByMachineController(MarechaiContext context) : ControllerB
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<List<MagazineByMachineDto>> GetByMagazine(long bookId) => await context.MagazinesByMachines public Task<List<MagazineByMachineDto>> GetByMagazine(long bookId) => context.MagazinesByMachines
.Where(p => p.MagazineId == bookId) .Where(p => p.MagazineId == bookId)
.Select(p => new MagazineByMachineDto .Select(p => new MagazineByMachineDto
{ {
@@ -65,6 +63,7 @@ public class MagazinesByMachineController(MarechaiContext context) : ControllerB
public async Task DeleteAsync(long id) public async Task DeleteAsync(long id)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return; if(userId is null) return;
MagazinesByMachine item = await context.MagazinesByMachines.FindAsync(id); MagazinesByMachine item = await context.MagazinesByMachines.FindAsync(id);
@@ -82,7 +81,9 @@ public class MagazinesByMachineController(MarechaiContext context) : ControllerB
public async Task<long> CreateAsync(int machineId, long bookId) public async Task<long> CreateAsync(int machineId, long bookId)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return 0; if(userId is null) return 0;
var item = new MagazinesByMachine var item = new MagazinesByMachine
{ {
MachineId = machineId, MachineId = machineId,

View File

@@ -23,7 +23,6 @@
// Copyright © 2003-2025 Natalia Portillo // Copyright © 2003-2025 Natalia Portillo
*******************************************************************************/ *******************************************************************************/
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Security.Claims; using System.Security.Claims;
@@ -34,7 +33,6 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Localization;
namespace Marechai.Server.Controllers; namespace Marechai.Server.Controllers;
@@ -46,8 +44,8 @@ public class MagazinesByMachineFamilyController(MarechaiContext context) : Contr
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<List<MagazineByMachineFamilyDto>> GetByMagazine(long bookId) => await context public Task<List<MagazineByMachineFamilyDto>> GetByMagazine(long bookId) => context.MagazinesByMachinesFamilies
.MagazinesByMachinesFamilies.Where(p => p.MagazineId == bookId) .Where(p => p.MagazineId == bookId)
.Select(p => new MagazineByMachineFamilyDto .Select(p => new MagazineByMachineFamilyDto
{ {
Id = p.Id, Id = p.Id,
@@ -65,6 +63,7 @@ public class MagazinesByMachineFamilyController(MarechaiContext context) : Contr
public async Task DeleteAsync(long id) public async Task DeleteAsync(long id)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return; if(userId is null) return;
MagazinesByMachineFamily item = await context.MagazinesByMachinesFamilies.FindAsync(id); MagazinesByMachineFamily item = await context.MagazinesByMachinesFamilies.FindAsync(id);
@@ -82,7 +81,9 @@ public class MagazinesByMachineFamilyController(MarechaiContext context) : Contr
public async Task<long> CreateAsync(int machineFamilyId, long bookId) public async Task<long> CreateAsync(int machineFamilyId, long bookId)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return 0; if(userId is null) return 0;
var item = new MagazinesByMachineFamily var item = new MagazinesByMachineFamily
{ {
MachineFamilyId = machineFamilyId, MachineFamilyId = machineFamilyId,

View File

@@ -23,7 +23,6 @@
// Copyright © 2003-2025 Natalia Portillo // Copyright © 2003-2025 Natalia Portillo
*******************************************************************************/ *******************************************************************************/
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Security.Claims; using System.Security.Claims;
@@ -34,7 +33,6 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Localization;
namespace Marechai.Server.Controllers; namespace Marechai.Server.Controllers;
@@ -46,7 +44,7 @@ public class MagazinesController(MarechaiContext context) : ControllerBase
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<List<MagazineDto>> GetAsync() => await context.Magazines.OrderBy(b => b.NativeTitle) public Task<List<MagazineDto>> GetAsync() => context.Magazines.OrderBy(b => b.NativeTitle)
.ThenBy(b => b.FirstPublication) .ThenBy(b => b.FirstPublication)
.ThenBy(b => b.Title) .ThenBy(b => b.Title)
.Select(b => new MagazineDto .Select(b => new MagazineDto
@@ -66,7 +64,7 @@ public class MagazinesController(MarechaiContext context) : ControllerBase
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<List<MagazineDto>> GetTitlesAsync() => await context.Magazines.OrderBy(b => b.Title) public Task<List<MagazineDto>> GetTitlesAsync() => context.Magazines.OrderBy(b => b.Title)
.ThenBy(b => b.FirstPublication) .ThenBy(b => b.FirstPublication)
.Select(b => new MagazineDto .Select(b => new MagazineDto
{ {
@@ -79,7 +77,7 @@ public class MagazinesController(MarechaiContext context) : ControllerBase
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<MagazineDto> GetAsync(long id) => await context.Magazines.Where(b => b.Id == id) public Task<MagazineDto> GetAsync(long id) => context.Magazines.Where(b => b.Id == id)
.Select(b => new MagazineDto .Select(b => new MagazineDto
{ {
Id = b.Id, Id = b.Id,
@@ -100,6 +98,7 @@ public class MagazinesController(MarechaiContext context) : ControllerBase
public async Task UpdateAsync(MagazineDto dto) public async Task UpdateAsync(MagazineDto dto)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return; if(userId is null) return;
Magazine model = await context.Magazines.FindAsync(dto.Id); Magazine model = await context.Magazines.FindAsync(dto.Id);
@@ -121,7 +120,9 @@ public class MagazinesController(MarechaiContext context) : ControllerBase
public async Task<long> CreateAsync(MagazineDto dto) public async Task<long> CreateAsync(MagazineDto dto)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return 0; if(userId is null) return 0;
var model = new Magazine var model = new Magazine
{ {
Title = dto.Title, Title = dto.Title,
@@ -152,6 +153,7 @@ public class MagazinesController(MarechaiContext context) : ControllerBase
public async Task DeleteAsync(long id) public async Task DeleteAsync(long id)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return; if(userId is null) return;
Magazine item = await context.Magazines.FindAsync(id); Magazine item = await context.Magazines.FindAsync(id);

View File

@@ -23,7 +23,6 @@
// Copyright © 2003-2025 Natalia Portillo // Copyright © 2003-2025 Natalia Portillo
*******************************************************************************/ *******************************************************************************/
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Security.Claims; using System.Security.Claims;
@@ -34,7 +33,6 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Localization;
namespace Marechai.Server.Controllers; namespace Marechai.Server.Controllers;
@@ -46,7 +44,7 @@ public class MediaController(MarechaiContext context) : ControllerBase
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<List<MediaDto>> GetAsync() => await context.Media.OrderBy(d => d.Title) public Task<List<MediaDto>> GetAsync() => context.Media.OrderBy(d => d.Title)
.Select(d => new MediaDto .Select(d => new MediaDto
{ {
Id = d.Id, Id = d.Id,
@@ -82,7 +80,7 @@ public class MediaController(MarechaiContext context) : ControllerBase
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<List<MediaDto>> GetTitlesAsync() => await context.Media.OrderBy(d => d.Title) public Task<List<MediaDto>> GetTitlesAsync() => context.Media.OrderBy(d => d.Title)
.Select(d => new MediaDto .Select(d => new MediaDto
{ {
Id = d.Id, Id = d.Id,
@@ -94,7 +92,7 @@ public class MediaController(MarechaiContext context) : ControllerBase
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<MediaDto> GetAsync(ulong id) => await context.Media.Where(d => d.Id == id) public Task<MediaDto> GetAsync(ulong id) => context.Media.Where(d => d.Id == id)
.Select(d => new MediaDto .Select(d => new MediaDto
{ {
Id = d.Id, Id = d.Id,
@@ -133,6 +131,7 @@ public class MediaController(MarechaiContext context) : ControllerBase
public async Task UpdateAsync(MediaDto dto) public async Task UpdateAsync(MediaDto dto)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return; if(userId is null) return;
Media model = await context.Media.FindAsync(dto.Id); Media model = await context.Media.FindAsync(dto.Id);
@@ -173,7 +172,9 @@ public class MediaController(MarechaiContext context) : ControllerBase
public async Task<ulong> CreateAsync(MediaDto dto) public async Task<ulong> CreateAsync(MediaDto dto)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return null; if(userId is null) return null;
var model = new Media var model = new Media
{ {
Title = dto.Title, Title = dto.Title,
@@ -216,6 +217,7 @@ public class MediaController(MarechaiContext context) : ControllerBase
public async Task DeleteAsync(ulong id) public async Task DeleteAsync(ulong id)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return; if(userId is null) return;
Media item = await context.Media.FindAsync(id); Media item = await context.Media.FindAsync(id);

View File

@@ -23,7 +23,6 @@
// Copyright © 2003-2025 Natalia Portillo // Copyright © 2003-2025 Natalia Portillo
*******************************************************************************/ *******************************************************************************/
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Security.Claims; using System.Security.Claims;
@@ -34,7 +33,6 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Localization;
namespace Marechai.Server.Controllers; namespace Marechai.Server.Controllers;
@@ -46,7 +44,7 @@ public class MemoriesByMachineController(MarechaiContext context) : ControllerBa
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<List<MemoryByMachineDto>> GetByMachine(int machineId) => await context.MemoryByMachine public Task<List<MemoryByMachineDto>> GetByMachine(int machineId) => context.MemoryByMachine
.Where(m => m.MachineId == machineId) .Where(m => m.MachineId == machineId)
.Select(m => new MemoryByMachineDto .Select(m => new MemoryByMachineDto
{ {
@@ -70,6 +68,7 @@ public class MemoriesByMachineController(MarechaiContext context) : ControllerBa
public async Task DeleteAsync(long id) public async Task DeleteAsync(long id)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return; if(userId is null) return;
MemoryByMachine item = await context.MemoryByMachine.FindAsync(id); MemoryByMachine item = await context.MemoryByMachine.FindAsync(id);
@@ -87,7 +86,9 @@ public class MemoriesByMachineController(MarechaiContext context) : ControllerBa
public async Task<long> CreateAsync(int machineId, MemoryType type, MemoryUsage usage, long? size, double? speed) public async Task<long> CreateAsync(int machineId, MemoryType type, MemoryUsage usage, long? size, double? speed)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return 0; if(userId is null) return 0;
var item = new MemoryByMachine var item = new MemoryByMachine
{ {
MachineId = machineId, MachineId = machineId,

View File

@@ -23,7 +23,6 @@
// Copyright © 2003-2025 Natalia Portillo // Copyright © 2003-2025 Natalia Portillo
*******************************************************************************/ *******************************************************************************/
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Security.Claims; using System.Security.Claims;
@@ -46,7 +45,7 @@ public class NewsController(MarechaiContext context, IStringLocalizer<NewsServic
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<List<NewsDto>> GetAsync() => await context.News.OrderByDescending(n => n.Date) public Task<List<NewsDto>> GetAsync() => context.News.OrderByDescending(n => n.Date)
.Select(n => new NewsDto .Select(n => new NewsDto
{ {
Id = n.Id, Id = n.Id,
@@ -162,6 +161,7 @@ public class NewsController(MarechaiContext context, IStringLocalizer<NewsServic
public async Task DeleteAsync(int id) public async Task DeleteAsync(int id)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return; if(userId is null) return;
News item = await context.News.FindAsync(id); News item = await context.News.FindAsync(id);

View File

@@ -23,7 +23,6 @@
// Copyright © 2003-2025 Natalia Portillo // Copyright © 2003-2025 Natalia Portillo
*******************************************************************************/ *******************************************************************************/
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Security.Claims; using System.Security.Claims;
@@ -34,7 +33,6 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Localization;
namespace Marechai.Server.Controllers; namespace Marechai.Server.Controllers;
@@ -46,7 +44,7 @@ public class PeopleController(MarechaiContext context) : ControllerBase
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<List<PersonDto>> GetAsync() => await context.People.OrderBy(p => p.DisplayName) public Task<List<PersonDto>> GetAsync() => context.People.OrderBy(p => p.DisplayName)
.ThenBy(p => p.Alias) .ThenBy(p => p.Alias)
.ThenBy(p => p.Name) .ThenBy(p => p.Name)
.ThenBy(p => p.Surname) .ThenBy(p => p.Surname)
@@ -71,7 +69,7 @@ public class PeopleController(MarechaiContext context) : ControllerBase
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<PersonDto> GetAsync(int id) => await context.People.Where(p => p.Id == id) public Task<PersonDto> GetAsync(int id) => context.People.Where(p => p.Id == id)
.Select(p => new PersonDto .Select(p => new PersonDto
{ {
Id = p.Id, Id = p.Id,
@@ -96,6 +94,7 @@ public class PeopleController(MarechaiContext context) : ControllerBase
public async Task UpdateAsync(PersonDto dto) public async Task UpdateAsync(PersonDto dto)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return; if(userId is null) return;
Person model = await context.People.FindAsync(dto.Id); Person model = await context.People.FindAsync(dto.Id);
@@ -123,7 +122,9 @@ public class PeopleController(MarechaiContext context) : ControllerBase
public async Task<int> CreateAsync(PersonDto dto) public async Task<int> CreateAsync(PersonDto dto)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return 0; if(userId is null) return 0;
var model = new Person var model = new Person
{ {
Name = dto.Name, Name = dto.Name,
@@ -152,6 +153,7 @@ public class PeopleController(MarechaiContext context) : ControllerBase
public async Task DeleteAsync(int id) public async Task DeleteAsync(int id)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return; if(userId is null) return;
Person item = await context.People.FindAsync(id); Person item = await context.People.FindAsync(id);

View File

@@ -23,7 +23,6 @@
// Copyright © 2003-2025 Natalia Portillo // Copyright © 2003-2025 Natalia Portillo
*******************************************************************************/ *******************************************************************************/
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Security.Claims; using System.Security.Claims;
@@ -34,7 +33,6 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Localization;
namespace Marechai.Server.Controllers; namespace Marechai.Server.Controllers;
@@ -46,8 +44,8 @@ public class ProcessorsByMachineController(MarechaiContext context) : Controller
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<List<ProcessorByMachineDto>> GetByMachine(int machineId) => await context public Task<List<ProcessorByMachineDto>> GetByMachine(int machineId) => context.ProcessorsByMachine
.ProcessorsByMachine.Where(p => p.MachineId == machineId) .Where(p => p.MachineId == machineId)
.Select(p => new ProcessorByMachineDto .Select(p => new ProcessorByMachineDto
{ {
Id = p.Id, Id = p.Id,
@@ -68,6 +66,7 @@ public class ProcessorsByMachineController(MarechaiContext context) : Controller
public async Task DeleteAsync(long id) public async Task DeleteAsync(long id)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return; if(userId is null) return;
ProcessorsByMachine item = await context.ProcessorsByMachine.FindAsync(id); ProcessorsByMachine item = await context.ProcessorsByMachine.FindAsync(id);
@@ -85,7 +84,9 @@ public class ProcessorsByMachineController(MarechaiContext context) : Controller
public async Task<long> CreateAsync(int processorId, int machineId, float? speed) public async Task<long> CreateAsync(int processorId, int machineId, float? speed)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return 0; if(userId is null) return 0;
var item = new ProcessorsByMachine var item = new ProcessorsByMachine
{ {
ProcessorId = processorId, ProcessorId = processorId,

View File

@@ -23,7 +23,6 @@
// Copyright © 2003-2025 Natalia Portillo // Copyright © 2003-2025 Natalia Portillo
*******************************************************************************/ *******************************************************************************/
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Security.Claims; using System.Security.Claims;
@@ -34,7 +33,6 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Localization;
namespace Marechai.Server.Controllers; namespace Marechai.Server.Controllers;
@@ -46,8 +44,7 @@ public class ProcessorsController(MarechaiContext context) : ControllerBase
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<List<ProcessorDto>> GetAsync() => await context.Processors public Task<List<ProcessorDto>> GetAsync() => context.Processors.Select(p => new ProcessorDto
.Select(p => new ProcessorDto
{ {
Name = p.Name, Name = p.Name,
CompanyName = p.Company.Name, CompanyName = p.Company.Name,
@@ -76,10 +73,8 @@ public class ProcessorsController(MarechaiContext context) : ControllerBase
L3 = p.L3, L3 = p.L3,
InstructionSet = p.InstructionSet.Name, InstructionSet = p.InstructionSet.Name,
Id = p.Id, Id = p.Id,
InstructionSetExtensions = InstructionSetExtensions = p.InstructionSetExtensions
p.InstructionSetExtensions .Select(e => e.Extension.Extension)
.Select(e => e.Extension
.Extension)
.ToList() .ToList()
}) })
.OrderBy(p => p.CompanyName) .OrderBy(p => p.CompanyName)
@@ -90,7 +85,7 @@ public class ProcessorsController(MarechaiContext context) : ControllerBase
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<List<ProcessorDto>> GetByMachineAsync(int machineId) => await context.ProcessorsByMachine public Task<List<ProcessorDto>> GetByMachineAsync(int machineId) => context.ProcessorsByMachine
.Where(p => p.MachineId == machineId) .Where(p => p.MachineId == machineId)
.Select(p => new ProcessorDto .Select(p => new ProcessorDto
{ {
@@ -121,8 +116,7 @@ public class ProcessorsController(MarechaiContext context) : ControllerBase
L3 = p.Processor.L3, L3 = p.Processor.L3,
InstructionSet = p.Processor.InstructionSet.Name, InstructionSet = p.Processor.InstructionSet.Name,
Id = p.Processor.Id, Id = p.Processor.Id,
InstructionSetExtensions = InstructionSetExtensions = p.Processor.InstructionSetExtensions.Select(e => e.Extension.Extension).ToList()
p.Processor.InstructionSetExtensions.Select(e => e.Extension.Extension).ToList()
}) })
.OrderBy(p => p.CompanyName) .OrderBy(p => p.CompanyName)
.ThenBy(p => p.Name) .ThenBy(p => p.Name)
@@ -132,7 +126,7 @@ public class ProcessorsController(MarechaiContext context) : ControllerBase
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<ProcessorDto> GetAsync(int id) => await context.Processors.Where(p => p.Id == id) public Task<ProcessorDto> GetAsync(int id) => context.Processors.Where(p => p.Id == id)
.Select(p => new ProcessorDto .Select(p => new ProcessorDto
{ {
Name = p.Name, Name = p.Name,
@@ -160,8 +154,7 @@ public class ProcessorsController(MarechaiContext context) : ControllerBase
L1Data = p.L1Data, L1Data = p.L1Data,
L2 = p.L2, L2 = p.L2,
L3 = p.L3, L3 = p.L3,
InstructionSet = InstructionSet = p.InstructionSet.Name,
p.InstructionSet.Name,
InstructionSetId = p.InstructionSetId InstructionSetId = p.InstructionSetId
}) })
.FirstOrDefaultAsync(); .FirstOrDefaultAsync();
@@ -173,6 +166,7 @@ public class ProcessorsController(MarechaiContext context) : ControllerBase
public async Task UpdateAsync(ProcessorDto dto) public async Task UpdateAsync(ProcessorDto dto)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return; if(userId is null) return;
Processor model = await context.Processors.FindAsync(dto.Id); Processor model = await context.Processors.FindAsync(dto.Id);
@@ -214,7 +208,9 @@ public class ProcessorsController(MarechaiContext context) : ControllerBase
public async Task<int> CreateAsync(ProcessorDto dto) public async Task<int> CreateAsync(ProcessorDto dto)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return 0; if(userId is null) return 0;
var model = new Processor var model = new Processor
{ {
AddrBus = dto.AddrBus, AddrBus = dto.AddrBus,
@@ -257,6 +253,7 @@ public class ProcessorsController(MarechaiContext context) : ControllerBase
public async Task DeleteAsync(int id) public async Task DeleteAsync(int id)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return; if(userId is null) return;
Processor item = await context.Processors.FindAsync(id); Processor item = await context.Processors.FindAsync(id);

View File

@@ -23,7 +23,6 @@
// Copyright © 2003-2025 Natalia Portillo // Copyright © 2003-2025 Natalia Portillo
*******************************************************************************/ *******************************************************************************/
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Security.Claims; using System.Security.Claims;
@@ -34,7 +33,6 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Localization;
namespace Marechai.Server.Controllers; namespace Marechai.Server.Controllers;
@@ -46,8 +44,7 @@ public class ResolutionsController(MarechaiContext context) : ControllerBase
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<List<ResolutionDto>> GetAsync() => await context.Resolutions public Task<List<ResolutionDto>> GetAsync() => context.Resolutions.Select(r => new ResolutionDto
.Select(r => new ResolutionDto
{ {
Id = r.Id, Id = r.Id,
Width = r.Width, Width = r.Width,
@@ -69,7 +66,7 @@ public class ResolutionsController(MarechaiContext context) : ControllerBase
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<ResolutionDto> GetAsync(int id) => await context.Resolutions.Where(r => r.Id == id) public Task<ResolutionDto> GetAsync(int id) => context.Resolutions.Where(r => r.Id == id)
.Select(r => new ResolutionDto .Select(r => new ResolutionDto
{ {
Id = r.Id, Id = r.Id,
@@ -89,6 +86,7 @@ public class ResolutionsController(MarechaiContext context) : ControllerBase
public async Task UpdateAsync(ResolutionDto dto) public async Task UpdateAsync(ResolutionDto dto)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return; if(userId is null) return;
Resolution model = await context.Resolutions.FindAsync(dto.Id); Resolution model = await context.Resolutions.FindAsync(dto.Id);
@@ -111,7 +109,9 @@ public class ResolutionsController(MarechaiContext context) : ControllerBase
public async Task<int> CreateAsync(ResolutionDto dto) public async Task<int> CreateAsync(ResolutionDto dto)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return 0; if(userId is null) return 0;
var model = new Resolution var model = new Resolution
{ {
Chars = dto.Chars, Chars = dto.Chars,
@@ -135,6 +135,7 @@ public class ResolutionsController(MarechaiContext context) : ControllerBase
public async Task DeleteAsync(int id) public async Task DeleteAsync(int id)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return; if(userId is null) return;
Resolution item = await context.Resolutions.FindAsync(id); Resolution item = await context.Resolutions.FindAsync(id);

View File

@@ -23,7 +23,6 @@
// Copyright © 2003-2025 Natalia Portillo // Copyright © 2003-2025 Natalia Portillo
*******************************************************************************/ *******************************************************************************/
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Security.Claims; using System.Security.Claims;
@@ -34,7 +33,6 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Localization;
namespace Marechai.Server.Controllers; namespace Marechai.Server.Controllers;
@@ -46,7 +44,7 @@ public class ScreensByMachineController(MarechaiContext context) : ControllerBas
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<List<ScreenByMachineDto>> GetByMachine(int machineId) => await context.ScreensByMachine public Task<List<ScreenByMachineDto>> GetByMachine(int machineId) => context.ScreensByMachine
.Where(s => s.MachineId == machineId) .Where(s => s.MachineId == machineId)
.Select(s => new ScreenByMachineDto .Select(s => new ScreenByMachineDto
{ {
@@ -83,6 +81,7 @@ public class ScreensByMachineController(MarechaiContext context) : ControllerBas
public async Task DeleteAsync(long id) public async Task DeleteAsync(long id)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return; if(userId is null) return;
ScreensByMachine item = await context.ScreensByMachine.FindAsync(id); ScreensByMachine item = await context.ScreensByMachine.FindAsync(id);
@@ -100,6 +99,7 @@ public class ScreensByMachineController(MarechaiContext context) : ControllerBas
public async Task<long> CreateAsync(int machineId, int screenId) public async Task<long> CreateAsync(int machineId, int screenId)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return 0; if(userId is null) return 0;
if(context.ScreensByMachine.Any(s => s.MachineId == machineId && s.ScreenId == screenId)) return 0; if(context.ScreensByMachine.Any(s => s.MachineId == machineId && s.ScreenId == screenId)) return 0;

View File

@@ -23,7 +23,6 @@
// Copyright © 2003-2025 Natalia Portillo // Copyright © 2003-2025 Natalia Portillo
*******************************************************************************/ *******************************************************************************/
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Security.Claims; using System.Security.Claims;
@@ -34,7 +33,6 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Localization;
namespace Marechai.Server.Controllers; namespace Marechai.Server.Controllers;
@@ -54,25 +52,16 @@ public class ScreensController(MarechaiContext context) : ControllerBase
Id = s.Id, Id = s.Id,
Type = s.Type, Type = s.Type,
Width = s.Width, Width = s.Width,
NativeResolutionId = NativeResolutionId = s.NativeResolutionId,
s.NativeResolutionId, NativeResolution = new ResolutionDto
NativeResolution =
new ResolutionDto
{ {
Chars = s.NativeResolution Chars = s.NativeResolution.Chars,
.Chars, Colors = s.NativeResolution.Colors,
Colors = s.NativeResolution Grayscale = s.NativeResolution.Grayscale,
.Colors, Height = s.NativeResolution.Height,
Grayscale = s.NativeResolution Id = s.NativeResolution.Id,
.Grayscale, Palette = s.NativeResolution.Palette,
Height = s.NativeResolution Width = s.NativeResolution.Width
.Height,
Id =
s.NativeResolution.Id,
Palette = s.NativeResolution
.Palette,
Width = s.NativeResolution
.Width
} }
}) })
.ToListAsync()).OrderBy(s => s.Diagonal) .ToListAsync()).OrderBy(s => s.Diagonal)
@@ -86,7 +75,7 @@ public class ScreensController(MarechaiContext context) : ControllerBase
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<ScreenDto> GetAsync(int id) => await context.Screens.Where(s => s.Id == id) public Task<ScreenDto> GetAsync(int id) => context.Screens.Where(s => s.Id == id)
.Select(s => new ScreenDto .Select(s => new ScreenDto
{ {
Diagonal = s.Diagonal, Diagonal = s.Diagonal,
@@ -97,12 +86,10 @@ public class ScreensController(MarechaiContext context) : ControllerBase
{ {
Chars = s.NativeResolution.Chars, Chars = s.NativeResolution.Chars,
Colors = s.NativeResolution.Colors, Colors = s.NativeResolution.Colors,
Grayscale = s.NativeResolution Grayscale = s.NativeResolution.Grayscale,
.Grayscale,
Height = s.NativeResolution.Height, Height = s.NativeResolution.Height,
Id = s.NativeResolution.Id, Id = s.NativeResolution.Id,
Palette = Palette = s.NativeResolution.Palette,
s.NativeResolution.Palette,
Width = s.NativeResolution.Width Width = s.NativeResolution.Width
}, },
NativeResolutionId = s.NativeResolutionId, NativeResolutionId = s.NativeResolutionId,
@@ -118,6 +105,7 @@ public class ScreensController(MarechaiContext context) : ControllerBase
public async Task UpdateAsync(ScreenDto dto) public async Task UpdateAsync(ScreenDto dto)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return; if(userId is null) return;
Screen model = await context.Screens.FindAsync(dto.Id); Screen model = await context.Screens.FindAsync(dto.Id);
@@ -144,7 +132,9 @@ public class ScreensController(MarechaiContext context) : ControllerBase
public async Task<int> CreateAsync(ScreenDto dto) public async Task<int> CreateAsync(ScreenDto dto)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return 0; if(userId is null) return 0;
var model = new Screen var model = new Screen
{ {
Diagonal = dto.Diagonal, Diagonal = dto.Diagonal,
@@ -168,6 +158,7 @@ public class ScreensController(MarechaiContext context) : ControllerBase
public async Task DeleteAsync(int id) public async Task DeleteAsync(int id)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return; if(userId is null) return;
Screen item = await context.Screens.FindAsync(id); Screen item = await context.Screens.FindAsync(id);

View File

@@ -23,7 +23,6 @@
// Copyright © 2003-2025 Natalia Portillo // Copyright © 2003-2025 Natalia Portillo
*******************************************************************************/ *******************************************************************************/
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Security.Claims; using System.Security.Claims;
@@ -34,7 +33,6 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Localization;
namespace Marechai.Server.Controllers; namespace Marechai.Server.Controllers;
@@ -46,7 +44,7 @@ public class SoftwareFamiliesController(MarechaiContext context) : ControllerBas
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<List<SoftwareFamilyDto>> GetAsync() => await context.SoftwareFamilies.OrderBy(b => b.Name) public Task<List<SoftwareFamilyDto>> GetAsync() => context.SoftwareFamilies.OrderBy(b => b.Name)
.Select(b => new SoftwareFamilyDto .Select(b => new SoftwareFamilyDto
{ {
Id = b.Id, Id = b.Id,
@@ -61,8 +59,7 @@ public class SoftwareFamiliesController(MarechaiContext context) : ControllerBas
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<SoftwareFamilyDto> GetAsync(ulong id) => await context.SoftwareFamilies public Task<SoftwareFamilyDto> GetAsync(ulong id) => context.SoftwareFamilies.Where(b => b.Id == id)
.Where(b => b.Id == id)
.Select(b => new SoftwareFamilyDto .Select(b => new SoftwareFamilyDto
{ {
Id = b.Id, Id = b.Id,
@@ -80,6 +77,7 @@ public class SoftwareFamiliesController(MarechaiContext context) : ControllerBas
public async Task UpdateAsync(SoftwareFamilyDto dto) public async Task UpdateAsync(SoftwareFamilyDto dto)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return; if(userId is null) return;
SoftwareFamily model = await context.SoftwareFamilies.FindAsync(dto.Id); SoftwareFamily model = await context.SoftwareFamilies.FindAsync(dto.Id);
@@ -98,7 +96,9 @@ public class SoftwareFamiliesController(MarechaiContext context) : ControllerBas
public async Task<ulong> CreateAsync(SoftwareFamilyDto dto) public async Task<ulong> CreateAsync(SoftwareFamilyDto dto)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return null; if(userId is null) return null;
var model = new SoftwareFamily var model = new SoftwareFamily
{ {
Name = dto.Name, Name = dto.Name,
@@ -119,6 +119,7 @@ public class SoftwareFamiliesController(MarechaiContext context) : ControllerBas
public async Task DeleteAsync(ulong id) public async Task DeleteAsync(ulong id)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return; if(userId is null) return;
SoftwareFamily item = await context.SoftwareFamilies.FindAsync(id); SoftwareFamily item = await context.SoftwareFamilies.FindAsync(id);

View File

@@ -23,7 +23,6 @@
// Copyright © 2003-2025 Natalia Portillo // Copyright © 2003-2025 Natalia Portillo
*******************************************************************************/ *******************************************************************************/
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Security.Claims; using System.Security.Claims;
@@ -34,7 +33,6 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Localization;
namespace Marechai.Server.Controllers; namespace Marechai.Server.Controllers;
@@ -46,7 +44,7 @@ public class SoftwareVariantsController(MarechaiContext context) : ControllerBas
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<List<SoftwareVariantDto>> GetAsync() => await context.SoftwareVariants public Task<List<SoftwareVariantDto>> GetAsync() => context.SoftwareVariants
.OrderBy(b => b.SoftwareVersion.Family.Name) .OrderBy(b => b.SoftwareVersion.Family.Name)
.ThenBy(b => b.SoftwareVersion.Version) .ThenBy(b => b.SoftwareVersion.Version)
.ThenBy(b => b.Name) .ThenBy(b => b.Name)
@@ -79,8 +77,7 @@ public class SoftwareVariantsController(MarechaiContext context) : ControllerBas
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<SoftwareVariantDto> GetAsync(ulong id) => await context.SoftwareVariants public Task<SoftwareVariantDto> GetAsync(ulong id) => context.SoftwareVariants.Where(b => b.Id == id)
.Where(b => b.Id == id)
.Select(b => new SoftwareVariantDto .Select(b => new SoftwareVariantDto
{ {
Id = b.Id, Id = b.Id,
@@ -91,8 +88,7 @@ public class SoftwareVariantsController(MarechaiContext context) : ControllerBas
Parent = Parent =
b.Parent.Name ?? b.Parent.Version, b.Parent.Name ?? b.Parent.Version,
SoftwareVersionId = b.SoftwareVersionId, SoftwareVersionId = b.SoftwareVersionId,
SoftwareVersion = SoftwareVersion = b.SoftwareVersion.Name ??
b.SoftwareVersion.Name ??
b.SoftwareVersion.Version, b.SoftwareVersion.Version,
MinimumMemory = b.MinimumMemory, MinimumMemory = b.MinimumMemory,
RecommendedMemory = b.RecommendedMemory, RecommendedMemory = b.RecommendedMemory,
@@ -112,6 +108,7 @@ public class SoftwareVariantsController(MarechaiContext context) : ControllerBas
public async Task UpdateAsync(SoftwareVariantDto dto) public async Task UpdateAsync(SoftwareVariantDto dto)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return; if(userId is null) return;
SoftwareVariant model = await context.SoftwareVariants.FindAsync(dto.Id); SoftwareVariant model = await context.SoftwareVariants.FindAsync(dto.Id);
@@ -141,7 +138,9 @@ public class SoftwareVariantsController(MarechaiContext context) : ControllerBas
public async Task<ulong> CreateAsync(SoftwareVariantDto dto) public async Task<ulong> CreateAsync(SoftwareVariantDto dto)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return null; if(userId is null) return null;
var model = new SoftwareVariant var model = new SoftwareVariant
{ {
Name = dto.Name, Name = dto.Name,
@@ -172,6 +171,7 @@ public class SoftwareVariantsController(MarechaiContext context) : ControllerBas
public async Task DeleteAsync(ulong id) public async Task DeleteAsync(ulong id)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return; if(userId is null) return;
SoftwareVariant item = await context.SoftwareVariants.FindAsync(id); SoftwareVariant item = await context.SoftwareVariants.FindAsync(id);

View File

@@ -23,7 +23,6 @@
// Copyright © 2003-2025 Natalia Portillo // Copyright © 2003-2025 Natalia Portillo
*******************************************************************************/ *******************************************************************************/
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Security.Claims; using System.Security.Claims;
@@ -34,7 +33,6 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Localization;
namespace Marechai.Server.Controllers; namespace Marechai.Server.Controllers;
@@ -46,8 +44,7 @@ public class SoftwareVersionsController(MarechaiContext context) : ControllerBas
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<List<SoftwareVersionDto>> GetAsync() => await context.SoftwareVersions public Task<List<SoftwareVersionDto>> GetAsync() => context.SoftwareVersions.OrderBy(b => b.Family.Name)
.OrderBy(b => b.Family.Name)
.ThenBy(b => b.Version) .ThenBy(b => b.Version)
.ThenBy(b => b.Introduced) .ThenBy(b => b.Introduced)
.Select(b => new SoftwareVersionDto .Select(b => new SoftwareVersionDto
@@ -70,8 +67,7 @@ public class SoftwareVersionsController(MarechaiContext context) : ControllerBas
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<SoftwareVersionDto> GetAsync(ulong id) => await context.SoftwareVersions public Task<SoftwareVersionDto> GetAsync(ulong id) => context.SoftwareVersions.Where(b => b.Id == id)
.Where(b => b.Id == id)
.Select(b => new SoftwareVersionDto .Select(b => new SoftwareVersionDto
{ {
Id = b.Id, Id = b.Id,
@@ -95,6 +91,7 @@ public class SoftwareVersionsController(MarechaiContext context) : ControllerBas
public async Task UpdateAsync(SoftwareVersionDto dto) public async Task UpdateAsync(SoftwareVersionDto dto)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return; if(userId is null) return;
SoftwareVersion model = await context.SoftwareVersions.FindAsync(dto.Id); SoftwareVersion model = await context.SoftwareVersions.FindAsync(dto.Id);
@@ -117,7 +114,9 @@ public class SoftwareVersionsController(MarechaiContext context) : ControllerBas
public async Task<ulong> CreateAsync(SoftwareVersionDto dto) public async Task<ulong> CreateAsync(SoftwareVersionDto dto)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return null; if(userId is null) return null;
var model = new SoftwareVersion var model = new SoftwareVersion
{ {
Name = dto.Name, Name = dto.Name,
@@ -142,6 +141,7 @@ public class SoftwareVersionsController(MarechaiContext context) : ControllerBas
public async Task DeleteAsync(ulong id) public async Task DeleteAsync(ulong id)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return; if(userId is null) return;
SoftwareVersion item = await context.SoftwareVersions.FindAsync(id); SoftwareVersion item = await context.SoftwareVersions.FindAsync(id);

View File

@@ -23,7 +23,6 @@
// Copyright © 2003-2025 Natalia Portillo // Copyright © 2003-2025 Natalia Portillo
*******************************************************************************/ *******************************************************************************/
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Security.Claims; using System.Security.Claims;
@@ -34,7 +33,6 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Localization;
namespace Marechai.Server.Controllers; namespace Marechai.Server.Controllers;
@@ -46,7 +44,7 @@ public class SoundSynthsByMachineController(MarechaiContext context) : Controlle
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<List<SoundSynthByMachineDto>> GetByMachine(int machineId) => await context.SoundByMachine public Task<List<SoundSynthByMachineDto>> GetByMachine(int machineId) => context.SoundByMachine
.Where(g => g.MachineId == machineId) .Where(g => g.MachineId == machineId)
.Select(g => new SoundSynthByMachineDto .Select(g => new SoundSynthByMachineDto
{ {
@@ -67,6 +65,7 @@ public class SoundSynthsByMachineController(MarechaiContext context) : Controlle
public async Task DeleteAsync(long id) public async Task DeleteAsync(long id)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return; if(userId is null) return;
SoundByMachine item = await context.SoundByMachine.FindAsync(id); SoundByMachine item = await context.SoundByMachine.FindAsync(id);
@@ -84,7 +83,9 @@ public class SoundSynthsByMachineController(MarechaiContext context) : Controlle
public async Task<long> CreateAsync(int soundSynthId, int machineId) public async Task<long> CreateAsync(int soundSynthId, int machineId)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return 0; if(userId is null) return 0;
var item = new SoundByMachine var item = new SoundByMachine
{ {
SoundSynthId = soundSynthId, SoundSynthId = soundSynthId,

View File

@@ -23,7 +23,6 @@
// Copyright © 2003-2025 Natalia Portillo // Copyright © 2003-2025 Natalia Portillo
*******************************************************************************/ *******************************************************************************/
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Security.Claims; using System.Security.Claims;
@@ -34,7 +33,6 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Localization;
namespace Marechai.Server.Controllers; namespace Marechai.Server.Controllers;
@@ -46,7 +44,7 @@ public class SoundSynthsController(MarechaiContext context) : ControllerBase
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<List<SoundSynthDto>> GetAsync() => await context.SoundSynths.OrderBy(s => s.Company.Name) public Task<List<SoundSynthDto>> GetAsync() => context.SoundSynths.OrderBy(s => s.Company.Name)
.ThenBy(s => s.Name) .ThenBy(s => s.Name)
.ThenBy(s => s.ModelCode) .ThenBy(s => s.ModelCode)
.Select(s => new SoundSynthDto .Select(s => new SoundSynthDto
@@ -70,7 +68,7 @@ public class SoundSynthsController(MarechaiContext context) : ControllerBase
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<List<SoundSynthDto>> GetByMachineAsync(int machineId) => await context.SoundByMachine public Task<List<SoundSynthDto>> GetByMachineAsync(int machineId) => context.SoundByMachine
.Where(s => s.MachineId == machineId) .Where(s => s.MachineId == machineId)
.Select(s => s.SoundSynth) .Select(s => s.SoundSynth)
.OrderBy(s => s.Company.Name) .OrderBy(s => s.Company.Name)
@@ -97,7 +95,7 @@ public class SoundSynthsController(MarechaiContext context) : ControllerBase
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<SoundSynthDto> GetAsync(int id) => await context.SoundSynths.Where(s => s.Id == id) public Task<SoundSynthDto> GetAsync(int id) => context.SoundSynths.Where(s => s.Id == id)
.Select(s => new SoundSynthDto .Select(s => new SoundSynthDto
{ {
Id = s.Id, Id = s.Id,
@@ -122,6 +120,7 @@ public class SoundSynthsController(MarechaiContext context) : ControllerBase
public async Task UpdateAsync(SoundSynthDto dto) public async Task UpdateAsync(SoundSynthDto dto)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return; if(userId is null) return;
SoundSynth model = await context.SoundSynths.FindAsync(dto.Id); SoundSynth model = await context.SoundSynths.FindAsync(dto.Id);
@@ -148,7 +147,9 @@ public class SoundSynthsController(MarechaiContext context) : ControllerBase
public async Task<int> CreateAsync(SoundSynthDto dto) public async Task<int> CreateAsync(SoundSynthDto dto)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return 0; if(userId is null) return 0;
var model = new SoundSynth var model = new SoundSynth
{ {
Depth = dto.Depth, Depth = dto.Depth,
@@ -176,6 +177,7 @@ public class SoundSynthsController(MarechaiContext context) : ControllerBase
public async Task DeleteAsync(int id) public async Task DeleteAsync(int id)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return; if(userId is null) return;
SoundSynth item = await context.SoundSynths.FindAsync(id); SoundSynth item = await context.SoundSynths.FindAsync(id);

View File

@@ -23,7 +23,6 @@
// Copyright © 2003-2025 Natalia Portillo // Copyright © 2003-2025 Natalia Portillo
*******************************************************************************/ *******************************************************************************/
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Security.Claims; using System.Security.Claims;
@@ -34,7 +33,6 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Localization;
namespace Marechai.Server.Controllers; namespace Marechai.Server.Controllers;
@@ -46,7 +44,7 @@ public class StorageByMachineController(MarechaiContext context) : ControllerBas
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<List<StorageByMachineDto>> GetByMachine(int machineId) => await context.StorageByMachine public Task<List<StorageByMachineDto>> GetByMachine(int machineId) => context.StorageByMachine
.Where(s => s.MachineId == machineId) .Where(s => s.MachineId == machineId)
.Select(s => new StorageByMachineDto .Select(s => new StorageByMachineDto
{ {
@@ -68,6 +66,7 @@ public class StorageByMachineController(MarechaiContext context) : ControllerBas
public async Task DeleteAsync(long id) public async Task DeleteAsync(long id)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return; if(userId is null) return;
StorageByMachine item = await context.StorageByMachine.FindAsync(id); StorageByMachine item = await context.StorageByMachine.FindAsync(id);
@@ -85,7 +84,9 @@ public class StorageByMachineController(MarechaiContext context) : ControllerBas
public async Task<long> CreateAsync(int machineId, StorageType type, StorageInterface @interface, long? capacity) public async Task<long> CreateAsync(int machineId, StorageType type, StorageInterface @interface, long? capacity)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return 0; if(userId is null) return 0;
var item = new StorageByMachine var item = new StorageByMachine
{ {
MachineId = machineId, MachineId = machineId,