aboutsummaryrefslogtreecommitdiff
path: root/src/DevHive.Services/Services/RatingService.cs
diff options
context:
space:
mode:
authortranstrike <transtrike@gmail.com>2021-02-01 16:03:38 +0200
committertranstrike <transtrike@gmail.com>2021-02-01 16:03:38 +0200
commitb41f887712ef8f2f0b602da3042261a78c5f492a (patch)
treefb6437ea34896da7c7db3a292bbdb8ee7d14e889 /src/DevHive.Services/Services/RatingService.cs
parentaa342542789b22f24ce3ecbfcb7888d4ff12d30c (diff)
downloadDevHive-b41f887712ef8f2f0b602da3042261a78c5f492a.tar
DevHive-b41f887712ef8f2f0b602da3042261a78c5f492a.tar.gz
DevHive-b41f887712ef8f2f0b602da3042261a78c5f492a.zip
Commented out implementation of Rating; Bug fixes
Diffstat (limited to 'src/DevHive.Services/Services/RatingService.cs')
-rw-r--r--src/DevHive.Services/Services/RatingService.cs54
1 files changed, 0 insertions, 54 deletions
diff --git a/src/DevHive.Services/Services/RatingService.cs b/src/DevHive.Services/Services/RatingService.cs
deleted file mode 100644
index 2c5a6b6..0000000
--- a/src/DevHive.Services/Services/RatingService.cs
+++ /dev/null
@@ -1,54 +0,0 @@
-using System;
-using System.Diagnostics;
-using System.Threading.Tasks;
-using AutoMapper;
-using DevHive.Data.Interfaces.Repositories;
-using DevHive.Data.Models;
-using DevHive.Services.Models.Post.Rating;
-using Microsoft.CodeAnalysis.CSharp.Syntax;
-
-namespace DevHive.Services.Services
-{
- public class RatingService
- {
- private readonly IPostRepository _postRepository;
- private readonly IRatingRepository _ratingRepository;
- private readonly IMapper _mapper;
-
- public RatingService(IPostRepository postRepository, IRatingRepository ratingRepository, IMapper mapper)
- {
- this._postRepository = postRepository;
- this._ratingRepository = ratingRepository;
- this._mapper = mapper;
- }
-
- public async Task<ReadRatingServiceModel> RatePost(RatePostServiceModel ratePostServiceModel)
- {
- if (!await this._postRepository.DoesPostExist(ratePostServiceModel.PostId))
- throw new ArgumentNullException("Post does not exist!");
-
- if (!await this._ratingRepository.HasUserRatedThisPost(ratePostServiceModel.UserId, ratePostServiceModel.PostId))
- throw new ArgumentException("You can't rate the same post more then one(duh, amigo)");
-
- Post post = await this._postRepository.GetByIdAsync(ratePostServiceModel.PostId);
-
- Rating rating = post.Rating;
- if (ratePostServiceModel.Liked)
- rating.Likes++;
- else
- rating.Dislikes++;
-
- bool success = await this._ratingRepository.EditAsync(rating.Id, rating);
- if (!success)
- throw new InvalidOperationException("Unable to rate the post!");
-
- Rating newRating = await this._ratingRepository.GetByIdAsync(rating.Id);
- return this._mapper.Map<ReadRatingServiceModel>(newRating);
- }
-
- public async Task<ReadRatingServiceModel> RemoveUserRateFromPost(Guid userId, Guid postId)
- {
- throw new NotImplementedException();
- }
- }
-}