feat(Lactose): convert FolderController actions to async
This commit is contained in:
@@ -29,10 +29,11 @@ namespace Lactose.Controllers;
|
||||
/// Creates a new folder for asset scanning.
|
||||
/// </summary>
|
||||
/// <param name="folderCreateDto">The folder creation data.</param>
|
||||
/// <param name="cancellationToken">Token to cancel the operation.</param>
|
||||
/// <returns>200 on success.</returns>
|
||||
[HttpPut]
|
||||
[Authorize(Roles = "Admin")]
|
||||
public ActionResult Create([FromBody] FolderCreateDto folderCreateDto) {
|
||||
public async Task<ActionResult> Create([FromBody] FolderCreateDto folderCreateDto, CancellationToken cancellationToken) {
|
||||
var accessLevel = authService.GetUserData(User)?.AccessLevel ?? EAccessLevel.User;
|
||||
|
||||
if (accessLevel != EAccessLevel.Admin) { return Unauthorized(); }
|
||||
@@ -43,40 +44,39 @@ namespace Lactose.Controllers;
|
||||
Active = false
|
||||
};
|
||||
|
||||
folderRepository.Insert(newFolder);
|
||||
await folderRepository.InsertAsync(newFolder, cancellationToken);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all tracked folders.
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">Token to cancel the operation.</param>
|
||||
/// <returns>A list of all folders.</returns>
|
||||
[HttpGet]
|
||||
[Authorize(Roles = "Admin")]
|
||||
public ActionResult<List<FolderFullDto>> GetAll() {
|
||||
public async Task<ActionResult<List<FolderFullDto>>> GetAll(CancellationToken cancellationToken) {
|
||||
var accessLevel = authService.GetUserData(User)?.AccessLevel ?? EAccessLevel.User;
|
||||
|
||||
if (accessLevel != EAccessLevel.Admin) { return Unauthorized(); }
|
||||
return Ok(
|
||||
folderRepository.GetAll()
|
||||
.Select(folder => folder.ToFolderDto())
|
||||
.ToList()
|
||||
);
|
||||
List<Folder> folders = await folderRepository.GetAllAsync(cancellationToken);
|
||||
return Ok(folders.Select(folder => folder.ToFolderDto()).ToList());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a specific folder by ID.
|
||||
/// </summary>
|
||||
/// <param name="id">The folder ID.</param>
|
||||
/// <param name="cancellationToken">Token to cancel the operation.</param>
|
||||
/// <returns>The folder details, or 404 if not found.</returns>
|
||||
[HttpGet("{id}")]
|
||||
[Authorize(Roles = "Admin")]
|
||||
public ActionResult<FolderFullDto> Get([FromRoute] Guid id) {
|
||||
public async Task<ActionResult<FolderFullDto>> Get([FromRoute] Guid id, CancellationToken cancellationToken) {
|
||||
var accessLevel = authService.GetUserData(User)?.AccessLevel ?? EAccessLevel.User;
|
||||
|
||||
if (accessLevel != EAccessLevel.Admin) { return Unauthorized(); }
|
||||
|
||||
var folder = folderRepository.Get(id);
|
||||
var folder = await folderRepository.GetAsync(id, cancellationToken);
|
||||
|
||||
if (folder == null) return NotFound();
|
||||
|
||||
@@ -88,22 +88,23 @@ namespace Lactose.Controllers;
|
||||
/// </summary>
|
||||
/// <param name="id">The folder ID.</param>
|
||||
/// <param name="folderUpdateDto">The folder update data.</param>
|
||||
/// <param name="cancellationToken">Token to cancel the operation.</param>
|
||||
/// <returns>200 on success, 404 if not found.</returns>
|
||||
[HttpPost("{id}")]
|
||||
[Authorize(Roles = "Admin")]
|
||||
public ActionResult Update([FromRoute] Guid id, [FromBody] FolderUpdateDto folderUpdateDto) {
|
||||
public async Task<ActionResult> Update([FromRoute] Guid id, [FromBody] FolderUpdateDto folderUpdateDto, CancellationToken cancellationToken) {
|
||||
var accessLevel = authService.GetUserData(User)?.AccessLevel ?? EAccessLevel.User;
|
||||
|
||||
if (accessLevel != EAccessLevel.Admin) { return Unauthorized(); }
|
||||
|
||||
Folder? folder = folderRepository.Get(id);
|
||||
Folder? folder = await folderRepository.GetAsync(id, cancellationToken);
|
||||
if (folder == null) return NotFound();
|
||||
|
||||
|
||||
folder.BasePath = folderUpdateDto.BasePath ?? folder.BasePath;
|
||||
folder.Active = folderUpdateDto.Active ?? folder.Active;
|
||||
folder.RegexPattern = folderUpdateDto.RegexPattern ?? folder.RegexPattern;
|
||||
|
||||
folderRepository.Update(id, folder);
|
||||
await folderRepository.UpdateAsync(id, folder, cancellationToken);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
@@ -112,15 +113,16 @@ namespace Lactose.Controllers;
|
||||
/// </summary>
|
||||
/// <param name="id">The folder ID.</param>
|
||||
/// <param name="count">Number of sample paths to return (default 10, max 50).</param>
|
||||
/// <param name="cancellationToken">Token to cancel the operation.</param>
|
||||
/// <returns>A list of up to <paramref name="count"/> random asset paths, or 404 if the folder is not found.</returns>
|
||||
[HttpGet("{id}/sample-paths")]
|
||||
[Authorize(Roles = "Admin")]
|
||||
public ActionResult<FolderSamplePathsDto> GetSamplePaths([FromRoute] Guid id, [FromQuery] int count = 10) {
|
||||
public async Task<ActionResult<FolderSamplePathsDto>> GetSamplePaths([FromRoute] Guid id, [FromQuery] int count = 10, CancellationToken cancellationToken = default) {
|
||||
var accessLevel = authService.GetUserData(User)?.AccessLevel ?? EAccessLevel.User;
|
||||
|
||||
if (accessLevel != EAccessLevel.Admin) { return Unauthorized(); }
|
||||
|
||||
var folder = folderRepository.Get(id);
|
||||
var folder = await folderRepository.GetAsync(id, cancellationToken);
|
||||
if (folder == null) return NotFound();
|
||||
|
||||
count = Math.Clamp(count, 1, 50);
|
||||
@@ -137,15 +139,16 @@ namespace Lactose.Controllers;
|
||||
/// Deletes a folder (stops tracking it).
|
||||
/// </summary>
|
||||
/// <param name="id">The folder ID.</param>
|
||||
/// <param name="cancellationToken">Token to cancel the operation.</param>
|
||||
/// <returns>200 on success.</returns>
|
||||
[HttpDelete("{id}")]
|
||||
[Authorize(Roles = "Admin")]
|
||||
public ActionResult Delete([FromRoute] Guid id) {
|
||||
public async Task<ActionResult> Delete([FromRoute] Guid id, CancellationToken cancellationToken) {
|
||||
var accessLevel = authService.GetUserData(User)?.AccessLevel ?? EAccessLevel.User;
|
||||
|
||||
if (accessLevel != EAccessLevel.Admin) { return Unauthorized(); }
|
||||
|
||||
folderRepository.Remove(id);
|
||||
await folderRepository.RemoveAsync(id, cancellationToken);
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user