From 866a5a15b8b722bc78d065f73adc0c465f264f55 Mon Sep 17 00:00:00 2001 From: transtrike Date: Sat, 30 Jan 2021 18:45:18 +0200 Subject: IDFK --- src/DevHive.Data/Repositories/RatingRepository.cs | 37 +++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/DevHive.Data/Repositories/RatingRepository.cs (limited to 'src/DevHive.Data/Repositories') 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, IRatingRepository + { + private readonly DevHiveContext _context; + + public RatingRepository(DevHiveContext context) + : base(context) + { + this._context = context; + } + + public async Task GetByPostId(Guid postId) + { + return await this._context.Rating + .FirstOrDefaultAsync(x => x.Post.Id == postId); + } + + public async Task> GetRating(Guid postId) + { + Rating rating = await this.GetByPostId(postId); + + return new Tuple(rating.Likes, rating.Dislikes); + } + + public async Task HasUserRatedThisPost(Guid userId, Guid postId) + { + throw new NotImplementedException(); + } + } +} -- cgit v1.2.3