public async Task <AddPostResponse> AddPostAsync(AddPostRequest request) { var response = new AddPostResponse(); bool isExists = await _postRepository.IsExistsByUrlAsync(request.Url); if (isExists) { response.StatusCode = (int)HttpStatusCode.Conflict; return(response); } var entity = _postMapper.ToEntity(request); bool isSuccess = await _postRepository.AddAsync(entity); if (!isSuccess) { response.StatusCode = (int)HttpStatusCode.InternalServerError; return(response); } response.Post = _postMapper.ToModel(entity); response.StatusCode = (int)HttpStatusCode.Created; return(response); }
public async Task <CreatePostResponse> CreatePostAsync(CreatePostRequest request, string userId) { var entity = _postMapper.ToEntity(request.Post); entity.UserId = userId; var result = await _postRepository.CreatePostAsync(entity); if (!result) { return new CreatePostResponse { StatusCode = (int)HttpStatusCode.Unauthorized } } ; var response = new CreatePostResponse { StatusCode = (int)HttpStatusCode.Created }; return(response); }