From f4eac9c89bef0c21d7ccb29cb0841fa621c79f46 Mon Sep 17 00:00:00 2001 From: transtrike Date: Wed, 7 Apr 2021 18:20:44 +0300 Subject: Friends endpoint init --- .../DevHive.Services/Interfaces/IFriendsService.cs | 11 +++++ .../DevHive.Services/Services/FriendsService.cs | 34 +++++++++++++++ .../Extensions/ConfigureDependencyInjection.cs | 3 ++ .../DevHive.Web/Controllers/FriendsController.cs | 50 ++++++++++++++++++++++ 4 files changed, 98 insertions(+) create mode 100644 src/Services/DevHive.Services/Interfaces/IFriendsService.cs create mode 100644 src/Services/DevHive.Services/Services/FriendsService.cs create mode 100644 src/Web/DevHive.Web/Controllers/FriendsController.cs (limited to 'src') diff --git a/src/Services/DevHive.Services/Interfaces/IFriendsService.cs b/src/Services/DevHive.Services/Interfaces/IFriendsService.cs new file mode 100644 index 0000000..6ab7b90 --- /dev/null +++ b/src/Services/DevHive.Services/Interfaces/IFriendsService.cs @@ -0,0 +1,11 @@ +using System; +using System.Threading.Tasks; + +namespace DevHive.Services.Interfaces +{ + public interface IFriendsService + { + Task AddFriend(Guid userId, Guid friendId); + Task RemoveFriend(Guid userId, Guid friendId); + } +} diff --git a/src/Services/DevHive.Services/Services/FriendsService.cs b/src/Services/DevHive.Services/Services/FriendsService.cs new file mode 100644 index 0000000..7577572 --- /dev/null +++ b/src/Services/DevHive.Services/Services/FriendsService.cs @@ -0,0 +1,34 @@ +using System; +using System.Threading.Tasks; +using AutoMapper; +using DevHive.Common.Jwt.Interfaces; +using DevHive.Services.Interfaces; + +namespace DevHive.Services.Services +{ + public class FriendsService : IFriendsService + { + private readonly IUserService _userService; + private readonly IMapper _userMapper; + private readonly IJwtService _jwtService; + + public FriendsService(IUserService userService, + IMapper mapper, + IJwtService jwtService) + { + this._userService = userService; + this._userMapper = mapper; + this._jwtService = jwtService; + } + + public async Task AddFriend(Guid userId, Guid friendId) + { + return new { Message = "FUCK YOU" }; + } + + public async Task RemoveFriend(Guid userId, Guid friendId) + { + return new { Message = "FUCK YOU" }; + } + } +} diff --git a/src/Web/DevHive.Web/Configurations/Extensions/ConfigureDependencyInjection.cs b/src/Web/DevHive.Web/Configurations/Extensions/ConfigureDependencyInjection.cs index a0d0979..ae14520 100644 --- a/src/Web/DevHive.Web/Configurations/Extensions/ConfigureDependencyInjection.cs +++ b/src/Web/DevHive.Web/Configurations/Extensions/ConfigureDependencyInjection.cs @@ -31,6 +31,9 @@ namespace DevHive.Web.Configurations.Extensions services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(options => new CloudinaryService( diff --git a/src/Web/DevHive.Web/Controllers/FriendsController.cs b/src/Web/DevHive.Web/Controllers/FriendsController.cs new file mode 100644 index 0000000..00d70a4 --- /dev/null +++ b/src/Web/DevHive.Web/Controllers/FriendsController.cs @@ -0,0 +1,50 @@ +using System; +using System.Threading.Tasks; +using AutoMapper; +using DevHive.Common.Jwt.Interfaces; +using DevHive.Common.Models.Identity; +using DevHive.Services.Interfaces; +using DevHive.Services.Models.User; +using DevHive.Web.Models.User; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using NSwag.Annotations; + +namespace DevHive.Web.Controllers +{ + [ApiController] + [Route("api/[controller]")] + public class FriendsController + { + private readonly IFriendsService _friendsService; + private readonly IMapper _mapper; + private readonly IJwtService _jwtService; + + public FriendsController(IFriendsService friendsService, IMapper mapper, IJwtService jwtService) + { + this._friendsService = friendsService; + this._mapper = mapper; + this._jwtService = jwtService; + } + + [HttpPost] + [Authorize(Roles = "User,Admin")] + public async Task AddFriend(Guid userId, Guid friendId, [FromHeader] string authorization) + { + if (!this._jwtService.ValidateToken(userId, authorization)) + return new UnauthorizedResult(); + + return null; + } + + [HttpDelete] + [Authorize(Roles = "User,Admin")] + public async Task RemoveFriend(Guid userId, Guid friendId, [FromHeader] string authorization) + { + if (!this._jwtService.ValidateToken(userId, authorization)) + return new UnauthorizedResult(); + + return null; + } + } +} -- cgit v1.2.3