aboutsummaryrefslogtreecommitdiff
path: root/src/Web/DevHive.Web
diff options
context:
space:
mode:
authortranstrike <transtrike@gmail.com>2021-04-07 18:20:44 +0300
committertranstrike <transtrike@gmail.com>2021-04-07 18:20:44 +0300
commitf4eac9c89bef0c21d7ccb29cb0841fa621c79f46 (patch)
treefb17fa087095bc32977e6c399dbc98bdf1411120 /src/Web/DevHive.Web
parent51f911378773ffbcebb62b135010d46a1d9aa0d5 (diff)
downloadDevHive-f4eac9c89bef0c21d7ccb29cb0841fa621c79f46.tar
DevHive-f4eac9c89bef0c21d7ccb29cb0841fa621c79f46.tar.gz
DevHive-f4eac9c89bef0c21d7ccb29cb0841fa621c79f46.zip
Friends endpoint init
Diffstat (limited to 'src/Web/DevHive.Web')
-rw-r--r--src/Web/DevHive.Web/Configurations/Extensions/ConfigureDependencyInjection.cs3
-rw-r--r--src/Web/DevHive.Web/Controllers/FriendsController.cs50
2 files changed, 53 insertions, 0 deletions
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<ICommentService, CommentService>();
services.AddTransient<IFeedService, FeedService>();
services.AddTransient<IRatingService, RatingService>();
+ services.AddTransient<IProfilePictureService, ProfilePictureService>();
+ services.AddTransient<IUserService, UserService>();
+ services.AddTransient<IFriendsService, FriendsService>();
services.AddTransient<ICloudService, CloudinaryService>(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<IActionResult> 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<IActionResult> RemoveFriend(Guid userId, Guid friendId, [FromHeader] string authorization)
+ {
+ if (!this._jwtService.ValidateToken(userId, authorization))
+ return new UnauthorizedResult();
+
+ return null;
+ }
+ }
+}