aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/DevHive.Data/DevHiveContext.cs1
-rw-r--r--src/DevHive.Data/Interfaces/Repositories/IPostRepository.cs4
-rw-r--r--src/DevHive.Data/Repositories/PostRepository.cs14
-rw-r--r--src/DevHive.Services/Interfaces/ILanguageService.cs2
-rw-r--r--src/DevHive.Services/Interfaces/IPostService.cs4
-rw-r--r--src/DevHive.Services/Interfaces/ITechnologyService.cs2
-rw-r--r--src/DevHive.Services/Models/Post/Comment/BaseCommentServiceModel.cs3
-rw-r--r--src/DevHive.Services/Services/LanguageService.cs14
-rw-r--r--src/DevHive.Services/Services/PostService.cs24
-rw-r--r--src/DevHive.Services/Services/TechnologyService.cs14
-rw-r--r--src/DevHive.Web/Controllers/LanguageController.cs9
-rw-r--r--src/DevHive.Web/Controllers/PostController.cs18
-rw-r--r--src/DevHive.Web/Controllers/TechnologyController.cs13
-rw-r--r--src/DevHive.Web/Models/Post/Comment/CommentWebModel.cs3
-rw-r--r--src/DevHive.code-workspace2
15 files changed, 85 insertions, 42 deletions
diff --git a/src/DevHive.Data/DevHiveContext.cs b/src/DevHive.Data/DevHiveContext.cs
index 10fd004..c1bda49 100644
--- a/src/DevHive.Data/DevHiveContext.cs
+++ b/src/DevHive.Data/DevHiveContext.cs
@@ -12,6 +12,7 @@ namespace DevHive.Data
public DbSet<Technology> Technologies { get; set; }
public DbSet<Language> Languages { get; set; }
+ public DbSet<Post> Posts { get; set; }
public DbSet<Comment> Comments { get; set; }
protected override void OnModelCreating(ModelBuilder builder)
diff --git a/src/DevHive.Data/Interfaces/Repositories/IPostRepository.cs b/src/DevHive.Data/Interfaces/Repositories/IPostRepository.cs
index 913d8c4..7a9c02e 100644
--- a/src/DevHive.Data/Interfaces/Repositories/IPostRepository.cs
+++ b/src/DevHive.Data/Interfaces/Repositories/IPostRepository.cs
@@ -9,12 +9,16 @@ namespace DevHive.Data.Interfaces.Repositories
{
Task<bool> AddCommentAsync(Comment entity);
+ Task<Post> GetPostByIssuerAndTimeCreatedAsync(Guid issuerId, DateTime timeCreated);
+
Task<Comment> GetCommentByIdAsync(Guid id);
+ Task<Comment> GetCommentByIssuerAndTimeCreatedAsync(Guid issuerId, DateTime timeCreated);
Task<bool> EditCommentAsync(Comment newEntity);
Task<bool> DeleteCommentAsync(Comment entity);
Task<bool> DoesCommentExist(Guid id);
+
Task<bool> DoesPostExist(Guid postId);
}
}
diff --git a/src/DevHive.Data/Repositories/PostRepository.cs b/src/DevHive.Data/Repositories/PostRepository.cs
index 3be14e3..c5e8569 100644
--- a/src/DevHive.Data/Repositories/PostRepository.cs
+++ b/src/DevHive.Data/Repositories/PostRepository.cs
@@ -43,6 +43,13 @@ namespace DevHive.Data.Repositories
.FindAsync(id);
}
+ public async Task<Post> GetPostByIssuerAndTimeCreatedAsync(Guid issuerId, DateTime timeCreated)
+ {
+ return await this._context.Posts
+ .FirstOrDefaultAsync(p => p.IssuerId == issuerId &&
+ p.TimeCreated == timeCreated);
+ }
+
public async Task<Comment> GetCommentByIdAsync(Guid id)
{
return await this._context
@@ -50,6 +57,13 @@ namespace DevHive.Data.Repositories
.FindAsync(id);
}
+ public async Task<Comment> GetCommentByIssuerAndTimeCreatedAsync(Guid issuerId, DateTime timeCreated)
+ {
+ return await this._context.Comments
+ .FirstOrDefaultAsync(p => p.IssuerId == issuerId &&
+ p.TimeCreated == timeCreated);
+ }
+
//Update
public async Task<bool> EditAsync(Post newPost)
{
diff --git a/src/DevHive.Services/Interfaces/ILanguageService.cs b/src/DevHive.Services/Interfaces/ILanguageService.cs
index 4d16ea3..0df9a95 100644
--- a/src/DevHive.Services/Interfaces/ILanguageService.cs
+++ b/src/DevHive.Services/Interfaces/ILanguageService.cs
@@ -6,7 +6,7 @@ namespace DevHive.Services.Interfaces
{
public interface ILanguageService
{
- Task<bool> CreateLanguage(CreateLanguageServiceModel createLanguageServiceModel);
+ Task<Guid> CreateLanguage(CreateLanguageServiceModel createLanguageServiceModel);
Task<ReadLanguageServiceModel> GetLanguageById(Guid id);
diff --git a/src/DevHive.Services/Interfaces/IPostService.cs b/src/DevHive.Services/Interfaces/IPostService.cs
index dd886b4..4364c67 100644
--- a/src/DevHive.Services/Interfaces/IPostService.cs
+++ b/src/DevHive.Services/Interfaces/IPostService.cs
@@ -7,8 +7,8 @@ namespace DevHive.Services.Interfaces
{
public interface IPostService
{
- Task<bool> CreatePost(CreatePostServiceModel postServiceModel);
- Task<bool> AddComment(CreateCommentServiceModel commentServiceModel);
+ Task<Guid> CreatePost(CreatePostServiceModel postServiceModel);
+ Task<Guid> AddComment(CreateCommentServiceModel commentServiceModel);
Task<CommentServiceModel> GetCommentById(Guid id);
Task<PostServiceModel> GetPostById(Guid id);
diff --git a/src/DevHive.Services/Interfaces/ITechnologyService.cs b/src/DevHive.Services/Interfaces/ITechnologyService.cs
index 9e1e955..9c5661d 100644
--- a/src/DevHive.Services/Interfaces/ITechnologyService.cs
+++ b/src/DevHive.Services/Interfaces/ITechnologyService.cs
@@ -6,7 +6,7 @@ namespace DevHive.Services.Interfaces
{
public interface ITechnologyService
{
- Task<bool> Create(CreateTechnologyServiceModel technologyServiceModel);
+ Task<Guid> Create(CreateTechnologyServiceModel technologyServiceModel);
Task<CreateTechnologyServiceModel> GetTechnologyById(Guid id);
diff --git a/src/DevHive.Services/Models/Post/Comment/BaseCommentServiceModel.cs b/src/DevHive.Services/Models/Post/Comment/BaseCommentServiceModel.cs
index 3aa92ee..54d6838 100644
--- a/src/DevHive.Services/Models/Post/Comment/BaseCommentServiceModel.cs
+++ b/src/DevHive.Services/Models/Post/Comment/BaseCommentServiceModel.cs
@@ -5,7 +5,8 @@ namespace DevHive.Services.Models.Post.Comment
public class BaseCommentServiceModel
{
public Guid Id { get; set; }
+ public Guid PostId { get; set; }
public Guid IssuerId { get; set; }
public string Message { get; set; }
}
-} \ No newline at end of file
+}
diff --git a/src/DevHive.Services/Services/LanguageService.cs b/src/DevHive.Services/Services/LanguageService.cs
index f457a31..e9c401e 100644
--- a/src/DevHive.Services/Services/LanguageService.cs
+++ b/src/DevHive.Services/Services/LanguageService.cs
@@ -21,15 +21,21 @@ namespace DevHive.Services.Services
#region Create
- public async Task<bool> CreateLanguage(CreateLanguageServiceModel createLanguageServiceModel)
+ public async Task<Guid> CreateLanguage(CreateLanguageServiceModel createLanguageServiceModel)
{
if (await this._languageRepository.DoesLanguageNameExistAsync(createLanguageServiceModel.Name))
throw new ArgumentException("Language already exists!");
Language language = this._languageMapper.Map<Language>(createLanguageServiceModel);
- bool result = await this._languageRepository.AddAsync(language);
-
- return result;
+ bool success = await this._languageRepository.AddAsync(language);
+
+ if(success)
+ {
+ Language newLanguage = await this._languageRepository.GetByNameAsync(createLanguageServiceModel.Name);
+ return newLanguage.Id;
+ }
+ else
+ return Guid.Empty;
}
#endregion
diff --git a/src/DevHive.Services/Services/PostService.cs b/src/DevHive.Services/Services/PostService.cs
index 6e83ad4..f2f60d1 100644
--- a/src/DevHive.Services/Services/PostService.cs
+++ b/src/DevHive.Services/Services/PostService.cs
@@ -26,21 +26,35 @@ namespace DevHive.Services.Services
}
//Create
- public async Task<bool> CreatePost(CreatePostServiceModel postServiceModel)
+ public async Task<Guid> CreatePost(CreatePostServiceModel postServiceModel)
{
Post post = this._postMapper.Map<Post>(postServiceModel);
- return await this._postRepository.AddAsync(post);
+ bool success = await this._postRepository.AddAsync(post);
+
+ if(success)
+ {
+ Post newPost = await this._postRepository.GetPostByIssuerAndTimeCreatedAsync(postServiceModel.IssuerId, postServiceModel.TimeCreated);
+ return newPost.Id;
+ }
+ else
+ return Guid.Empty;
}
- public async Task<bool> AddComment(CreateCommentServiceModel commentServiceModel)
+ public async Task<Guid> AddComment(CreateCommentServiceModel commentServiceModel)
{
commentServiceModel.TimeCreated = DateTime.Now;
Comment comment = this._postMapper.Map<Comment>(commentServiceModel);
- bool result = await this._postRepository.AddCommentAsync(comment);
+ bool success = await this._postRepository.AddCommentAsync(comment);
- return result;
+ if(success)
+ {
+ Comment newComment = await this._postRepository.GetCommentByIssuerAndTimeCreatedAsync(commentServiceModel.IssuerId, commentServiceModel.TimeCreated);
+ return newComment.Id;
+ }
+ else
+ return Guid.Empty;
}
//Read
diff --git a/src/DevHive.Services/Services/TechnologyService.cs b/src/DevHive.Services/Services/TechnologyService.cs
index 4e74c83..1b2f0ff 100644
--- a/src/DevHive.Services/Services/TechnologyService.cs
+++ b/src/DevHive.Services/Services/TechnologyService.cs
@@ -21,15 +21,21 @@ namespace DevHive.Services.Services
#region Create
- public async Task<bool> Create(CreateTechnologyServiceModel technologyServiceModel)
+ public async Task<Guid> Create(CreateTechnologyServiceModel technologyServiceModel)
{
if (await this._technologyRepository.DoesTechnologyNameExistAsync(technologyServiceModel.Name))
throw new ArgumentException("Technology already exists!");
Technology technology = this._technologyMapper.Map<Technology>(technologyServiceModel);
- bool result = await this._technologyRepository.AddAsync(technology);
-
- return result;
+ bool success = await this._technologyRepository.AddAsync(technology);
+
+ if(success)
+ {
+ Technology newTechnology = await this._technologyRepository.GetByNameAsync(technologyServiceModel.Name);
+ return newTechnology.Id;
+ }
+ else
+ return Guid.Empty;
}
#endregion
diff --git a/src/DevHive.Web/Controllers/LanguageController.cs b/src/DevHive.Web/Controllers/LanguageController.cs
index bbac409..e2d0dec 100644
--- a/src/DevHive.Web/Controllers/LanguageController.cs
+++ b/src/DevHive.Web/Controllers/LanguageController.cs
@@ -26,12 +26,11 @@ namespace DevHive.Web.Controllers
{
CreateLanguageServiceModel languageServiceModel = this._languageMapper.Map<CreateLanguageServiceModel>(createLanguageWebModel);
- bool result = await this._languageService.CreateLanguage(languageServiceModel);
+ Guid id = await this._languageService.CreateLanguage(languageServiceModel);
- if (!result)
- return new BadRequestObjectResult("Could not create Language");
-
- return new OkResult();
+ return id == Guid.Empty ?
+ new BadRequestObjectResult($"Could not create language {createLanguageWebModel.Name}") :
+ new OkObjectResult(new { Id = id });
}
[HttpGet]
diff --git a/src/DevHive.Web/Controllers/PostController.cs b/src/DevHive.Web/Controllers/PostController.cs
index 15adb1b..2a08605 100644
--- a/src/DevHive.Web/Controllers/PostController.cs
+++ b/src/DevHive.Web/Controllers/PostController.cs
@@ -32,12 +32,11 @@ namespace DevHive.Web.Controllers
CreatePostServiceModel postServiceModel =
this._postMapper.Map<CreatePostServiceModel>(createPostModel);
- bool result = await this._postService.CreatePost(postServiceModel);
+ Guid id = await this._postService.CreatePost(postServiceModel);
- if (!result)
- return new BadRequestObjectResult("Could not create post!");
-
- return new OkResult();
+ return id == Guid.Empty ?
+ new BadRequestObjectResult("Could not create post") :
+ new OkObjectResult(new { Id = id });
}
[HttpPost]
@@ -46,12 +45,11 @@ namespace DevHive.Web.Controllers
{
CreateCommentServiceModel createCommentServiceModel = this._postMapper.Map<CreateCommentServiceModel>(commentWebModel);
- bool result = await this._postService.AddComment(createCommentServiceModel);
+ Guid id = await this._postService.AddComment(createCommentServiceModel);
- if (!result)
- return new BadRequestObjectResult("Could not create the Comment");
-
- return new OkResult();
+ return id == Guid.Empty ?
+ new BadRequestObjectResult("Could not create language") :
+ new OkObjectResult(new { Id = id });
}
//Read
diff --git a/src/DevHive.Web/Controllers/TechnologyController.cs b/src/DevHive.Web/Controllers/TechnologyController.cs
index 104b96e..ba2ffdc 100644
--- a/src/DevHive.Web/Controllers/TechnologyController.cs
+++ b/src/DevHive.Web/Controllers/TechnologyController.cs
@@ -22,16 +22,15 @@ namespace DevHive.Web.Controllers
}
[HttpPost]
- public async Task<IActionResult> Create([FromBody] CreateTechnologyWebModel technologyWebModel)
+ public async Task<IActionResult> Create([FromBody] CreateTechnologyWebModel createTechnologyWebModel)
{
- CreateTechnologyServiceModel technologyServiceModel = this._technologyMapper.Map<CreateTechnologyServiceModel>(technologyWebModel);
+ CreateTechnologyServiceModel technologyServiceModel = this._technologyMapper.Map<CreateTechnologyServiceModel>(createTechnologyWebModel);
- bool result = await this._technologyService.Create(technologyServiceModel);
+ Guid id = await this._technologyService.Create(technologyServiceModel);
- if (!result)
- return new BadRequestObjectResult("Could not create the Technology");
-
- return new OkResult();
+ return id == Guid.Empty ?
+ new BadRequestObjectResult($"Could not create technology {createTechnologyWebModel.Name}") :
+ new OkObjectResult(new { Id = id });
}
[HttpGet]
diff --git a/src/DevHive.Web/Models/Post/Comment/CommentWebModel.cs b/src/DevHive.Web/Models/Post/Comment/CommentWebModel.cs
index 3cdc7c4..d66e5c9 100644
--- a/src/DevHive.Web/Models/Post/Comment/CommentWebModel.cs
+++ b/src/DevHive.Web/Models/Post/Comment/CommentWebModel.cs
@@ -5,7 +5,8 @@ namespace DevHive.Web.Models.Post.Comment
public class CommentWebModel
{
public Guid IssuerId { get; set; }
+ public Guid PostId { get; set; }
public string Message { get; set; }
public DateTime TimeCreated { get; set; }
}
-} \ No newline at end of file
+}
diff --git a/src/DevHive.code-workspace b/src/DevHive.code-workspace
index 4f764c2..28b1e3c 100644
--- a/src/DevHive.code-workspace
+++ b/src/DevHive.code-workspace
@@ -62,7 +62,7 @@
"ASPNETCORE_ENVIRONMENT": "Development"
},
"launchBrowser": {
- "enabled": true
+ "enabled": false
}
},
],