diff options
| author | Danail Dimitrov <danaildimitrov321@gmail.com> | 2021-02-21 22:21:08 +0200 |
|---|---|---|
| committer | Danail Dimitrov <danaildimitrov321@gmail.com> | 2021-02-21 22:21:08 +0200 |
| commit | a851adfac47a26cae83e9161d37902a219e5ebf3 (patch) | |
| tree | f8b214b22d83c78c3036796383cc4edba6483a28 /src/Data | |
| parent | 1d2f0ea1665b6eb2d9cc3334841318a39ab41e0e (diff) | |
| download | DevHive-a851adfac47a26cae83e9161d37902a219e5ebf3.tar DevHive-a851adfac47a26cae83e9161d37902a219e5ebf3.tar.gz DevHive-a851adfac47a26cae83e9161d37902a219e5ebf3.zip | |
model update for rating
Diffstat (limited to 'src/Data')
| -rw-r--r-- | src/Data/DevHive.Data.Models/Interfaces/IRating.cs | 7 | ||||
| -rw-r--r-- | src/Data/DevHive.Data.Models/Post.cs | 4 | ||||
| -rw-r--r-- | src/Data/DevHive.Data.Models/Rating.cs | 5 | ||||
| -rw-r--r-- | src/Data/DevHive.Data/DevHiveContext.cs | 5 | ||||
| -rw-r--r-- | src/Data/DevHive.Data/Interfaces/IRatingRepository.cs | 3 | ||||
| -rw-r--r-- | src/Data/DevHive.Data/Repositories/PostRepository.cs | 2 | ||||
| -rw-r--r-- | src/Data/DevHive.Data/Repositories/RatingRepository.cs | 5 |
7 files changed, 18 insertions, 13 deletions
diff --git a/src/Data/DevHive.Data.Models/Interfaces/IRating.cs b/src/Data/DevHive.Data.Models/Interfaces/IRating.cs index 1b081b0..f04f823 100644 --- a/src/Data/DevHive.Data.Models/Interfaces/IRating.cs +++ b/src/Data/DevHive.Data.Models/Interfaces/IRating.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using DevHive.Data.Models; @@ -5,10 +6,10 @@ namespace DevHive.Data.Models.Interfaces { public interface IRating : IModel { - // Post Post { get; set; } + bool IsLike { get; set; } - int Rate { get; set; } + Post Post { get; set; } - // HashSet<User> UsersThatRated { get; set; } + User User { get; set; } } } diff --git a/src/Data/DevHive.Data.Models/Post.cs b/src/Data/DevHive.Data.Models/Post.cs index 15b6b77..716248f 100644 --- a/src/Data/DevHive.Data.Models/Post.cs +++ b/src/Data/DevHive.Data.Models/Post.cs @@ -19,7 +19,9 @@ namespace DevHive.Data.Models public List<Comment> Comments { get; set; } = new(); - public Rating Rating { get; set; } = new(); + 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.Models/Rating.cs b/src/Data/DevHive.Data.Models/Rating.cs index 13fdbce..8743a3e 100644 --- a/src/Data/DevHive.Data.Models/Rating.cs +++ b/src/Data/DevHive.Data.Models/Rating.cs @@ -6,12 +6,13 @@ namespace DevHive.Data.Models { public class Rating : IRating { + //if adding rating to comments change Post for intreface IRatable! public Guid Id { get; set; } - public Guid PostId { get; set; } + public User User { get; set; } public Post Post { get; set; } - public int Rate { get; set; } + public bool IsLike { get; set; } } } diff --git a/src/Data/DevHive.Data/DevHiveContext.cs b/src/Data/DevHive.Data/DevHiveContext.cs index ece3439..b0bbdc6 100644 --- a/src/Data/DevHive.Data/DevHiveContext.cs +++ b/src/Data/DevHive.Data/DevHiveContext.cs @@ -88,11 +88,10 @@ namespace DevHive.Data builder.Entity<Rating>() .HasOne(x => x.Post) - .WithOne(x => x.Rating) - .HasForeignKey<Rating>(x => x.PostId); + .WithMany(x => x.Ratings); builder.Entity<Post>() - .HasOne(x => x.Rating) + .HasMany(x => x.Ratings) .WithOne(x => x.Post); /* User Rated Posts */ diff --git a/src/Data/DevHive.Data/Interfaces/IRatingRepository.cs b/src/Data/DevHive.Data/Interfaces/IRatingRepository.cs index b5aff88..c8636b6 100644 --- a/src/Data/DevHive.Data/Interfaces/IRatingRepository.cs +++ b/src/Data/DevHive.Data/Interfaces/IRatingRepository.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Threading.Tasks; using DevHive.Data.Models; using DevHive.Data.Repositories.Interfaces; @@ -7,7 +8,7 @@ namespace DevHive.Data.Interfaces { public interface IRatingRepository : IRepository<Rating> { - Task<Rating> GetRatingByPostId(Guid postId); + Task<List<Rating>> GetRatingsByPostId(Guid postId); Task<bool> UserRatedPost(Guid userId, Guid postId); } } diff --git a/src/Data/DevHive.Data/Repositories/PostRepository.cs b/src/Data/DevHive.Data/Repositories/PostRepository.cs index b6c5e37..0ab1afb 100644 --- a/src/Data/DevHive.Data/Repositories/PostRepository.cs +++ b/src/Data/DevHive.Data/Repositories/PostRepository.cs @@ -36,7 +36,7 @@ namespace DevHive.Data.Repositories .Include(x => x.Comments) .Include(x => x.Creator) .Include(x => x.Attachments) - // .Include(x => x.Rating) + .Include(x => x.CurrentRating) .FirstOrDefaultAsync(x => x.Id == id); } diff --git a/src/Data/DevHive.Data/Repositories/RatingRepository.cs b/src/Data/DevHive.Data/Repositories/RatingRepository.cs index b361693..2f56aee 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,10 +20,10 @@ namespace DevHive.Data.Repositories this._postRepository = postRepository; } - public async Task<Rating> GetRatingByPostId(Guid postId) + public async Task<List<Rating>> GetRatingsByPostId(Guid postId) { return await this._context.Rating - .FirstOrDefaultAsync(x => x.Post.Id == postId); + .Where(x => x.Post.Id == postId).ToListAsync(); } public async Task<bool> UserRatedPost(Guid userId, Guid postId) |
