aboutsummaryrefslogtreecommitdiff
path: root/src/Data
diff options
context:
space:
mode:
Diffstat (limited to 'src/Data')
-rw-r--r--src/Data/DevHive.Data.Models/Interfaces/IRating.cs7
-rw-r--r--src/Data/DevHive.Data.Models/Post.cs4
-rw-r--r--src/Data/DevHive.Data.Models/Rating.cs5
-rw-r--r--src/Data/DevHive.Data/DevHiveContext.cs5
-rw-r--r--src/Data/DevHive.Data/Interfaces/IRatingRepository.cs3
-rw-r--r--src/Data/DevHive.Data/Repositories/PostRepository.cs2
-rw-r--r--src/Data/DevHive.Data/Repositories/RatingRepository.cs5
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)