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.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Localization;
namespace Marechai.Server.Controllers;
@@ -53,34 +52,29 @@ public class BookScansController(MarechaiContext context) : ControllerBase
[AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<BookScanDto> GetAsync(Guid id) => await context.BookScans.Where(p => p.Id == id)
.Select(p => new BookScanDto
{
Author = p.Author,
BookId = p.Book.Id,
ColorSpace = p.ColorSpace,
Comments = p.Comments,
CreationDate = p.CreationDate,
ExifVersion = p.ExifVersion,
HorizontalResolution =
p.HorizontalResolution,
Id = p.Id,
ResolutionUnit =
p.ResolutionUnit,
Page = p.Page,
ScannerManufacturer =
p.ScannerManufacturer,
ScannerModel = p.ScannerModel,
SoftwareUsed = p.SoftwareUsed,
Type = p.Type,
UploadDate = p.UploadDate,
UserId = p.UserId,
VerticalResolution =
p.VerticalResolution,
OriginalExtension =
p.OriginalExtension
})
.FirstOrDefaultAsync();
public Task<BookScanDto> GetAsync(Guid id) => context.BookScans.Where(p => p.Id == id)
.Select(p => new BookScanDto
{
Author = p.Author,
BookId = p.Book.Id,
ColorSpace = p.ColorSpace,
Comments = p.Comments,
CreationDate = p.CreationDate,
ExifVersion = p.ExifVersion,
HorizontalResolution = p.HorizontalResolution,
Id = p.Id,
ResolutionUnit = p.ResolutionUnit,
Page = p.Page,
ScannerManufacturer = p.ScannerManufacturer,
ScannerModel = p.ScannerModel,
SoftwareUsed = p.SoftwareUsed,
Type = p.Type,
UploadDate = p.UploadDate,
UserId = p.UserId,
VerticalResolution = p.VerticalResolution,
OriginalExtension = p.OriginalExtension
})
.FirstOrDefaultAsync();
[HttpPost]
[Authorize(Roles = "Admin,UberAdmin")]
@@ -89,6 +83,7 @@ public class BookScansController(MarechaiContext context) : ControllerBase
public async Task UpdateAsync(BookScanDto dto)
{
string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return;
BookScan model = await context.BookScans.FindAsync(dto.Id);
@@ -118,7 +113,9 @@ public class BookScansController(MarechaiContext context) : ControllerBase
public async Task<Guid> CreateAsync(BookScanDto dto)
{
string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return null;
var model = new BookScan
{
Author = dto.Author,
@@ -154,6 +151,7 @@ public class BookScansController(MarechaiContext context) : ControllerBase
public async Task DeleteAsync(Guid id)
{
string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return;
BookScan item = await context.BookScans.FindAsync(id);
@@ -163,4 +161,4 @@ public class BookScansController(MarechaiContext context) : ControllerBase
await context.SaveChangesWithUserAsync(userId);
}
}
}

View File

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

View File

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

View File

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

View File

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

View File

@@ -23,7 +23,6 @@
// Copyright © 2003-2025 Natalia Portillo
*******************************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
@@ -46,80 +45,70 @@ public class CompaniesController(MarechaiContext context, IStringLocalizer<Compa
[AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<List<CompanyDto>> GetAsync() => await context.Companies.Include(c => c.Logos)
.OrderBy(c => c.Name)
.Select(c => new CompanyDto
{
Id = c.Id,
LastLogo =
c.Logos
.OrderByDescending(l => l.Year)
.FirstOrDefault()
.Guid,
Name = c.Name,
Founded = c.Founded,
Sold = c.Sold,
SoldToId = c.SoldToId,
CountryId = c.CountryId,
Status = c.Status,
Website = c.Website,
Twitter = c.Twitter,
Facebook = c.Facebook,
Address = c.Address,
City = c.City,
Province = c.Province,
PostalCode = c.PostalCode,
Country = c.Country.Name,
FoundedDayIsUnknown =
c.FoundedDayIsUnknown,
FoundedMonthIsUnknown =
c.FoundedMonthIsUnknown,
SoldDayIsUnknown =
c.SoldDayIsUnknown,
SoldMonthIsUnknown =
c.SoldMonthIsUnknown,
LegalName = c.LegalName
})
.ToListAsync();
public Task<List<CompanyDto>> GetAsync() => context.Companies.Include(c => c.Logos)
.OrderBy(c => c.Name)
.Select(c => new CompanyDto
{
Id = c.Id,
LastLogo =
c.Logos.OrderByDescending(l => l.Year)
.FirstOrDefault()
.Guid,
Name = c.Name,
Founded = c.Founded,
Sold = c.Sold,
SoldToId = c.SoldToId,
CountryId = c.CountryId,
Status = c.Status,
Website = c.Website,
Twitter = c.Twitter,
Facebook = c.Facebook,
Address = c.Address,
City = c.City,
Province = c.Province,
PostalCode = c.PostalCode,
Country = c.Country.Name,
FoundedDayIsUnknown = c.FoundedDayIsUnknown,
FoundedMonthIsUnknown = c.FoundedMonthIsUnknown,
SoldDayIsUnknown = c.SoldDayIsUnknown,
SoldMonthIsUnknown = c.SoldMonthIsUnknown,
LegalName = c.LegalName
})
.ToListAsync();
[HttpGet]
[AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<CompanyDto> GetAsync(int id) => await context.Companies.Where(c => c.Id == id)
.Select(c => new CompanyDto
{
Id = c.Id,
LastLogo =
c.Logos
.OrderByDescending(l => l.Year)
.FirstOrDefault()
.Guid,
Name = c.Name,
Founded = c.Founded,
Sold = c.Sold,
SoldToId = c.SoldToId,
CountryId = c.CountryId,
Status = c.Status,
Website = c.Website,
Twitter = c.Twitter,
Facebook = c.Facebook,
Address = c.Address,
City = c.City,
Province = c.Province,
PostalCode = c.PostalCode,
Country = c.Country.Name,
FoundedDayIsUnknown =
c.FoundedDayIsUnknown,
FoundedMonthIsUnknown =
c.FoundedMonthIsUnknown,
SoldDayIsUnknown =
c.SoldDayIsUnknown,
SoldMonthIsUnknown =
c.SoldMonthIsUnknown,
LegalName = c.LegalName
})
.FirstOrDefaultAsync();
public Task<CompanyDto> GetAsync(int id) => context.Companies.Where(c => c.Id == id)
.Select(c => new CompanyDto
{
Id = c.Id,
LastLogo =
c.Logos.OrderByDescending(l => l.Year)
.FirstOrDefault()
.Guid,
Name = c.Name,
Founded = c.Founded,
Sold = c.Sold,
SoldToId = c.SoldToId,
CountryId = c.CountryId,
Status = c.Status,
Website = c.Website,
Twitter = c.Twitter,
Facebook = c.Facebook,
Address = c.Address,
City = c.City,
Province = c.Province,
PostalCode = c.PostalCode,
Country = c.Country.Name,
FoundedDayIsUnknown = c.FoundedDayIsUnknown,
FoundedMonthIsUnknown = c.FoundedMonthIsUnknown,
SoldDayIsUnknown = c.SoldDayIsUnknown,
SoldMonthIsUnknown = c.SoldMonthIsUnknown,
LegalName = c.LegalName
})
.FirstOrDefaultAsync();
[HttpPost]
[Authorize(Roles = "Admin,UberAdmin")]
@@ -128,6 +117,7 @@ public class CompaniesController(MarechaiContext context, IStringLocalizer<Compa
public async Task UpdateAsync(CompanyDto dto)
{
string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return;
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)
{
string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return 0;
var model = new Company
{
Name = dto.Name,
@@ -194,15 +186,15 @@ public class CompaniesController(MarechaiContext context, IStringLocalizer<Compa
[AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<List<Machine>> GetMachinesAsync(int id) => await context.Machines.Where(m => m.CompanyId == id)
.OrderBy(m => m.Name)
.Select(m => new Machine
{
Id = m.Id,
Name = m.Name,
Type = m.Type
})
.ToListAsync();
public Task<List<Machine>> GetMachinesAsync(int id) => context.Machines.Where(m => m.CompanyId == id)
.OrderBy(m => m.Name)
.Select(m => new Machine
{
Id = m.Id,
Name = m.Name,
Type = m.Type
})
.ToListAsync();
[HttpGet]
[AllowAnonymous]
@@ -219,12 +211,12 @@ public class CompaniesController(MarechaiContext context, IStringLocalizer<Compa
[AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<Company> GetSoldToAsync(int? id) => await context.Companies.Select(c => new Company
{
Id = c.Id,
Name = c.Name
})
.FirstOrDefaultAsync(c => c.Id == id);
public Task<Company> GetSoldToAsync(int? id) => context.Companies.Select(c => new Company
{
Id = c.Id,
Name = c.Name
})
.FirstOrDefaultAsync(c => c.Id == id);
[HttpGet]
[AllowAnonymous]
@@ -237,8 +229,7 @@ public class CompaniesController(MarechaiContext context, IStringLocalizer<Compa
[AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
public Task<List<CompanyDto>> GetCompaniesByCountryAsync(int countryId) => context.Companies
.Include(c => c.Logos)
public Task<List<CompanyDto>> GetCompaniesByCountryAsync(int countryId) => context.Companies.Include(c => c.Logos)
.Where(c => c.CountryId == countryId)
.OrderBy(c => c.Name)
.Select(c => new CompanyDto
@@ -271,6 +262,7 @@ public class CompaniesController(MarechaiContext context, IStringLocalizer<Compa
public async Task DeleteAsync(int id)
{
string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return;
Company item = await context.Companies.FindAsync(id);
@@ -285,24 +277,25 @@ public class CompaniesController(MarechaiContext context, IStringLocalizer<Compa
[AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<CompanyDescriptionDto> GetDescriptionAsync(int id) => await context.CompanyDescriptions
.Where(d => d.CompanyId == id)
.Select(d => new CompanyDescriptionDto
{
Id = d.Id,
CompanyId = d.CompanyId,
Html = d.Html,
Markdown = d.Text
})
.FirstOrDefaultAsync();
public Task<CompanyDescriptionDto> GetDescriptionAsync(int id) => context.CompanyDescriptions
.Where(d => d.CompanyId == id)
.Select(d => new CompanyDescriptionDto
{
Id = d.Id,
CompanyId = d.CompanyId,
Html = d.Html,
Markdown = d.Text
})
.FirstOrDefaultAsync();
[HttpPost]
[Authorize(Roles = "Admin,UberAdmin")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<int> CreateOrUpdateDescriptionAsync(int id, CompanyDescriptionDto description)
public async Task<int> CreateOrUpdateDescriptionAsync(int id, CompanyDescriptionDto description)
{
string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return 0;
CompanyDescription current = await context.CompanyDescriptions.FirstOrDefaultAsync(d => d.CompanyId == id);
@@ -327,4 +320,4 @@ public class CompaniesController(MarechaiContext context, IStringLocalizer<Compa
return current.Id;
}
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -34,7 +34,6 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Localization;
namespace Marechai.Server.Controllers;
@@ -53,29 +52,29 @@ public class DocumentScansController(MarechaiContext context) : ControllerBase
[AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<DocumentScanDto> GetAsync(Guid id) => await context.DocumentScans.Where(p => p.Id == id)
.Select(p => new DocumentScanDto
{
Author = p.Author,
DocumentId = p.Document.Id,
ColorSpace = p.ColorSpace,
Comments = p.Comments,
CreationDate = p.CreationDate,
ExifVersion = p.ExifVersion,
HorizontalResolution = p.HorizontalResolution,
Id = p.Id,
ResolutionUnit = p.ResolutionUnit,
Page = p.Page,
ScannerManufacturer = p.ScannerManufacturer,
ScannerModel = p.ScannerModel,
SoftwareUsed = p.SoftwareUsed,
Type = p.Type,
UploadDate = p.UploadDate,
UserId = p.UserId,
VerticalResolution = p.VerticalResolution,
OriginalExtension = p.OriginalExtension
})
.FirstOrDefaultAsync();
public Task<DocumentScanDto> GetAsync(Guid id) => context.DocumentScans.Where(p => p.Id == id)
.Select(p => new DocumentScanDto
{
Author = p.Author,
DocumentId = p.Document.Id,
ColorSpace = p.ColorSpace,
Comments = p.Comments,
CreationDate = p.CreationDate,
ExifVersion = p.ExifVersion,
HorizontalResolution = p.HorizontalResolution,
Id = p.Id,
ResolutionUnit = p.ResolutionUnit,
Page = p.Page,
ScannerManufacturer = p.ScannerManufacturer,
ScannerModel = p.ScannerModel,
SoftwareUsed = p.SoftwareUsed,
Type = p.Type,
UploadDate = p.UploadDate,
UserId = p.UserId,
VerticalResolution = p.VerticalResolution,
OriginalExtension = p.OriginalExtension
})
.FirstOrDefaultAsync();
[HttpPost]
[Authorize(Roles = "Admin,UberAdmin")]
@@ -84,6 +83,7 @@ public class DocumentScansController(MarechaiContext context) : ControllerBase
public async Task UpdateAsync(DocumentScanDto dto)
{
string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return;
DocumentScan model = await context.DocumentScans.FindAsync(dto.Id);
@@ -113,7 +113,9 @@ public class DocumentScansController(MarechaiContext context) : ControllerBase
public async Task<Guid> CreateAsync(DocumentScanDto dto)
{
string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return null;
var model = new DocumentScan
{
Author = dto.Author,
@@ -149,6 +151,7 @@ public class DocumentScansController(MarechaiContext context) : ControllerBase
public async Task DeleteAsync(Guid id)
{
string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return;
DocumentScan item = await context.DocumentScans.FindAsync(id);
@@ -158,4 +161,4 @@ public class DocumentScansController(MarechaiContext context) : ControllerBase
await context.SaveChangesWithUserAsync(userId);
}
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -23,18 +23,14 @@
// Copyright © 2003-2025 Natalia Portillo
*******************************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
using Marechai.Data.Dtos;
using Marechai.Database.Models;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Localization;
namespace Marechai.Server.Controllers;
@@ -46,5 +42,5 @@ public class Iso4217Controller(MarechaiContext context) : ControllerBase
[AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<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
*******************************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
using Marechai.Data.Dtos;
using Marechai.Database.Models;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Localization;
namespace Marechai.Server.Controllers;
@@ -46,34 +43,34 @@ public class LicensesController(MarechaiContext context) : ControllerBase
[AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<List<License>> GetAsync() => await context.Licenses.OrderBy(l => l.Name)
.Select(l => new License
{
FsfApproved = l.FsfApproved,
Id = l.Id,
Link = l.Link,
Name = l.Name,
OsiApproved = l.OsiApproved,
SPDX = l.SPDX
})
.ToListAsync();
public Task<List<License>> GetAsync() => context.Licenses.OrderBy(l => l.Name)
.Select(l => new License
{
FsfApproved = l.FsfApproved,
Id = l.Id,
Link = l.Link,
Name = l.Name,
OsiApproved = l.OsiApproved,
SPDX = l.SPDX
})
.ToListAsync();
[HttpGet]
[AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<License> GetAsync(int id) => await context.Licenses.Where(l => l.Id == id)
.Select(l => new License
{
FsfApproved = l.FsfApproved,
Id = l.Id,
Link = l.Link,
Name = l.Name,
OsiApproved = l.OsiApproved,
SPDX = l.SPDX,
Text = l.Text
})
.FirstOrDefaultAsync();
public Task<License> GetAsync(int id) => context.Licenses.Where(l => l.Id == id)
.Select(l => new License
{
FsfApproved = l.FsfApproved,
Id = l.Id,
Link = l.Link,
Name = l.Name,
OsiApproved = l.OsiApproved,
SPDX = l.SPDX,
Text = l.Text
})
.FirstOrDefaultAsync();
[HttpPost]
[Authorize(Roles = "Admin,UberAdmin")]
@@ -82,6 +79,7 @@ public class LicensesController(MarechaiContext context) : ControllerBase
public async Task UpdateAsync(License viewModel)
{
string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return;
License model = await context.Licenses.FindAsync(viewModel.Id);
@@ -104,7 +102,9 @@ public class LicensesController(MarechaiContext context) : ControllerBase
public async Task<int> CreateAsync(License viewModel)
{
string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return 0;
var model = new License
{
FsfApproved = viewModel.FsfApproved,
@@ -128,6 +128,7 @@ public class LicensesController(MarechaiContext context) : ControllerBase
public async Task DeleteAsync(int id)
{
string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return;
License item = await context.Licenses.FindAsync(id);
@@ -137,4 +138,4 @@ public class LicensesController(MarechaiContext context) : ControllerBase
await context.SaveChangesWithUserAsync(userId);
}
}
}

View File

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

View File

@@ -34,7 +34,6 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Localization;
namespace Marechai.Server.Controllers;
@@ -53,57 +52,53 @@ public class MachinePhotosController(MarechaiContext context) : ControllerBase
[AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<MachinePhotoDto> GetAsync(Guid id) => await context.MachinePhotos.Where(p => p.Id == id)
.Select(p => new MachinePhotoDto
{
Aperture = p.Aperture,
Author = p.Author,
CameraManufacturer = p.CameraManufacturer,
CameraModel = p.CameraModel,
ColorSpace = p.ColorSpace,
Comments = p.Comments,
Contrast = p.Contrast,
CreationDate = p.CreationDate,
DigitalZoomRatio = p.DigitalZoomRatio,
ExifVersion = p.ExifVersion,
ExposureTime = p.ExposureTime,
ExposureMethod = p.ExposureMethod,
ExposureProgram = p.ExposureProgram,
Flash = p.Flash,
Focal = p.Focal,
FocalLength = p.FocalLength,
FocalLengthEquivalent =
p.FocalLengthEquivalent,
HorizontalResolution =
p.HorizontalResolution,
Id = p.Id,
IsoRating = p.IsoRating,
Lens = p.Lens,
LicenseId = p.LicenseId,
LicenseName = p.License.Name,
LightSource = p.LightSource,
MachineCompanyName =
p.Machine.Company.Name,
MachineId = p.MachineId,
MachineName = p.Machine.Name,
MeteringMode = p.MeteringMode,
ResolutionUnit = p.ResolutionUnit,
Orientation = p.Orientation,
Saturation = p.Saturation,
SceneCaptureType = p.SceneCaptureType,
SensingMethod = p.SensingMethod,
Sharpness = p.Sharpness,
SoftwareUsed = p.SoftwareUsed,
Source = p.Source,
SubjectDistanceRange =
p.SubjectDistanceRange,
UploadDate = p.UploadDate,
UserId = p.UserId,
VerticalResolution = p.VerticalResolution,
WhiteBalance = p.WhiteBalance,
OriginalExtension = p.OriginalExtension
})
.FirstOrDefaultAsync();
public Task<MachinePhotoDto> GetAsync(Guid id) => context.MachinePhotos.Where(p => p.Id == id)
.Select(p => new MachinePhotoDto
{
Aperture = p.Aperture,
Author = p.Author,
CameraManufacturer = p.CameraManufacturer,
CameraModel = p.CameraModel,
ColorSpace = p.ColorSpace,
Comments = p.Comments,
Contrast = p.Contrast,
CreationDate = p.CreationDate,
DigitalZoomRatio = p.DigitalZoomRatio,
ExifVersion = p.ExifVersion,
ExposureTime = p.ExposureTime,
ExposureMethod = p.ExposureMethod,
ExposureProgram = p.ExposureProgram,
Flash = p.Flash,
Focal = p.Focal,
FocalLength = p.FocalLength,
FocalLengthEquivalent = p.FocalLengthEquivalent,
HorizontalResolution = p.HorizontalResolution,
Id = p.Id,
IsoRating = p.IsoRating,
Lens = p.Lens,
LicenseId = p.LicenseId,
LicenseName = p.License.Name,
LightSource = p.LightSource,
MachineCompanyName = p.Machine.Company.Name,
MachineId = p.MachineId,
MachineName = p.Machine.Name,
MeteringMode = p.MeteringMode,
ResolutionUnit = p.ResolutionUnit,
Orientation = p.Orientation,
Saturation = p.Saturation,
SceneCaptureType = p.SceneCaptureType,
SensingMethod = p.SensingMethod,
Sharpness = p.Sharpness,
SoftwareUsed = p.SoftwareUsed,
Source = p.Source,
SubjectDistanceRange = p.SubjectDistanceRange,
UploadDate = p.UploadDate,
UserId = p.UserId,
VerticalResolution = p.VerticalResolution,
WhiteBalance = p.WhiteBalance,
OriginalExtension = p.OriginalExtension
})
.FirstOrDefaultAsync();
[HttpPost]
[Authorize(Roles = "Admin,UberAdmin")]
@@ -112,6 +107,7 @@ public class MachinePhotosController(MarechaiContext context) : ControllerBase
public async Task UpdateAsync(MachinePhotoDto dto)
{
string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return;
MachinePhoto model = await context.MachinePhotos.FindAsync(dto.Id);
@@ -162,7 +158,9 @@ public class MachinePhotosController(MarechaiContext context) : ControllerBase
public async Task<Guid> CreateAsync(MachinePhotoDto dto)
{
string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return null;
var model = new MachinePhoto
{
Aperture = dto.Aperture,
@@ -211,4 +209,4 @@ public class MachinePhotosController(MarechaiContext context) : ControllerBase
return model.Id;
}
}
}

View File

@@ -40,48 +40,51 @@ namespace Marechai.Server.Controllers;
[Route("/machines")]
[ApiController]
public class MachinesController(MarechaiContext context,
public class MachinesController
(
MarechaiContext context,
IStringLocalizer<MachinesService> localizer,
GpusService gpusService,
ProcessorsService processorsService,
SoundSynthsService soundSynthsService) : ControllerBase
SoundSynthsService soundSynthsService
) : ControllerBase
{
[HttpGet]
[AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<List<MachineDto>> GetAsync() => await context.Machines.OrderBy(m => m.Company.Name)
.ThenBy(m => m.Name)
.ThenBy(m => m.Family.Name)
.Select(m => new MachineDto
{
Id = m.Id,
Company = m.Company.Name,
Name = m.Name,
Model = m.Model,
Introduced = m.Introduced,
Type = m.Type,
Family = m.Family.Name
})
.ToListAsync();
public Task<List<MachineDto>> GetAsync() => context.Machines.OrderBy(m => m.Company.Name)
.ThenBy(m => m.Name)
.ThenBy(m => m.Family.Name)
.Select(m => new MachineDto
{
Id = m.Id,
Company = m.Company.Name,
Name = m.Name,
Model = m.Model,
Introduced = m.Introduced,
Type = m.Type,
Family = m.Family.Name
})
.ToListAsync();
[HttpGet]
[AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<MachineDto> GetAsync(int id) => await context.Machines.Where(m => m.Id == id)
.Select(m => new MachineDto
{
Id = m.Id,
Company = m.Company.Name,
CompanyId = m.CompanyId,
Name = m.Name,
Model = m.Model,
Introduced = m.Introduced,
Type = m.Type,
FamilyId = m.FamilyId
})
.FirstOrDefaultAsync();
public Task<MachineDto> GetAsync(int id) => context.Machines.Where(m => m.Id == id)
.Select(m => new MachineDto
{
Id = m.Id,
Company = m.Company.Name,
CompanyId = m.CompanyId,
Name = m.Name,
Model = m.Model,
Introduced = m.Introduced,
Type = m.Type,
FamilyId = m.FamilyId
})
.FirstOrDefaultAsync();
[HttpPost]
[Authorize(Roles = "Admin,UberAdmin")]
@@ -90,6 +93,7 @@ public class MachinesController(MarechaiContext context,
public async Task UpdateAsync(MachineDto dto)
{
string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return;
Machine model = await context.Machines.FindAsync(dto.Id);
@@ -136,7 +140,9 @@ public class MachinesController(MarechaiContext context,
public async Task<int> CreateAsync(MachineDto dto)
{
string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return 0;
var model = new Machine
{
CompanyId = dto.CompanyId,
@@ -209,9 +215,7 @@ public class MachinesController(MarechaiContext context,
IQueryable<CompanyLogo> logos = context.CompanyLogos.Where(l => l.CompanyId == company.Id);
if(model.Introduced.HasValue)
{
model.CompanyLogo = (await logos.FirstOrDefaultAsync(l => l.Year >= model.Introduced.Value.Year))?.Guid;
}
if(model.CompanyLogo is null && logos.Any()) model.CompanyLogo = (await logos.FirstAsync())?.Guid;
}
@@ -227,27 +231,27 @@ public class MachinesController(MarechaiContext context,
model.Gpus = await gpusService.GetByMachineAsync(machine.Id);
model.Memory = await context.MemoryByMachine.Where(m => m.MachineId == machine.Id)
.Select(m => new MemoryDto
{
Type = m.Type,
Usage = m.Usage,
Size = m.Size,
Speed = m.Speed
})
.ToListAsync();
.Select(m => new MemoryDto
{
Type = m.Type,
Usage = m.Usage,
Size = m.Size,
Speed = m.Speed
})
.ToListAsync();
model.Processors = await processorsService.GetByMachineAsync(machine.Id);
model.SoundSynthesizers = await soundSynthsService.GetByMachineAsync(machine.Id);
model.Storage = await context.StorageByMachine.Where(s => s.MachineId == machine.Id)
.Select(s => new StorageDto
{
Type = s.Type,
Interface = s.Interface,
Capacity = s.Capacity
})
.ToListAsync();
.Select(s => new StorageDto
{
Type = s.Type,
Interface = s.Interface,
Capacity = s.Capacity
})
.ToListAsync();
return model;
}
@@ -259,6 +263,7 @@ public class MachinesController(MarechaiContext context,
public async Task DeleteAsync(int id)
{
string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return;
Machine item = await context.Machines.FindAsync(id);
@@ -268,4 +273,4 @@ public class MachinesController(MarechaiContext context,
await context.SaveChangesWithUserAsync(userId);
}
}
}

View File

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

View File

@@ -34,7 +34,6 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Localization;
namespace Marechai.Server.Controllers;
@@ -53,29 +52,29 @@ public class MagazineScansController(MarechaiContext context) : ControllerBase
[AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<MagazineScanDto> GetAsync(Guid id) => await context.MagazineScans.Where(p => p.Id == id)
.Select(p => new MagazineScanDto
{
Author = p.Author,
MagazineId = p.Magazine.Id,
ColorSpace = p.ColorSpace,
Comments = p.Comments,
CreationDate = p.CreationDate,
ExifVersion = p.ExifVersion,
HorizontalResolution = p.HorizontalResolution,
Id = p.Id,
ResolutionUnit = p.ResolutionUnit,
Page = p.Page,
ScannerManufacturer = p.ScannerManufacturer,
ScannerModel = p.ScannerModel,
SoftwareUsed = p.SoftwareUsed,
Type = p.Type,
UploadDate = p.UploadDate,
UserId = p.UserId,
VerticalResolution = p.VerticalResolution,
OriginalExtension = p.OriginalExtension
})
.FirstOrDefaultAsync();
public Task<MagazineScanDto> GetAsync(Guid id) => context.MagazineScans.Where(p => p.Id == id)
.Select(p => new MagazineScanDto
{
Author = p.Author,
MagazineId = p.Magazine.Id,
ColorSpace = p.ColorSpace,
Comments = p.Comments,
CreationDate = p.CreationDate,
ExifVersion = p.ExifVersion,
HorizontalResolution = p.HorizontalResolution,
Id = p.Id,
ResolutionUnit = p.ResolutionUnit,
Page = p.Page,
ScannerManufacturer = p.ScannerManufacturer,
ScannerModel = p.ScannerModel,
SoftwareUsed = p.SoftwareUsed,
Type = p.Type,
UploadDate = p.UploadDate,
UserId = p.UserId,
VerticalResolution = p.VerticalResolution,
OriginalExtension = p.OriginalExtension
})
.FirstOrDefaultAsync();
[HttpPost]
[Authorize(Roles = "Admin,UberAdmin")]
@@ -84,6 +83,7 @@ public class MagazineScansController(MarechaiContext context) : ControllerBase
public async Task UpdateAsync(MagazineScanDto dto)
{
string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return;
MagazineScan model = await context.MagazineScans.FindAsync(dto.Id);
@@ -113,7 +113,9 @@ public class MagazineScansController(MarechaiContext context) : ControllerBase
public async Task<Guid> CreateAsync(MagazineScanDto dto)
{
string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return null;
var model = new MagazineScan
{
Author = dto.Author,
@@ -149,6 +151,7 @@ public class MagazineScansController(MarechaiContext context) : ControllerBase
public async Task DeleteAsync(Guid id)
{
string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return;
MagazineScan item = await context.MagazineScans.FindAsync(id);
@@ -158,4 +161,4 @@ public class MagazineScansController(MarechaiContext context) : ControllerBase
await context.SaveChangesWithUserAsync(userId);
}
}
}

View File

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

View File

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

View File

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

View File

@@ -23,7 +23,6 @@
// Copyright © 2003-2025 Natalia Portillo
*******************************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
@@ -34,7 +33,6 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Localization;
namespace Marechai.Server.Controllers;
@@ -46,85 +44,85 @@ public class MediaController(MarechaiContext context) : ControllerBase
[AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<List<MediaDto>> GetAsync() => await context.Media.OrderBy(d => d.Title)
.Select(d => new MediaDto
{
Id = d.Id,
Title = d.Title,
Sequence = d.Sequence,
LastSequence = d.LastSequence,
Type = d.Type,
WriteOffset = d.WriteOffset,
Sides = d.Sides,
Layers = d.Layers,
Sessions = d.Sessions,
Tracks = d.Tracks,
Sectors = d.Sectors,
Size = d.Size,
CopyProtection = d.CopyProtection,
PartNumber = d.PartNumber,
SerialNumber = d.SerialNumber,
Barcode = d.Barcode,
CatalogueNumber = d.CatalogueNumber,
Manufacturer = d.Manufacturer,
Model = d.Model,
Revision = d.Revision,
Firmware = d.Firmware,
PhysicalBlockSize = d.PhysicalBlockSize,
LogicalBlockSize = d.LogicalBlockSize,
BlockSizes = d.BlockSizes,
StorageInterface = d.StorageInterface,
TableOfContents = d.TableOfContents
})
.ToListAsync();
public Task<List<MediaDto>> GetAsync() => context.Media.OrderBy(d => d.Title)
.Select(d => new MediaDto
{
Id = d.Id,
Title = d.Title,
Sequence = d.Sequence,
LastSequence = d.LastSequence,
Type = d.Type,
WriteOffset = d.WriteOffset,
Sides = d.Sides,
Layers = d.Layers,
Sessions = d.Sessions,
Tracks = d.Tracks,
Sectors = d.Sectors,
Size = d.Size,
CopyProtection = d.CopyProtection,
PartNumber = d.PartNumber,
SerialNumber = d.SerialNumber,
Barcode = d.Barcode,
CatalogueNumber = d.CatalogueNumber,
Manufacturer = d.Manufacturer,
Model = d.Model,
Revision = d.Revision,
Firmware = d.Firmware,
PhysicalBlockSize = d.PhysicalBlockSize,
LogicalBlockSize = d.LogicalBlockSize,
BlockSizes = d.BlockSizes,
StorageInterface = d.StorageInterface,
TableOfContents = d.TableOfContents
})
.ToListAsync();
[HttpGet]
[AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<List<MediaDto>> GetTitlesAsync() => await context.Media.OrderBy(d => d.Title)
.Select(d => new MediaDto
{
Id = d.Id,
Title = d.Title
})
.ToListAsync();
public Task<List<MediaDto>> GetTitlesAsync() => context.Media.OrderBy(d => d.Title)
.Select(d => new MediaDto
{
Id = d.Id,
Title = d.Title
})
.ToListAsync();
[HttpGet]
[AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<MediaDto> GetAsync(ulong id) => await context.Media.Where(d => d.Id == id)
.Select(d => new MediaDto
{
Id = d.Id,
Title = d.Title,
Sequence = d.Sequence,
LastSequence = d.LastSequence,
Type = d.Type,
WriteOffset = d.WriteOffset,
Sides = d.Sides,
Layers = d.Layers,
Sessions = d.Sessions,
Tracks = d.Tracks,
Sectors = d.Sectors,
Size = d.Size,
CopyProtection = d.CopyProtection,
PartNumber = d.PartNumber,
SerialNumber = d.SerialNumber,
Barcode = d.Barcode,
CatalogueNumber = d.CatalogueNumber,
Manufacturer = d.Manufacturer,
Model = d.Model,
Revision = d.Revision,
Firmware = d.Firmware,
PhysicalBlockSize = d.PhysicalBlockSize,
LogicalBlockSize = d.LogicalBlockSize,
BlockSizes = d.BlockSizes,
StorageInterface = d.StorageInterface,
TableOfContents = d.TableOfContents
})
.FirstOrDefaultAsync();
public Task<MediaDto> GetAsync(ulong id) => context.Media.Where(d => d.Id == id)
.Select(d => new MediaDto
{
Id = d.Id,
Title = d.Title,
Sequence = d.Sequence,
LastSequence = d.LastSequence,
Type = d.Type,
WriteOffset = d.WriteOffset,
Sides = d.Sides,
Layers = d.Layers,
Sessions = d.Sessions,
Tracks = d.Tracks,
Sectors = d.Sectors,
Size = d.Size,
CopyProtection = d.CopyProtection,
PartNumber = d.PartNumber,
SerialNumber = d.SerialNumber,
Barcode = d.Barcode,
CatalogueNumber = d.CatalogueNumber,
Manufacturer = d.Manufacturer,
Model = d.Model,
Revision = d.Revision,
Firmware = d.Firmware,
PhysicalBlockSize = d.PhysicalBlockSize,
LogicalBlockSize = d.LogicalBlockSize,
BlockSizes = d.BlockSizes,
StorageInterface = d.StorageInterface,
TableOfContents = d.TableOfContents
})
.FirstOrDefaultAsync();
[HttpPost]
[Authorize(Roles = "Admin,UberAdmin")]
@@ -133,6 +131,7 @@ public class MediaController(MarechaiContext context) : ControllerBase
public async Task UpdateAsync(MediaDto dto)
{
string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return;
Media model = await context.Media.FindAsync(dto.Id);
@@ -173,7 +172,9 @@ public class MediaController(MarechaiContext context) : ControllerBase
public async Task<ulong> CreateAsync(MediaDto dto)
{
string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return null;
var model = new Media
{
Title = dto.Title,
@@ -216,6 +217,7 @@ public class MediaController(MarechaiContext context) : ControllerBase
public async Task DeleteAsync(ulong id)
{
string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return;
Media item = await context.Media.FindAsync(id);
@@ -225,4 +227,4 @@ public class MediaController(MarechaiContext context) : ControllerBase
await context.SaveChangesWithUserAsync(userId);
}
}
}

View File

@@ -23,7 +23,6 @@
// Copyright © 2003-2025 Natalia Portillo
*******************************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
@@ -34,7 +33,6 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Localization;
namespace Marechai.Server.Controllers;
@@ -46,22 +44,22 @@ public class MemoriesByMachineController(MarechaiContext context) : ControllerBa
[AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<List<MemoryByMachineDto>> GetByMachine(int machineId) => await context.MemoryByMachine
.Where(m => m.MachineId == machineId)
.Select(m => new MemoryByMachineDto
{
Id = m.Id,
Type = m.Type,
Usage = m.Usage,
Size = m.Size,
Speed = m.Speed,
MachineId = m.MachineId
})
.OrderBy(m => m.Type)
.ThenBy(m => m.Usage)
.ThenBy(m => m.Size)
.ThenBy(m => m.Speed)
.ToListAsync();
public Task<List<MemoryByMachineDto>> GetByMachine(int machineId) => context.MemoryByMachine
.Where(m => m.MachineId == machineId)
.Select(m => new MemoryByMachineDto
{
Id = m.Id,
Type = m.Type,
Usage = m.Usage,
Size = m.Size,
Speed = m.Speed,
MachineId = m.MachineId
})
.OrderBy(m => m.Type)
.ThenBy(m => m.Usage)
.ThenBy(m => m.Size)
.ThenBy(m => m.Speed)
.ToListAsync();
[HttpDelete]
[Authorize(Roles = "Admin,UberAdmin")]
@@ -70,6 +68,7 @@ public class MemoriesByMachineController(MarechaiContext context) : ControllerBa
public async Task DeleteAsync(long id)
{
string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return;
MemoryByMachine item = await context.MemoryByMachine.FindAsync(id);
@@ -84,10 +83,12 @@ public class MemoriesByMachineController(MarechaiContext context) : ControllerBa
[Authorize(Roles = "Admin,UberAdmin")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<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);
if(userId is null) return 0;
var item = new MemoryByMachine
{
MachineId = machineId,
@@ -102,4 +103,4 @@ public class MemoriesByMachineController(MarechaiContext context) : ControllerBa
return item.Id;
}
}
}

View File

@@ -23,7 +23,6 @@
// Copyright © 2003-2025 Natalia Portillo
*******************************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
@@ -46,15 +45,15 @@ public class NewsController(MarechaiContext context, IStringLocalizer<NewsServic
[AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<List<NewsDto>> GetAsync() => await context.News.OrderByDescending(n => n.Date)
.Select(n => new NewsDto
{
Id = n.Id,
Timestamp = n.Date,
Type = n.Type,
AffectedId = n.AddedId
})
.ToListAsync();
public Task<List<NewsDto>> GetAsync() => context.News.OrderByDescending(n => n.Date)
.Select(n => new NewsDto
{
Id = n.Id,
Timestamp = n.Date,
Type = n.Type,
AffectedId = n.AddedId
})
.ToListAsync();
[HttpGet]
[AllowAnonymous]
@@ -74,72 +73,72 @@ public class NewsController(MarechaiContext context, IStringLocalizer<NewsServic
{
case NewsType.NewComputerInDb:
news.Add(new NewsDto(@new.AddedId,
localizer["New computer in database"],
@new.Date,
"machine",
$"{machine.Company.Name} {machine.Name}"));
localizer["New computer in database"],
@new.Date,
"machine",
$"{machine.Company.Name} {machine.Name}"));
break;
case NewsType.NewConsoleInDb:
news.Add(new NewsDto(@new.AddedId,
localizer["New console in database"],
@new.Date,
"machine",
$"{machine.Company.Name} {machine.Name}"));
localizer["New console in database"],
@new.Date,
"machine",
$"{machine.Company.Name} {machine.Name}"));
break;
case NewsType.NewComputerInCollection:
news.Add(new NewsDto(@new.AddedId,
localizer["New computer in collection"],
@new.Date,
"machine",
$"{machine.Company.Name} {machine.Name}"));
localizer["New computer in collection"],
@new.Date,
"machine",
$"{machine.Company.Name} {machine.Name}"));
break;
case NewsType.NewConsoleInCollection:
news.Add(new NewsDto(@new.AddedId,
localizer["New console in collection"],
@new.Date,
"machine",
$"{machine.Company.Name} {machine.Name}"));
localizer["New console in collection"],
@new.Date,
"machine",
$"{machine.Company.Name} {machine.Name}"));
break;
case NewsType.UpdatedComputerInDb:
news.Add(new NewsDto(@new.AddedId,
localizer["Updated computer in database"],
@new.Date,
"machine",
$"{machine.Company.Name} {machine.Name}"));
localizer["Updated computer in database"],
@new.Date,
"machine",
$"{machine.Company.Name} {machine.Name}"));
break;
case NewsType.UpdatedConsoleInDb:
news.Add(new NewsDto(@new.AddedId,
localizer["Updated console in database"],
@new.Date,
"machine",
$"{machine.Company.Name} {machine.Name}"));
localizer["Updated console in database"],
@new.Date,
"machine",
$"{machine.Company.Name} {machine.Name}"));
break;
case NewsType.UpdatedComputerInCollection:
news.Add(new NewsDto(@new.AddedId,
localizer["Updated computer in collection"],
@new.Date,
"machine",
$"{machine.Company.Name} {machine.Name}"));
localizer["Updated computer in collection"],
@new.Date,
"machine",
$"{machine.Company.Name} {machine.Name}"));
break;
case NewsType.UpdatedConsoleInCollection:
news.Add(new NewsDto(@new.AddedId,
localizer["Updated console in collection"],
@new.Date,
"machine",
$"{machine.Company.Name} {machine.Name}"));
localizer["Updated console in collection"],
@new.Date,
"machine",
$"{machine.Company.Name} {machine.Name}"));
break;
@@ -162,6 +161,7 @@ public class NewsController(MarechaiContext context, IStringLocalizer<NewsServic
public async Task DeleteAsync(int id)
{
string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return;
News item = await context.News.FindAsync(id);
@@ -171,4 +171,4 @@ public class NewsController(MarechaiContext context, IStringLocalizer<NewsServic
await context.SaveChangesWithUserAsync(userId);
}
}
}

View File

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

View File

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

View File

@@ -23,7 +23,6 @@
// Copyright © 2003-2025 Natalia Portillo
*******************************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
@@ -34,7 +33,6 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Localization;
namespace Marechai.Server.Controllers;
@@ -46,83 +44,79 @@ public class ProcessorsController(MarechaiContext context) : ControllerBase
[AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<List<ProcessorDto>> GetAsync() => await context.Processors
.Select(p => new ProcessorDto
{
Name = p.Name,
CompanyName = p.Company.Name,
CompanyId = p.Company.Id,
ModelCode = p.ModelCode,
Introduced = p.Introduced,
Speed = p.Speed,
Package = p.Package,
Gprs = p.Gprs,
GprSize = p.GprSize,
Fprs = p.Fprs,
FprSize = p.FprSize,
Cores = p.Cores,
ThreadsPerCore = p.ThreadsPerCore,
Process = p.Process,
ProcessNm = p.ProcessNm,
DieSize = p.DieSize,
Transistors = p.Transistors,
DataBus = p.DataBus,
AddrBus = p.AddrBus,
SimdRegisters = p.SimdRegisters,
SimdSize = p.SimdSize,
L1Instruction = p.L1Instruction,
L1Data = p.L1Data,
L2 = p.L2,
L3 = p.L3,
InstructionSet = p.InstructionSet.Name,
Id = p.Id,
InstructionSetExtensions =
p.InstructionSetExtensions
.Select(e => e.Extension
.Extension)
.ToList()
})
.OrderBy(p => p.CompanyName)
.ThenBy(p => p.Name)
.ToListAsync();
public Task<List<ProcessorDto>> GetAsync() => context.Processors.Select(p => new ProcessorDto
{
Name = p.Name,
CompanyName = p.Company.Name,
CompanyId = p.Company.Id,
ModelCode = p.ModelCode,
Introduced = p.Introduced,
Speed = p.Speed,
Package = p.Package,
Gprs = p.Gprs,
GprSize = p.GprSize,
Fprs = p.Fprs,
FprSize = p.FprSize,
Cores = p.Cores,
ThreadsPerCore = p.ThreadsPerCore,
Process = p.Process,
ProcessNm = p.ProcessNm,
DieSize = p.DieSize,
Transistors = p.Transistors,
DataBus = p.DataBus,
AddrBus = p.AddrBus,
SimdRegisters = p.SimdRegisters,
SimdSize = p.SimdSize,
L1Instruction = p.L1Instruction,
L1Data = p.L1Data,
L2 = p.L2,
L3 = p.L3,
InstructionSet = p.InstructionSet.Name,
Id = p.Id,
InstructionSetExtensions = p.InstructionSetExtensions
.Select(e => e.Extension.Extension)
.ToList()
})
.OrderBy(p => p.CompanyName)
.ThenBy(p => p.Name)
.ToListAsync();
[HttpGet]
[AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<List<ProcessorDto>> GetByMachineAsync(int machineId) => await context.ProcessorsByMachine
public Task<List<ProcessorDto>> GetByMachineAsync(int machineId) => context.ProcessorsByMachine
.Where(p => p.MachineId == machineId)
.Select(p => new ProcessorDto
{
Name = p.Processor.Name,
CompanyName = p.Processor.Company.Name,
CompanyId = p.Processor.Company.Id,
ModelCode = p.Processor.ModelCode,
Introduced = p.Processor.Introduced,
Speed = p.Speed,
Package = p.Processor.Package,
Gprs = p.Processor.Gprs,
GprSize = p.Processor.GprSize,
Fprs = p.Processor.Fprs,
FprSize = p.Processor.FprSize,
Cores = p.Processor.Cores,
ThreadsPerCore = p.Processor.ThreadsPerCore,
Process = p.Processor.Process,
ProcessNm = p.Processor.ProcessNm,
DieSize = p.Processor.DieSize,
Transistors = p.Processor.Transistors,
DataBus = p.Processor.DataBus,
AddrBus = p.Processor.AddrBus,
SimdRegisters = p.Processor.SimdRegisters,
SimdSize = p.Processor.SimdSize,
L1Instruction = p.Processor.L1Instruction,
L1Data = p.Processor.L1Data,
L2 = p.Processor.L2,
L3 = p.Processor.L3,
InstructionSet = p.Processor.InstructionSet.Name,
Id = p.Processor.Id,
InstructionSetExtensions =
p.Processor.InstructionSetExtensions.Select(e => e.Extension.Extension).ToList()
Name = p.Processor.Name,
CompanyName = p.Processor.Company.Name,
CompanyId = p.Processor.Company.Id,
ModelCode = p.Processor.ModelCode,
Introduced = p.Processor.Introduced,
Speed = p.Speed,
Package = p.Processor.Package,
Gprs = p.Processor.Gprs,
GprSize = p.Processor.GprSize,
Fprs = p.Processor.Fprs,
FprSize = p.Processor.FprSize,
Cores = p.Processor.Cores,
ThreadsPerCore = p.Processor.ThreadsPerCore,
Process = p.Processor.Process,
ProcessNm = p.Processor.ProcessNm,
DieSize = p.Processor.DieSize,
Transistors = p.Processor.Transistors,
DataBus = p.Processor.DataBus,
AddrBus = p.Processor.AddrBus,
SimdRegisters = p.Processor.SimdRegisters,
SimdSize = p.Processor.SimdSize,
L1Instruction = p.Processor.L1Instruction,
L1Data = p.Processor.L1Data,
L2 = p.Processor.L2,
L3 = p.Processor.L3,
InstructionSet = p.Processor.InstructionSet.Name,
Id = p.Processor.Id,
InstructionSetExtensions = p.Processor.InstructionSetExtensions.Select(e => e.Extension.Extension).ToList()
})
.OrderBy(p => p.CompanyName)
.ThenBy(p => p.Name)
@@ -132,39 +126,38 @@ public class ProcessorsController(MarechaiContext context) : ControllerBase
[AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<ProcessorDto> GetAsync(int id) => await context.Processors.Where(p => p.Id == id)
.Select(p => new ProcessorDto
{
Name = p.Name,
CompanyName = p.Company.Name,
CompanyId = p.Company.Id,
ModelCode = p.ModelCode,
Introduced = p.Introduced,
Speed = p.Speed,
Package = p.Package,
Gprs = p.Gprs,
GprSize = p.GprSize,
Fprs = p.Fprs,
FprSize = p.FprSize,
Cores = p.Cores,
ThreadsPerCore = p.ThreadsPerCore,
Process = p.Process,
ProcessNm = p.ProcessNm,
DieSize = p.DieSize,
Transistors = p.Transistors,
DataBus = p.DataBus,
AddrBus = p.AddrBus,
SimdRegisters = p.SimdRegisters,
SimdSize = p.SimdSize,
L1Instruction = p.L1Instruction,
L1Data = p.L1Data,
L2 = p.L2,
L3 = p.L3,
InstructionSet =
p.InstructionSet.Name,
InstructionSetId = p.InstructionSetId
})
.FirstOrDefaultAsync();
public Task<ProcessorDto> GetAsync(int id) => context.Processors.Where(p => p.Id == id)
.Select(p => new ProcessorDto
{
Name = p.Name,
CompanyName = p.Company.Name,
CompanyId = p.Company.Id,
ModelCode = p.ModelCode,
Introduced = p.Introduced,
Speed = p.Speed,
Package = p.Package,
Gprs = p.Gprs,
GprSize = p.GprSize,
Fprs = p.Fprs,
FprSize = p.FprSize,
Cores = p.Cores,
ThreadsPerCore = p.ThreadsPerCore,
Process = p.Process,
ProcessNm = p.ProcessNm,
DieSize = p.DieSize,
Transistors = p.Transistors,
DataBus = p.DataBus,
AddrBus = p.AddrBus,
SimdRegisters = p.SimdRegisters,
SimdSize = p.SimdSize,
L1Instruction = p.L1Instruction,
L1Data = p.L1Data,
L2 = p.L2,
L3 = p.L3,
InstructionSet = p.InstructionSet.Name,
InstructionSetId = p.InstructionSetId
})
.FirstOrDefaultAsync();
[HttpPost]
[Authorize(Roles = "Admin,UberAdmin")]
@@ -173,6 +166,7 @@ public class ProcessorsController(MarechaiContext context) : ControllerBase
public async Task UpdateAsync(ProcessorDto dto)
{
string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return;
Processor model = await context.Processors.FindAsync(dto.Id);
@@ -214,7 +208,9 @@ public class ProcessorsController(MarechaiContext context) : ControllerBase
public async Task<int> CreateAsync(ProcessorDto dto)
{
string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return 0;
var model = new Processor
{
AddrBus = dto.AddrBus,
@@ -257,6 +253,7 @@ public class ProcessorsController(MarechaiContext context) : ControllerBase
public async Task DeleteAsync(int id)
{
string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return;
Processor item = await context.Processors.FindAsync(id);
@@ -266,4 +263,4 @@ public class ProcessorsController(MarechaiContext context) : ControllerBase
await context.SaveChangesWithUserAsync(userId);
}
}
}

View File

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

View File

@@ -23,7 +23,6 @@
// Copyright © 2003-2025 Natalia Portillo
*******************************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
@@ -34,7 +33,6 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Localization;
namespace Marechai.Server.Controllers;
@@ -46,35 +44,35 @@ public class ScreensByMachineController(MarechaiContext context) : ControllerBas
[AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<List<ScreenByMachineDto>> GetByMachine(int machineId) => await context.ScreensByMachine
.Where(s => s.MachineId == machineId)
.Select(s => new ScreenByMachineDto
{
Id = s.Id,
ScreenId = s.ScreenId,
MachineId = s.MachineId,
Screen = new ScreenDto
{
Diagonal = s.Screen.Diagonal,
EffectiveColors = s.Screen.EffectiveColors,
Height = s.Screen.Height,
Id = s.Screen.Id,
NativeResolution = new ResolutionDto
{
Chars = s.Screen.NativeResolution.Chars,
Colors = s.Screen.NativeResolution.Colors,
Grayscale = s.Screen.NativeResolution.Grayscale,
Height = s.Screen.NativeResolution.Height,
Id = s.Screen.NativeResolutionId,
Palette = s.Screen.NativeResolution.Palette,
Width = s.Screen.NativeResolution.Width
},
NativeResolutionId = s.Screen.NativeResolutionId,
Type = s.Screen.Type,
Width = s.Screen.Width
}
})
.ToListAsync();
public Task<List<ScreenByMachineDto>> GetByMachine(int machineId) => context.ScreensByMachine
.Where(s => s.MachineId == machineId)
.Select(s => new ScreenByMachineDto
{
Id = s.Id,
ScreenId = s.ScreenId,
MachineId = s.MachineId,
Screen = new ScreenDto
{
Diagonal = s.Screen.Diagonal,
EffectiveColors = s.Screen.EffectiveColors,
Height = s.Screen.Height,
Id = s.Screen.Id,
NativeResolution = new ResolutionDto
{
Chars = s.Screen.NativeResolution.Chars,
Colors = s.Screen.NativeResolution.Colors,
Grayscale = s.Screen.NativeResolution.Grayscale,
Height = s.Screen.NativeResolution.Height,
Id = s.Screen.NativeResolutionId,
Palette = s.Screen.NativeResolution.Palette,
Width = s.Screen.NativeResolution.Width
},
NativeResolutionId = s.Screen.NativeResolutionId,
Type = s.Screen.Type,
Width = s.Screen.Width
}
})
.ToListAsync();
[HttpDelete]
[Authorize(Roles = "Admin,UberAdmin")]
@@ -83,6 +81,7 @@ public class ScreensByMachineController(MarechaiContext context) : ControllerBas
public async Task DeleteAsync(long id)
{
string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return;
ScreensByMachine item = await context.ScreensByMachine.FindAsync(id);
@@ -100,6 +99,7 @@ public class ScreensByMachineController(MarechaiContext context) : ControllerBas
public async Task<long> CreateAsync(int machineId, int screenId)
{
string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return 0;
if(context.ScreensByMachine.Any(s => s.MachineId == machineId && s.ScreenId == screenId)) return 0;
@@ -114,4 +114,4 @@ public class ScreensByMachineController(MarechaiContext context) : ControllerBas
return item.Id;
}
}
}

View File

@@ -23,7 +23,6 @@
// Copyright © 2003-2025 Natalia Portillo
*******************************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
@@ -34,7 +33,6 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Localization;
namespace Marechai.Server.Controllers;
@@ -47,69 +45,58 @@ public class ScreensController(MarechaiContext context) : ControllerBase
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<List<ScreenDto>> GetAsync() => (await context.Screens.Select(s => new ScreenDto
{
Diagonal = s.Diagonal,
EffectiveColors = s.EffectiveColors,
Height = s.Height,
Id = s.Id,
Type = s.Type,
Width = s.Width,
NativeResolutionId =
s.NativeResolutionId,
NativeResolution =
new ResolutionDto
{
Chars = s.NativeResolution
.Chars,
Colors = s.NativeResolution
.Colors,
Grayscale = s.NativeResolution
.Grayscale,
Height = s.NativeResolution
.Height,
Id =
s.NativeResolution.Id,
Palette = s.NativeResolution
.Palette,
Width = s.NativeResolution
.Width
}
})
.ToListAsync()).OrderBy(s => s.Diagonal)
.ThenBy(s => s.EffectiveColors)
.ThenBy(s => s.NativeResolution.ToString())
.ThenBy(s => s.Type)
.ThenBy(s => s.Size)
.ToList();
{
Diagonal = s.Diagonal,
EffectiveColors = s.EffectiveColors,
Height = s.Height,
Id = s.Id,
Type = s.Type,
Width = s.Width,
NativeResolutionId = s.NativeResolutionId,
NativeResolution = new ResolutionDto
{
Chars = s.NativeResolution.Chars,
Colors = s.NativeResolution.Colors,
Grayscale = s.NativeResolution.Grayscale,
Height = s.NativeResolution.Height,
Id = s.NativeResolution.Id,
Palette = s.NativeResolution.Palette,
Width = s.NativeResolution.Width
}
})
.ToListAsync()).OrderBy(s => s.Diagonal)
.ThenBy(s => s.EffectiveColors)
.ThenBy(s => s.NativeResolution.ToString())
.ThenBy(s => s.Type)
.ThenBy(s => s.Size)
.ToList();
[HttpGet]
[AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<ScreenDto> GetAsync(int id) => await context.Screens.Where(s => s.Id == id)
.Select(s => new ScreenDto
{
Diagonal = s.Diagonal,
EffectiveColors = s.EffectiveColors,
Height = s.Height,
Id = s.Id,
NativeResolution = new ResolutionDto
{
Chars = s.NativeResolution.Chars,
Colors = s.NativeResolution.Colors,
Grayscale = s.NativeResolution
.Grayscale,
Height = s.NativeResolution.Height,
Id = s.NativeResolution.Id,
Palette =
s.NativeResolution.Palette,
Width = s.NativeResolution.Width
},
NativeResolutionId = s.NativeResolutionId,
Type = s.Type,
Width = s.Width
})
.FirstOrDefaultAsync();
public Task<ScreenDto> GetAsync(int id) => context.Screens.Where(s => s.Id == id)
.Select(s => new ScreenDto
{
Diagonal = s.Diagonal,
EffectiveColors = s.EffectiveColors,
Height = s.Height,
Id = s.Id,
NativeResolution = new ResolutionDto
{
Chars = s.NativeResolution.Chars,
Colors = s.NativeResolution.Colors,
Grayscale = s.NativeResolution.Grayscale,
Height = s.NativeResolution.Height,
Id = s.NativeResolution.Id,
Palette = s.NativeResolution.Palette,
Width = s.NativeResolution.Width
},
NativeResolutionId = s.NativeResolutionId,
Type = s.Type,
Width = s.Width
})
.FirstOrDefaultAsync();
[HttpPost]
[Authorize(Roles = "Admin,UberAdmin")]
@@ -118,6 +105,7 @@ public class ScreensController(MarechaiContext context) : ControllerBase
public async Task UpdateAsync(ScreenDto dto)
{
string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return;
Screen model = await context.Screens.FindAsync(dto.Id);
@@ -144,7 +132,9 @@ public class ScreensController(MarechaiContext context) : ControllerBase
public async Task<int> CreateAsync(ScreenDto dto)
{
string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return 0;
var model = new Screen
{
Diagonal = dto.Diagonal,
@@ -168,6 +158,7 @@ public class ScreensController(MarechaiContext context) : ControllerBase
public async Task DeleteAsync(int id)
{
string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return;
Screen item = await context.Screens.FindAsync(id);
@@ -177,4 +168,4 @@ public class ScreensController(MarechaiContext context) : ControllerBase
await context.SaveChangesWithUserAsync(userId);
}
}
}

View File

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

View File

@@ -23,7 +23,6 @@
// Copyright © 2003-2025 Natalia Portillo
*******************************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
@@ -34,7 +33,6 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Localization;
namespace Marechai.Server.Controllers;
@@ -46,64 +44,62 @@ public class SoftwareVariantsController(MarechaiContext context) : ControllerBas
[AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<List<SoftwareVariantDto>> GetAsync() => await context.SoftwareVariants
.OrderBy(b => b.SoftwareVersion.Family.Name)
.ThenBy(b => b.SoftwareVersion.Version)
.ThenBy(b => b.Name)
.ThenBy(b => b.Version)
.ThenBy(b => b.Introduced)
.Select(b => new SoftwareVariantDto
{
Id = b.Id,
Name = b.Name,
Version = b.Version,
Introduced = b.Introduced,
ParentId = b.ParentId,
Parent = b.Parent.Name ?? b.Parent.Version,
SoftwareVersionId = b.SoftwareVersionId,
SoftwareVersion =
b.SoftwareVersion.Name ??
b.SoftwareVersion.Version,
MinimumMemory = b.MinimumMemory,
RecommendedMemory = b.RecommendedMemory,
RequiredStorage = b.RequiredStorage,
PartNumber = b.PartNumber,
SerialNumber = b.SerialNumber,
ProductCode = b.ProductCode,
CatalogueNumber = b.CatalogueNumber,
DistributionMode = b.DistributionMode
})
.ToListAsync();
public Task<List<SoftwareVariantDto>> GetAsync() => context.SoftwareVariants
.OrderBy(b => b.SoftwareVersion.Family.Name)
.ThenBy(b => b.SoftwareVersion.Version)
.ThenBy(b => b.Name)
.ThenBy(b => b.Version)
.ThenBy(b => b.Introduced)
.Select(b => new SoftwareVariantDto
{
Id = b.Id,
Name = b.Name,
Version = b.Version,
Introduced = b.Introduced,
ParentId = b.ParentId,
Parent = b.Parent.Name ?? b.Parent.Version,
SoftwareVersionId = b.SoftwareVersionId,
SoftwareVersion =
b.SoftwareVersion.Name ??
b.SoftwareVersion.Version,
MinimumMemory = b.MinimumMemory,
RecommendedMemory = b.RecommendedMemory,
RequiredStorage = b.RequiredStorage,
PartNumber = b.PartNumber,
SerialNumber = b.SerialNumber,
ProductCode = b.ProductCode,
CatalogueNumber = b.CatalogueNumber,
DistributionMode = b.DistributionMode
})
.ToListAsync();
[HttpGet]
[AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<SoftwareVariantDto> GetAsync(ulong id) => await context.SoftwareVariants
.Where(b => b.Id == id)
.Select(b => new SoftwareVariantDto
{
Id = b.Id,
Name = b.Name,
Version = b.Version,
Introduced = b.Introduced,
ParentId = b.ParentId,
Parent =
b.Parent.Name ?? b.Parent.Version,
SoftwareVersionId = b.SoftwareVersionId,
SoftwareVersion =
b.SoftwareVersion.Name ??
b.SoftwareVersion.Version,
MinimumMemory = b.MinimumMemory,
RecommendedMemory = b.RecommendedMemory,
RequiredStorage = b.RequiredStorage,
PartNumber = b.PartNumber,
SerialNumber = b.SerialNumber,
ProductCode = b.ProductCode,
CatalogueNumber = b.CatalogueNumber,
DistributionMode = b.DistributionMode
})
.FirstOrDefaultAsync();
public Task<SoftwareVariantDto> GetAsync(ulong id) => context.SoftwareVariants.Where(b => b.Id == id)
.Select(b => new SoftwareVariantDto
{
Id = b.Id,
Name = b.Name,
Version = b.Version,
Introduced = b.Introduced,
ParentId = b.ParentId,
Parent =
b.Parent.Name ?? b.Parent.Version,
SoftwareVersionId = b.SoftwareVersionId,
SoftwareVersion = b.SoftwareVersion.Name ??
b.SoftwareVersion.Version,
MinimumMemory = b.MinimumMemory,
RecommendedMemory = b.RecommendedMemory,
RequiredStorage = b.RequiredStorage,
PartNumber = b.PartNumber,
SerialNumber = b.SerialNumber,
ProductCode = b.ProductCode,
CatalogueNumber = b.CatalogueNumber,
DistributionMode = b.DistributionMode
})
.FirstOrDefaultAsync();
[HttpPost]
[Authorize(Roles = "Admin,UberAdmin")]
@@ -112,6 +108,7 @@ public class SoftwareVariantsController(MarechaiContext context) : ControllerBas
public async Task UpdateAsync(SoftwareVariantDto dto)
{
string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return;
SoftwareVariant model = await context.SoftwareVariants.FindAsync(dto.Id);
@@ -141,7 +138,9 @@ public class SoftwareVariantsController(MarechaiContext context) : ControllerBas
public async Task<ulong> CreateAsync(SoftwareVariantDto dto)
{
string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return null;
var model = new SoftwareVariant
{
Name = dto.Name,
@@ -172,6 +171,7 @@ public class SoftwareVariantsController(MarechaiContext context) : ControllerBas
public async Task DeleteAsync(ulong id)
{
string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return;
SoftwareVariant item = await context.SoftwareVariants.FindAsync(id);
@@ -181,4 +181,4 @@ public class SoftwareVariantsController(MarechaiContext context) : ControllerBas
await context.SaveChangesWithUserAsync(userId);
}
}
}

View File

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

View File

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

View File

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

View File

@@ -23,7 +23,6 @@
// Copyright © 2003-2025 Natalia Portillo
*******************************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
@@ -34,7 +33,6 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Localization;
namespace Marechai.Server.Controllers;
@@ -46,20 +44,20 @@ public class StorageByMachineController(MarechaiContext context) : ControllerBas
[AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<List<StorageByMachineDto>> GetByMachine(int machineId) => await context.StorageByMachine
.Where(s => s.MachineId == machineId)
.Select(s => new StorageByMachineDto
{
Id = s.Id,
Type = s.Type,
Interface = s.Interface,
Capacity = s.Capacity,
MachineId = s.MachineId
})
.OrderBy(s => s.Type)
.ThenBy(s => s.Interface)
.ThenBy(s => s.Capacity)
.ToListAsync();
public Task<List<StorageByMachineDto>> GetByMachine(int machineId) => context.StorageByMachine
.Where(s => s.MachineId == machineId)
.Select(s => new StorageByMachineDto
{
Id = s.Id,
Type = s.Type,
Interface = s.Interface,
Capacity = s.Capacity,
MachineId = s.MachineId
})
.OrderBy(s => s.Type)
.ThenBy(s => s.Interface)
.ThenBy(s => s.Capacity)
.ToListAsync();
[HttpDelete]
[Authorize(Roles = "Admin,UberAdmin")]
@@ -68,6 +66,7 @@ public class StorageByMachineController(MarechaiContext context) : ControllerBas
public async Task DeleteAsync(long id)
{
string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return;
StorageByMachine item = await context.StorageByMachine.FindAsync(id);
@@ -82,10 +81,12 @@ public class StorageByMachineController(MarechaiContext context) : ControllerBas
[Authorize(Roles = "Admin,UberAdmin")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<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);
if(userId is null) return 0;
var item = new StorageByMachine
{
MachineId = machineId,
@@ -99,4 +100,4 @@ public class StorageByMachineController(MarechaiContext context) : ControllerBas
return item.Id;
}
}
}