aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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
-rw-r--r--src/Services/DevHive.Services.Models/Post/Rating/CreateRatingServiceModel.cs (renamed from src/Services/DevHive.Services.Models/Post/Rating/RatePostServiceModel.cs)4
-rw-r--r--src/Services/DevHive.Services.Models/Post/Rating/ReadRatingServiceModel.cs (renamed from src/Services/DevHive.Services.Models/Post/Rating/ReadPostRatingServiceModel.cs)2
-rw-r--r--src/Services/DevHive.Services.Models/Post/ReadPostServiceModel.cs3
-rw-r--r--src/Services/DevHive.Services/Interfaces/IRatingService.cs (renamed from src/Services/DevHive.Services/Interfaces/IRateService.cs)4
-rw-r--r--src/Services/DevHive.Services/Services/PostService.cs1
-rw-r--r--src/Services/DevHive.Services/Services/RatingService.cs (renamed from src/Services/DevHive.Services/Services/RateService.cs)8
-rw-r--r--src/Web/DevHive.Web.Models/Post/ReadPostWebModel.cs2
-rw-r--r--src/Web/DevHive.Web/Configurations/Extensions/ConfigureDependencyInjection.cs2
-rw-r--r--src/Web/DevHive.Web/Configurations/Mapping/RatingMappings.cs4
-rw-r--r--src/Web/DevHive.Web/Controllers/RateController.cs8
17 files changed, 39 insertions, 30 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)
diff --git a/src/Services/DevHive.Services.Models/Post/Rating/RatePostServiceModel.cs b/src/Services/DevHive.Services.Models/Post/Rating/CreateRatingServiceModel.cs
index d4eb7bd..aaeab73 100644
--- a/src/Services/DevHive.Services.Models/Post/Rating/RatePostServiceModel.cs
+++ b/src/Services/DevHive.Services.Models/Post/Rating/CreateRatingServiceModel.cs
@@ -2,12 +2,12 @@ using System;
namespace DevHive.Services.Models.Post.Rating
{
- public class RatePostServiceModel
+ public class CreateRatingServiceModel
{
public Guid UserId { get; set; }
public Guid PostId { get; set; }
- public bool Liked { get; set; }
+ public bool IsLike { get; set; }
}
}
diff --git a/src/Services/DevHive.Services.Models/Post/Rating/ReadPostRatingServiceModel.cs b/src/Services/DevHive.Services.Models/Post/Rating/ReadRatingServiceModel.cs
index 8c73aaf..dbc7ecc 100644
--- a/src/Services/DevHive.Services.Models/Post/Rating/ReadPostRatingServiceModel.cs
+++ b/src/Services/DevHive.Services.Models/Post/Rating/ReadRatingServiceModel.cs
@@ -2,7 +2,7 @@ using System;
namespace DevHive.Services.Models.Post.Rating
{
- public class ReadPostRatingServiceModel
+ public class ReadRatingServiceModel
{
public Guid Id { get; set; }
diff --git a/src/Services/DevHive.Services.Models/Post/ReadPostServiceModel.cs b/src/Services/DevHive.Services.Models/Post/ReadPostServiceModel.cs
index a7aa882..33d6520 100644
--- a/src/Services/DevHive.Services.Models/Post/ReadPostServiceModel.cs
+++ b/src/Services/DevHive.Services.Models/Post/ReadPostServiceModel.cs
@@ -21,6 +21,7 @@ namespace DevHive.Services.Models.Post
public List<IdModel> Comments { get; set; } = new();
public List<string> FileUrls { get; set; }
- // public List<FileContentResult> Files { get; set; } = new();
+
+ public int CurrentRating { get; set; }
}
}
diff --git a/src/Services/DevHive.Services/Interfaces/IRateService.cs b/src/Services/DevHive.Services/Interfaces/IRatingService.cs
index 359ef55..adb4313 100644
--- a/src/Services/DevHive.Services/Interfaces/IRateService.cs
+++ b/src/Services/DevHive.Services/Interfaces/IRatingService.cs
@@ -5,9 +5,9 @@ using DevHive.Services.Models.Post.Rating;
namespace DevHive.Services.Interfaces
{
- public interface IRateService
+ public interface IRatingService
{
- Task<ReadPostRatingServiceModel> RatePost(RatePostServiceModel ratePostServiceModel);
+ Task<ReadRatingServiceModel> RatePost(CreateRatingServiceModel ratePostServiceModel);
bool HasUserRatedThisPost(User user, Post post);
}
diff --git a/src/Services/DevHive.Services/Services/PostService.cs b/src/Services/DevHive.Services/Services/PostService.cs
index a3d5117..4bece90 100644
--- a/src/Services/DevHive.Services/Services/PostService.cs
+++ b/src/Services/DevHive.Services/Services/PostService.cs
@@ -46,6 +46,7 @@ namespace DevHive.Services.Services
post.Creator = await this._userRepository.GetByIdAsync(createPostServiceModel.CreatorId);
post.TimeCreated = DateTime.Now;
+ post.CurrentRating = 0;
bool success = await this._postRepository.AddAsync(post);
if (success)
diff --git a/src/Services/DevHive.Services/Services/RateService.cs b/src/Services/DevHive.Services/Services/RatingService.cs
index caf4b80..45ff7c0 100644
--- a/src/Services/DevHive.Services/Services/RateService.cs
+++ b/src/Services/DevHive.Services/Services/RatingService.cs
@@ -9,14 +9,14 @@ using DevHive.Services.Models.Post.Rating;
namespace DevHive.Services.Services
{
- public class RateService : IRateService
+ public class RatingService : IRatingService
{
private readonly IPostRepository _postRepository;
private readonly IUserRepository _userRepository;
private readonly IRatingRepository _ratingRepository;
private readonly IMapper _mapper;
- public RateService(IPostRepository postRepository, IRatingRepository ratingRepository, IUserRepository userRepository, IMapper mapper)
+ public RatingService(IPostRepository postRepository, IRatingRepository ratingRepository, IUserRepository userRepository, IMapper mapper)
{
this._postRepository = postRepository;
this._ratingRepository = ratingRepository;
@@ -24,7 +24,7 @@ namespace DevHive.Services.Services
this._mapper = mapper;
}
- public async Task<ReadPostRatingServiceModel> RatePost(RatePostServiceModel ratePostServiceModel)
+ public async Task<ReadRatingServiceModel> RatePost(CreateRatingServiceModel ratePostServiceModel)
{
throw new NotImplementedException();
// if (!await this._postRepository.DoesPostExist(ratePostServiceModel.PostId))
@@ -49,7 +49,7 @@ namespace DevHive.Services.Services
// return this._mapper.Map<ReadPostRatingServiceModel>(newRating);
}
- public async Task<ReadPostRatingServiceModel> RemoveUserRateFromPost(Guid userId, Guid postId)
+ public async Task<ReadRatingServiceModel> RemoveUserRateFromPost(Guid userId, Guid postId)
{
throw new NotImplementedException();
// Post post = await this._postRepository.GetByIdAsync(postId);
diff --git a/src/Web/DevHive.Web.Models/Post/ReadPostWebModel.cs b/src/Web/DevHive.Web.Models/Post/ReadPostWebModel.cs
index 3ae93aa..d6ea1f4 100644
--- a/src/Web/DevHive.Web.Models/Post/ReadPostWebModel.cs
+++ b/src/Web/DevHive.Web.Models/Post/ReadPostWebModel.cs
@@ -21,5 +21,7 @@ namespace DevHive.Web.Models.Post
public List<IdModel> Comments { get; set; }
public List<string> FileUrls { get; set; }
+
+ public int CurrentRating { get; set; }
}
}
diff --git a/src/Web/DevHive.Web/Configurations/Extensions/ConfigureDependencyInjection.cs b/src/Web/DevHive.Web/Configurations/Extensions/ConfigureDependencyInjection.cs
index c547951..153b17f 100644
--- a/src/Web/DevHive.Web/Configurations/Extensions/ConfigureDependencyInjection.cs
+++ b/src/Web/DevHive.Web/Configurations/Extensions/ConfigureDependencyInjection.cs
@@ -32,7 +32,7 @@ namespace DevHive.Web.Configurations.Extensions
cloudName: configuration.GetSection("Cloud").GetSection("cloudName").Value,
apiKey: configuration.GetSection("Cloud").GetSection("apiKey").Value,
apiSecret: configuration.GetSection("Cloud").GetSection("apiSecret").Value));
- services.AddTransient<IRateService, RateService>();
+ services.AddTransient<IRatingService, RatingService>();
}
}
}
diff --git a/src/Web/DevHive.Web/Configurations/Mapping/RatingMappings.cs b/src/Web/DevHive.Web/Configurations/Mapping/RatingMappings.cs
index a29e06c..1b43b2b 100644
--- a/src/Web/DevHive.Web/Configurations/Mapping/RatingMappings.cs
+++ b/src/Web/DevHive.Web/Configurations/Mapping/RatingMappings.cs
@@ -8,9 +8,9 @@ namespace DevHive.Web.Configurations.Mapping
{
public RatingMappings()
{
- CreateMap<RatePostWebModel, RatePostServiceModel>();
+ CreateMap<RatePostWebModel, CreateRatingServiceModel>();
- CreateMap<ReadPostRatingServiceModel, ReadPostRatingWebModel>();
+ CreateMap<ReadRatingServiceModel, ReadPostRatingWebModel>();
}
}
}
diff --git a/src/Web/DevHive.Web/Controllers/RateController.cs b/src/Web/DevHive.Web/Controllers/RateController.cs
index 72eb932..7f8a95f 100644
--- a/src/Web/DevHive.Web/Controllers/RateController.cs
+++ b/src/Web/DevHive.Web/Controllers/RateController.cs
@@ -13,11 +13,11 @@ namespace DevHive.Web.Controllers
[Route("api/[controller]")]
public class RateController
{
- private readonly IRateService _rateService;
+ private readonly IRatingService _rateService;
private readonly IUserService _userService;
private readonly IMapper _mapper;
- public RateController(IRateService rateService, IUserService userService, IMapper mapper)
+ public RateController(IRatingService rateService, IUserService userService, IMapper mapper)
{
this._rateService = rateService;
this._userService = userService;
@@ -28,10 +28,10 @@ namespace DevHive.Web.Controllers
[Authorize(Roles = "Admin,User")]
public async Task<IActionResult> RatePost(Guid userId, [FromBody] RatePostWebModel ratePostWebModel, [FromHeader] string authorization)
{
- RatePostServiceModel ratePostServiceModel = this._mapper.Map<RatePostServiceModel>(ratePostWebModel);
+ CreateRatingServiceModel ratePostServiceModel = this._mapper.Map<CreateRatingServiceModel>(ratePostWebModel);
ratePostServiceModel.UserId = userId;
- ReadPostRatingServiceModel readPostRatingServiceModel = await this._rateService.RatePost(ratePostServiceModel);
+ ReadRatingServiceModel readPostRatingServiceModel = await this._rateService.RatePost(ratePostServiceModel);
ReadPostRatingWebModel readPostRatingWebModel = this._mapper.Map<ReadPostRatingWebModel>(readPostRatingServiceModel);
return new OkObjectResult(readPostRatingWebModel);