diff options
| author | Danail Dimitrov <danaildimitrov321@gmail.com> | 2021-02-26 23:00:50 +0200 |
|---|---|---|
| committer | Danail Dimitrov <danaildimitrov321@gmail.com> | 2021-02-26 23:00:50 +0200 |
| commit | 379eda6a42fdba0a6ed7e7ae53e0fbf2acd774b6 (patch) | |
| tree | cee90836aaa0d4f540a40b32a589a783eb71fdb8 /src/Web | |
| parent | 8e0038628e866ac5ce716e7971e150d2a8f23f4c (diff) | |
| download | DevHive-379eda6a42fdba0a6ed7e7ae53e0fbf2acd774b6.tar DevHive-379eda6a42fdba0a6ed7e7ae53e0fbf2acd774b6.tar.gz DevHive-379eda6a42fdba0a6ed7e7ae53e0fbf2acd774b6.zip | |
Adding update layer for rating_system
Diffstat (limited to 'src/Web')
3 files changed, 37 insertions, 2 deletions
diff --git a/src/Web/DevHive.Web.Models/Rating/UpdateRatingWebModel.cs b/src/Web/DevHive.Web.Models/Rating/UpdateRatingWebModel.cs new file mode 100644 index 0000000..07ba0c3 --- /dev/null +++ b/src/Web/DevHive.Web.Models/Rating/UpdateRatingWebModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DevHive.Web.Models.Rating +{ + public class UpdateRatingWebModel + { + public Guid PostId { get; set; } + + public bool IsLike { get; set; } + } +} diff --git a/src/Web/DevHive.Web/Configurations/Mapping/RatingMappings.cs b/src/Web/DevHive.Web/Configurations/Mapping/RatingMappings.cs index aabee01..23c3eeb 100644 --- a/src/Web/DevHive.Web/Configurations/Mapping/RatingMappings.cs +++ b/src/Web/DevHive.Web/Configurations/Mapping/RatingMappings.cs @@ -11,6 +11,8 @@ namespace DevHive.Web.Configurations.Mapping CreateMap<CreateRatingWebModel, CreateRatingServiceModel>(); CreateMap<ReadRatingServiceModel, ReadRatingWebModel>(); + + CreateMap<UpdateRatingWebModel, UpdateRatingServiceModel>(); } } } diff --git a/src/Web/DevHive.Web/Controllers/RatingController.cs b/src/Web/DevHive.Web/Controllers/RatingController.cs index d2a7801..216dc27 100644 --- a/src/Web/DevHive.Web/Controllers/RatingController.cs +++ b/src/Web/DevHive.Web/Controllers/RatingController.cs @@ -10,6 +10,7 @@ using Microsoft.AspNetCore.Mvc; namespace DevHive.Web.Controllers { [ApiController] + //[Authorize(Roles = "Admin,User")] [Route("api/[controller]")] public class RatingController { @@ -25,7 +26,6 @@ namespace DevHive.Web.Controllers } [HttpPost] - [Authorize(Roles = "Admin,User")] public async Task<IActionResult> RatePost(Guid userId, [FromBody] CreateRatingWebModel createRatingWebModel, [FromHeader] string authorization) { CreateRatingServiceModel ratePostServiceModel = this._mapper.Map<CreateRatingServiceModel>(createRatingWebModel); @@ -36,7 +36,7 @@ namespace DevHive.Web.Controllers if (Guid.Empty == id) return new BadRequestResult(); - return new OkObjectResult(id); + return new OkObjectResult(new { Id = id }); } [HttpGet] @@ -47,5 +47,23 @@ namespace DevHive.Web.Controllers return new OkObjectResult(readPostRatingWebModel); } + + [HttpPut] + public async Task<IActionResult> UpdateRating(Guid userId, [FromBody] UpdateRatingWebModel updateRatingWebModel, [FromHeader] string authorization) + { + UpdateRatingServiceModel updateRatingServiceModel = + this._mapper.Map<UpdateRatingServiceModel>(updateRatingWebModel); + updateRatingServiceModel.UserId = userId; + + ReadRatingServiceModel readRatingServiceModel = await this._rateService.UpdateRating(updateRatingServiceModel); + + if (readRatingServiceModel == null) + return new BadRequestResult(); + else + { + ReadRatingWebModel readRatingWebModel = this._mapper.Map<ReadRatingWebModel>(readRatingServiceModel); + return new OkObjectResult(readRatingWebModel); + } + } } } |
