Example #1
0
        public IActionResult UpdatePost(Guid id, Guid topicId, Guid userId, string content)
        {
            var userType = getByIdUserUseCase.GetById(userId);
            var topic    = getByIdTopicUseCase.GetById(topicId);
            var postId   = getByIdPostUseCase.GetById(id);

            if (postId == null && topic == null && userType == null || userType.UserType != 1)
            {
                return(BadRequest("Something went wrong"));
            }

            var post = new Domain.Entities.Post(postId.Id, postId.Title, content, topic, postId.CreatedAt);

            updatePostUseCase.Update(post);
            return(new OkObjectResult(post));
        }
Example #2
0
        public IActionResult CreateComment(string content, Guid postId, Guid userId)
        {
            var post = getByIdPostUseCase.GetById(postId);
            var user = getByIdUserUseCase.GetById(userId);

            if (post == null && user == null)
            {
                return(BadRequest());
            }
            var comment = new Domain.Entities.Comment(content, post, user);

            var validationResult = new CommentValidator().Validate(comment);

            if (!validationResult.IsValid)
            {
                return(BadRequest(validationResult.Errors));
            }

            addCommentUseCase.Add(comment);
            return(new OkObjectResult(comment));
        }