diff options
| author | Danail Dimitrov <danaildimitrov321@gmail.com> | 2020-12-30 17:48:30 +0200 |
|---|---|---|
| committer | Danail Dimitrov <danaildimitrov321@gmail.com> | 2020-12-30 17:48:30 +0200 |
| commit | fb56c49681746c8c47c1da43c918b37df5f214a1 (patch) | |
| tree | 780a7ae16198a0649988cd4a677e984477ffb150 /src/DevHive.Services | |
| parent | e2958817c79f29722fedc1ea8ddcedea894a0f20 (diff) | |
| download | DevHive-fb56c49681746c8c47c1da43c918b37df5f214a1.tar DevHive-fb56c49681746c8c47c1da43c918b37df5f214a1.tar.gz DevHive-fb56c49681746c8c47c1da43c918b37df5f214a1.zip | |
Adding coomment layers
Diffstat (limited to 'src/DevHive.Services')
5 files changed, 107 insertions, 0 deletions
diff --git a/src/DevHive.Services/Configurations/Mapping/CommentMappings.cs b/src/DevHive.Services/Configurations/Mapping/CommentMappings.cs new file mode 100644 index 0000000..8120488 --- /dev/null +++ b/src/DevHive.Services/Configurations/Mapping/CommentMappings.cs @@ -0,0 +1,17 @@ +using DevHive.Data.Models; +using AutoMapper; +using DevHive.Services.Models.Comment; + +namespace DevHive.Services.Configurations.Mapping +{ + public class CommentMappings : Profile + { + public CommentMappings() + { + CreateMap<CommentServiceModel, Comment>(); + CreateMap<Language, CommentServiceModel>(); + CreateMap<UpdateCommentServiceModel, Language>(); + CreateMap<GetByIdCommentServiceModel, Language>(); + } + } +}
\ No newline at end of file diff --git a/src/DevHive.Services/Models/Comment/CommentServiceModel.cs b/src/DevHive.Services/Models/Comment/CommentServiceModel.cs new file mode 100644 index 0000000..f3638ac --- /dev/null +++ b/src/DevHive.Services/Models/Comment/CommentServiceModel.cs @@ -0,0 +1,10 @@ +using System; + +namespace DevHive.Services.Models.Comment +{ + public class CommentServiceModel + { + public Guid UserId { get; set; } + public string Message { get; set; } + } +}
\ No newline at end of file diff --git a/src/DevHive.Services/Models/Comment/GetByIdCommentServiceModel.cs b/src/DevHive.Services/Models/Comment/GetByIdCommentServiceModel.cs new file mode 100644 index 0000000..c2b84b3 --- /dev/null +++ b/src/DevHive.Services/Models/Comment/GetByIdCommentServiceModel.cs @@ -0,0 +1,9 @@ +using System; + +namespace DevHive.Services.Models.Comment +{ + public class GetByIdCommentServiceModel : CommentServiceModel + { + public DateTime Date { get; set; } + } +}
\ No newline at end of file diff --git a/src/DevHive.Services/Models/Comment/UpdateCommnetServiceModel.cs b/src/DevHive.Services/Models/Comment/UpdateCommnetServiceModel.cs new file mode 100644 index 0000000..3a461c5 --- /dev/null +++ b/src/DevHive.Services/Models/Comment/UpdateCommnetServiceModel.cs @@ -0,0 +1,9 @@ +using System; + +namespace DevHive.Services.Models.Comment +{ + public class UpdateCommentServiceModel : CommentServiceModel + { + public Guid Id { get; set; } + } +} diff --git a/src/DevHive.Services/Services/CommentService.cs b/src/DevHive.Services/Services/CommentService.cs new file mode 100644 index 0000000..69dbcc0 --- /dev/null +++ b/src/DevHive.Services/Services/CommentService.cs @@ -0,0 +1,62 @@ +using System; +using System.Threading.Tasks; +using AutoMapper; +using DevHive.Data.Models; +using DevHive.Data.Repositories; +using DevHive.Services.Models.Comment; + +namespace DevHive.Services.Services +{ + public class CommentService + { + private readonly CommentRepository _commentRepository; + private readonly IMapper _commentMapper; + + public CommentService(CommentRepository commentRepository, IMapper mapper) + { + this._commentRepository = commentRepository; + this._commentMapper = mapper; + } + + public async Task<bool> CreateComment(CommentServiceModel commentServiceModel) + { + Comment comment = this._commentMapper.Map<Comment>(commentServiceModel); + comment.Date = DateTime.Now; + bool result = await this._commentRepository.AddAsync(comment); + + return result; + } + + public async Task<GetByIdCommentServiceModel> GetCommentById(Guid id) + { + Comment comment = await this._commentRepository.GetByIdAsync(id); + + if(comment == null) + throw new ArgumentException("The comment does not exist"); + + return this._commentMapper.Map<GetByIdCommentServiceModel>(comment); + } + + public async Task<bool> UpdateComment(UpdateCommentServiceModel commentServiceModel) + { + if (!await this._commentRepository.DoesCommentExist(commentServiceModel.Id)) + throw new ArgumentException("Comment does not exist!"); + + Comment comment = this._commentMapper.Map<Comment>(commentServiceModel); + bool result = await this._commentRepository.EditAsync(comment); + + return result; + } + + public async Task<bool> DeleteComment(Guid id) + { + if (!await this._commentRepository.DoesCommentExist(id)) + throw new ArgumentException("Comment does not exist!"); + + Comment comment = await this._commentRepository.GetByIdAsync(id); + bool result = await this._commentRepository.DeleteAsync(comment); + + return result; + } + } +}
\ No newline at end of file |
