aboutsummaryrefslogtreecommitdiff
path: root/src/Web
diff options
context:
space:
mode:
Diffstat (limited to 'src/Web')
-rw-r--r--src/Web/DevHive.Web.Models/Rating/CreateRatingWebModel.cs2
-rw-r--r--src/Web/DevHive.Web/Configurations/Extensions/ConfigureDependencyInjection.cs2
-rw-r--r--src/Web/DevHive.Web/Controllers/RatingController.cs25
3 files changed, 21 insertions, 8 deletions
diff --git a/src/Web/DevHive.Web.Models/Rating/CreateRatingWebModel.cs b/src/Web/DevHive.Web.Models/Rating/CreateRatingWebModel.cs
index 010e04e..abbb702 100644
--- a/src/Web/DevHive.Web.Models/Rating/CreateRatingWebModel.cs
+++ b/src/Web/DevHive.Web.Models/Rating/CreateRatingWebModel.cs
@@ -6,6 +6,6 @@ namespace DevHive.Web.Models.Rating
{
public Guid PostId { get; set; }
- public bool IsLiked { get; set; }
+ public bool IsLike { get; set; }
}
}
diff --git a/src/Web/DevHive.Web/Configurations/Extensions/ConfigureDependencyInjection.cs b/src/Web/DevHive.Web/Configurations/Extensions/ConfigureDependencyInjection.cs
index 6a5799f..a0d0979 100644
--- a/src/Web/DevHive.Web/Configurations/Extensions/ConfigureDependencyInjection.cs
+++ b/src/Web/DevHive.Web/Configurations/Extensions/ConfigureDependencyInjection.cs
@@ -30,7 +30,7 @@ namespace DevHive.Web.Configurations.Extensions
services.AddTransient<IPostService, PostService>();
services.AddTransient<ICommentService, CommentService>();
services.AddTransient<IFeedService, FeedService>();
- services.AddTransient<IRateService, RateService>();
+ services.AddTransient<IRatingService, RatingService>();
services.AddTransient<ICloudService, CloudinaryService>(options =>
new CloudinaryService(
diff --git a/src/Web/DevHive.Web/Controllers/RatingController.cs b/src/Web/DevHive.Web/Controllers/RatingController.cs
index 344acb2..5716b85 100644
--- a/src/Web/DevHive.Web/Controllers/RatingController.cs
+++ b/src/Web/DevHive.Web/Controllers/RatingController.cs
@@ -1,6 +1,7 @@
using System;
using System.Threading.Tasks;
using AutoMapper;
+using DevHive.Common.Jwt.Interfaces;
using DevHive.Services.Interfaces;
using DevHive.Services.Models.Post.Rating;
using DevHive.Web.Models.Rating;
@@ -17,18 +18,20 @@ namespace DevHive.Web.Controllers
private readonly IRatingService _rateService;
private readonly IUserService _userService;
private readonly IMapper _mapper;
+ private readonly IJwtService _jwtService;
- public RatingController(IRatingService rateService, IUserService userService, IMapper mapper)
+ public RatingController(IRatingService rateService, IUserService userService, IMapper mapper, IJwtService jwtService)
{
this._rateService = rateService;
this._userService = userService;
this._mapper = mapper;
+ this._jwtService = jwtService;
}
[HttpPost]
public async Task<IActionResult> RatePost(Guid userId, [FromBody] CreateRatingWebModel createRatingWebModel, [FromHeader] string authorization)
{
- if (!await this._rateService.ValidateJwtForCreating(userId, authorization))
+ if (!this._jwtService.ValidateToken(userId, authorization))
return new UnauthorizedResult();
CreateRatingServiceModel ratePostServiceModel = this._mapper.Map<CreateRatingServiceModel>(createRatingWebModel);
@@ -51,10 +54,20 @@ namespace DevHive.Web.Controllers
return new OkObjectResult(readPostRatingWebModel);
}
+ [HttpGet]
+ [Route("GetByUserAndPost")]
+ public async Task<IActionResult> GetRatingByUserAndPost(Guid userId, Guid postId)
+ {
+ ReadRatingServiceModel readRatingServiceModel = await this._rateService.GetRatingByPostAndUser(userId, postId);
+ ReadRatingWebModel readPostRatingWebModel = this._mapper.Map<ReadRatingWebModel>(readRatingServiceModel);
+
+ return new OkObjectResult(readPostRatingWebModel);
+ }
+
[HttpPut]
public async Task<IActionResult> UpdateRating(Guid userId, [FromBody] UpdateRatingWebModel updateRatingWebModel, [FromHeader] string authorization)
{
- if (!await this._rateService.ValidateJwtForRating(updateRatingWebModel.Id, authorization))
+ if (!this._jwtService.ValidateToken(userId, authorization))
return new UnauthorizedResult();
UpdateRatingServiceModel updateRatingServiceModel =
@@ -73,12 +86,12 @@ namespace DevHive.Web.Controllers
}
[HttpDelete]
- public async Task<IActionResult> DeleteTating(Guid id, [FromHeader] string authorization)
+ public async Task<IActionResult> DeleteTating(Guid userId, Guid ratingId, [FromHeader] string authorization)
{
- if (!await this._rateService.ValidateJwtForRating(id, authorization))
+ if (!this._jwtService.ValidateToken(userId, authorization))
return new UnauthorizedResult();
- return await this._rateService.DeleteRating(id) ?
+ return await this._rateService.DeleteRating(ratingId) ?
new OkResult() :
new BadRequestObjectResult("Could not delete Rating");
}