aboutsummaryrefslogtreecommitdiff
path: root/src/DevHive.Data/Repositories
diff options
context:
space:
mode:
authortranstrike <transtrike@gmail.com>2021-02-05 19:00:24 +0200
committertranstrike <transtrike@gmail.com>2021-02-05 19:00:24 +0200
commit75eeb4358e746d887677903052ed4bd5ca176f4d (patch)
tree9f9b9eb0103d61f488c08fa4b4b5f308ca9ab35a /src/DevHive.Data/Repositories
parent51e157d1e1dc57ea2ba9c29b355fa7982a29bebe (diff)
parent4eb5ccdfc8ee4ac9795c48c701e565dbe2b641f9 (diff)
downloadDevHive-75eeb4358e746d887677903052ed4bd5ca176f4d.tar
DevHive-75eeb4358e746d887677903052ed4bd5ca176f4d.tar.gz
DevHive-75eeb4358e746d887677903052ed4bd5ca176f4d.zip
Merge branch 'dev' of github.com:Team-Kaleidoscope/DevHive into dev
Diffstat (limited to 'src/DevHive.Data/Repositories')
-rw-r--r--src/DevHive.Data/Repositories/CommentRepository.cs3
-rw-r--r--src/DevHive.Data/Repositories/FeedRepository.cs18
-rw-r--r--src/DevHive.Data/Repositories/LanguageRepository.cs3
-rw-r--r--src/DevHive.Data/Repositories/PostRepository.cs20
-rw-r--r--src/DevHive.Data/Repositories/RatingRepository.cs15
-rw-r--r--src/DevHive.Data/Repositories/TechnologyRepository.cs3
6 files changed, 47 insertions, 15 deletions
diff --git a/src/DevHive.Data/Repositories/CommentRepository.cs b/src/DevHive.Data/Repositories/CommentRepository.cs
index 382c666..bee7624 100644
--- a/src/DevHive.Data/Repositories/CommentRepository.cs
+++ b/src/DevHive.Data/Repositories/CommentRepository.cs
@@ -28,6 +28,9 @@ namespace DevHive.Data.Repositories
.FirstOrDefaultAsync(x => x.Id == id);
}
+ /// <summary>
+ /// This method returns the comment that is made at exactly the given time and by the given creator
+ /// </summary>
public async Task<Comment> GetCommentByIssuerAndTimeCreatedAsync(Guid issuerId, DateTime timeCreated)
{
return await this._context.Comments
diff --git a/src/DevHive.Data/Repositories/FeedRepository.cs b/src/DevHive.Data/Repositories/FeedRepository.cs
index 271c3a5..8d3e5e1 100644
--- a/src/DevHive.Data/Repositories/FeedRepository.cs
+++ b/src/DevHive.Data/Repositories/FeedRepository.cs
@@ -18,6 +18,15 @@ namespace DevHive.Data.Repositories
this._context = context;
}
+ /// <summary>
+ /// This returns a given amount of posts of all given friends, created before "firstRequestIssued",
+ /// ordered from latest to oldest (time created).
+ /// PageSize specifies how many posts to get, and pageNumber specifices how many posts to skip (pageNumber * pageSize).
+ ///
+ /// This method is used in the feed page.
+ /// Posts from friends are meant to be gotten in chunks, meaning you get X posts, and then get another amount of posts,
+ /// that are after the first X posts.
+ /// </summary>
public async Task<List<Post>> GetFriendsPosts(List<User> friendsList, DateTime firstRequestIssued, int pageNumber, int pageSize)
{
List<Guid> friendsIds = friendsList.Select(f => f.Id).ToList();
@@ -39,6 +48,15 @@ namespace DevHive.Data.Repositories
return posts;
}
+ /// <summary>
+ /// This returns a given amount of posts, that a user has made, created before "firstRequestIssued",
+ /// ordered from latest to oldest (time created).
+ /// PageSize specifies how many posts to get, and pageNumber specifices how many posts to skip (pageNumber * pageSize).
+ ///
+ /// This method is used in the profile page.
+ /// Posts from friends are meant to be gotten in chunks, meaning you get X posts, and then get another amount of posts,
+ /// that are after the first X posts.
+ /// </summary>
public async Task<List<Post>> GetUsersPosts(User user, DateTime firstRequestIssued, int pageNumber, int pageSize)
{
List<Post> posts = await this._context.Posts
diff --git a/src/DevHive.Data/Repositories/LanguageRepository.cs b/src/DevHive.Data/Repositories/LanguageRepository.cs
index 7f4b946..31d0b86 100644
--- a/src/DevHive.Data/Repositories/LanguageRepository.cs
+++ b/src/DevHive.Data/Repositories/LanguageRepository.cs
@@ -25,6 +25,9 @@ namespace DevHive.Data.Repositories
.FirstOrDefaultAsync(x => x.Name == languageName);
}
+ /// <summary>
+ /// Returns all technologies that exist in the database
+ /// </summary>
public HashSet<Language> GetLanguages()
{
return this._context.Languages.ToHashSet();
diff --git a/src/DevHive.Data/Repositories/PostRepository.cs b/src/DevHive.Data/Repositories/PostRepository.cs
index 0fec435..52c5b4e 100644
--- a/src/DevHive.Data/Repositories/PostRepository.cs
+++ b/src/DevHive.Data/Repositories/PostRepository.cs
@@ -2,14 +2,14 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
-using DevHive.Data.Interfaces.Models;
using DevHive.Data.Interfaces.Repositories;
using DevHive.Data.Models;
+using DevHive.Data.RelationModels;
using Microsoft.EntityFrameworkCore;
namespace DevHive.Data.Repositories
{
- public class PostRepository : BaseRepository<Post>, IPostRepository
+ public class PostRepository : BaseRepository<Post>, IPostRepository
{
private readonly DevHiveContext _context;
private readonly IUserRepository _userRepository;
@@ -35,10 +35,14 @@ namespace DevHive.Data.Repositories
return await this._context.Posts
.Include(x => x.Comments)
.Include(x => x.Creator)
+ .Include(x => x.Attachments)
// .Include(x => x.Rating)
.FirstOrDefaultAsync(x => x.Id == id);
}
+ /// <summary>
+ /// This method returns the post that is made at exactly the given time and by the given creator
+ /// </summary>
public async Task<Post> GetPostByCreatorAndTimeCreatedAsync(Guid creatorId, DateTime timeCreated)
{
return await this._context.Posts
@@ -48,7 +52,7 @@ namespace DevHive.Data.Repositories
public async Task<List<string>> GetFileUrls(Guid postId)
{
- return (await this.GetByIdAsync(postId)).FileUrls;
+ return (await this.GetByIdAsync(postId)).Attachments.Select(x => x.FileUrl).ToList();
}
#endregion
@@ -63,10 +67,10 @@ namespace DevHive.Data.Repositories
.CurrentValues
.SetValues(newEntity);
- List<string> fileUrls = new();
- foreach(var fileUrl in newEntity.FileUrls)
- fileUrls.Add(fileUrl);
- post.FileUrls = fileUrls;
+ List<PostAttachments> postAttachments = new();
+ foreach(var attachment in newEntity.Attachments)
+ postAttachments.Add(attachment);
+ post.Attachments = postAttachments;
post.Comments.Clear();
foreach(var comment in newEntity.Comments)
@@ -93,7 +97,7 @@ namespace DevHive.Data.Repositories
return await this._context.Posts
.AsNoTracking()
.Where(x => x.Id == postId)
- .Select(x => x.FileUrls)
+ .Select(x => x.Attachments)
.AnyAsync();
}
#endregion
diff --git a/src/DevHive.Data/Repositories/RatingRepository.cs b/src/DevHive.Data/Repositories/RatingRepository.cs
index d676f27..1be8fe8 100644
--- a/src/DevHive.Data/Repositories/RatingRepository.cs
+++ b/src/DevHive.Data/Repositories/RatingRepository.cs
@@ -1,4 +1,5 @@
using System;
+using System.Linq;
using System.Threading.Tasks;
using DevHive.Data.Interfaces.Repositories;
using DevHive.Data.Models;
@@ -18,17 +19,17 @@ namespace DevHive.Data.Repositories
this._postRepository = postRepository;
}
- public async Task<Rating> GetByPostId(Guid postId)
+ public async Task<Rating> GetRatingByPostId(Guid postId)
{
- throw new NotImplementedException();
- // return await this._context.Rating
- // .FirstOrDefaultAsync(x => x.Post.Id == postId);
+ return await this._context.Rating
+ .FirstOrDefaultAsync(x => x.Post.Id == postId);
}
- public async Task<int> GetRating(Guid postId)
+ public async Task<bool> UserRatedPost(Guid userId, Guid postId)
{
- throw new NotImplementedException();
- // return (await this.GetByPostId(postId)).Rate;
+ return await this._context.UserRate
+ .Where(x => x.Post.Id == postId)
+ .AnyAsync(x => x.User.Id == userId);
}
}
}
diff --git a/src/DevHive.Data/Repositories/TechnologyRepository.cs b/src/DevHive.Data/Repositories/TechnologyRepository.cs
index 7bb43cc..6f0d10f 100644
--- a/src/DevHive.Data/Repositories/TechnologyRepository.cs
+++ b/src/DevHive.Data/Repositories/TechnologyRepository.cs
@@ -25,6 +25,9 @@ namespace DevHive.Data.Repositories
.FirstOrDefaultAsync(x => x.Name == technologyName);
}
+ /// <summary>
+ /// Returns all technologies that exist in the database
+ /// </summary>
public HashSet<Technology> GetTechnologies()
{
return this._context.Technologies.ToHashSet();