aboutsummaryrefslogtreecommitdiff
path: root/src/DevHive.Data/Repositories/PostRepository.cs
diff options
context:
space:
mode:
authorSyndamia <kamen.d.mladenov@protonmail.com>2021-02-05 17:46:59 +0200
committerSyndamia <kamen.d.mladenov@protonmail.com>2021-02-05 17:46:59 +0200
commita0a048d1fc6672a6478169f3c9139d9e5a6ff474 (patch)
tree441ae3b35e2f6b55c9912e70f8a0f304ba26bc83 /src/DevHive.Data/Repositories/PostRepository.cs
parent60ed435203f0c60d4c6fabe77aa4e87656aaf8c1 (diff)
downloadDevHive-a0a048d1fc6672a6478169f3c9139d9e5a6ff474.tar
DevHive-a0a048d1fc6672a6478169f3c9139d9e5a6ff474.tar.gz
DevHive-a0a048d1fc6672a6478169f3c9139d9e5a6ff474.zip
Implemented post attachments, which move post file urls to their own table; updated post repository and post service to work with them (but didn't update service or web models)
Diffstat (limited to 'src/DevHive.Data/Repositories/PostRepository.cs')
-rw-r--r--src/DevHive.Data/Repositories/PostRepository.cs17
1 files changed, 9 insertions, 8 deletions
diff --git a/src/DevHive.Data/Repositories/PostRepository.cs b/src/DevHive.Data/Repositories/PostRepository.cs
index ed2fa1b..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,6 +35,7 @@ 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);
}
@@ -51,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
@@ -66,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)
@@ -96,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