From e31d09d1ef195bbcc1f8455d58f401125a3050a9 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Wed, 12 May 2021 16:04:48 +0300 Subject: Implemented interfaces for services in add feature template; Added an interfaces for UserService --- ExamTemplate/Services/Interfaces/IUserService.cs | 27 +++++++++++++++++++++++ ExamTemplate/Services/UserService.cs | 3 ++- ExamTemplate/Web/Controllers/AccountController.cs | 6 ++--- ExamTemplate/Web/Startup.cs | 3 ++- 4 files changed, 34 insertions(+), 5 deletions(-) create mode 100644 ExamTemplate/Services/Interfaces/IUserService.cs (limited to 'ExamTemplate') diff --git a/ExamTemplate/Services/Interfaces/IUserService.cs b/ExamTemplate/Services/Interfaces/IUserService.cs new file mode 100644 index 0000000..7f4c26f --- /dev/null +++ b/ExamTemplate/Services/Interfaces/IUserService.cs @@ -0,0 +1,27 @@ +using System.Security.Claims; +using System.Threading.Tasks; +using ExamTemplate.Services.Models.User; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; + +namespace ExamTemplate.Services.Interfaces +{ + public interface IUserService + { + Task RegisterUserAsync(RegisterUserServiceModel registerUserServiceModel); + + Task LoginUserAsync(LoginUserServiceModel loginUserServiceModel); + + Task LogoutAsync(); + + Task GetUserByUsernameAsync(string username); + + Task GetUserByClaimsAsync(ClaimsPrincipal claimsPrincipal); + + Task EditUserAsync(ClaimsPrincipal claimsPrincipal, EditUserServiceModel editUserServiceModel); + + Task DeleteUserAsync(ClaimsPrincipal claimsPrincipal); + + bool IsSignedIn(ClaimsPrincipal claimsPrincipal); + } +} diff --git a/ExamTemplate/Services/UserService.cs b/ExamTemplate/Services/UserService.cs index 8c54e0f..3099bda 100644 --- a/ExamTemplate/Services/UserService.cs +++ b/ExamTemplate/Services/UserService.cs @@ -7,10 +7,11 @@ using ExamTemplate.Data.Models; using ExamTemplate.Services.Models.User; using Microsoft.AspNetCore.Identity; using Microsoft.EntityFrameworkCore; +using ExamTemplate.Services.Interfaces; namespace ExamTemplate.Services { - public class UserService + public class UserService : IUserService { private readonly IMapper _autoMapper; private readonly TemplateContext _context; diff --git a/ExamTemplate/Web/Controllers/AccountController.cs b/ExamTemplate/Web/Controllers/AccountController.cs index a7ad771..b7a1207 100644 --- a/ExamTemplate/Web/Controllers/AccountController.cs +++ b/ExamTemplate/Web/Controllers/AccountController.cs @@ -1,4 +1,4 @@ -using ExamTemplate.Services; +using ExamTemplate.Services.Interfaces; using Microsoft.AspNetCore.Mvc; using ExamTemplate.Web.Models.User; using AutoMapper; @@ -12,9 +12,9 @@ namespace ExamTemplate.Web.Controllers public class AccountController : Controller { private readonly IMapper _autoMapper; - private readonly UserService _userService; + private readonly IUserService _userService; - public AccountController(IMapper autoMapper, UserService userService) + public AccountController(IMapper autoMapper, IUserService userService) { this._autoMapper = autoMapper; this._userService = userService; diff --git a/ExamTemplate/Web/Startup.cs b/ExamTemplate/Web/Startup.cs index 691d60f..d627c52 100644 --- a/ExamTemplate/Web/Startup.cs +++ b/ExamTemplate/Web/Startup.cs @@ -4,6 +4,7 @@ using ExamTemplate.Common; using ExamTemplate.Data; using ExamTemplate.Data.Models; using ExamTemplate.Services; +using ExamTemplate.Services.Interfaces; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Identity; @@ -38,7 +39,7 @@ namespace ExamTemplate.Web cloudName: this.Configuration.GetSection("Cloud").GetSection("cloudName").Value, apiKey: this.Configuration.GetSection("Cloud").GetSection("apiKey").Value, apiSecret: this.Configuration.GetSection("Cloud").GetSection("apiSecret").Value)); - services.AddTransient(); + services.AddTransient(); /* * Database configuration -- cgit v1.2.3