aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDanail Dimitrov <danaildimitrov321@gmail.com>2021-03-03 10:27:26 +0200
committerDanail Dimitrov <danaildimitrov321@gmail.com>2021-03-03 10:27:26 +0200
commitf986ca67edd425c32eaec5a20fecdc5786f9d8e3 (patch)
tree1d63feb6622257735a4a5e878ba9e7fd1cafbfc7 /src
parent804d274223734ea1c67920622ceb453cca602fc9 (diff)
downloadDevHive-f986ca67edd425c32eaec5a20fecdc5786f9d8e3.tar
DevHive-f986ca67edd425c32eaec5a20fecdc5786f9d8e3.tar.gz
DevHive-f986ca67edd425c32eaec5a20fecdc5786f9d8e3.zip
Fixing bugs in rating layer
Diffstat (limited to 'src')
-rw-r--r--src/Data/DevHive.Data/Repositories/RatingRepository.cs4
-rw-r--r--src/Services/DevHive.Services/Interfaces/IRatingService.cs2
-rw-r--r--src/Services/DevHive.Services/Services/RatingService.cs8
-rw-r--r--src/Web/DevHive.Web.Models/Rating/UpdateRatingWebModel.cs4
-rw-r--r--src/Web/DevHive.Web/Controllers/RatingController.cs3
5 files changed, 7 insertions, 14 deletions
diff --git a/src/Data/DevHive.Data/Repositories/RatingRepository.cs b/src/Data/DevHive.Data/Repositories/RatingRepository.cs
index 9bb2368..1784144 100644
--- a/src/Data/DevHive.Data/Repositories/RatingRepository.cs
+++ b/src/Data/DevHive.Data/Repositories/RatingRepository.cs
@@ -30,6 +30,8 @@ namespace DevHive.Data.Repositories
public async Task<List<Rating>> GetRatingsByPostId(Guid postId)
{
return await this._context.Rating
+ .Include(x => x.User)
+ .Include(x => x.Post)
.Where(x => x.Post.Id == postId).ToListAsync();
}
public async Task<bool> UserRatedPost(Guid userId, Guid postId)
@@ -41,6 +43,8 @@ namespace DevHive.Data.Repositories
public async Task<Rating> GetRatingByUserAndPostId(Guid userId, Guid postId)
{
return await this._context.Rating
+ .Include(x => x.User)
+ .Include(x => x.Post)
.FirstOrDefaultAsync(x => x.Post.Id == postId && x.User.Id == userId);
}
diff --git a/src/Services/DevHive.Services/Interfaces/IRatingService.cs b/src/Services/DevHive.Services/Interfaces/IRatingService.cs
index beea821..b262f45 100644
--- a/src/Services/DevHive.Services/Interfaces/IRatingService.cs
+++ b/src/Services/DevHive.Services/Interfaces/IRatingService.cs
@@ -16,7 +16,5 @@ namespace DevHive.Services.Interfaces
Task<ReadRatingServiceModel> UpdateRating(UpdateRatingServiceModel updateRatingServiceModel);
Task<bool> DeleteRating(Guid ratingId);
-
- Task<bool> HasUserRatedThisPost(Guid userId, Guid postId);
}
}
diff --git a/src/Services/DevHive.Services/Services/RatingService.cs b/src/Services/DevHive.Services/Services/RatingService.cs
index 6ddba1c..6d0d0b9 100644
--- a/src/Services/DevHive.Services/Services/RatingService.cs
+++ b/src/Services/DevHive.Services/Services/RatingService.cs
@@ -81,7 +81,7 @@ namespace DevHive.Services.Services
#region Update
public async Task<ReadRatingServiceModel> UpdateRating(UpdateRatingServiceModel updateRatingServiceModel)
{
- Rating rating = await this._ratingRepository.GetByIdAsync(updateRatingServiceModel.Id) ??
+ Rating rating = await this._ratingRepository.GetRatingByUserAndPostId(updateRatingServiceModel.UserId, updateRatingServiceModel.PostId) ??
throw new ArgumentException("Rating does not exist!");
User user = await this._userRepository.GetByIdAsync(updateRatingServiceModel.UserId) ??
@@ -115,11 +115,5 @@ namespace DevHive.Services.Services
return await this._ratingRepository.DeleteAsync(rating);
}
#endregion
-
- public async Task<bool> HasUserRatedThisPost(Guid userId, Guid postId)
- {
- return await this._ratingRepository
- .UserRatedPost(userId, postId);
- }
}
}
diff --git a/src/Web/DevHive.Web.Models/Rating/UpdateRatingWebModel.cs b/src/Web/DevHive.Web.Models/Rating/UpdateRatingWebModel.cs
index 425c3e1..176c099 100644
--- a/src/Web/DevHive.Web.Models/Rating/UpdateRatingWebModel.cs
+++ b/src/Web/DevHive.Web.Models/Rating/UpdateRatingWebModel.cs
@@ -8,10 +8,6 @@ namespace DevHive.Web.Models.Rating
{
public class UpdateRatingWebModel
{
- public Guid Id { get; set; }
-
- public Guid PostId { get; set; }
-
public bool IsLike { get; set; }
}
}
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<IActionResult> UpdateRating(Guid userId, [FromBody] UpdateRatingWebModel updateRatingWebModel, [FromHeader] string authorization)
+ public async Task<IActionResult> 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<UpdateRatingServiceModel>(updateRatingWebModel);
updateRatingServiceModel.UserId = userId;
+ updateRatingServiceModel.PostId = postId;
ReadRatingServiceModel readRatingServiceModel = await this._rateService.UpdateRating(updateRatingServiceModel);