aboutsummaryrefslogtreecommitdiff
path: root/src/Data/DevHive.Data/Repositories/RatingRepository.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Data/DevHive.Data/Repositories/RatingRepository.cs')
-rw-r--r--src/Data/DevHive.Data/Repositories/RatingRepository.cs28
1 files changed, 24 insertions, 4 deletions
diff --git a/src/Data/DevHive.Data/Repositories/RatingRepository.cs b/src/Data/DevHive.Data/Repositories/RatingRepository.cs
index b361693..9bb2368 100644
--- a/src/Data/DevHive.Data/Repositories/RatingRepository.cs
+++ b/src/Data/DevHive.Data/Repositories/RatingRepository.cs
@@ -1,4 +1,5 @@
using System;
+using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using DevHive.Data.Interfaces;
@@ -19,17 +20,36 @@ namespace DevHive.Data.Repositories
this._postRepository = postRepository;
}
- public async Task<Rating> GetRatingByPostId(Guid postId)
+ public override async Task<Rating> GetByIdAsync(Guid id)
{
return await this._context.Rating
- .FirstOrDefaultAsync(x => x.Post.Id == postId);
+ .Include(x => x.User)
+ .Include(x => x.Post)
+ .FirstOrDefaultAsync(x => x.Id == id);
+ }
+ public async Task<List<Rating>> GetRatingsByPostId(Guid postId)
+ {
+ return await this._context.Rating
+ .Where(x => x.Post.Id == postId).ToListAsync();
}
-
public async Task<bool> UserRatedPost(Guid userId, Guid postId)
{
- return await this._context.UserRate
+ return await this._context.Rating
.Where(x => x.Post.Id == postId)
.AnyAsync(x => x.User.Id == userId);
}
+ public async Task<Rating> GetRatingByUserAndPostId(Guid userId, Guid postId)
+ {
+ return await this._context.Rating
+ .FirstOrDefaultAsync(x => x.Post.Id == postId && x.User.Id == userId);
+ }
+
+ public async Task<bool> DoesRatingExist(Guid id)
+ {
+ return await this._context.Rating
+ .AsNoTracking()
+ .AnyAsync(r => r.Id == id);
+ }
}
}
+