aboutsummaryrefslogtreecommitdiff
path: root/src/DevHive.Data
diff options
context:
space:
mode:
authortranstrike <transtrike@gmail.com>2021-01-29 20:39:07 +0200
committertranstrike <transtrike@gmail.com>2021-01-29 20:39:07 +0200
commitb38d6693476917972345397298b534af2b8b8f78 (patch)
tree5e62376cf693a7233cec4ab341f658be5d9c4ec2 /src/DevHive.Data
parent2417df3ff2939b67695b80905f301ef53c905260 (diff)
downloadDevHive-b38d6693476917972345397298b534af2b8b8f78.tar
DevHive-b38d6693476917972345397298b534af2b8b8f78.tar.gz
DevHive-b38d6693476917972345397298b534af2b8b8f78.zip
File Upload implemented; Post Layers adapted to File Uploading
Diffstat (limited to 'src/DevHive.Data')
-rw-r--r--src/DevHive.Data/Interfaces/Models/IPost.cs2
-rw-r--r--src/DevHive.Data/Interfaces/Repositories/IPostRepository.cs4
-rw-r--r--src/DevHive.Data/Models/Post.cs2
-rw-r--r--src/DevHive.Data/Repositories/BaseRepository.cs6
-rw-r--r--src/DevHive.Data/Repositories/PostRepository.cs16
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
}
}