diff options
| -rw-r--r-- | ExamTemplate/Services/Interfaces/IUserService.cs | 27 | ||||
| -rw-r--r-- | ExamTemplate/Services/UserService.cs | 3 | ||||
| -rw-r--r-- | ExamTemplate/Web/Controllers/AccountController.cs | 6 | ||||
| -rw-r--r-- | ExamTemplate/Web/Startup.cs | 3 | ||||
| -rwxr-xr-x | tools/add-feature-template.sh | 36 |
5 files changed, 64 insertions, 11 deletions
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<bool> RegisterUserAsync(RegisterUserServiceModel registerUserServiceModel); + + Task<bool> LoginUserAsync(LoginUserServiceModel loginUserServiceModel); + + Task LogoutAsync(); + + Task<UserServiceModel> GetUserByUsernameAsync(string username); + + Task<UserServiceModel> GetUserByClaimsAsync(ClaimsPrincipal claimsPrincipal); + + Task<bool> EditUserAsync(ClaimsPrincipal claimsPrincipal, EditUserServiceModel editUserServiceModel); + + Task<bool> 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<UserService>();
+ services.AddTransient<IUserService, UserService>();
/*
* Database configuration
diff --git a/tools/add-feature-template.sh b/tools/add-feature-template.sh index 131f2c0..ca0c8d5 100755 --- a/tools/add-feature-template.sh +++ b/tools/add-feature-template.sh @@ -64,9 +64,33 @@ fi dir="../$project_name/Services" # {{{ ---------------------------> -# Create Service +# Create Service and Interface + +cat > $dir/Interfaces/I${feature_name}Service.cs<< EOF +using System; +using System.Threading.Tasks; +using $project_name.Services.Models.$feature_name; +using System.Collections.Generic; + +namespace $project_name.Services.Interfaces +{ + public interface I${feature_name}Service + { + Task<bool> CreateAsync(Create${feature_name}ServiceModel create${feature_name}ServiceModel); + + Task<${feature_name}ServiceModel> GetByIdAsync(Guid id); + + List<${feature_name}ServiceModel> GetAll(); + + Task<bool> EditAsync(Edit${feature_name}ServiceModel edit${feature_name}ServiceModel); + + Task<bool> DeleteAsync(Guid id); + } +} +EOF cat > $dir/${feature_name}Service.cs<< EOF +using $project_name.Services.Interfaces; using System; using System.Threading.Tasks; using AutoMapper; @@ -78,7 +102,7 @@ using System.Linq; namespace $project_name.Services { - public class ${feature_name}Service + public class ${feature_name}Service : I${feature_name}Service { private readonly IMapper _autoMapper; private readonly ${project_name}Context _context; @@ -221,7 +245,7 @@ dir="../$project_name/Web" startup_path="$dir/Startup.cs" service_name="${feature_name}Service" if ! grep -q "$service_name" "$startup_path"; then - sed -z -i "s/.*AddTransient[^\n]*\n/&\t\t\tservices.AddTransient<$service_name>();\n/" $startup_path + sed -z -i "s/.*AddTransient[^\n]*\n/&\t\t\tservices.AddTransient<I$service_name, $service_name>();\n/" $startup_path fi # }}} ---------------------------< @@ -359,7 +383,7 @@ cat > $subdir/${feature_name}Controller.cs<< EOF using System; using System.Threading.Tasks; using AutoMapper; -using $project_name.Services; +using $project_name.Services.Interfaces; using $project_name.Services.Models.$feature_name; using $project_name.Web.Models.$feature_name; using Microsoft.AspNetCore.Mvc; @@ -369,9 +393,9 @@ namespace $project_name.Web.Controllers public class ${feature_name}Controller : Controller { private readonly IMapper _autoMapper; - private readonly ${feature_name}Service _service; + private readonly I${feature_name}Service _service; - public ${feature_name}Controller(IMapper autoMapper, ${feature_name}Service service) + public ${feature_name}Controller(IMapper autoMapper, I${feature_name}Service service) { this._autoMapper = autoMapper; this._service = service; |
