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 delete a Library.

Joseph Milazzo5e18c1bf3a52
diff --git a/API/Controllers/LibraryController.cs b/API/Controllers/LibraryController.cs
index 40e9eb1f1..b72094f17 100644
--- a/API/Controllers/LibraryController.cs
+++ b/API/Controllers/LibraryController.cs
@@ -146,5 +146,12 @@ namespace API.Controllers
{
return Ok(await _seriesRepository.GetSeriesDtoForLibraryIdAsync(libraryId));
}
+
+ [Authorize(Policy = "RequireAdminRole")]
+ [HttpDelete("delete")]
+ public async Task<ActionResult<bool>> DeleteLibrary(int libraryId)
+ {
+ return Ok(await _libraryRepository.DeleteLibrary(libraryId));
+ }
}
}
\ No newline at end of file
diff --git a/API/Data/LibraryRepository.cs b/API/Data/LibraryRepository.cs
index ef8b416d3..9c2c74b29 100644
--- a/API/Data/LibraryRepository.cs
+++ b/API/Data/LibraryRepository.cs
@@ -53,6 +53,13 @@ namespace API.Data
.SingleAsync();
}
+ public async Task<bool> DeleteLibrary(int libraryId)
+ {
+ var library = await GetLibraryForIdAsync(libraryId);
+ _context.Library.Remove(library);
+ return await _context.SaveChangesAsync() > 0;
+ }
+
public async Task<IEnumerable<LibraryDto>> GetLibrariesAsync()
{
return await _context.Library
diff --git a/API/Interfaces/ILibraryRepository.cs b/API/Interfaces/ILibraryRepository.cs
index 93a0832ae..5a919770c 100644
--- a/API/Interfaces/ILibraryRepository.cs
+++ b/API/Interfaces/ILibraryRepository.cs
@@ -15,5 +15,7 @@ namespace API.Interfaces
bool SaveAll();
Task<IEnumerable<LibraryDto>> GetLibrariesDtoForUsernameAsync(string userName);
Task<Library> GetLibraryForNameAsync(string libraryName);
+
+ Task<bool> DeleteLibrary(int libraryId);
}
}
\ No newline at end of file