diff options
| author | transtrike <transtrike@gmail.com> | 2021-01-30 18:45:18 +0200 |
|---|---|---|
| committer | transtrike <transtrike@gmail.com> | 2021-01-30 18:45:18 +0200 |
| commit | 866a5a15b8b722bc78d065f73adc0c465f264f55 (patch) | |
| tree | 93e6514e9717f42e9323cc5ebd17261c14eb2748 /src/DevHive.Data/Repositories | |
| parent | dde27f48caf455f9b342d68b0a4a5c95f302b9f7 (diff) | |
| download | DevHive-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.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(); + } + } +} |
