diff options
Diffstat (limited to 'src/DevHive.Data/Repositories')
| -rw-r--r-- | src/DevHive.Data/Repositories/RatingRepository.cs | 37 |
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(); + } + } +} |
