From f986ca67edd425c32eaec5a20fecdc5786f9d8e3 Mon Sep 17 00:00:00 2001 From: Danail Dimitrov Date: Wed, 3 Mar 2021 10:27:26 +0200 Subject: Fixing bugs in rating layer --- src/Web/DevHive.Web/Controllers/RatingController.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/Web/DevHive.Web') diff --git a/src/Web/DevHive.Web/Controllers/RatingController.cs b/src/Web/DevHive.Web/Controllers/RatingController.cs index 5716b85..8d3ac92 100644 --- a/src/Web/DevHive.Web/Controllers/RatingController.cs +++ b/src/Web/DevHive.Web/Controllers/RatingController.cs @@ -65,7 +65,7 @@ namespace DevHive.Web.Controllers } [HttpPut] - public async Task UpdateRating(Guid userId, [FromBody] UpdateRatingWebModel updateRatingWebModel, [FromHeader] string authorization) + public async Task UpdateRating(Guid userId, Guid postId, [FromBody] UpdateRatingWebModel updateRatingWebModel, [FromHeader] string authorization) { if (!this._jwtService.ValidateToken(userId, authorization)) return new UnauthorizedResult(); @@ -73,6 +73,7 @@ namespace DevHive.Web.Controllers UpdateRatingServiceModel updateRatingServiceModel = this._mapper.Map(updateRatingWebModel); updateRatingServiceModel.UserId = userId; + updateRatingServiceModel.PostId = postId; ReadRatingServiceModel readRatingServiceModel = await this._rateService.UpdateRating(updateRatingServiceModel); -- cgit v1.2.3 From 4612913c72c3d2b4d3e28629df9f2ed97f0c29a9 Mon Sep 17 00:00:00 2001 From: Danail Dimitrov Date: Wed, 3 Mar 2021 10:55:28 +0200 Subject: Moved Rating service models outside of Post folder --- .../Post/Rating/CreateRatingServiceModel.cs | 13 ------------- .../Post/Rating/ReadRatingServiceModel.cs | 15 --------------- .../Post/Rating/UpdateRatingServiceModel.cs | 15 --------------- .../Rating/CreateRatingServiceModel.cs | 13 +++++++++++++ .../Rating/ReadRatingServiceModel.cs | 15 +++++++++++++++ .../Rating/UpdateRatingServiceModel.cs | 15 +++++++++++++++ .../Configurations/Mapping/RatingMappings.cs | 2 +- .../DevHive.Services/Interfaces/IRatingService.cs | 2 +- src/Services/DevHive.Services/Services/RatingService.cs | 2 +- .../DevHive.Web/Configurations/Mapping/RatingMappings.cs | 2 +- src/Web/DevHive.Web/Controllers/RatingController.cs | 2 +- 11 files changed, 48 insertions(+), 48 deletions(-) delete mode 100644 src/Services/DevHive.Services.Models/Post/Rating/CreateRatingServiceModel.cs delete mode 100644 src/Services/DevHive.Services.Models/Post/Rating/ReadRatingServiceModel.cs delete mode 100644 src/Services/DevHive.Services.Models/Post/Rating/UpdateRatingServiceModel.cs create mode 100644 src/Services/DevHive.Services.Models/Rating/CreateRatingServiceModel.cs create mode 100644 src/Services/DevHive.Services.Models/Rating/ReadRatingServiceModel.cs create mode 100644 src/Services/DevHive.Services.Models/Rating/UpdateRatingServiceModel.cs (limited to 'src/Web/DevHive.Web') diff --git a/src/Services/DevHive.Services.Models/Post/Rating/CreateRatingServiceModel.cs b/src/Services/DevHive.Services.Models/Post/Rating/CreateRatingServiceModel.cs deleted file mode 100644 index aaeab73..0000000 --- a/src/Services/DevHive.Services.Models/Post/Rating/CreateRatingServiceModel.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; - -namespace DevHive.Services.Models.Post.Rating -{ - public class CreateRatingServiceModel - { - public Guid UserId { get; set; } - - public Guid PostId { get; set; } - - public bool IsLike { get; set; } - } -} diff --git a/src/Services/DevHive.Services.Models/Post/Rating/ReadRatingServiceModel.cs b/src/Services/DevHive.Services.Models/Post/Rating/ReadRatingServiceModel.cs deleted file mode 100644 index 86b4957..0000000 --- a/src/Services/DevHive.Services.Models/Post/Rating/ReadRatingServiceModel.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; - -namespace DevHive.Services.Models.Post.Rating -{ - public class ReadRatingServiceModel - { - public Guid Id { get; set; } - - public Guid PostId { get; set; } - - public Guid UserId { get; set; } - - public bool IsLike { get; set; } - } -} diff --git a/src/Services/DevHive.Services.Models/Post/Rating/UpdateRatingServiceModel.cs b/src/Services/DevHive.Services.Models/Post/Rating/UpdateRatingServiceModel.cs deleted file mode 100644 index 1ea8d8f..0000000 --- a/src/Services/DevHive.Services.Models/Post/Rating/UpdateRatingServiceModel.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; - -namespace DevHive.Services.Models.Post.Rating -{ - public class UpdateRatingServiceModel - { - public Guid Id { get; set; } - - public Guid UserId { get; set; } - - public Guid PostId { get; set; } - - public bool IsLike { get; set; } - } -} diff --git a/src/Services/DevHive.Services.Models/Rating/CreateRatingServiceModel.cs b/src/Services/DevHive.Services.Models/Rating/CreateRatingServiceModel.cs new file mode 100644 index 0000000..486e3d2 --- /dev/null +++ b/src/Services/DevHive.Services.Models/Rating/CreateRatingServiceModel.cs @@ -0,0 +1,13 @@ +using System; + +namespace DevHive.Services.Models.Rating +{ + public class CreateRatingServiceModel + { + public Guid UserId { get; set; } + + public Guid PostId { get; set; } + + public bool IsLike { get; set; } + } +} diff --git a/src/Services/DevHive.Services.Models/Rating/ReadRatingServiceModel.cs b/src/Services/DevHive.Services.Models/Rating/ReadRatingServiceModel.cs new file mode 100644 index 0000000..56a5ab0 --- /dev/null +++ b/src/Services/DevHive.Services.Models/Rating/ReadRatingServiceModel.cs @@ -0,0 +1,15 @@ +using System; + +namespace DevHive.Services.Models.Rating +{ + public class ReadRatingServiceModel + { + public Guid Id { get; set; } + + public Guid PostId { get; set; } + + public Guid UserId { get; set; } + + public bool IsLike { get; set; } + } +} diff --git a/src/Services/DevHive.Services.Models/Rating/UpdateRatingServiceModel.cs b/src/Services/DevHive.Services.Models/Rating/UpdateRatingServiceModel.cs new file mode 100644 index 0000000..923e789 --- /dev/null +++ b/src/Services/DevHive.Services.Models/Rating/UpdateRatingServiceModel.cs @@ -0,0 +1,15 @@ +using System; + +namespace DevHive.Services.Models.Rating +{ + public class UpdateRatingServiceModel + { + public Guid Id { get; set; } + + public Guid UserId { get; set; } + + public Guid PostId { get; set; } + + public bool IsLike { get; set; } + } +} diff --git a/src/Services/DevHive.Services/Configurations/Mapping/RatingMappings.cs b/src/Services/DevHive.Services/Configurations/Mapping/RatingMappings.cs index 4534511..9ad5f25 100644 --- a/src/Services/DevHive.Services/Configurations/Mapping/RatingMappings.cs +++ b/src/Services/DevHive.Services/Configurations/Mapping/RatingMappings.cs @@ -1,6 +1,6 @@ using AutoMapper; using DevHive.Data.Models; -using DevHive.Services.Models.Post.Rating; +using DevHive.Services.Models.Rating; namespace DevHive.Services.Configurations.Mapping { diff --git a/src/Services/DevHive.Services/Interfaces/IRatingService.cs b/src/Services/DevHive.Services/Interfaces/IRatingService.cs index b262f45..be33300 100644 --- a/src/Services/DevHive.Services/Interfaces/IRatingService.cs +++ b/src/Services/DevHive.Services/Interfaces/IRatingService.cs @@ -1,7 +1,7 @@ using System; using System.Threading.Tasks; using DevHive.Data.Models; -using DevHive.Services.Models.Post.Rating; +using DevHive.Services.Models.Rating; namespace DevHive.Services.Interfaces { diff --git a/src/Services/DevHive.Services/Services/RatingService.cs b/src/Services/DevHive.Services/Services/RatingService.cs index 6d0d0b9..1f77a6e 100644 --- a/src/Services/DevHive.Services/Services/RatingService.cs +++ b/src/Services/DevHive.Services/Services/RatingService.cs @@ -8,7 +8,7 @@ using AutoMapper; using DevHive.Data.Interfaces; using DevHive.Data.Models; using DevHive.Services.Interfaces; -using DevHive.Services.Models.Post.Rating; +using DevHive.Services.Models.Rating; namespace DevHive.Services.Services { diff --git a/src/Web/DevHive.Web/Configurations/Mapping/RatingMappings.cs b/src/Web/DevHive.Web/Configurations/Mapping/RatingMappings.cs index 23c3eeb..1d731d8 100644 --- a/src/Web/DevHive.Web/Configurations/Mapping/RatingMappings.cs +++ b/src/Web/DevHive.Web/Configurations/Mapping/RatingMappings.cs @@ -1,5 +1,5 @@ using AutoMapper; -using DevHive.Services.Models.Post.Rating; +using DevHive.Services.Models.Rating; using DevHive.Web.Models.Rating; namespace DevHive.Web.Configurations.Mapping diff --git a/src/Web/DevHive.Web/Controllers/RatingController.cs b/src/Web/DevHive.Web/Controllers/RatingController.cs index 8d3ac92..c93a56d 100644 --- a/src/Web/DevHive.Web/Controllers/RatingController.cs +++ b/src/Web/DevHive.Web/Controllers/RatingController.cs @@ -3,7 +3,7 @@ using System.Threading.Tasks; using AutoMapper; using DevHive.Common.Jwt.Interfaces; using DevHive.Services.Interfaces; -using DevHive.Services.Models.Post.Rating; +using DevHive.Services.Models.Rating; using DevHive.Web.Models.Rating; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; -- cgit v1.2.3 From 95693f70a2314eab65ac289580d264fe12c42a06 Mon Sep 17 00:00:00 2001 From: Danail Dimitrov Date: Wed, 3 Mar 2021 10:56:48 +0200 Subject: Adding authorization to Rating Controller --- src/Web/DevHive.Web/Controllers/RatingController.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Web/DevHive.Web') diff --git a/src/Web/DevHive.Web/Controllers/RatingController.cs b/src/Web/DevHive.Web/Controllers/RatingController.cs index c93a56d..8c44243 100644 --- a/src/Web/DevHive.Web/Controllers/RatingController.cs +++ b/src/Web/DevHive.Web/Controllers/RatingController.cs @@ -11,7 +11,7 @@ using Microsoft.AspNetCore.Mvc; namespace DevHive.Web.Controllers { [ApiController] - //[Authorize(Roles = "Admin,User")] + [Authorize(Roles = "Admin,User")] [Route("api/[controller]")] public class RatingController { -- cgit v1.2.3 From 6cc1bceebfa1ed01472303db226c000c2345b016 Mon Sep 17 00:00:00 2001 From: Danail Dimitrov Date: Wed, 3 Mar 2021 10:57:49 +0200 Subject: Removed _userService from RatingController --- src/Web/DevHive.Web/Controllers/RatingController.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src/Web/DevHive.Web') diff --git a/src/Web/DevHive.Web/Controllers/RatingController.cs b/src/Web/DevHive.Web/Controllers/RatingController.cs index 8c44243..f6ab0c5 100644 --- a/src/Web/DevHive.Web/Controllers/RatingController.cs +++ b/src/Web/DevHive.Web/Controllers/RatingController.cs @@ -16,14 +16,12 @@ namespace DevHive.Web.Controllers public class RatingController { private readonly IRatingService _rateService; - private readonly IUserService _userService; private readonly IMapper _mapper; private readonly IJwtService _jwtService; - public RatingController(IRatingService rateService, IUserService userService, IMapper mapper, IJwtService jwtService) + public RatingController(IRatingService rateService, IMapper mapper, IJwtService jwtService) { this._rateService = rateService; - this._userService = userService; this._mapper = mapper; this._jwtService = jwtService; } -- cgit v1.2.3 From b3fd74a4207334b7b31e9450a078bd10437648c3 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sat, 13 Mar 2021 08:46:31 +0200 Subject: Fixed type in delete rating method name in rating controller --- src/Web/DevHive.Web/Controllers/RatingController.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Web/DevHive.Web') diff --git a/src/Web/DevHive.Web/Controllers/RatingController.cs b/src/Web/DevHive.Web/Controllers/RatingController.cs index f6ab0c5..7d21795 100644 --- a/src/Web/DevHive.Web/Controllers/RatingController.cs +++ b/src/Web/DevHive.Web/Controllers/RatingController.cs @@ -85,7 +85,7 @@ namespace DevHive.Web.Controllers } [HttpDelete] - public async Task DeleteTating(Guid userId, Guid ratingId, [FromHeader] string authorization) + public async Task DeleteRating(Guid userId, Guid ratingId, [FromHeader] string authorization) { if (!this._jwtService.ValidateToken(userId, authorization)) return new UnauthorizedResult(); -- cgit v1.2.3 From e68181d5452f8e2c553c1eb36e689bab1ae080e3 Mon Sep 17 00:00:00 2001 From: Danail Dimitrov Date: Sun, 14 Mar 2021 21:16:53 +0200 Subject: added documentaion for rating repository --- .../DevHive.Data/Repositories/RatingRepository.cs | 22 ++++++++++++++++++++++ src/Web/DevHive.Web/Startup.cs | 1 - 2 files changed, 22 insertions(+), 1 deletion(-) (limited to 'src/Web/DevHive.Web') diff --git a/src/Data/DevHive.Data/Repositories/RatingRepository.cs b/src/Data/DevHive.Data/Repositories/RatingRepository.cs index 1784144..e4a5d5d 100644 --- a/src/Data/DevHive.Data/Repositories/RatingRepository.cs +++ b/src/Data/DevHive.Data/Repositories/RatingRepository.cs @@ -27,6 +27,11 @@ namespace DevHive.Data.Repositories .Include(x => x.Post) .FirstOrDefaultAsync(x => x.Id == id); } + /// + /// Gets all the ratings for a psot. + /// + /// Id of the post. + /// public async Task> GetRatingsByPostId(Guid postId) { return await this._context.Rating @@ -34,12 +39,24 @@ namespace DevHive.Data.Repositories .Include(x => x.Post) .Where(x => x.Post.Id == postId).ToListAsync(); } + /// + /// Checks if a user rated a given post. + /// + /// Id of the user. + /// Id of the psot. + /// True if the user has already rated the post and false if he hasn't. public async Task UserRatedPost(Guid userId, Guid postId) { return await this._context.Rating .Where(x => x.Post.Id == postId) .AnyAsync(x => x.User.Id == userId); } + /// + /// Gets a rating by the post to which the rating corresponds and the user who created it. + /// + /// Id of the user. + /// Id of the post. + /// Rating for the given post by the given user. public async Task GetRatingByUserAndPostId(Guid userId, Guid postId) { return await this._context.Rating @@ -48,6 +65,11 @@ namespace DevHive.Data.Repositories .FirstOrDefaultAsync(x => x.Post.Id == postId && x.User.Id == userId); } + /// + /// Checks if a given rating already exist + /// + /// Id of the rating + /// True if the rating exists and false if it does not. public async Task DoesRatingExist(Guid id) { return await this._context.Rating diff --git a/src/Web/DevHive.Web/Startup.cs b/src/Web/DevHive.Web/Startup.cs index 40f674d..1c714ec 100644 --- a/src/Web/DevHive.Web/Startup.cs +++ b/src/Web/DevHive.Web/Startup.cs @@ -5,7 +5,6 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using DevHive.Web.Configurations.Extensions; using Newtonsoft.Json; -using System.Threading.Tasks; namespace DevHive.Web { -- cgit v1.2.3