diff options
| author | Danail Dimitrov <danaildimitrov321@gmail.com> | 2021-02-26 23:00:50 +0200 |
|---|---|---|
| committer | Danail Dimitrov <danaildimitrov321@gmail.com> | 2021-02-26 23:00:50 +0200 |
| commit | 379eda6a42fdba0a6ed7e7ae53e0fbf2acd774b6 (patch) | |
| tree | cee90836aaa0d4f540a40b32a589a783eb71fdb8 /src/Data | |
| parent | 8e0038628e866ac5ce716e7971e150d2a8f23f4c (diff) | |
| download | DevHive-379eda6a42fdba0a6ed7e7ae53e0fbf2acd774b6.tar DevHive-379eda6a42fdba0a6ed7e7ae53e0fbf2acd774b6.tar.gz DevHive-379eda6a42fdba0a6ed7e7ae53e0fbf2acd774b6.zip | |
Adding update layer for rating_system
Diffstat (limited to 'src/Data')
| -rw-r--r-- | src/Data/DevHive.Data.Models/Post.cs | 2 | ||||
| -rw-r--r-- | src/Data/DevHive.Data/Interfaces/IRatingRepository.cs | 2 | ||||
| -rw-r--r-- | src/Data/DevHive.Data/Repositories/RatingRepository.cs | 11 |
3 files changed, 10 insertions, 5 deletions
diff --git a/src/Data/DevHive.Data.Models/Post.cs b/src/Data/DevHive.Data.Models/Post.cs index 716248f..c95a8f1 100644 --- a/src/Data/DevHive.Data.Models/Post.cs +++ b/src/Data/DevHive.Data.Models/Post.cs @@ -21,8 +21,6 @@ namespace DevHive.Data.Models public List<Rating> Ratings { get; set; } - public int CurrentRating { get; set; } - public List<PostAttachments> Attachments { get; set; } = new(); } } 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); + } } } |
