aboutsummaryrefslogtreecommitdiff
path: root/src/Data/DevHive.Data
diff options
context:
space:
mode:
Diffstat (limited to 'src/Data/DevHive.Data')
-rw-r--r--src/Data/DevHive.Data/Interfaces/IRatingRepository.cs2
-rw-r--r--src/Data/DevHive.Data/Repositories/RatingRepository.cs11
2 files changed, 10 insertions, 3 deletions
diff --git a/src/Data/DevHive.Data/Interfaces/IRatingRepository.cs b/src/Data/DevHive.Data/Interfaces/IRatingRepository.cs
index 4cc34c8..db37d00 100644
--- a/src/Data/DevHive.Data/Interfaces/IRatingRepository.cs
+++ b/src/Data/DevHive.Data/Interfaces/IRatingRepository.cs
@@ -11,5 +11,7 @@ namespace DevHive.Data.Interfaces
Task<List<Rating>> GetRatingsByPostId(Guid postId);
Task<bool> UserRatedPost(Guid userId, Guid postId);
Task<Rating> GetRatingByUserAndPostId(Guid userId, Guid postId);
+
+ Task<bool> DoesRatingExist(Guid id);
}
}
diff --git a/src/Data/DevHive.Data/Repositories/RatingRepository.cs b/src/Data/DevHive.Data/Repositories/RatingRepository.cs
index 02f92c0..9bb2368 100644
--- a/src/Data/DevHive.Data/Repositories/RatingRepository.cs
+++ b/src/Data/DevHive.Data/Repositories/RatingRepository.cs
@@ -32,19 +32,24 @@ namespace DevHive.Data.Repositories
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);
+ }
}
}