aboutsummaryrefslogtreecommitdiff
path: root/src/DevHive.Services/Services/RateService.cs
diff options
context:
space:
mode:
authorVictor S <57849063+transtrike@users.noreply.github.com>2021-02-05 10:54:49 -0800
committerGitHub <noreply@github.com>2021-02-05 10:54:49 -0800
commitf4a70c6430db923af9fa9958a11c2d6612cb52cc (patch)
treeca0ea403ba5500df20bc8854ec50529a25c64245 /src/DevHive.Services/Services/RateService.cs
parent1ccdefdac025b1b986ad2bd0bc3eda7505d6e7c3 (diff)
parent2269b5aa6c8d3dcb407c34fa256200bdc573585a (diff)
downloadDevHive-f4a70c6430db923af9fa9958a11c2d6612cb52cc.tar
DevHive-f4a70c6430db923af9fa9958a11c2d6612cb52cc.tar.gz
DevHive-f4a70c6430db923af9fa9958a11c2d6612cb52cc.zip
Merge pull request #18 from Team-Kaleidoscope/devv0.1
First stage: Complete. Awaiting further progress...
Diffstat (limited to 'src/DevHive.Services/Services/RateService.cs')
-rw-r--r--src/DevHive.Services/Services/RateService.cs80
1 files changed, 80 insertions, 0 deletions
diff --git a/src/DevHive.Services/Services/RateService.cs b/src/DevHive.Services/Services/RateService.cs
new file mode 100644
index 0000000..204c550
--- /dev/null
+++ b/src/DevHive.Services/Services/RateService.cs
@@ -0,0 +1,80 @@
+using System;
+using System.Linq;
+using System.Threading.Tasks;
+using AutoMapper;
+using DevHive.Data.Interfaces.Repositories;
+using DevHive.Data.Models;
+using DevHive.Services.Interfaces;
+using DevHive.Services.Models.Post.Rating;
+
+namespace DevHive.Services.Services
+{
+ public class RateService : IRateService
+ {
+ private readonly IPostRepository _postRepository;
+ private readonly IUserRepository _userRepository;
+ private readonly IRatingRepository _ratingRepository;
+ private readonly IMapper _mapper;
+
+ public RateService(IPostRepository postRepository, IRatingRepository ratingRepository, IUserRepository userRepository, IMapper mapper)
+ {
+ this._postRepository = postRepository;
+ this._ratingRepository = ratingRepository;
+ this._userRepository = userRepository;
+ this._mapper = mapper;
+ }
+
+ public async Task<ReadPostRatingServiceModel> RatePost(RatePostServiceModel ratePostServiceModel)
+ {
+ throw new NotImplementedException();
+ // if (!await this._postRepository.DoesPostExist(ratePostServiceModel.PostId))
+ // throw new ArgumentException("Post does not exist!");
+
+ // if (!await this._userRepository.DoesUserExistAsync(ratePostServiceModel.UserId))
+ // throw new ArgumentException("User does not exist!");
+
+ // Post post = await this._postRepository.GetByIdAsync(ratePostServiceModel.PostId);
+ // User user = await this._userRepository.GetByIdAsync(ratePostServiceModel.UserId);
+
+ // if (this.HasUserRatedThisPost(user, post))
+ // throw new ArgumentException("You can't rate the same post more then one(duh, amigo)");
+
+ // this.Rate(user, post, ratePostServiceModel.Liked);
+
+ // bool success = await this._ratingRepository.EditAsync(post.Rating.Id, post.Rating);
+ // if (!success)
+ // throw new InvalidOperationException("Unable to rate the post!");
+
+ // Rating newRating = await this._ratingRepository.GetByIdAsync(post.Rating.Id);
+ // return this._mapper.Map<ReadPostRatingServiceModel>(newRating);
+ }
+
+ public async Task<ReadPostRatingServiceModel> RemoveUserRateFromPost(Guid userId, Guid postId)
+ {
+ throw new NotImplementedException();
+ // Post post = await this._postRepository.GetByIdAsync(postId);
+ // User user = await this._userRepository.GetByIdAsync(userId);
+
+ // if (!this.HasUserRatedThisPost(user, post))
+ // throw new ArgumentException("You haven't rated this post, lmao!");
+ }
+
+ public bool HasUserRatedThisPost(User user, Post post)
+ {
+ throw new NotImplementedException();
+ // return post.Rating.UsersThatRated
+ // .Any(x => x.Id == user.Id);
+ }
+
+ private void Rate(User user, Post post, bool liked)
+ {
+ throw new NotImplementedException();
+ // if (liked)
+ // post.Rating.Rate++;
+ // else
+ // post.Rating.Rate--;
+
+ // post.Rating.UsersThatRated.Add(user);
+ }
+ }
+}