From f8d7581a1287df4faf4dcd4928a471a87493968d Mon Sep 17 00:00:00 2001 From: Andrew Song Date: Sun, 20 Dec 2020 18:32:24 -0600 Subject: [PATCH] adding admin exists api --- API/Controllers/AdminController.cs | 24 ++++++++++++++++++++++++ API/Data/UserRepository.cs | 6 ++++++ API/Interfaces/IUserRepository.cs | 1 + 3 files changed, 31 insertions(+) create mode 100644 API/Controllers/AdminController.cs diff --git a/API/Controllers/AdminController.cs b/API/Controllers/AdminController.cs new file mode 100644 index 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> AdminExists() + { + return await _userRepository.AdminExists(); + } + + + } +} \ No newline at end of file diff --git a/API/Data/UserRepository.cs b/API/Data/UserRepository.cs index 1a8692c97..3ecf5578e 100644 --- a/API/Data/UserRepository.cs +++ b/API/Data/UserRepository.cs @@ -62,5 +62,11 @@ namespace API.Data .ProjectTo(_mapper.ConfigurationProvider) .SingleOrDefaultAsync(); } + + public async Task AdminExists() + { + return await _context.Users.AnyAsync(x => x.IsAdmin); + + } } } \ No newline at end of file diff --git a/API/Interfaces/IUserRepository.cs b/API/Interfaces/IUserRepository.cs index 69b872821..4ed10236f 100644 --- a/API/Interfaces/IUserRepository.cs +++ b/API/Interfaces/IUserRepository.cs @@ -15,5 +15,6 @@ namespace API.Interfaces Task GetUserByUsernameAsync(string username); Task> GetMembersAsync(); Task GetMemberAsync(string username); + Task AdminExists(); } } \ No newline at end of file