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.
C# annotationscbzcomicinfocomicscomics-readercross-platformcsharpepubepub-readerfreelinuxmangamedia-servermetadataopdsopds-feedpdfself-hostedubooquitywindows
adding admin exists api
Andrew Songf8d7581a1287
diff --git a/API/Controllers/AdminController.cs b/API/Controllers/AdminController.csnew file mode 100644index 000000000..155a53bfa--- /dev/null+++ b/API/Controllers/AdminController.cs@@ -0,0 +1,24 @@+using System.Threading.Tasks;+using API.Interfaces;+using Microsoft.AspNetCore.Mvc;++namespace API.Controllers+{+ public class AdminController : BaseApiController+ {+ private readonly IUserRepository _userRepository;++ public AdminController(IUserRepository userRepository)+ {+ _userRepository = userRepository;+ }++ [HttpGet]+ public async Task<ActionResult<bool>> AdminExists()+ {+ return await _userRepository.AdminExists();+ }+++ }+}\ No newline at end of filediff --git a/API/Data/UserRepository.cs b/API/Data/UserRepository.csindex 1a8692c97..3ecf5578e 100644--- a/API/Data/UserRepository.cs+++ b/API/Data/UserRepository.cs@@ -62,5 +62,11 @@ namespace API.Data.ProjectTo<MemberDto>(_mapper.ConfigurationProvider).SingleOrDefaultAsync();}++ public async Task<bool> AdminExists()+ {+ return await _context.Users.AnyAsync(x => x.IsAdmin);++ }}}\ No newline at end of filediff --git a/API/Interfaces/IUserRepository.cs b/API/Interfaces/IUserRepository.csindex 69b872821..4ed10236f 100644--- a/API/Interfaces/IUserRepository.cs+++ b/API/Interfaces/IUserRepository.cs@@ -15,5 +15,6 @@ namespace API.InterfacesTask<AppUser> GetUserByUsernameAsync(string username);Task<IEnumerable<MemberDto>> GetMembersAsync();Task<MemberDto> GetMemberAsync(string username);+ Task<bool> AdminExists();}}\ No newline at end of file