diff options
Diffstat (limited to 'src/DevHive.Data')
| -rw-r--r-- | src/DevHive.Data/Interfaces/Models/IPost.cs | 2 | ||||
| -rw-r--r-- | src/DevHive.Data/Interfaces/Repositories/IPostRepository.cs | 4 | ||||
| -rw-r--r-- | src/DevHive.Data/Models/Post.cs | 2 | ||||
| -rw-r--r-- | src/DevHive.Data/Repositories/BaseRepository.cs | 6 | ||||
| -rw-r--r-- | src/DevHive.Data/Repositories/PostRepository.cs | 16 |
5 files changed, 25 insertions, 5 deletions
diff --git a/src/DevHive.Data/Interfaces/Models/IPost.cs b/src/DevHive.Data/Interfaces/Models/IPost.cs index 0902465..86469a7 100644 --- a/src/DevHive.Data/Interfaces/Models/IPost.cs +++ b/src/DevHive.Data/Interfaces/Models/IPost.cs @@ -14,6 +14,6 @@ namespace DevHive.Data.Interfaces.Models List<Comment> Comments { get; set; } - //List<Files> Files + List<string> FileUrls { get; set; } } } diff --git a/src/DevHive.Data/Interfaces/Repositories/IPostRepository.cs b/src/DevHive.Data/Interfaces/Repositories/IPostRepository.cs index aa0afc7..5022df5 100644 --- a/src/DevHive.Data/Interfaces/Repositories/IPostRepository.cs +++ b/src/DevHive.Data/Interfaces/Repositories/IPostRepository.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Threading.Tasks; using DevHive.Data.Models; using DevHive.Data.Repositories.Interfaces; @@ -8,6 +9,9 @@ namespace DevHive.Data.Interfaces.Repositories public interface IPostRepository : IRepository<Post> { Task<Post> GetPostByCreatorAndTimeCreatedAsync(Guid issuerId, DateTime timeCreated); + Task<List<string>> GetFileUrls(Guid postId); + Task<bool> DoesPostExist(Guid postId); + Task<bool> DoesPostHaveFiles(Guid postId); } } diff --git a/src/DevHive.Data/Models/Post.cs b/src/DevHive.Data/Models/Post.cs index 0ea7142..c513eb4 100644 --- a/src/DevHive.Data/Models/Post.cs +++ b/src/DevHive.Data/Models/Post.cs @@ -18,6 +18,6 @@ namespace DevHive.Data.Models public List<Comment> Comments { get; set; } = new(); - // public List<string> Files { get; set; } = new(); + public List<string> FileUrls { get; set; } = new(); } } diff --git a/src/DevHive.Data/Repositories/BaseRepository.cs b/src/DevHive.Data/Repositories/BaseRepository.cs index f1e6673..cac802e 100644 --- a/src/DevHive.Data/Repositories/BaseRepository.cs +++ b/src/DevHive.Data/Repositories/BaseRepository.cs @@ -34,10 +34,10 @@ namespace DevHive.Data.Repositories public virtual async Task<bool> EditAsync(Guid id, TEntity newEntity) { var entry = this._context.Entry(newEntity); - if (entry.State == EntityState.Detached) - this._context.Attach(newEntity); + if (entry.State == EntityState.Detached) + this._context.Attach(newEntity); - entry.State = EntityState.Modified; + entry.State = EntityState.Modified; return await this.SaveChangesAsync(_context); } diff --git a/src/DevHive.Data/Repositories/PostRepository.cs b/src/DevHive.Data/Repositories/PostRepository.cs index 67988f2..78b40cd 100644 --- a/src/DevHive.Data/Repositories/PostRepository.cs +++ b/src/DevHive.Data/Repositories/PostRepository.cs @@ -1,4 +1,6 @@ using System; +using System.Collections.Generic; +using System.Linq; using System.Threading.Tasks; using DevHive.Data.Interfaces.Repositories; using DevHive.Data.Models; @@ -30,6 +32,11 @@ namespace DevHive.Data.Repositories .FirstOrDefaultAsync(p => p.Creator.Id == creatorId && p.TimeCreated == timeCreated); } + + public async Task<List<string>> GetFileUrls(Guid postId) + { + return (await this.GetByIdAsync(postId)).FileUrls; + } #endregion #region Validations @@ -39,6 +46,15 @@ namespace DevHive.Data.Repositories .AsNoTracking() .AnyAsync(r => r.Id == postId); } + + public async Task<bool> DoesPostHaveFiles(Guid postId) + { + return await this._context.Posts + .AsNoTracking() + .Where(x => x.Id == postId) + .Select(x => x.FileUrls) + .AnyAsync(); + } #endregion } } |
