aboutsummaryrefslogtreecommitdiff
path: root/src/DevHive.Data/Repositories
diff options
context:
space:
mode:
authortranstrike <transtrike@gmail.com>2021-01-30 18:45:18 +0200
committertranstrike <transtrike@gmail.com>2021-01-30 18:45:18 +0200
commit866a5a15b8b722bc78d065f73adc0c465f264f55 (patch)
tree93e6514e9717f42e9323cc5ebd17261c14eb2748 /src/DevHive.Data/Repositories
parentdde27f48caf455f9b342d68b0a4a5c95f302b9f7 (diff)
downloadDevHive-866a5a15b8b722bc78d065f73adc0c465f264f55.tar
DevHive-866a5a15b8b722bc78d065f73adc0c465f264f55.tar.gz
DevHive-866a5a15b8b722bc78d065f73adc0c465f264f55.zip
IDFK
Diffstat (limited to 'src/DevHive.Data/Repositories')
-rw-r--r--src/DevHive.Data/Repositories/RatingRepository.cs37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/DevHive.Data/Repositories/RatingRepository.cs b/src/DevHive.Data/Repositories/RatingRepository.cs
new file mode 100644
index 0000000..43fe90d
--- /dev/null
+++ b/src/DevHive.Data/Repositories/RatingRepository.cs
@@ -0,0 +1,37 @@
+using System;
+using System.Threading.Tasks;
+using DevHive.Data.Interfaces.Repositories;
+using DevHive.Data.Models;
+using Microsoft.EntityFrameworkCore;
+
+namespace DevHive.Data.Repositories
+{
+ public class RatingRepository : BaseRepository<Rating>, IRatingRepository
+ {
+ private readonly DevHiveContext _context;
+
+ public RatingRepository(DevHiveContext context)
+ : base(context)
+ {
+ this._context = context;
+ }
+
+ public async Task<Rating> GetByPostId(Guid postId)
+ {
+ return await this._context.Rating
+ .FirstOrDefaultAsync(x => x.Post.Id == postId);
+ }
+
+ public async Task<Tuple<int, int>> GetRating(Guid postId)
+ {
+ Rating rating = await this.GetByPostId(postId);
+
+ return new Tuple<int, int>(rating.Likes, rating.Dislikes);
+ }
+
+ public async Task<bool> HasUserRatedThisPost(Guid userId, Guid postId)
+ {
+ throw new NotImplementedException();
+ }
+ }
+}