PostGetAllDto IPostBusinessLogic.Create(PostCreateDto post) { Post createdPost = mapper.Map <Post>(post); ImageGetDto image = imageService.Create(new ImageCreateDto() { Image = post.MediaPath, Prefix = "posts" }); CreateContentScanTaskDto createContentScanTaskDto = new CreateContentScanTaskDto() { ImageUrl = image != null?imageService.GetFullImageUrl(image.Url) : null, Text = post.Description, CallbackUrl = $"/api/v1/trends/{post.TrendId}/posts/{createdPost.Id}/content-scan-result" }; contentScanTaskService.CreateTask(createContentScanTaskDto); createdPost.MediaPath = image != null ? image.Url : imageService.GetDefaultImageUrl(); postRepository.Insert(createdPost); postRepository.SaveChanges(); return(mapper.Map <PostGetAllDto>(createdPost)); }
CommentGetDto ICommentBusinessLogic.Create(CommentCreateDto comment) { Comment newComment = mapper.Map <Comment>(comment); newComment.ApprovedImage = false; newComment.ApprovedText = false; commentRepository.Insert(newComment); Post post = postRepository.GetById(comment.PostId); ++post.CommentsCount; postRepository.Update(post); postRepository.SaveChanges(); CreateContentScanTaskDto createContentScanTaskDto = new CreateContentScanTaskDto() { ImageUrl = null, Text = newComment.Text, CallbackUrl = $"/api/v1/trends/{post.TrendId}/posts/{post.Id}/comments/{newComment.Id}/content-scan-result" }; contentScanTaskService.CreateTask(createContentScanTaskDto); return(mapper.Map <CommentGetDto>(newComment)); }
TrendGetAllDto ITrendBusinessLogic.Create(TrendCreateDto trend) { Trend createdTrend = mapper.Map <Trend>(trend); ImageGetDto image = imageService.Create(new ImageCreateDto() { Image = trend.Image, Prefix = "trends" }); CreateContentScanTaskDto createContentScanTaskDto = new CreateContentScanTaskDto() { ImageUrl = image != null?imageService.GetFullImageUrl(image.Url) : null, Text = trend.Description, CallbackUrl = $"/api/v1/trends/{createdTrend.Id}/content-scan-result" }; contentScanTaskService.CreateTask(createContentScanTaskDto); createdTrend.ImageUrl = image != null ? image.Url : imageService.GetDefaultImageUrl(); trendRepository.Insert(createdTrend); trendRepository.SaveChanges(); return(mapper.Map <TrendGetAllDto>(createdTrend)); }
async public void CreateTask(CreateContentScanTaskDto scanTaskDto) { if (!serverConfiguration.DoSendContentScanningRequest) { return; } QueueName parent = new QueueName(googleTasksConfiguration.ProjectId, googleTasksConfiguration.Location, googleTasksConfiguration.QueueName); string payload = JsonSerializer.Serialize(scanTaskDto); await cloudTasksClient.CreateTaskAsync(new CreateTaskRequest { Parent = parent.ToString(), Task = new Task { HttpRequest = new HttpRequest { HttpMethod = HttpMethod.Post, Url = googleTasksConfiguration.GoogleFunctionUrl, Body = ByteString.CopyFromUtf8(payload) } } }); }