Skip to content

Kavita is a fast, feature rich, cross platform reading server. Built with the goal of being a full solution for all your reading needs. Setup your own server and share your reading collection with your friends and family.

Implemented the ability to update a library including folders.

Joseph Milazzo219f6e675a0f
diff --git a/API/Controllers/LibraryController.cs b/API/Controllers/LibraryController.cs
index b72094f17..aba75d760 100644
--- a/API/Controllers/LibraryController.cs
+++ b/API/Controllers/LibraryController.cs
@@ -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));
}
@@ -152,6 +152,25 @@ namespace API.Controllers
public async Task<ActionResult<bool>> DeleteLibrary(int libraryId)
{
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);
+ library.Name = libraryForUserDto.Name;
+ library.Folders = libraryForUserDto.Folders.Select(s => new FolderPath() {Path = s}).ToList();
+
+ _libraryRepository.Update(library);
+
+ if (await _libraryRepository.SaveAllAsync())
+ {
+ // TODO: We should probably call ScanLibrary after this
+ return Ok();
+ }
+
+ return BadRequest("There was a critical issue updating the library.");
+ }
}
}
\ No newline at end of file
diff --git a/API/DTOs/UpdateLibraryDto.cs b/API/DTOs/UpdateLibraryDto.cs
index c664b1df6..0a922172a 100644
--- a/API/DTOs/UpdateLibraryDto.cs
+++ b/API/DTOs/UpdateLibraryDto.cs
@@ -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; }
}
}
\ No newline at end of file
diff --git a/API/DTOs/UpdateLibraryForUserDto.cs b/API/DTOs/UpdateLibraryForUserDto.cs
new file mode 100644
index 000000000..5280f3dd7
--- /dev/null
+++ b/API/DTOs/UpdateLibraryForUserDto.cs
@@ -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; }
+ }
+}
\ No newline at end of file
diff --git a/API/Startup.cs b/API/Startup.cs
index 4ad56e85a..28ed23b46 100644
--- a/API/Startup.cs
+++ b/API/Startup.cs
@@ -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!"));
diff --git a/images/Image-1.jpg b/images/Image-1.jpg
new file mode 100644
index 000000000..b4dfd57c6
Binary files /dev/null and b/images/Image-1.jpg differ