mirror of
https://github.com/Kareadita/Kavita.git
synced 2025-07-09 03:04:19 -04:00
Merge pull request #19 from Kareadita/feature/ui-cleanup
Update Library API
This commit is contained in:
commit
98cb94f31c
@ -106,15 +106,15 @@ namespace API.Controllers
|
||||
|
||||
[Authorize(Policy = "RequireAdminRole")]
|
||||
[HttpPut("update-for")]
|
||||
public async Task<ActionResult<MemberDto>> UpdateLibrary(UpdateLibraryDto updateLibraryDto)
|
||||
public async Task<ActionResult<MemberDto>> AddLibraryToUser(UpdateLibraryForUserDto updateLibraryForUserDto)
|
||||
{
|
||||
var user = await _userRepository.GetUserByUsernameAsync(updateLibraryDto.Username);
|
||||
var user = await _userRepository.GetUserByUsernameAsync(updateLibraryForUserDto.Username);
|
||||
|
||||
if (user == null) return BadRequest("Could not validate user");
|
||||
|
||||
user.Libraries = new List<Library>();
|
||||
|
||||
foreach (var selectedLibrary in updateLibraryDto.SelectedLibraries)
|
||||
foreach (var selectedLibrary in updateLibraryForUserDto.SelectedLibraries)
|
||||
{
|
||||
user.Libraries.Add(_mapper.Map<Library>(selectedLibrary));
|
||||
}
|
||||
@ -153,5 +153,34 @@ namespace API.Controllers
|
||||
{
|
||||
return Ok(await _libraryRepository.DeleteLibrary(libraryId));
|
||||
}
|
||||
|
||||
[Authorize(Policy = "RequireAdminRole")]
|
||||
[HttpPost("update")]
|
||||
public async Task<ActionResult> UpdateLibrary(UpdateLibraryDto libraryForUserDto)
|
||||
{
|
||||
var library = await _libraryRepository.GetLibraryForIdAsync(libraryForUserDto.Id);
|
||||
|
||||
var originalFolders = library.Folders.Select(x => x.Path);
|
||||
var differenceBetweenFolders = originalFolders.Except(libraryForUserDto.Folders);
|
||||
|
||||
library.Name = libraryForUserDto.Name;
|
||||
library.Folders = libraryForUserDto.Folders.Select(s => new FolderPath() {Path = s}).ToList();
|
||||
|
||||
|
||||
|
||||
_libraryRepository.Update(library);
|
||||
|
||||
if (await _libraryRepository.SaveAllAsync())
|
||||
{
|
||||
if (differenceBetweenFolders.Any())
|
||||
{
|
||||
BackgroundJob.Enqueue(() => _directoryService.ScanLibrary(library.Id));
|
||||
}
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
return BadRequest("There was a critical issue updating the library.");
|
||||
}
|
||||
}
|
||||
}
|
@ -2,10 +2,10 @@
|
||||
|
||||
namespace API.DTOs
|
||||
{
|
||||
// NOTE: Should this be a Record? https://www.youtube.com/watch?v=9Byvwa9yF-I
|
||||
public class UpdateLibraryDto
|
||||
{
|
||||
public string Username { get; init; }
|
||||
public IEnumerable<LibraryDto> SelectedLibraries { get; init; }
|
||||
public int Id { get; init; }
|
||||
public string Name { get; init; }
|
||||
public IEnumerable<string> Folders { get; init; }
|
||||
}
|
||||
}
|
10
API/DTOs/UpdateLibraryForUserDto.cs
Normal file
10
API/DTOs/UpdateLibraryForUserDto.cs
Normal file
@ -0,0 +1,10 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace API.DTOs
|
||||
{
|
||||
public class UpdateLibraryForUserDto
|
||||
{
|
||||
public string Username { get; init; }
|
||||
public IEnumerable<LibraryDto> SelectedLibraries { get; init; }
|
||||
}
|
||||
}
|
@ -45,6 +45,7 @@ namespace API
|
||||
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "API v1"));
|
||||
}
|
||||
|
||||
|
||||
app.UseHangfireDashboard();
|
||||
backgroundJobs.Enqueue(() => Console.WriteLine("Hello world from Hangfire!"));
|
||||
|
||||
|
BIN
images/Image-1.jpg
Normal file
BIN
images/Image-1.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.1 MiB |
Loading…
x
Reference in New Issue
Block a user