aboutsummaryrefslogtreecommitdiff
path: root/src/Services/DevHive.Services
diff options
context:
space:
mode:
authorDanail Dimitrov <danaildimitrov321@gmail.com>2021-03-03 10:43:22 +0200
committerDanail Dimitrov <danaildimitrov321@gmail.com>2021-03-03 10:43:22 +0200
commit55df3e16982c18b37d9a734215be3e00f64a8e19 (patch)
tree267585b01222c440cc375fafc10e3f8ebf3cfa87 /src/Services/DevHive.Services
parent5486896004672d5646834054d0536b6b025763ee (diff)
downloadDevHive-55df3e16982c18b37d9a734215be3e00f64a8e19.tar
DevHive-55df3e16982c18b37d9a734215be3e00f64a8e19.tar.gz
DevHive-55df3e16982c18b37d9a734215be3e00f64a8e19.zip
Adding Post.CurrentRating functionality
Diffstat (limited to 'src/Services/DevHive.Services')
-rw-r--r--src/Services/DevHive.Services/Services/PostService.cs10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/Services/DevHive.Services/Services/PostService.cs b/src/Services/DevHive.Services/Services/PostService.cs
index a3d5117..a565473 100644
--- a/src/Services/DevHive.Services/Services/PostService.cs
+++ b/src/Services/DevHive.Services/Services/PostService.cs
@@ -76,11 +76,21 @@ namespace DevHive.Services.Services
User user = await this._userRepository.GetByIdAsync(post.Creator.Id) ??
throw new ArgumentException("The user does not exist!");
+ int currentRating = 0;
+ foreach (Rating rating in post.Ratings)
+ {
+ if (rating.IsLike)
+ currentRating++;
+ else
+ currentRating--;
+ }
+
ReadPostServiceModel readPostServiceModel = this._postMapper.Map<ReadPostServiceModel>(post);
readPostServiceModel.CreatorFirstName = user.FirstName;
readPostServiceModel.CreatorLastName = user.LastName;
readPostServiceModel.CreatorUsername = user.UserName;
readPostServiceModel.FileUrls = post.Attachments.Select(x => x.FileUrl).ToList();
+ readPostServiceModel.CurrentRating = currentRating;
return readPostServiceModel;
}