aboutsummaryrefslogtreecommitdiff
path: root/src/DevHive.Web
diff options
context:
space:
mode:
Diffstat (limited to 'src/DevHive.Web')
-rw-r--r--src/DevHive.Web/Configurations/Extensions/ConfigureDependencyInjection.cs1
-rw-r--r--src/DevHive.Web/Configurations/Mapping/RatingMappings.cs16
-rw-r--r--src/DevHive.Web/Controllers/RateController.cs40
-rw-r--r--src/DevHive.Web/Models/Post/Rating/RatePostWebModel.cs11
-rw-r--r--src/DevHive.Web/Models/Post/Rating/ReadPostRatingWebModel.cs15
5 files changed, 83 insertions, 0 deletions
diff --git a/src/DevHive.Web/Configurations/Extensions/ConfigureDependencyInjection.cs b/src/DevHive.Web/Configurations/Extensions/ConfigureDependencyInjection.cs
index 5c0d378..88f21d4 100644
--- a/src/DevHive.Web/Configurations/Extensions/ConfigureDependencyInjection.cs
+++ b/src/DevHive.Web/Configurations/Extensions/ConfigureDependencyInjection.cs
@@ -32,6 +32,7 @@ namespace DevHive.Web.Configurations.Extensions
cloudName: configuration.GetSection("Cloud").GetSection("cloudName").Value,
apiKey: configuration.GetSection("Cloud").GetSection("apiKey").Value,
apiSecret: configuration.GetSection("Cloud").GetSection("apiSecret").Value));
+ services.AddTransient<IRateService, RateService>();
}
}
}
diff --git a/src/DevHive.Web/Configurations/Mapping/RatingMappings.cs b/src/DevHive.Web/Configurations/Mapping/RatingMappings.cs
new file mode 100644
index 0000000..4e071de
--- /dev/null
+++ b/src/DevHive.Web/Configurations/Mapping/RatingMappings.cs
@@ -0,0 +1,16 @@
+using AutoMapper;
+using DevHive.Services.Models.Post.Rating;
+using DevHive.Web.Models.Post.Rating;
+
+namespace DevHive.Web.Configurations.Mapping
+{
+ public class RatingMappings : Profile
+ {
+ public RatingMappings()
+ {
+ CreateMap<RatePostWebModel, RatePostServiceModel>();
+
+ CreateMap<ReadPostRatingServiceModel, ReadPostRatingWebModel>();
+ }
+ }
+}
diff --git a/src/DevHive.Web/Controllers/RateController.cs b/src/DevHive.Web/Controllers/RateController.cs
new file mode 100644
index 0000000..68b859b
--- /dev/null
+++ b/src/DevHive.Web/Controllers/RateController.cs
@@ -0,0 +1,40 @@
+using System;
+using System.Threading.Tasks;
+using AutoMapper;
+using DevHive.Services.Interfaces;
+using DevHive.Services.Models.Post.Rating;
+using DevHive.Web.Models.Post.Rating;
+using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Mvc;
+
+namespace DevHive.Web.Controllers
+{
+ [ApiController]
+ [Route("api/[controller]")]
+ public class RateController
+ {
+ private readonly IRateService _rateService;
+ private readonly IUserService _userService;
+ private readonly IMapper _mapper;
+
+ public RateController(IRateService rateService, IUserService userService, IMapper mapper)
+ {
+ this._rateService = rateService;
+ this._userService = userService;
+ this._mapper = mapper;
+ }
+
+ [HttpPost]
+ [Authorize(Roles = "Admin,User")]
+ public async Task<IActionResult> RatePost(Guid userId, [FromBody] RatePostWebModel ratePostWebModel, [FromHeader] string authorization)
+ {
+ RatePostServiceModel ratePostServiceModel = this._mapper.Map<RatePostServiceModel>(ratePostWebModel);
+ ratePostServiceModel.UserId = userId;
+
+ ReadPostRatingServiceModel readPostRatingServiceModel = await this._rateService.RatePost(ratePostServiceModel);
+ ReadPostRatingWebModel readPostRatingWebModel = this._mapper.Map<ReadPostRatingWebModel>(readPostRatingServiceModel);
+
+ return new OkObjectResult(readPostRatingWebModel);
+ }
+ }
+}
diff --git a/src/DevHive.Web/Models/Post/Rating/RatePostWebModel.cs b/src/DevHive.Web/Models/Post/Rating/RatePostWebModel.cs
new file mode 100644
index 0000000..5f0e58f
--- /dev/null
+++ b/src/DevHive.Web/Models/Post/Rating/RatePostWebModel.cs
@@ -0,0 +1,11 @@
+using System;
+
+namespace DevHive.Web.Models.Post.Rating
+{
+ public class RatePostWebModel
+ {
+ public Guid PostId { get; set; }
+
+ public bool Liked { get; set; }
+ }
+}
diff --git a/src/DevHive.Web/Models/Post/Rating/ReadPostRatingWebModel.cs b/src/DevHive.Web/Models/Post/Rating/ReadPostRatingWebModel.cs
new file mode 100644
index 0000000..a551fb8
--- /dev/null
+++ b/src/DevHive.Web/Models/Post/Rating/ReadPostRatingWebModel.cs
@@ -0,0 +1,15 @@
+using System;
+
+namespace DevHive.Web.Models.Post.Rating
+{
+ public class ReadPostRatingWebModel
+ {
+ public Guid Id { get; set; }
+
+ public Guid PostId { get; set; }
+
+ public int Likes { get; set; }
+
+ public int Dislikes { get; set; }
+ }
+}