Ejemplo n.º 1
0
 public IActionResult Post(
     [FromBody] PostDto dto,
     [FromServices] ICreatePostCommand command)
 {
     _executor.ExecuteCommand(command, dto);
     return(StatusCode(StatusCodes.Status201Created));
 }
Ejemplo n.º 2
0
 public PostsController(IGetPostsCommand getPosts, IGetPostCommand getOne, ICreatePostCommand postCreate, ICreateImageCommand imageCreate, IGetImageCommand getImage, IEditPostPictureCommand editImage, IEditPostCommand editPost, IDeletePostCommand deltePost)
 {
     _getPosts    = getPosts;
     _getOne      = getOne;
     _postCreate  = postCreate;
     _imageCreate = imageCreate;
     _getImage    = getImage;
     _editImage   = editImage;
     _editPost    = editPost;
     _deltePost   = deltePost;
 }
Ejemplo n.º 3
0
 public CommandHandler(
     IOutputWriter writer,
     ICreatePostCommand createPostCommand,
     IFollowUserCommand followUserCommand,
     IWallQuery wallQuery,
     IGetPostListByUserQuery getPostListByUserQuery)
 {
     _writer                 = writer;
     _createPostCommand      = createPostCommand;
     _followUserCommand      = followUserCommand;
     _wallQuery              = wallQuery;
     _getPostListByUserQuery = getPostListByUserQuery;
 }
 public IActionResult Post([FromBody] AddPost dto, [FromServices] ICreatePostCommand command)
 {
     try
     {
         executor.ExecuteCommand(command, dto);
         return(StatusCode(201, "Succesfully added a new post."));
     }
     catch (EntityNotFoundException e)
     {
         if (e.Message == "Product not found.")
         {
             return(NotFound(e.Message));
         }
         return(UnprocessableEntity(e.Message));
     }
 }
Ejemplo n.º 5
0
        public IActionResult Post([FromForm] UploadPostDto UPDto, [FromServices] ICreatePostCommand command, [FromServices] PostDto dto)
        {
            if (UPDto.Image == null)
            {
                return(StatusCode(StatusCodes.Status422UnprocessableEntity, new
                {
                    message = "Validation error",
                    Errors = "Image is required!"
                }));
            }
            var guid      = Guid.NewGuid();
            var extension = Path.GetExtension(UPDto.Image.FileName);

            if (extension != ".jpg" && extension != ".jpeg" && extension != ".png")
            {
                return(StatusCode(StatusCodes.Status422UnprocessableEntity, new
                {
                    message = "Validation error",
                    Errors = "Only jpg, jpeg and png images are allowed!"
                }));
            }
            var FileName = guid + extension;
            var path     = Path.Combine("wwwroot", "images", FileName);

            using (var fileStream = new FileStream(path, FileMode.Create))
            {
                UPDto.Image.CopyTo(fileStream);
            }
            dto.UserId    = _actor.Id;
            dto.Title     = UPDto.Title;
            dto.Content   = UPDto.Content;
            dto.PhotoPath = "images/" + FileName;
            dto.TopicId   = UPDto.TopicId;
            _executor.ExecuteCommand(command, dto);
            return(StatusCode(StatusCodes.Status201Created));
        }
Ejemplo n.º 6
0
 public void Post([FromBody] PostDto dto,
                  [FromServices] ICreatePostCommand command)
 {
     _executor.ExecuteCommand(command, dto);
 }
Ejemplo n.º 7
0
 public IActionResult Post([FromForm] PostDto dto, [FromServices] ICreatePostCommand command)
 {
     dto.UserId = actor.Id;
     executor.ExecuteCommand(command, dto);
     return(StatusCode(StatusCodes.Status201Created));
 }
Ejemplo n.º 8
0
 public PostController(UseCaseExecutor executor, IApplicationActor actor, ICreatePostCommand addPost)
 {
     this.executor = executor;
     this.actor    = actor;
     _addPost      = addPost;
 }
 public IActionResult Post([FromForm] CreatePostDto request, [FromServices] ICreatePostCommand command)
 {
     _executor.ExecuteCommand(command, request);
     return(StatusCode(StatusCodes.Status201Created));
 }