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> 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 DeleteLibrary(int libraryId) + { + var library = await GetLibraryForIdAsync(libraryId); + _context.Library.Remove(library); + return await _context.SaveChangesAsync() > 0; + } + public async Task> 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> GetLibrariesDtoForUsernameAsync(string userName); Task GetLibraryForNameAsync(string libraryName); + + Task DeleteLibrary(int libraryId); } } \ No newline at end of file