Website Summary Files Commits Branches @commit @diff @stats
path: root / src / DevHive.Data
diff options
context:
space:
mode:
Commitb38d6693476917972345397298b534af2b8b8f78 (patch)
Author
 transtrike <transtrike@gmail.com>
2021-01-29 20:39:07 +0200
Committer
 transtrike <transtrike@gmail.com>
2021-01-29 20:39:07 +0200
Files5e62376cf693a7233cec4ab341f658be5d9c4ec2 /src/DevHive.Data
DevHive-b38d6693476917972345397298b534af2b8b8f78.tar
DevHive-b38d6693476917972345397298b534af2b8b8f78.tar.gz
DevHive-b38d6693476917972345397298b534af2b8b8f78.zip
Parent2417df3ff2939b67695b80905f301ef53c905260 (diff)
File Upload implemented; Post Layers adapted to File Uploading
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
}
}