mirror of
https://github.com/claunia/marechai.git
synced 2025-12-16 19:14:25 +00:00
Refactor controller methods to return ActionResult for better error handling
This commit is contained in:
@@ -80,14 +80,14 @@ public class BookScansController(MarechaiContext context) : ControllerBase
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task UpdateAsync(BookScanDto dto)
|
||||
public async Task<ActionResult> UpdateAsync(BookScanDto dto)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return;
|
||||
if(userId is null) return Unauthorized();
|
||||
BookScan model = await context.BookScans.FindAsync(dto.Id);
|
||||
|
||||
if(model is null) return;
|
||||
if(model is null) return NotFound();
|
||||
|
||||
model.Author = dto.Author;
|
||||
model.ColorSpace = dto.ColorSpace;
|
||||
@@ -104,17 +104,19 @@ public class BookScansController(MarechaiContext context) : ControllerBase
|
||||
model.VerticalResolution = dto.VerticalResolution;
|
||||
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task<Guid> CreateAsync(BookScanDto dto)
|
||||
public async Task<ActionResult<Guid>> CreateAsync(BookScanDto dto)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return null;
|
||||
if(userId is null) return Unauthorized();
|
||||
|
||||
var model = new BookScan
|
||||
{
|
||||
@@ -148,17 +150,19 @@ public class BookScansController(MarechaiContext context) : ControllerBase
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task DeleteAsync(Guid id)
|
||||
public async Task<ActionResult> DeleteAsync(Guid id)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return;
|
||||
if(userId is null) return Unauthorized();
|
||||
BookScan item = await context.BookScans.FindAsync(id);
|
||||
|
||||
if(item is null) return;
|
||||
if(item is null) return NotFound();
|
||||
|
||||
context.BookScans.Remove(item);
|
||||
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
@@ -90,14 +90,14 @@ public class BooksController(MarechaiContext context) : ControllerBase
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task UpdateAsync(BookDto dto)
|
||||
public async Task<ActionResult> UpdateAsync(BookDto dto)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return;
|
||||
if(userId is null) return Unauthorized();
|
||||
Book model = await context.Books.FindAsync(dto.Id);
|
||||
|
||||
if(model is null) return;
|
||||
if(model is null) return NotFound();
|
||||
|
||||
model.Title = dto.Title;
|
||||
model.NativeTitle = dto.NativeTitle;
|
||||
@@ -110,6 +110,8 @@ public class BooksController(MarechaiContext context) : ControllerBase
|
||||
model.PreviousId = dto.PreviousId;
|
||||
model.SourceId = dto.SourceId;
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
@@ -153,17 +155,19 @@ public class BooksController(MarechaiContext context) : ControllerBase
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task DeleteAsync(long id)
|
||||
public async Task<ActionResult> DeleteAsync(long id)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return;
|
||||
if(userId is null) return Unauthorized();
|
||||
Book item = await context.Books.FindAsync(id);
|
||||
|
||||
if(item is null) return;
|
||||
if(item is null) return NotFound();
|
||||
|
||||
context.Books.Remove(item);
|
||||
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
@@ -63,29 +63,31 @@ public class CompaniesByBookController(MarechaiContext context) : ControllerBase
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task DeleteAsync(long id)
|
||||
public async Task<ActionResult> DeleteAsync(long id)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return;
|
||||
if(userId is null) return Unauthorized();
|
||||
CompaniesByBook item = await context.CompaniesByBooks.FindAsync(id);
|
||||
|
||||
if(item is null) return;
|
||||
if(item is null) return NotFound();
|
||||
|
||||
context.CompaniesByBooks.Remove(item);
|
||||
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task<long> CreateAsync(int companyId, long bookId, string roleId)
|
||||
public async Task<ActionResult<long>> CreateAsync(int companyId, long bookId, string roleId)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return 0;
|
||||
if(userId is null) return Unauthorized();
|
||||
|
||||
var item = new CompaniesByBook
|
||||
{
|
||||
|
||||
@@ -63,29 +63,31 @@ public class CompaniesByDocumentController(MarechaiContext context) : Controller
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task DeleteAsync(long id)
|
||||
public async Task<ActionResult> DeleteAsync(long id)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return;
|
||||
if(userId is null) return Unauthorized();
|
||||
CompaniesByDocument item = await context.CompaniesByDocuments.FindAsync(id);
|
||||
|
||||
if(item is null) return;
|
||||
if(item is null) return NotFound();
|
||||
|
||||
context.CompaniesByDocuments.Remove(item);
|
||||
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task<long> CreateAsync(int companyId, long documentId, string roleId)
|
||||
public async Task<ActionResult<long>> CreateAsync(int companyId, long documentId, string roleId)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return 0;
|
||||
if(userId is null) return Unauthorized();
|
||||
|
||||
var item = new CompaniesByDocument
|
||||
{
|
||||
|
||||
@@ -63,29 +63,31 @@ public class CompaniesByMagazineController(MarechaiContext context) : Controller
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task DeleteAsync(long id)
|
||||
public async Task<ActionResult> DeleteAsync(long id)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return;
|
||||
if(userId is null) return Unauthorized();
|
||||
CompaniesByMagazine item = await context.CompaniesByMagazines.FindAsync(id);
|
||||
|
||||
if(item is null) return;
|
||||
if(item is null) return NotFound();
|
||||
|
||||
context.CompaniesByMagazines.Remove(item);
|
||||
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task<long> CreateAsync(int companyId, long magazineId, string roleId)
|
||||
public async Task<ActionResult<long>> CreateAsync(int companyId, long magazineId, string roleId)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return 0;
|
||||
if(userId is null) return Unauthorized();
|
||||
|
||||
var item = new CompaniesByMagazine
|
||||
{
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
// Copyright © 2003-2025 Natalia Portillo
|
||||
*******************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Claims;
|
||||
@@ -34,7 +33,6 @@ using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Localization;
|
||||
|
||||
namespace Marechai.Server.Controllers;
|
||||
|
||||
@@ -46,46 +44,51 @@ public class CompaniesBySoftwareFamilyController(MarechaiContext context) : Cont
|
||||
[AllowAnonymous]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task<List<CompanyBySoftwareFamilyDto>> GetBySoftwareFamily(ulong softwareFamilyId) =>
|
||||
await context.CompaniesBySoftwareFamilies.Where(p => p.SoftwareFamilyId == softwareFamilyId)
|
||||
.Select(p => new CompanyBySoftwareFamilyDto
|
||||
{
|
||||
Id = p.Id,
|
||||
Company = p.Company.Name,
|
||||
CompanyId = p.CompanyId,
|
||||
RoleId = p.RoleId,
|
||||
Role = p.Role.Name,
|
||||
SoftwareFamilyId = p.SoftwareFamilyId
|
||||
})
|
||||
.OrderBy(p => p.Company)
|
||||
.ThenBy(p => p.Role)
|
||||
.ToListAsync();
|
||||
public async Task<List<CompanyBySoftwareFamilyDto>> GetBySoftwareFamily(ulong softwareFamilyId) => await context
|
||||
.CompaniesBySoftwareFamilies.Where(p => p.SoftwareFamilyId == softwareFamilyId)
|
||||
.Select(p => new CompanyBySoftwareFamilyDto
|
||||
{
|
||||
Id = p.Id,
|
||||
Company = p.Company.Name,
|
||||
CompanyId = p.CompanyId,
|
||||
RoleId = p.RoleId,
|
||||
Role = p.Role.Name,
|
||||
SoftwareFamilyId = p.SoftwareFamilyId
|
||||
})
|
||||
.OrderBy(p => p.Company)
|
||||
.ThenBy(p => p.Role)
|
||||
.ToListAsync();
|
||||
|
||||
[HttpDelete]
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task DeleteAsync(ulong id)
|
||||
public async Task<ActionResult> DeleteAsync(ulong id)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
if(userId is null) return;
|
||||
|
||||
if(userId is null) return Unauthorized();
|
||||
CompaniesBySoftwareFamily item = await context.CompaniesBySoftwareFamilies.FindAsync(id);
|
||||
|
||||
if(item is null) return;
|
||||
if(item is null) return NotFound();
|
||||
|
||||
context.CompaniesBySoftwareFamilies.Remove(item);
|
||||
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task<ulong> CreateAsync(int companyId, ulong softwareFamilyId, string roleId)
|
||||
public async Task<ActionResult<ulong>> CreateAsync(int companyId, ulong softwareFamilyId, string roleId)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
if(userId is null) return null;
|
||||
|
||||
if(userId is null) return Unauthorized();
|
||||
|
||||
var item = new CompaniesBySoftwareFamily
|
||||
{
|
||||
CompanyId = companyId,
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
// Copyright © 2003-2025 Natalia Portillo
|
||||
*******************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Claims;
|
||||
@@ -34,7 +33,6 @@ using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Localization;
|
||||
|
||||
namespace Marechai.Server.Controllers;
|
||||
|
||||
@@ -46,46 +44,51 @@ public class CompaniesBySoftwareVariantController(MarechaiContext context) : Con
|
||||
[AllowAnonymous]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task<List<CompanyBySoftwareVariantDto>> GetBySoftwareVariant(ulong softwareVariantId) =>
|
||||
await context.CompaniesBySoftwareVariants.Where(p => p.SoftwareVariantId == softwareVariantId)
|
||||
.Select(p => new CompanyBySoftwareVariantDto
|
||||
{
|
||||
Id = p.Id,
|
||||
Company = p.Company.Name,
|
||||
CompanyId = p.CompanyId,
|
||||
RoleId = p.RoleId,
|
||||
Role = p.Role.Name,
|
||||
SoftwareVariantId = p.SoftwareVariantId
|
||||
})
|
||||
.OrderBy(p => p.Company)
|
||||
.ThenBy(p => p.Role)
|
||||
.ToListAsync();
|
||||
public async Task<List<CompanyBySoftwareVariantDto>> GetBySoftwareVariant(ulong softwareVariantId) => await context
|
||||
.CompaniesBySoftwareVariants.Where(p => p.SoftwareVariantId == softwareVariantId)
|
||||
.Select(p => new CompanyBySoftwareVariantDto
|
||||
{
|
||||
Id = p.Id,
|
||||
Company = p.Company.Name,
|
||||
CompanyId = p.CompanyId,
|
||||
RoleId = p.RoleId,
|
||||
Role = p.Role.Name,
|
||||
SoftwareVariantId = p.SoftwareVariantId
|
||||
})
|
||||
.OrderBy(p => p.Company)
|
||||
.ThenBy(p => p.Role)
|
||||
.ToListAsync();
|
||||
|
||||
[HttpDelete]
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task DeleteAsync(ulong id)
|
||||
public async Task<ActionResult> DeleteAsync(ulong id)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
if(userId is null) return;
|
||||
|
||||
if(userId is null) return Unauthorized();
|
||||
CompaniesBySoftwareVariant item = await context.CompaniesBySoftwareVariants.FindAsync(id);
|
||||
|
||||
if(item is null) return;
|
||||
if(item is null) return NotFound();
|
||||
|
||||
context.CompaniesBySoftwareVariants.Remove(item);
|
||||
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task<ulong> CreateAsync(int companyId, ulong softwareVariantId, string roleId)
|
||||
public async Task<ActionResult<ulong>> CreateAsync(int companyId, ulong softwareVariantId, string roleId)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
if(userId is null) return null;
|
||||
|
||||
if(userId is null) return Unauthorized();
|
||||
|
||||
var item = new CompaniesBySoftwareVariant
|
||||
{
|
||||
CompanyId = companyId,
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
// Copyright © 2003-2025 Natalia Portillo
|
||||
*******************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Claims;
|
||||
@@ -34,7 +33,6 @@ using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Localization;
|
||||
|
||||
namespace Marechai.Server.Controllers;
|
||||
|
||||
@@ -46,46 +44,51 @@ public class CompaniesBySoftwareVersionController(MarechaiContext context) : Con
|
||||
[AllowAnonymous]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task<List<CompanyBySoftwareVersionDto>> GetBySoftwareVersion(ulong softwareVersionId) =>
|
||||
await context.CompaniesBySoftwareVersions.Where(p => p.SoftwareVersionId == softwareVersionId)
|
||||
.Select(p => new CompanyBySoftwareVersionDto
|
||||
{
|
||||
Id = p.Id,
|
||||
Company = p.Company.Name,
|
||||
CompanyId = p.CompanyId,
|
||||
RoleId = p.RoleId,
|
||||
Role = p.Role.Name,
|
||||
SoftwareVersionId = p.SoftwareVersionId
|
||||
})
|
||||
.OrderBy(p => p.Company)
|
||||
.ThenBy(p => p.Role)
|
||||
.ToListAsync();
|
||||
public async Task<List<CompanyBySoftwareVersionDto>> GetBySoftwareVersion(ulong softwareVersionId) => await context
|
||||
.CompaniesBySoftwareVersions.Where(p => p.SoftwareVersionId == softwareVersionId)
|
||||
.Select(p => new CompanyBySoftwareVersionDto
|
||||
{
|
||||
Id = p.Id,
|
||||
Company = p.Company.Name,
|
||||
CompanyId = p.CompanyId,
|
||||
RoleId = p.RoleId,
|
||||
Role = p.Role.Name,
|
||||
SoftwareVersionId = p.SoftwareVersionId
|
||||
})
|
||||
.OrderBy(p => p.Company)
|
||||
.ThenBy(p => p.Role)
|
||||
.ToListAsync();
|
||||
|
||||
[HttpDelete]
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task DeleteAsync(ulong id)
|
||||
public async Task<ActionResult> DeleteAsync(ulong id)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
if(userId is null) return;
|
||||
|
||||
if(userId is null) return Unauthorized();
|
||||
CompaniesBySoftwareVersion item = await context.CompaniesBySoftwareVersions.FindAsync(id);
|
||||
|
||||
if(item is null) return;
|
||||
if(item is null) return NotFound();
|
||||
|
||||
context.CompaniesBySoftwareVersions.Remove(item);
|
||||
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task<ulong> CreateAsync(int companyId, ulong softwareVersionId, string roleId)
|
||||
public async Task<ActionResult<ulong>> CreateAsync(int companyId, ulong softwareVersionId, string roleId)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
if(userId is null) return null;
|
||||
|
||||
if(userId is null) return Unauthorized();
|
||||
|
||||
var item = new CompaniesBySoftwareVersion
|
||||
{
|
||||
CompanyId = companyId,
|
||||
|
||||
@@ -33,7 +33,6 @@ using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Localization;
|
||||
|
||||
namespace Marechai.Server.Controllers;
|
||||
|
||||
@@ -114,14 +113,14 @@ public class CompaniesController(MarechaiContext context) : ControllerBase
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task UpdateAsync(CompanyDto dto)
|
||||
public async Task<ActionResult> UpdateAsync(CompanyDto dto)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return;
|
||||
if(userId is null) return Unauthorized();
|
||||
Company model = await context.Companies.FindAsync(dto.Id);
|
||||
|
||||
if(model is null) return;
|
||||
if(model is null) return NotFound();
|
||||
|
||||
model.Name = dto.Name;
|
||||
model.Founded = dto.Founded;
|
||||
@@ -142,17 +141,19 @@ public class CompaniesController(MarechaiContext context) : ControllerBase
|
||||
model.SoldMonthIsUnknown = dto.SoldMonthIsUnknown;
|
||||
model.LegalName = dto.LegalName;
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task<int> CreateAsync(CompanyDto dto)
|
||||
public async Task<ActionResult<int>> CreateAsync(CompanyDto dto)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return 0;
|
||||
if(userId is null) return Unauthorized();
|
||||
|
||||
var model = new Company
|
||||
{
|
||||
@@ -259,18 +260,20 @@ public class CompaniesController(MarechaiContext context) : ControllerBase
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task DeleteAsync(int id)
|
||||
public async Task<ActionResult> DeleteAsync(int id)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return;
|
||||
if(userId is null) return Unauthorized();
|
||||
Company item = await context.Companies.FindAsync(id);
|
||||
|
||||
if(item is null) return;
|
||||
if(item is null) return NotFound();
|
||||
|
||||
context.Companies.Remove(item);
|
||||
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
@@ -292,11 +295,11 @@ public class CompaniesController(MarechaiContext context) : ControllerBase
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task<int> CreateOrUpdateDescriptionAsync(int id, CompanyDescriptionDto description)
|
||||
public async Task<ActionResult<int>> CreateOrUpdateDescriptionAsync(int id, CompanyDescriptionDto description)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return 0;
|
||||
if(userId is null) return Unauthorized();
|
||||
CompanyDescription current = await context.CompanyDescriptions.FirstOrDefaultAsync(d => d.CompanyId == id);
|
||||
|
||||
if(current is null)
|
||||
|
||||
@@ -25,16 +25,16 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Security.Claims;
|
||||
using System.Threading.Tasks;
|
||||
using Marechai.Data.Dtos;
|
||||
using Marechai.Database.Models;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Localization;
|
||||
|
||||
namespace Marechai.Server.Controllers;
|
||||
|
||||
@@ -53,18 +53,19 @@ public class CompanyLogosController(MarechaiContext context, IWebHostEnvironment
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task DeleteAsync(int id)
|
||||
public async Task<ActionResult> DeleteAsync(int id)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
if(userId is null) return;
|
||||
|
||||
if(userId is null) return Unauthorized();
|
||||
CompanyLogo logo = await context.CompanyLogos.Where(l => l.Id == id).FirstOrDefaultAsync();
|
||||
|
||||
if(logo is null) return;
|
||||
if(logo is null) return NotFound();
|
||||
|
||||
context.CompanyLogos.Remove(logo);
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
if(File.Exists(Path.Combine(_webRootPath, "assets/logos", logo.Guid + ".svg")))
|
||||
if(System.IO.File.Exists(Path.Combine(_webRootPath, "assets/logos", logo.Guid + ".svg")))
|
||||
File.Delete(Path.Combine(_webRootPath, "assets/logos", logo.Guid + ".svg"));
|
||||
|
||||
if(File.Exists(Path.Combine(_webRootPath, "assets/logos/webp/1x", logo.Guid + ".webp")))
|
||||
@@ -108,26 +109,31 @@ public class CompanyLogosController(MarechaiContext context, IWebHostEnvironment
|
||||
[AllowAnonymous]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task ChangeYearAsync(int id, int? year)
|
||||
public async Task<ActionResult> ChangeYearAsync(int id, int? year)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
if(userId is null) return;
|
||||
|
||||
if(userId is null) return Unauthorized();
|
||||
CompanyLogo logo = await context.CompanyLogos.Where(l => l.Id == id).FirstOrDefaultAsync();
|
||||
|
||||
if(logo is null) return;
|
||||
if(logo is null) return NotFound();
|
||||
|
||||
logo.Year = year;
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task<int> CreateAsync(int companyId, Guid guid, int? year)
|
||||
public async Task<ActionResult<int>> CreateAsync(int companyId, Guid guid, int? year)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
if(userId is null) return 0;
|
||||
|
||||
if(userId is null) return Unauthorized();
|
||||
|
||||
var logo = new CompanyLogo
|
||||
{
|
||||
Guid = guid,
|
||||
|
||||
@@ -24,8 +24,10 @@
|
||||
*******************************************************************************/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Marechai.Data.Dtos;
|
||||
using Marechai.Database;
|
||||
using Marechai.Database.Models;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
||||
@@ -24,8 +24,10 @@
|
||||
*******************************************************************************/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Marechai.Data.Dtos;
|
||||
using Marechai.Database;
|
||||
using Marechai.Database.Models;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
||||
@@ -75,30 +75,32 @@ public class CurrencyInflationController(MarechaiContext context) : ControllerBa
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task UpdateAsync(CurrencyInflationDto dto)
|
||||
public async Task<ActionResult> UpdateAsync(CurrencyInflationDto dto)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return;
|
||||
if(userId is null) return Unauthorized();
|
||||
CurrencyInflation model = await context.CurrenciesInflation.FindAsync(dto.Id);
|
||||
|
||||
if(model is null) return;
|
||||
if(model is null) return NotFound();
|
||||
|
||||
model.CurrencyCode = dto.CurrencyCode;
|
||||
model.Year = dto.Year;
|
||||
model.Inflation = dto.Inflation;
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task<int> CreateAsync(CurrencyInflationDto dto)
|
||||
public async Task<ActionResult<int>> CreateAsync(CurrencyInflationDto dto)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return 0;
|
||||
if(userId is null) return Unauthorized();
|
||||
|
||||
var model = new CurrencyInflation
|
||||
{
|
||||
@@ -117,17 +119,19 @@ public class CurrencyInflationController(MarechaiContext context) : ControllerBa
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task DeleteAsync(int id)
|
||||
public async Task<ActionResult> DeleteAsync(int id)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return;
|
||||
if(userId is null) return Unauthorized();
|
||||
CurrencyInflation item = await context.CurrenciesInflation.FindAsync(id);
|
||||
|
||||
if(item is null) return;
|
||||
if(item is null) return NotFound();
|
||||
|
||||
context.CurrenciesInflation.Remove(item);
|
||||
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
@@ -83,14 +83,14 @@ public class CurrencyPeggingController(MarechaiContext context) : ControllerBase
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task UpdateAsync(CurrencyPeggingDto dto)
|
||||
public async Task<ActionResult> UpdateAsync(CurrencyPeggingDto dto)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return;
|
||||
if(userId is null) return Unauthorized();
|
||||
CurrencyPegging model = await context.CurrenciesPegging.FindAsync(dto.Id);
|
||||
|
||||
if(model is null) return;
|
||||
if(model is null) return NotFound();
|
||||
|
||||
model.SourceCode = dto.SourceCode;
|
||||
model.DestinationCode = dto.DestinationCode;
|
||||
@@ -98,17 +98,19 @@ public class CurrencyPeggingController(MarechaiContext context) : ControllerBase
|
||||
model.Start = dto.Start;
|
||||
model.End = dto.End;
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task<int> CreateAsync(CurrencyPeggingDto dto)
|
||||
public async Task<ActionResult<int>> CreateAsync(CurrencyPeggingDto dto)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return 0;
|
||||
if(userId is null) return Unauthorized();
|
||||
|
||||
var model = new CurrencyPegging
|
||||
{
|
||||
@@ -129,17 +131,19 @@ public class CurrencyPeggingController(MarechaiContext context) : ControllerBase
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task DeleteAsync(int id)
|
||||
public async Task<ActionResult> DeleteAsync(int id)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return;
|
||||
if(userId is null) return Unauthorized();
|
||||
CurrencyPegging item = await context.CurrenciesPegging.FindAsync(id);
|
||||
|
||||
if(item is null) return;
|
||||
if(item is null) return NotFound();
|
||||
|
||||
context.CurrenciesPegging.Remove(item);
|
||||
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
@@ -71,30 +71,32 @@ public class DocumentCompaniesController(MarechaiContext context) : ControllerBa
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task UpdateAsync(DocumentCompanyDto dto)
|
||||
public async Task<ActionResult> UpdateAsync(DocumentCompanyDto dto)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return;
|
||||
if(userId is null) return Unauthorized();
|
||||
DocumentCompany model = await context.DocumentCompanies.FindAsync(dto.Id);
|
||||
|
||||
if(model is null) return;
|
||||
if(model is null) return NotFound();
|
||||
|
||||
model.CompanyId = dto.CompanyId;
|
||||
model.Name = dto.Name;
|
||||
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task<int> CreateAsync(DocumentCompanyDto dto)
|
||||
public async Task<ActionResult<int>> CreateAsync(DocumentCompanyDto dto)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return 0;
|
||||
if(userId is null) return Unauthorized();
|
||||
|
||||
var model = new DocumentCompany
|
||||
{
|
||||
@@ -112,17 +114,19 @@ public class DocumentCompaniesController(MarechaiContext context) : ControllerBa
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task DeleteAsync(int id)
|
||||
public async Task<ActionResult> DeleteAsync(int id)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return;
|
||||
if(userId is null) return Unauthorized();
|
||||
DocumentCompany item = await context.DocumentCompanies.FindAsync(id);
|
||||
|
||||
if(item is null) return;
|
||||
if(item is null) return NotFound();
|
||||
|
||||
context.DocumentCompanies.Remove(item);
|
||||
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
@@ -77,14 +77,14 @@ public class DocumentPeopleController(MarechaiContext context) : ControllerBase
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task UpdateAsync(DocumentPersonDto dto)
|
||||
public async Task<ActionResult> UpdateAsync(DocumentPersonDto dto)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return;
|
||||
if(userId is null) return Unauthorized();
|
||||
DocumentPerson model = await context.DocumentPeople.FindAsync(dto.Id);
|
||||
|
||||
if(model is null) return;
|
||||
if(model is null) return NotFound();
|
||||
|
||||
model.Alias = dto.Alias;
|
||||
model.Name = dto.Name;
|
||||
@@ -93,17 +93,19 @@ public class DocumentPeopleController(MarechaiContext context) : ControllerBase
|
||||
model.PersonId = dto.PersonId;
|
||||
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task<int> CreateAsync(DocumentPersonDto dto)
|
||||
public async Task<ActionResult<int>> CreateAsync(DocumentPersonDto dto)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return 0;
|
||||
if(userId is null) return Unauthorized();
|
||||
|
||||
var model = new DocumentPerson
|
||||
{
|
||||
@@ -124,17 +126,19 @@ public class DocumentPeopleController(MarechaiContext context) : ControllerBase
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task DeleteAsync(int id)
|
||||
public async Task<ActionResult> DeleteAsync(int id)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return;
|
||||
if(userId is null) return Unauthorized();
|
||||
DocumentPerson item = await context.DocumentPeople.FindAsync(id);
|
||||
|
||||
if(item is null) return;
|
||||
if(item is null) return NotFound();
|
||||
|
||||
context.DocumentPeople.Remove(item);
|
||||
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
@@ -80,14 +80,14 @@ public class DocumentScansController(MarechaiContext context) : ControllerBase
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task UpdateAsync(DocumentScanDto dto)
|
||||
public async Task<ActionResult> UpdateAsync(DocumentScanDto dto)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return;
|
||||
if(userId is null) return Unauthorized();
|
||||
DocumentScan model = await context.DocumentScans.FindAsync(dto.Id);
|
||||
|
||||
if(model is null) return;
|
||||
if(model is null) return NotFound();
|
||||
|
||||
model.Author = dto.Author;
|
||||
model.ColorSpace = dto.ColorSpace;
|
||||
@@ -104,17 +104,19 @@ public class DocumentScansController(MarechaiContext context) : ControllerBase
|
||||
model.VerticalResolution = dto.VerticalResolution;
|
||||
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task<Guid> CreateAsync(DocumentScanDto dto)
|
||||
public async Task<ActionResult<Guid>> CreateAsync(DocumentScanDto dto)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return null;
|
||||
if(userId is null) return Unauthorized();
|
||||
|
||||
var model = new DocumentScan
|
||||
{
|
||||
@@ -148,17 +150,19 @@ public class DocumentScansController(MarechaiContext context) : ControllerBase
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task DeleteAsync(Guid id)
|
||||
public async Task<ActionResult> DeleteAsync(Guid id)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return;
|
||||
if(userId is null) return Unauthorized();
|
||||
DocumentScan item = await context.DocumentScans.FindAsync(id);
|
||||
|
||||
if(item is null) return;
|
||||
if(item is null) return NotFound();
|
||||
|
||||
context.DocumentScans.Remove(item);
|
||||
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
@@ -60,29 +60,31 @@ public class DocumentsByMachineController(MarechaiContext context) : ControllerB
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task DeleteAsync(long id)
|
||||
public async Task<ActionResult> DeleteAsync(long id)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return;
|
||||
if(userId is null) return Unauthorized();
|
||||
DocumentsByMachine item = await context.DocumentsByMachines.FindAsync(id);
|
||||
|
||||
if(item is null) return;
|
||||
if(item is null) return NotFound();
|
||||
|
||||
context.DocumentsByMachines.Remove(item);
|
||||
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task<long> CreateAsync(int machineId, long bookId)
|
||||
public async Task<ActionResult<long>> CreateAsync(int machineId, long bookId)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return 0;
|
||||
if(userId is null) return Unauthorized();
|
||||
|
||||
var item = new DocumentsByMachine
|
||||
{
|
||||
|
||||
@@ -60,29 +60,31 @@ public class DocumentsByMachineFamilyController(MarechaiContext context) : Contr
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task DeleteAsync(long id)
|
||||
public async Task<ActionResult> DeleteAsync(long id)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return;
|
||||
if(userId is null) return Unauthorized();
|
||||
DocumentsByMachineFamily item = await context.DocumentsByMachineFamilies.FindAsync(id);
|
||||
|
||||
if(item is null) return;
|
||||
if(item is null) return NotFound();
|
||||
|
||||
context.DocumentsByMachineFamilies.Remove(item);
|
||||
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task<long> CreateAsync(int machineFamilyId, long bookId)
|
||||
public async Task<ActionResult<long>> CreateAsync(int machineFamilyId, long bookId)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return 0;
|
||||
if(userId is null) return Unauthorized();
|
||||
|
||||
var item = new DocumentsByMachineFamily
|
||||
{
|
||||
|
||||
@@ -80,14 +80,14 @@ public class DocumentsController(MarechaiContext context) : ControllerBase
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task UpdateAsync(DocumentDto dto)
|
||||
public async Task<ActionResult> UpdateAsync(DocumentDto dto)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return;
|
||||
if(userId is null) return Unauthorized();
|
||||
Document model = await context.Documents.FindAsync(dto.Id);
|
||||
|
||||
if(model is null) return;
|
||||
if(model is null) return NotFound();
|
||||
|
||||
model.Title = dto.Title;
|
||||
model.NativeTitle = dto.NativeTitle;
|
||||
@@ -95,17 +95,19 @@ public class DocumentsController(MarechaiContext context) : ControllerBase
|
||||
model.Synopsis = dto.Synopsis;
|
||||
model.CountryId = dto.CountryId;
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task<long> CreateAsync(DocumentDto dto)
|
||||
public async Task<ActionResult<long>> CreateAsync(DocumentDto dto)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return 0;
|
||||
if(userId is null) return Unauthorized();
|
||||
|
||||
var model = new Document
|
||||
{
|
||||
@@ -133,17 +135,19 @@ public class DocumentsController(MarechaiContext context) : ControllerBase
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task DeleteAsync(long id)
|
||||
public async Task<ActionResult> DeleteAsync(long id)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return;
|
||||
if(userId is null) return Unauthorized();
|
||||
Document item = await context.Documents.FindAsync(id);
|
||||
|
||||
if(item is null) return;
|
||||
if(item is null) return NotFound();
|
||||
|
||||
context.Documents.Remove(item);
|
||||
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
@@ -85,14 +85,14 @@ public class DumpsController(MarechaiContext context) : ControllerBase
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task UpdateAsync(DumpDto dto)
|
||||
public async Task<ActionResult> UpdateAsync(DumpDto dto)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return;
|
||||
if(userId is null) return Unauthorized();
|
||||
Dump model = await context.Dumps.FindAsync(dto.Id);
|
||||
|
||||
if(model is null) return;
|
||||
if(model is null) return NotFound();
|
||||
|
||||
model.Dumper = dto.Dumper;
|
||||
model.UserId = dto.UserId;
|
||||
@@ -101,17 +101,19 @@ public class DumpsController(MarechaiContext context) : ControllerBase
|
||||
model.MediaId = dto.MediaId;
|
||||
model.MediaDumpId = dto.MediaDumpId;
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task<ulong> CreateAsync(DumpDto dto)
|
||||
public async Task<ActionResult<ulong>> CreateAsync(DumpDto dto)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return null;
|
||||
if(userId is null) return Unauthorized();
|
||||
|
||||
var model = new Dump
|
||||
{
|
||||
@@ -133,17 +135,19 @@ public class DumpsController(MarechaiContext context) : ControllerBase
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task DeleteAsync(ulong id)
|
||||
public async Task<ActionResult> DeleteAsync(ulong id)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return;
|
||||
if(userId is null) return Unauthorized();
|
||||
Dump item = await context.Dumps.FindAsync(id);
|
||||
|
||||
if(item is null) return;
|
||||
if(item is null) return NotFound();
|
||||
|
||||
context.Dumps.Remove(item);
|
||||
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
@@ -62,29 +62,31 @@ public class GpusByMachineController(MarechaiContext context) : ControllerBase
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task DeleteAsync(long id)
|
||||
public async Task<ActionResult> DeleteAsync(long id)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return;
|
||||
if(userId is null) return Unauthorized();
|
||||
GpusByMachine item = await context.GpusByMachine.FindAsync(id);
|
||||
|
||||
if(item is null) return;
|
||||
if(item is null) return NotFound();
|
||||
|
||||
context.GpusByMachine.Remove(item);
|
||||
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task<long> CreateAsync(int gpuId, int machineId)
|
||||
public async Task<ActionResult<long>> CreateAsync(int gpuId, int machineId)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return 0;
|
||||
if(userId is null) return Unauthorized();
|
||||
|
||||
var item = new GpusByMachine
|
||||
{
|
||||
|
||||
@@ -106,14 +106,14 @@ public class GpusController(MarechaiContext context) : ControllerBase
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task UpdateAsync(GpuDto dto)
|
||||
public async Task<ActionResult> UpdateAsync(GpuDto dto)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return;
|
||||
if(userId is null) return Unauthorized();
|
||||
Gpu model = await context.Gpus.FindAsync(dto.Id);
|
||||
|
||||
if(model is null) return;
|
||||
if(model is null) return NotFound();
|
||||
|
||||
model.Name = dto.Name;
|
||||
model.CompanyId = dto.CompanyId;
|
||||
@@ -126,17 +126,19 @@ public class GpusController(MarechaiContext context) : ControllerBase
|
||||
model.Transistors = dto.Transistors;
|
||||
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task<int> CreateAsync(GpuDto dto)
|
||||
public async Task<ActionResult<int>> CreateAsync(GpuDto dto)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return 0;
|
||||
if(userId is null) return Unauthorized();
|
||||
|
||||
var model = new Gpu
|
||||
{
|
||||
@@ -161,17 +163,19 @@ public class GpusController(MarechaiContext context) : ControllerBase
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task DeleteAsync(int id)
|
||||
public async Task<ActionResult> DeleteAsync(int id)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return;
|
||||
if(userId is null) return Unauthorized();
|
||||
Gpu item = await context.Gpus.FindAsync(id);
|
||||
|
||||
if(item is null) return;
|
||||
if(item is null) return NotFound();
|
||||
|
||||
context.Gpus.Remove(item);
|
||||
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,6 @@
|
||||
// Copyright © 2003-2025 Natalia Portillo
|
||||
*******************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Claims;
|
||||
@@ -34,7 +33,6 @@ using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Localization;
|
||||
|
||||
namespace Marechai.Server.Controllers;
|
||||
|
||||
@@ -46,44 +44,49 @@ public class InstructionSetExtensionsByProcessorController(MarechaiContext conte
|
||||
[AllowAnonymous]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task<List<InstructionSetExtensionByProcessorDto>> GetByProcessor(int processorId) =>
|
||||
await context.InstructionSetExtensionsByProcessor.Where(e => e.ProcessorId == processorId)
|
||||
.Select(e => new InstructionSetExtensionByProcessorDto
|
||||
{
|
||||
Id = e.Id,
|
||||
Extension = e.Extension.Extension,
|
||||
Processor = e.Processor.Name,
|
||||
ProcessorId = e.ProcessorId,
|
||||
ExtensionId = e.ExtensionId
|
||||
})
|
||||
.OrderBy(e => e.Extension)
|
||||
.ToListAsync();
|
||||
public async Task<List<InstructionSetExtensionByProcessorDto>> GetByProcessor(int processorId) => await context
|
||||
.InstructionSetExtensionsByProcessor.Where(e => e.ProcessorId == processorId)
|
||||
.Select(e => new InstructionSetExtensionByProcessorDto
|
||||
{
|
||||
Id = e.Id,
|
||||
Extension = e.Extension.Extension,
|
||||
Processor = e.Processor.Name,
|
||||
ProcessorId = e.ProcessorId,
|
||||
ExtensionId = e.ExtensionId
|
||||
})
|
||||
.OrderBy(e => e.Extension)
|
||||
.ToListAsync();
|
||||
|
||||
[HttpDelete]
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task DeleteAsync(int id)
|
||||
public async Task<ActionResult> DeleteAsync(int id)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
if(userId is null) return;
|
||||
|
||||
if(userId is null) return Unauthorized();
|
||||
InstructionSetExtensionsByProcessor item = await context.InstructionSetExtensionsByProcessor.FindAsync(id);
|
||||
|
||||
if(item is null) return;
|
||||
if(item is null) return NotFound();
|
||||
|
||||
context.InstructionSetExtensionsByProcessor.Remove(item);
|
||||
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task<int> CreateAsync(int processorId, int extensionId)
|
||||
public async Task<ActionResult<int>> CreateAsync(int processorId, int extensionId)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
if(userId is null) return 0;
|
||||
|
||||
if(userId is null) return Unauthorized();
|
||||
|
||||
var item = new InstructionSetExtensionsByProcessor
|
||||
{
|
||||
ProcessorId = processorId,
|
||||
|
||||
@@ -68,29 +68,31 @@ public class InstructionSetExtensionsController(MarechaiContext context) : Contr
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task UpdateAsync(InstructionSetExtension viewModel)
|
||||
public async Task<ActionResult> UpdateAsync(InstructionSetExtension viewModel)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return;
|
||||
if(userId is null) return Unauthorized();
|
||||
InstructionSetExtension model = await context.InstructionSetExtensions.FindAsync(viewModel.Id);
|
||||
|
||||
if(model is null) return;
|
||||
if(model is null) return NotFound();
|
||||
|
||||
model.Extension = viewModel.Extension;
|
||||
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task<int> CreateAsync(InstructionSetExtension viewModel)
|
||||
public async Task<ActionResult<int>> CreateAsync(InstructionSetExtension viewModel)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return 0;
|
||||
if(userId is null) return Unauthorized();
|
||||
|
||||
var model = new InstructionSetExtension
|
||||
{
|
||||
@@ -107,18 +109,20 @@ public class InstructionSetExtensionsController(MarechaiContext context) : Contr
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task DeleteAsync(int id)
|
||||
public async Task<ActionResult> DeleteAsync(int id)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return;
|
||||
if(userId is null) return Unauthorized();
|
||||
InstructionSetExtension item = await context.InstructionSetExtensions.FindAsync(id);
|
||||
|
||||
if(item is null) return;
|
||||
if(item is null) return NotFound();
|
||||
|
||||
context.InstructionSetExtensions.Remove(item);
|
||||
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
|
||||
@@ -68,29 +68,31 @@ public class InstructionSetsController(MarechaiContext context) : ControllerBase
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task UpdateAsync(InstructionSet viewModel)
|
||||
public async Task<ActionResult> UpdateAsync(InstructionSet viewModel)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return;
|
||||
if(userId is null) return Unauthorized();
|
||||
InstructionSet model = await context.InstructionSets.FindAsync(viewModel.Id);
|
||||
|
||||
if(model is null) return;
|
||||
if(model is null) return NotFound();
|
||||
|
||||
model.Name = viewModel.Name;
|
||||
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task<int> CreateAsync(InstructionSet viewModel)
|
||||
public async Task<ActionResult<int>> CreateAsync(InstructionSet viewModel)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return 0;
|
||||
if(userId is null) return Unauthorized();
|
||||
|
||||
var model = new InstructionSet
|
||||
{
|
||||
@@ -107,18 +109,20 @@ public class InstructionSetsController(MarechaiContext context) : ControllerBase
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task DeleteAsync(int id)
|
||||
public async Task<ActionResult> DeleteAsync(int id)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return;
|
||||
if(userId is null) return Unauthorized();
|
||||
InstructionSet item = await context.InstructionSets.FindAsync(id);
|
||||
|
||||
if(item is null) return;
|
||||
if(item is null) return NotFound();
|
||||
|
||||
context.InstructionSets.Remove(item);
|
||||
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
|
||||
@@ -76,14 +76,14 @@ public class LicensesController(MarechaiContext context) : ControllerBase
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task UpdateAsync(License viewModel)
|
||||
public async Task<ActionResult> UpdateAsync(License viewModel)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return;
|
||||
if(userId is null) return Unauthorized();
|
||||
License model = await context.Licenses.FindAsync(viewModel.Id);
|
||||
|
||||
if(model is null) return;
|
||||
if(model is null) return NotFound();
|
||||
|
||||
model.FsfApproved = viewModel.FsfApproved;
|
||||
model.Link = viewModel.Link;
|
||||
@@ -93,17 +93,19 @@ public class LicensesController(MarechaiContext context) : ControllerBase
|
||||
model.Text = viewModel.Text;
|
||||
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task<int> CreateAsync(License viewModel)
|
||||
public async Task<ActionResult<int>> CreateAsync(License viewModel)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return 0;
|
||||
if(userId is null) return Unauthorized();
|
||||
|
||||
var model = new License
|
||||
{
|
||||
@@ -125,17 +127,19 @@ public class LicensesController(MarechaiContext context) : ControllerBase
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task DeleteAsync(int id)
|
||||
public async Task<ActionResult> DeleteAsync(int id)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return;
|
||||
if(userId is null) return Unauthorized();
|
||||
License item = await context.Licenses.FindAsync(id);
|
||||
|
||||
if(item is null) return;
|
||||
if(item is null) return NotFound();
|
||||
|
||||
context.Licenses.Remove(item);
|
||||
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
@@ -72,30 +72,32 @@ public class MachineFamiliesController(MarechaiContext context) : ControllerBase
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task UpdateAsync(MachineFamilyDto dto)
|
||||
public async Task<ActionResult> UpdateAsync(MachineFamilyDto dto)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return;
|
||||
if(userId is null) return Unauthorized();
|
||||
MachineFamily model = await context.MachineFamilies.FindAsync(dto.Id);
|
||||
|
||||
if(model is null) return;
|
||||
if(model is null) return NotFound();
|
||||
|
||||
model.Name = dto.Name;
|
||||
model.CompanyId = dto.CompanyId;
|
||||
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task<int> CreateAsync(MachineFamilyDto dto)
|
||||
public async Task<ActionResult<int>> CreateAsync(MachineFamilyDto dto)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return 0;
|
||||
if(userId is null) return Unauthorized();
|
||||
|
||||
var model = new MachineFamily
|
||||
{
|
||||
@@ -113,17 +115,19 @@ public class MachineFamiliesController(MarechaiContext context) : ControllerBase
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task DeleteAsync(int id)
|
||||
public async Task<ActionResult> DeleteAsync(int id)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return;
|
||||
if(userId is null) return Unauthorized();
|
||||
MachineFamily item = await context.MachineFamilies.FindAsync(id);
|
||||
|
||||
if(item is null) return;
|
||||
if(item is null) return NotFound();
|
||||
|
||||
context.MachineFamilies.Remove(item);
|
||||
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
@@ -104,14 +104,14 @@ public class MachinePhotosController(MarechaiContext context) : ControllerBase
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task UpdateAsync(MachinePhotoDto dto)
|
||||
public async Task<ActionResult> UpdateAsync(MachinePhotoDto dto)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return;
|
||||
if(userId is null) return Unauthorized();
|
||||
MachinePhoto model = await context.MachinePhotos.FindAsync(dto.Id);
|
||||
|
||||
if(model is null) return;
|
||||
if(model is null) return NotFound();
|
||||
|
||||
model.Aperture = dto.Aperture;
|
||||
model.Author = dto.Author;
|
||||
@@ -149,17 +149,19 @@ public class MachinePhotosController(MarechaiContext context) : ControllerBase
|
||||
model.WhiteBalance = dto.WhiteBalance;
|
||||
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task<Guid> CreateAsync(MachinePhotoDto dto)
|
||||
public async Task<ActionResult<Guid>> CreateAsync(MachinePhotoDto dto)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return null;
|
||||
if(userId is null) return Unauthorized();
|
||||
|
||||
var model = new MachinePhoto
|
||||
{
|
||||
|
||||
@@ -29,6 +29,7 @@ using System.Linq;
|
||||
using System.Security.Claims;
|
||||
using System.Threading.Tasks;
|
||||
using Marechai.Data.Dtos;
|
||||
using Marechai.Database;
|
||||
using Marechai.Database.Models;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
@@ -90,14 +91,14 @@ public class MachinesController
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task UpdateAsync(MachineDto dto)
|
||||
public async Task<ActionResult> UpdateAsync(MachineDto dto)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return;
|
||||
if(userId is null) return Unauthorized();
|
||||
Machine model = await context.Machines.FindAsync(dto.Id);
|
||||
|
||||
if(model is null) return;
|
||||
if(model is null) return NotFound();
|
||||
|
||||
model.CompanyId = dto.CompanyId;
|
||||
model.Name = dto.Name;
|
||||
@@ -131,17 +132,19 @@ public class MachinesController
|
||||
if(news != null) await context.News.AddAsync(news);
|
||||
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task<int> CreateAsync(MachineDto dto)
|
||||
public async Task<ActionResult<int>> CreateAsync(MachineDto dto)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return 0;
|
||||
if(userId is null) return Unauthorized();
|
||||
|
||||
var model = new Machine
|
||||
{
|
||||
@@ -260,17 +263,19 @@ public class MachinesController
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task DeleteAsync(int id)
|
||||
public async Task<ActionResult> DeleteAsync(int id)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return;
|
||||
if(userId is null) return Unauthorized();
|
||||
Machine item = await context.Machines.FindAsync(id);
|
||||
|
||||
if(item is null) return;
|
||||
if(item is null) return NotFound();
|
||||
|
||||
context.Machines.Remove(item);
|
||||
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
@@ -84,14 +84,14 @@ public class MagazineIssuesController(MarechaiContext context) : ControllerBase
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task UpdateAsync(MagazineIssueDto dto)
|
||||
public async Task<ActionResult> UpdateAsync(MagazineIssueDto dto)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return;
|
||||
if(userId is null) return Unauthorized();
|
||||
MagazineIssue model = await context.MagazineIssues.FindAsync(dto.Id);
|
||||
|
||||
if(model is null) return;
|
||||
if(model is null) return NotFound();
|
||||
|
||||
model.MagazineId = dto.MagazineId;
|
||||
model.Caption = dto.Caption;
|
||||
@@ -101,17 +101,19 @@ public class MagazineIssuesController(MarechaiContext context) : ControllerBase
|
||||
model.Pages = dto.Pages;
|
||||
model.IssueNumber = dto.IssueNumber;
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task<long> CreateAsync(MagazineIssueDto dto)
|
||||
public async Task<ActionResult<long>> CreateAsync(MagazineIssueDto dto)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return 0;
|
||||
if(userId is null) return Unauthorized();
|
||||
|
||||
var model = new MagazineIssue
|
||||
{
|
||||
@@ -134,17 +136,19 @@ public class MagazineIssuesController(MarechaiContext context) : ControllerBase
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task DeleteAsync(long id)
|
||||
public async Task<ActionResult> DeleteAsync(long id)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return;
|
||||
if(userId is null) return Unauthorized();
|
||||
MagazineIssue item = await context.MagazineIssues.FindAsync(id);
|
||||
|
||||
if(item is null) return;
|
||||
if(item is null) return NotFound();
|
||||
|
||||
context.MagazineIssues.Remove(item);
|
||||
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
@@ -80,14 +80,14 @@ public class MagazineScansController(MarechaiContext context) : ControllerBase
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task UpdateAsync(MagazineScanDto dto)
|
||||
public async Task<ActionResult> UpdateAsync(MagazineScanDto dto)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return;
|
||||
if(userId is null) return Unauthorized();
|
||||
MagazineScan model = await context.MagazineScans.FindAsync(dto.Id);
|
||||
|
||||
if(model is null) return;
|
||||
if(model is null) return NotFound();
|
||||
|
||||
model.Author = dto.Author;
|
||||
model.ColorSpace = dto.ColorSpace;
|
||||
@@ -104,17 +104,19 @@ public class MagazineScansController(MarechaiContext context) : ControllerBase
|
||||
model.VerticalResolution = dto.VerticalResolution;
|
||||
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task<Guid> CreateAsync(MagazineScanDto dto)
|
||||
public async Task<ActionResult<Guid>> CreateAsync(MagazineScanDto dto)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return null;
|
||||
if(userId is null) return Unauthorized();
|
||||
|
||||
var model = new MagazineScan
|
||||
{
|
||||
@@ -148,17 +150,19 @@ public class MagazineScansController(MarechaiContext context) : ControllerBase
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task DeleteAsync(Guid id)
|
||||
public async Task<ActionResult> DeleteAsync(Guid id)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return;
|
||||
if(userId is null) return Unauthorized();
|
||||
MagazineScan item = await context.MagazineScans.FindAsync(id);
|
||||
|
||||
if(item is null) return;
|
||||
if(item is null) return NotFound();
|
||||
|
||||
context.MagazineScans.Remove(item);
|
||||
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
@@ -60,29 +60,31 @@ public class MagazinesByMachineController(MarechaiContext context) : ControllerB
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task DeleteAsync(long id)
|
||||
public async Task<ActionResult> DeleteAsync(long id)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return;
|
||||
if(userId is null) return Unauthorized();
|
||||
MagazinesByMachine item = await context.MagazinesByMachines.FindAsync(id);
|
||||
|
||||
if(item is null) return;
|
||||
if(item is null) return NotFound();
|
||||
|
||||
context.MagazinesByMachines.Remove(item);
|
||||
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task<long> CreateAsync(int machineId, long bookId)
|
||||
public async Task<ActionResult<long>> CreateAsync(int machineId, long bookId)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return 0;
|
||||
if(userId is null) return Unauthorized();
|
||||
|
||||
var item = new MagazinesByMachine
|
||||
{
|
||||
|
||||
@@ -60,29 +60,31 @@ public class MagazinesByMachineFamilyController(MarechaiContext context) : Contr
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task DeleteAsync(long id)
|
||||
public async Task<ActionResult> DeleteAsync(long id)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return;
|
||||
if(userId is null) return Unauthorized();
|
||||
MagazinesByMachineFamily item = await context.MagazinesByMachinesFamilies.FindAsync(id);
|
||||
|
||||
if(item is null) return;
|
||||
if(item is null) return NotFound();
|
||||
|
||||
context.MagazinesByMachinesFamilies.Remove(item);
|
||||
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task<long> CreateAsync(int machineFamilyId, long bookId)
|
||||
public async Task<ActionResult<long>> CreateAsync(int machineFamilyId, long bookId)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return 0;
|
||||
if(userId is null) return Unauthorized();
|
||||
|
||||
var item = new MagazinesByMachineFamily
|
||||
{
|
||||
|
||||
@@ -95,14 +95,14 @@ public class MagazinesController(MarechaiContext context) : ControllerBase
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task UpdateAsync(MagazineDto dto)
|
||||
public async Task<ActionResult> UpdateAsync(MagazineDto dto)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return;
|
||||
if(userId is null) return Unauthorized();
|
||||
Magazine model = await context.Magazines.FindAsync(dto.Id);
|
||||
|
||||
if(model is null) return;
|
||||
if(model is null) return NotFound();
|
||||
|
||||
model.Title = dto.Title;
|
||||
model.NativeTitle = dto.NativeTitle;
|
||||
@@ -111,17 +111,19 @@ public class MagazinesController(MarechaiContext context) : ControllerBase
|
||||
model.CountryId = dto.CountryId;
|
||||
model.Issn = dto.Issn;
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task<long> CreateAsync(MagazineDto dto)
|
||||
public async Task<ActionResult<long>> CreateAsync(MagazineDto dto)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return 0;
|
||||
if(userId is null) return Unauthorized();
|
||||
|
||||
var model = new Magazine
|
||||
{
|
||||
@@ -150,17 +152,19 @@ public class MagazinesController(MarechaiContext context) : ControllerBase
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task DeleteAsync(long id)
|
||||
public async Task<ActionResult> DeleteAsync(long id)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return;
|
||||
if(userId is null) return Unauthorized();
|
||||
Magazine item = await context.Magazines.FindAsync(id);
|
||||
|
||||
if(item is null) return;
|
||||
if(item is null) return NotFound();
|
||||
|
||||
context.Magazines.Remove(item);
|
||||
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
@@ -128,14 +128,14 @@ public class MediaController(MarechaiContext context) : ControllerBase
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task UpdateAsync(MediaDto dto)
|
||||
public async Task<ActionResult> UpdateAsync(MediaDto dto)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return;
|
||||
if(userId is null) return Unauthorized();
|
||||
Media model = await context.Media.FindAsync(dto.Id);
|
||||
|
||||
if(model is null) return;
|
||||
if(model is null) return NotFound();
|
||||
|
||||
model.Title = dto.Title;
|
||||
model.Sequence = dto.Sequence;
|
||||
@@ -163,17 +163,19 @@ public class MediaController(MarechaiContext context) : ControllerBase
|
||||
model.StorageInterface = dto.StorageInterface;
|
||||
model.TableOfContents = dto.TableOfContents;
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task<ulong> CreateAsync(MediaDto dto)
|
||||
public async Task<ActionResult<ulong>> CreateAsync(MediaDto dto)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return null;
|
||||
if(userId is null) return Unauthorized();
|
||||
|
||||
var model = new Media
|
||||
{
|
||||
@@ -214,17 +216,19 @@ public class MediaController(MarechaiContext context) : ControllerBase
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task DeleteAsync(ulong id)
|
||||
public async Task<ActionResult> DeleteAsync(ulong id)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return;
|
||||
if(userId is null) return Unauthorized();
|
||||
Media item = await context.Media.FindAsync(id);
|
||||
|
||||
if(item is null) return;
|
||||
if(item is null) return NotFound();
|
||||
|
||||
context.Media.Remove(item);
|
||||
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
@@ -28,6 +28,7 @@ using System.Linq;
|
||||
using System.Security.Claims;
|
||||
using System.Threading.Tasks;
|
||||
using Marechai.Data.Dtos;
|
||||
using Marechai.Database;
|
||||
using Marechai.Database.Models;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
@@ -65,29 +66,32 @@ public class MemoriesByMachineController(MarechaiContext context) : ControllerBa
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task DeleteAsync(long id)
|
||||
public async Task<ActionResult> DeleteAsync(long id)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return;
|
||||
if(userId is null) return Unauthorized();
|
||||
MemoryByMachine item = await context.MemoryByMachine.FindAsync(id);
|
||||
|
||||
if(item is null) return;
|
||||
if(item is null) return NotFound();
|
||||
|
||||
context.MemoryByMachine.Remove(item);
|
||||
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task<long> CreateAsync(int machineId, MemoryType type, MemoryUsage usage, long? size, double? speed)
|
||||
public async Task<ActionResult<long>> CreateAsync(int machineId, MemoryType type, MemoryUsage usage, long? size,
|
||||
double? speed)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return 0;
|
||||
if(userId is null) return Unauthorized();
|
||||
|
||||
var item = new MemoryByMachine
|
||||
{
|
||||
|
||||
@@ -28,12 +28,12 @@ using System.Linq;
|
||||
using System.Security.Claims;
|
||||
using System.Threading.Tasks;
|
||||
using Marechai.Data.Dtos;
|
||||
using Marechai.Database;
|
||||
using Marechai.Database.Models;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Localization;
|
||||
|
||||
namespace Marechai.Server.Controllers;
|
||||
|
||||
@@ -158,17 +158,19 @@ public class NewsController(MarechaiContext context) : ControllerBase
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task DeleteAsync(int id)
|
||||
public async Task<ActionResult> DeleteAsync(int id)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return;
|
||||
if(userId is null) return Unauthorized();
|
||||
News item = await context.News.FindAsync(id);
|
||||
|
||||
if(item is null) return;
|
||||
if(item is null) return NotFound();
|
||||
|
||||
context.News.Remove(item);
|
||||
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,6 @@
|
||||
// Copyright © 2003-2025 Natalia Portillo
|
||||
*******************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Claims;
|
||||
@@ -34,7 +33,6 @@ using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Localization;
|
||||
|
||||
namespace Marechai.Server.Controllers;
|
||||
|
||||
@@ -47,50 +45,53 @@ public class PeopleByBookController(MarechaiContext context) : ControllerBase
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task<List<PersonByBookDto>> GetByBook(long bookId) => (await context.PeopleByBooks
|
||||
.Where(p => p.BookId == bookId)
|
||||
.Select(p => new PersonByBookDto
|
||||
{
|
||||
Id = p.Id,
|
||||
Name = p.Person.Name,
|
||||
Surname = p.Person.Surname,
|
||||
Alias = p.Person.Alias,
|
||||
DisplayName =
|
||||
p.Person.DisplayName,
|
||||
PersonId = p.PersonId,
|
||||
RoleId = p.RoleId,
|
||||
Role = p.Role.Name,
|
||||
BookId = p.BookId
|
||||
})
|
||||
.ToListAsync())
|
||||
.OrderBy(p => p.FullName)
|
||||
.ThenBy(p => p.Role)
|
||||
.ToList();
|
||||
.Where(p => p.BookId == bookId)
|
||||
.Select(p => new PersonByBookDto
|
||||
{
|
||||
Id = p.Id,
|
||||
Name = p.Person.Name,
|
||||
Surname = p.Person.Surname,
|
||||
Alias = p.Person.Alias,
|
||||
DisplayName = p.Person.DisplayName,
|
||||
PersonId = p.PersonId,
|
||||
RoleId = p.RoleId,
|
||||
Role = p.Role.Name,
|
||||
BookId = p.BookId
|
||||
})
|
||||
.ToListAsync()).OrderBy(p => p.FullName)
|
||||
.ThenBy(p => p.Role)
|
||||
.ToList();
|
||||
|
||||
[HttpDelete]
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task DeleteAsync(long id)
|
||||
public async Task<ActionResult> DeleteAsync(long id)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
if(userId is null) return;
|
||||
|
||||
if(userId is null) return Unauthorized();
|
||||
PeopleByBook item = await context.PeopleByBooks.FindAsync(id);
|
||||
|
||||
if(item is null) return;
|
||||
if(item is null) return NotFound();
|
||||
|
||||
context.PeopleByBooks.Remove(item);
|
||||
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task<long> CreateAsync(int personId, long bookId, string roleId)
|
||||
public async Task<ActionResult<long>> CreateAsync(int personId, long bookId, string roleId)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
if(userId is null) return 0;
|
||||
|
||||
if(userId is null) return Unauthorized();
|
||||
|
||||
var item = new PeopleByBook
|
||||
{
|
||||
PersonId = personId,
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
// Copyright © 2003-2025 Natalia Portillo
|
||||
*******************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Claims;
|
||||
@@ -34,7 +33,6 @@ using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Localization;
|
||||
|
||||
namespace Marechai.Server.Controllers;
|
||||
|
||||
@@ -46,49 +44,54 @@ public class PeopleByDocumentController(MarechaiContext context) : ControllerBas
|
||||
[AllowAnonymous]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task<List<PersonByDocumentDto>> GetByDocument(long documentId) => (await context
|
||||
.PeopleByDocuments.Where(p => p.DocumentId == documentId)
|
||||
.Select(p => new PersonByDocumentDto
|
||||
{
|
||||
Id = p.Id,
|
||||
Name = p.Person.Name,
|
||||
Surname = p.Person.Surname,
|
||||
Alias = p.Person.Alias,
|
||||
DisplayName = p.Person.DisplayName,
|
||||
PersonId = p.PersonId,
|
||||
RoleId = p.RoleId,
|
||||
Role = p.Role.Name,
|
||||
DocumentId = p.DocumentId
|
||||
})
|
||||
.ToListAsync()).OrderBy(p => p.FullName)
|
||||
.ThenBy(p => p.Role)
|
||||
.ToList();
|
||||
public async Task<List<PersonByDocumentDto>> GetByDocument(long documentId) => (await context.PeopleByDocuments
|
||||
.Where(p => p.DocumentId == documentId)
|
||||
.Select(p => new PersonByDocumentDto
|
||||
{
|
||||
Id = p.Id,
|
||||
Name = p.Person.Name,
|
||||
Surname = p.Person.Surname,
|
||||
Alias = p.Person.Alias,
|
||||
DisplayName = p.Person.DisplayName,
|
||||
PersonId = p.PersonId,
|
||||
RoleId = p.RoleId,
|
||||
Role = p.Role.Name,
|
||||
DocumentId = p.DocumentId
|
||||
})
|
||||
.ToListAsync()).OrderBy(p => p.FullName)
|
||||
.ThenBy(p => p.Role)
|
||||
.ToList();
|
||||
|
||||
[HttpDelete]
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task DeleteAsync(long id)
|
||||
public async Task<ActionResult> DeleteAsync(long id)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
if(userId is null) return;
|
||||
|
||||
if(userId is null) return Unauthorized();
|
||||
PeopleByDocument item = await context.PeopleByDocuments.FindAsync(id);
|
||||
|
||||
if(item is null) return;
|
||||
if(item is null) return NotFound();
|
||||
|
||||
context.PeopleByDocuments.Remove(item);
|
||||
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task<long> CreateAsync(int personId, long documentId, string roleId)
|
||||
public async Task<ActionResult<long>> CreateAsync(int personId, long documentId, string roleId)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
if(userId is null) return 0;
|
||||
|
||||
if(userId is null) return Unauthorized();
|
||||
|
||||
var item = new PeopleByDocument
|
||||
{
|
||||
PersonId = personId,
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
// Copyright © 2003-2025 Natalia Portillo
|
||||
*******************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Claims;
|
||||
@@ -34,7 +33,6 @@ using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Localization;
|
||||
|
||||
namespace Marechai.Server.Controllers;
|
||||
|
||||
@@ -46,49 +44,54 @@ public class PeopleByMagazineController(MarechaiContext context) : ControllerBas
|
||||
[AllowAnonymous]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task<List<PersonByMagazineDto>> GetByMagazine(long magazineId) => (await context
|
||||
.PeopleByMagazines.Where(p => p.MagazineId == magazineId)
|
||||
.Select(p => new PersonByMagazineDto
|
||||
{
|
||||
Id = p.Id,
|
||||
Name = p.Person.Name,
|
||||
Surname = p.Person.Surname,
|
||||
Alias = p.Person.Alias,
|
||||
DisplayName = p.Person.DisplayName,
|
||||
PersonId = p.PersonId,
|
||||
RoleId = p.RoleId,
|
||||
Role = p.Role.Name,
|
||||
MagazineId = p.MagazineId
|
||||
})
|
||||
.ToListAsync()).OrderBy(p => p.FullName)
|
||||
.ThenBy(p => p.Role)
|
||||
.ToList();
|
||||
public async Task<List<PersonByMagazineDto>> GetByMagazine(long magazineId) => (await context.PeopleByMagazines
|
||||
.Where(p => p.MagazineId == magazineId)
|
||||
.Select(p => new PersonByMagazineDto
|
||||
{
|
||||
Id = p.Id,
|
||||
Name = p.Person.Name,
|
||||
Surname = p.Person.Surname,
|
||||
Alias = p.Person.Alias,
|
||||
DisplayName = p.Person.DisplayName,
|
||||
PersonId = p.PersonId,
|
||||
RoleId = p.RoleId,
|
||||
Role = p.Role.Name,
|
||||
MagazineId = p.MagazineId
|
||||
})
|
||||
.ToListAsync()).OrderBy(p => p.FullName)
|
||||
.ThenBy(p => p.Role)
|
||||
.ToList();
|
||||
|
||||
[HttpDelete]
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task DeleteAsync(long id)
|
||||
public async Task<ActionResult> DeleteAsync(long id)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
if(userId is null) return;
|
||||
|
||||
if(userId is null) return Unauthorized();
|
||||
PeopleByMagazine item = await context.PeopleByMagazines.FindAsync(id);
|
||||
|
||||
if(item is null) return;
|
||||
if(item is null) return NotFound();
|
||||
|
||||
context.PeopleByMagazines.Remove(item);
|
||||
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task<long> CreateAsync(int personId, long magazineId, string roleId)
|
||||
public async Task<ActionResult<long>> CreateAsync(int personId, long magazineId, string roleId)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
if(userId is null) return 0;
|
||||
|
||||
if(userId is null) return Unauthorized();
|
||||
|
||||
var item = new PeopleByMagazine
|
||||
{
|
||||
PersonId = personId,
|
||||
|
||||
@@ -91,14 +91,14 @@ public class PeopleController(MarechaiContext context) : ControllerBase
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task UpdateAsync(PersonDto dto)
|
||||
public async Task<ActionResult> UpdateAsync(PersonDto dto)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return;
|
||||
if(userId is null) return Unauthorized();
|
||||
Person model = await context.People.FindAsync(dto.Id);
|
||||
|
||||
if(model is null) return;
|
||||
if(model is null) return NotFound();
|
||||
|
||||
model.Name = dto.Name;
|
||||
model.Surname = dto.Surname;
|
||||
@@ -113,17 +113,19 @@ public class PeopleController(MarechaiContext context) : ControllerBase
|
||||
model.DisplayName = dto.DisplayName;
|
||||
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task<int> CreateAsync(PersonDto dto)
|
||||
public async Task<ActionResult<int>> CreateAsync(PersonDto dto)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return 0;
|
||||
if(userId is null) return Unauthorized();
|
||||
|
||||
var model = new Person
|
||||
{
|
||||
@@ -150,17 +152,19 @@ public class PeopleController(MarechaiContext context) : ControllerBase
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task DeleteAsync(int id)
|
||||
public async Task<ActionResult> DeleteAsync(int id)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return;
|
||||
if(userId is null) return Unauthorized();
|
||||
Person item = await context.People.FindAsync(id);
|
||||
|
||||
if(item is null) return;
|
||||
if(item is null) return NotFound();
|
||||
|
||||
context.People.Remove(item);
|
||||
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
@@ -63,29 +63,31 @@ public class ProcessorsByMachineController(MarechaiContext context) : Controller
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task DeleteAsync(long id)
|
||||
public async Task<ActionResult> DeleteAsync(long id)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return;
|
||||
if(userId is null) return Unauthorized();
|
||||
ProcessorsByMachine item = await context.ProcessorsByMachine.FindAsync(id);
|
||||
|
||||
if(item is null) return;
|
||||
if(item is null) return NotFound();
|
||||
|
||||
context.ProcessorsByMachine.Remove(item);
|
||||
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task<long> CreateAsync(int processorId, int machineId, float? speed)
|
||||
public async Task<ActionResult<long>> CreateAsync(int processorId, int machineId, float? speed)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return 0;
|
||||
if(userId is null) return Unauthorized();
|
||||
|
||||
var item = new ProcessorsByMachine
|
||||
{
|
||||
|
||||
@@ -163,14 +163,14 @@ public class ProcessorsController(MarechaiContext context) : ControllerBase
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task UpdateAsync(ProcessorDto dto)
|
||||
public async Task<ActionResult> UpdateAsync(ProcessorDto dto)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return;
|
||||
if(userId is null) return Unauthorized();
|
||||
Processor model = await context.Processors.FindAsync(dto.Id);
|
||||
|
||||
if(model is null) return;
|
||||
if(model is null) return NotFound();
|
||||
|
||||
model.AddrBus = dto.AddrBus;
|
||||
model.CompanyId = dto.CompanyId;
|
||||
@@ -199,17 +199,19 @@ public class ProcessorsController(MarechaiContext context) : ControllerBase
|
||||
model.Transistors = dto.Transistors;
|
||||
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task<int> CreateAsync(ProcessorDto dto)
|
||||
public async Task<ActionResult<int>> CreateAsync(ProcessorDto dto)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return 0;
|
||||
if(userId is null) return Unauthorized();
|
||||
|
||||
var model = new Processor
|
||||
{
|
||||
@@ -250,17 +252,19 @@ public class ProcessorsController(MarechaiContext context) : ControllerBase
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task DeleteAsync(int id)
|
||||
public async Task<ActionResult> DeleteAsync(int id)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return;
|
||||
if(userId is null) return Unauthorized();
|
||||
Processor item = await context.Processors.FindAsync(id);
|
||||
|
||||
if(item is null) return;
|
||||
if(item is null) return NotFound();
|
||||
|
||||
context.Processors.Remove(item);
|
||||
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,6 @@
|
||||
// Copyright © 2003-2025 Natalia Portillo
|
||||
*******************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Claims;
|
||||
@@ -34,7 +33,6 @@ using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Localization;
|
||||
|
||||
namespace Marechai.Server.Controllers;
|
||||
|
||||
@@ -47,56 +45,65 @@ public class ResolutionsByGpuController(MarechaiContext context) : ControllerBas
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task<List<ResolutionByGpuDto>> GetByGpu(int resolutionId) => (await context.ResolutionsByGpu
|
||||
.Where(r => r.ResolutionId == resolutionId)
|
||||
.Select(r => new ResolutionByGpuDto
|
||||
{
|
||||
Id = r.Id,
|
||||
GpuId = r.GpuId,
|
||||
Resolution = new ResolutionDto
|
||||
{
|
||||
Id = r.Resolution.Id,
|
||||
Width = r.Resolution.Width,
|
||||
Height = r.Resolution.Height,
|
||||
Colors = r.Resolution.Colors,
|
||||
Palette = r.Resolution.Palette,
|
||||
Chars = r.Resolution.Chars,
|
||||
Grayscale = r.Resolution.Grayscale
|
||||
},
|
||||
ResolutionId = r.ResolutionId
|
||||
})
|
||||
.ToListAsync()).OrderBy(r => r.Resolution.Width)
|
||||
.ThenBy(r => r.Resolution.Height)
|
||||
.ThenBy(r => r.Resolution.Chars)
|
||||
.ThenBy(r => r.Resolution.Grayscale)
|
||||
.ThenBy(r => r.Resolution.Colors)
|
||||
.ThenBy(r => r.Resolution.Palette)
|
||||
.ToList();
|
||||
.Where(r => r.ResolutionId ==
|
||||
resolutionId)
|
||||
.Select(r => new ResolutionByGpuDto
|
||||
{
|
||||
Id = r.Id,
|
||||
GpuId = r.GpuId,
|
||||
Resolution = new ResolutionDto
|
||||
{
|
||||
Id = r.Resolution.Id,
|
||||
Width = r.Resolution.Width,
|
||||
Height = r.Resolution.Height,
|
||||
Colors = r.Resolution.Colors,
|
||||
Palette = r.Resolution
|
||||
.Palette,
|
||||
Chars = r.Resolution.Chars,
|
||||
Grayscale = r.Resolution
|
||||
.Grayscale
|
||||
},
|
||||
ResolutionId = r.ResolutionId
|
||||
})
|
||||
.ToListAsync())
|
||||
.OrderBy(r => r.Resolution.Width)
|
||||
.ThenBy(r => r.Resolution.Height)
|
||||
.ThenBy(r => r.Resolution.Chars)
|
||||
.ThenBy(r => r.Resolution.Grayscale)
|
||||
.ThenBy(r => r.Resolution.Colors)
|
||||
.ThenBy(r => r.Resolution.Palette)
|
||||
.ToList();
|
||||
|
||||
[HttpDelete]
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task DeleteAsync(long id)
|
||||
public async Task<ActionResult> DeleteAsync(long id)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
if(userId is null) return;
|
||||
|
||||
if(userId is null) return Unauthorized();
|
||||
ResolutionsByGpu item = await context.ResolutionsByGpu.FindAsync(id);
|
||||
|
||||
if(item is null) return;
|
||||
if(item is null) return NotFound();
|
||||
|
||||
context.ResolutionsByGpu.Remove(item);
|
||||
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task<long> CreateAsync(int resolutionId, int gpuId)
|
||||
public async Task<ActionResult<long>> CreateAsync(int resolutionId, int gpuId)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
if(userId is null) return 0;
|
||||
|
||||
if(userId is null) return Unauthorized();
|
||||
|
||||
var item = new ResolutionsByGpu
|
||||
{
|
||||
GpuId = gpuId,
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
// Copyright © 2003-2025 Natalia Portillo
|
||||
*******************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Claims;
|
||||
@@ -34,7 +33,6 @@ using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Localization;
|
||||
|
||||
namespace Marechai.Server.Controllers;
|
||||
|
||||
@@ -46,57 +44,62 @@ public class ResolutionsByScreenController(MarechaiContext context) : Controller
|
||||
[AllowAnonymous]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task<List<ResolutionByScreenDto>> GetByScreen(int resolutionId) => (await context
|
||||
.ResolutionsByScreen.Where(r => r.ResolutionId == resolutionId)
|
||||
.Select(r => new ResolutionByScreenDto
|
||||
{
|
||||
Id = r.Id,
|
||||
ScreenId = r.ScreenId,
|
||||
Resolution = new ResolutionDto
|
||||
{
|
||||
Id = r.Resolution.Id,
|
||||
Width = r.Resolution.Width,
|
||||
Height = r.Resolution.Height,
|
||||
Colors = r.Resolution.Colors,
|
||||
Palette = r.Resolution.Palette,
|
||||
Chars = r.Resolution.Chars,
|
||||
Grayscale = r.Resolution.Grayscale
|
||||
},
|
||||
ResolutionId = r.ResolutionId
|
||||
})
|
||||
.ToListAsync()).OrderBy(r => r.Resolution.Width)
|
||||
.ThenBy(r => r.Resolution.Height)
|
||||
.ThenBy(r => r.Resolution.Chars)
|
||||
.ThenBy(r => r.Resolution.Grayscale)
|
||||
.ThenBy(r => r.Resolution.Colors)
|
||||
.ThenBy(r => r.Resolution.Palette)
|
||||
.ToList();
|
||||
public async Task<List<ResolutionByScreenDto>> GetByScreen(int resolutionId) => (await context.ResolutionsByScreen
|
||||
.Where(r => r.ResolutionId == resolutionId)
|
||||
.Select(r => new ResolutionByScreenDto
|
||||
{
|
||||
Id = r.Id,
|
||||
ScreenId = r.ScreenId,
|
||||
Resolution = new ResolutionDto
|
||||
{
|
||||
Id = r.Resolution.Id,
|
||||
Width = r.Resolution.Width,
|
||||
Height = r.Resolution.Height,
|
||||
Colors = r.Resolution.Colors,
|
||||
Palette = r.Resolution.Palette,
|
||||
Chars = r.Resolution.Chars,
|
||||
Grayscale = r.Resolution.Grayscale
|
||||
},
|
||||
ResolutionId = r.ResolutionId
|
||||
})
|
||||
.ToListAsync()).OrderBy(r => r.Resolution.Width)
|
||||
.ThenBy(r => r.Resolution.Height)
|
||||
.ThenBy(r => r.Resolution.Chars)
|
||||
.ThenBy(r => r.Resolution.Grayscale)
|
||||
.ThenBy(r => r.Resolution.Colors)
|
||||
.ThenBy(r => r.Resolution.Palette)
|
||||
.ToList();
|
||||
|
||||
[HttpDelete]
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task DeleteAsync(long id)
|
||||
public async Task<ActionResult> DeleteAsync(long id)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
if(userId is null) return;
|
||||
|
||||
if(userId is null) return Unauthorized();
|
||||
ResolutionsByScreen item = await context.ResolutionsByScreen.FindAsync(id);
|
||||
|
||||
if(item is null) return;
|
||||
if(item is null) return NotFound();
|
||||
|
||||
context.ResolutionsByScreen.Remove(item);
|
||||
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task<long> CreateAsync(int resolutionId, int screenId)
|
||||
public async Task<ActionResult<long>> CreateAsync(int resolutionId, int screenId)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
if(userId is null) return 0;
|
||||
|
||||
if(userId is null) return Unauthorized();
|
||||
|
||||
var item = new ResolutionsByScreen
|
||||
{
|
||||
ScreenId = screenId,
|
||||
|
||||
@@ -83,14 +83,14 @@ public class ResolutionsController(MarechaiContext context) : ControllerBase
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task UpdateAsync(ResolutionDto dto)
|
||||
public async Task<ActionResult> UpdateAsync(ResolutionDto dto)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return;
|
||||
if(userId is null) return Unauthorized();
|
||||
Resolution model = await context.Resolutions.FindAsync(dto.Id);
|
||||
|
||||
if(model is null) return;
|
||||
if(model is null) return NotFound();
|
||||
|
||||
model.Chars = dto.Chars;
|
||||
model.Colors = dto.Colors;
|
||||
@@ -100,17 +100,19 @@ public class ResolutionsController(MarechaiContext context) : ControllerBase
|
||||
model.Width = dto.Width;
|
||||
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task<int> CreateAsync(ResolutionDto dto)
|
||||
public async Task<ActionResult<int>> CreateAsync(ResolutionDto dto)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return 0;
|
||||
if(userId is null) return Unauthorized();
|
||||
|
||||
var model = new Resolution
|
||||
{
|
||||
@@ -132,17 +134,19 @@ public class ResolutionsController(MarechaiContext context) : ControllerBase
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task DeleteAsync(int id)
|
||||
public async Task<ActionResult> DeleteAsync(int id)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return;
|
||||
if(userId is null) return Unauthorized();
|
||||
Resolution item = await context.Resolutions.FindAsync(id);
|
||||
|
||||
if(item is null) return;
|
||||
if(item is null) return NotFound();
|
||||
|
||||
context.Resolutions.Remove(item);
|
||||
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
@@ -78,29 +78,31 @@ public class ScreensByMachineController(MarechaiContext context) : ControllerBas
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task DeleteAsync(long id)
|
||||
public async Task<ActionResult> DeleteAsync(long id)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return;
|
||||
if(userId is null) return Unauthorized();
|
||||
ScreensByMachine item = await context.ScreensByMachine.FindAsync(id);
|
||||
|
||||
if(item is null) return;
|
||||
if(item is null) return NotFound();
|
||||
|
||||
context.ScreensByMachine.Remove(item);
|
||||
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task<long> CreateAsync(int machineId, int screenId)
|
||||
public async Task<ActionResult<long>> CreateAsync(int machineId, int screenId)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return 0;
|
||||
if(userId is null) return Unauthorized();
|
||||
if(context.ScreensByMachine.Any(s => s.MachineId == machineId && s.ScreenId == screenId)) return 0;
|
||||
|
||||
var item = new ScreensByMachine
|
||||
|
||||
@@ -102,18 +102,18 @@ public class ScreensController(MarechaiContext context) : ControllerBase
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task UpdateAsync(ScreenDto dto)
|
||||
public async Task<ActionResult> UpdateAsync(ScreenDto dto)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return;
|
||||
if(userId is null) return Unauthorized();
|
||||
Screen model = await context.Screens.FindAsync(dto.Id);
|
||||
|
||||
if(model is null) return;
|
||||
if(model is null) return NotFound();
|
||||
|
||||
Resolution nativeResolution = await context.Resolutions.FindAsync(dto.NativeResolutionId);
|
||||
|
||||
if(nativeResolution is null) return;
|
||||
if(nativeResolution is null) return NotFound();
|
||||
|
||||
model.Diagonal = dto.Diagonal;
|
||||
model.EffectiveColors = dto.EffectiveColors;
|
||||
@@ -123,17 +123,19 @@ public class ScreensController(MarechaiContext context) : ControllerBase
|
||||
model.Width = dto.Width;
|
||||
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task<int> CreateAsync(ScreenDto dto)
|
||||
public async Task<ActionResult<int>> CreateAsync(ScreenDto dto)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return 0;
|
||||
if(userId is null) return Unauthorized();
|
||||
|
||||
var model = new Screen
|
||||
{
|
||||
@@ -155,17 +157,19 @@ public class ScreensController(MarechaiContext context) : ControllerBase
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task DeleteAsync(int id)
|
||||
public async Task<ActionResult> DeleteAsync(int id)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return;
|
||||
if(userId is null) return Unauthorized();
|
||||
Screen item = await context.Screens.FindAsync(id);
|
||||
|
||||
if(item is null) return;
|
||||
if(item is null) return NotFound();
|
||||
|
||||
context.Screens.Remove(item);
|
||||
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
@@ -74,30 +74,32 @@ public class SoftwareFamiliesController(MarechaiContext context) : ControllerBas
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task UpdateAsync(SoftwareFamilyDto dto)
|
||||
public async Task<ActionResult> UpdateAsync(SoftwareFamilyDto dto)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return;
|
||||
if(userId is null) return Unauthorized();
|
||||
SoftwareFamily model = await context.SoftwareFamilies.FindAsync(dto.Id);
|
||||
|
||||
if(model is null) return;
|
||||
if(model is null) return NotFound();
|
||||
|
||||
model.Name = dto.Name;
|
||||
model.ParentId = dto.ParentId;
|
||||
model.Introduced = dto.Introduced;
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task<ulong> CreateAsync(SoftwareFamilyDto dto)
|
||||
public async Task<ActionResult<ulong>> CreateAsync(SoftwareFamilyDto dto)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return null;
|
||||
if(userId is null) return Unauthorized();
|
||||
|
||||
var model = new SoftwareFamily
|
||||
{
|
||||
@@ -116,17 +118,19 @@ public class SoftwareFamiliesController(MarechaiContext context) : ControllerBas
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task DeleteAsync(ulong id)
|
||||
public async Task<ActionResult> DeleteAsync(ulong id)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return;
|
||||
if(userId is null) return Unauthorized();
|
||||
SoftwareFamily item = await context.SoftwareFamilies.FindAsync(id);
|
||||
|
||||
if(item is null) return;
|
||||
if(item is null) return NotFound();
|
||||
|
||||
context.SoftwareFamilies.Remove(item);
|
||||
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
@@ -105,14 +105,14 @@ public class SoftwareVariantsController(MarechaiContext context) : ControllerBas
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task UpdateAsync(SoftwareVariantDto dto)
|
||||
public async Task<ActionResult> UpdateAsync(SoftwareVariantDto dto)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return;
|
||||
if(userId is null) return Unauthorized();
|
||||
SoftwareVariant model = await context.SoftwareVariants.FindAsync(dto.Id);
|
||||
|
||||
if(model is null) return;
|
||||
if(model is null) return NotFound();
|
||||
|
||||
model.Name = dto.Name;
|
||||
model.Version = dto.Version;
|
||||
@@ -129,17 +129,19 @@ public class SoftwareVariantsController(MarechaiContext context) : ControllerBas
|
||||
model.DistributionMode = dto.DistributionMode;
|
||||
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task<ulong> CreateAsync(SoftwareVariantDto dto)
|
||||
public async Task<ActionResult<ulong>> CreateAsync(SoftwareVariantDto dto)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return null;
|
||||
if(userId is null) return Unauthorized();
|
||||
|
||||
var model = new SoftwareVariant
|
||||
{
|
||||
@@ -168,17 +170,19 @@ public class SoftwareVariantsController(MarechaiContext context) : ControllerBas
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task DeleteAsync(ulong id)
|
||||
public async Task<ActionResult> DeleteAsync(ulong id)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return;
|
||||
if(userId is null) return Unauthorized();
|
||||
SoftwareVariant item = await context.SoftwareVariants.FindAsync(id);
|
||||
|
||||
if(item is null) return;
|
||||
if(item is null) return NotFound();
|
||||
|
||||
context.SoftwareVariants.Remove(item);
|
||||
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
@@ -88,14 +88,14 @@ public class SoftwareVersionsController(MarechaiContext context) : ControllerBas
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task UpdateAsync(SoftwareVersionDto dto)
|
||||
public async Task<ActionResult> UpdateAsync(SoftwareVersionDto dto)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return;
|
||||
if(userId is null) return Unauthorized();
|
||||
SoftwareVersion model = await context.SoftwareVersions.FindAsync(dto.Id);
|
||||
|
||||
if(model is null) return;
|
||||
if(model is null) return NotFound();
|
||||
|
||||
model.Name = dto.Name;
|
||||
model.Codename = dto.Codename;
|
||||
@@ -105,17 +105,19 @@ public class SoftwareVersionsController(MarechaiContext context) : ControllerBas
|
||||
model.LicenseId = dto.LicenseId;
|
||||
model.PreviousId = dto.PreviousId;
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task<ulong> CreateAsync(SoftwareVersionDto dto)
|
||||
public async Task<ActionResult<ulong>> CreateAsync(SoftwareVersionDto dto)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return null;
|
||||
if(userId is null) return Unauthorized();
|
||||
|
||||
var model = new SoftwareVersion
|
||||
{
|
||||
@@ -138,17 +140,19 @@ public class SoftwareVersionsController(MarechaiContext context) : ControllerBas
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task DeleteAsync(ulong id)
|
||||
public async Task<ActionResult> DeleteAsync(ulong id)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return;
|
||||
if(userId is null) return Unauthorized();
|
||||
SoftwareVersion item = await context.SoftwareVersions.FindAsync(id);
|
||||
|
||||
if(item is null) return;
|
||||
if(item is null) return NotFound();
|
||||
|
||||
context.SoftwareVersions.Remove(item);
|
||||
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
@@ -62,29 +62,31 @@ public class SoundSynthsByMachineController(MarechaiContext context) : Controlle
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task DeleteAsync(long id)
|
||||
public async Task<ActionResult> DeleteAsync(long id)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return;
|
||||
if(userId is null) return Unauthorized();
|
||||
SoundByMachine item = await context.SoundByMachine.FindAsync(id);
|
||||
|
||||
if(item is null) return;
|
||||
if(item is null) return NotFound();
|
||||
|
||||
context.SoundByMachine.Remove(item);
|
||||
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task<long> CreateAsync(int soundSynthId, int machineId)
|
||||
public async Task<ActionResult<long>> CreateAsync(int soundSynthId, int machineId)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return 0;
|
||||
if(userId is null) return Unauthorized();
|
||||
|
||||
var item = new SoundByMachine
|
||||
{
|
||||
|
||||
@@ -117,14 +117,14 @@ public class SoundSynthsController(MarechaiContext context) : ControllerBase
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task UpdateAsync(SoundSynthDto dto)
|
||||
public async Task<ActionResult> UpdateAsync(SoundSynthDto dto)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return;
|
||||
if(userId is null) return Unauthorized();
|
||||
SoundSynth model = await context.SoundSynths.FindAsync(dto.Id);
|
||||
|
||||
if(model is null) return;
|
||||
if(model is null) return NotFound();
|
||||
|
||||
model.Depth = dto.Depth;
|
||||
model.Frequency = dto.Frequency;
|
||||
@@ -138,17 +138,19 @@ public class SoundSynthsController(MarechaiContext context) : ControllerBase
|
||||
model.WhiteNoise = dto.WhiteNoise;
|
||||
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task<int> CreateAsync(SoundSynthDto dto)
|
||||
public async Task<ActionResult<int>> CreateAsync(SoundSynthDto dto)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return 0;
|
||||
if(userId is null) return Unauthorized();
|
||||
|
||||
var model = new SoundSynth
|
||||
{
|
||||
@@ -174,17 +176,19 @@ public class SoundSynthsController(MarechaiContext context) : ControllerBase
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task DeleteAsync(int id)
|
||||
public async Task<ActionResult> DeleteAsync(int id)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return;
|
||||
if(userId is null) return Unauthorized();
|
||||
SoundSynth item = await context.SoundSynths.FindAsync(id);
|
||||
|
||||
if(item is null) return;
|
||||
if(item is null) return NotFound();
|
||||
|
||||
context.SoundSynths.Remove(item);
|
||||
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
@@ -28,6 +28,7 @@ using System.Linq;
|
||||
using System.Security.Claims;
|
||||
using System.Threading.Tasks;
|
||||
using Marechai.Data.Dtos;
|
||||
using Marechai.Database;
|
||||
using Marechai.Database.Models;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
@@ -63,29 +64,32 @@ public class StorageByMachineController(MarechaiContext context) : ControllerBas
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task DeleteAsync(long id)
|
||||
public async Task<ActionResult> DeleteAsync(long id)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return;
|
||||
if(userId is null) return Unauthorized();
|
||||
StorageByMachine item = await context.StorageByMachine.FindAsync(id);
|
||||
|
||||
if(item is null) return;
|
||||
if(item is null) return NotFound();
|
||||
|
||||
context.StorageByMachine.Remove(item);
|
||||
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task<long> CreateAsync(int machineId, StorageType type, StorageInterface @interface, long? capacity)
|
||||
public async Task<ActionResult<long>> CreateAsync(int machineId, StorageType type, StorageInterface @interface,
|
||||
long? capacity)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return 0;
|
||||
if(userId is null) return Unauthorized();
|
||||
|
||||
var item = new StorageByMachine
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user