public async Task <UserPostReadDto> CreatePostAsync(Guid userId, UserPostCreateDto post) { var contentType = post.File.FileName.GetContentType(); var type = contentType.Substring(0, 5); var extension = contentType.Substring(6); var fileNewNameGuid = Guid.NewGuid().ToString(); var fileNewName = fileNewNameGuid + '.' + extension; var thumbnailNewName = Guid.NewGuid().ToString() + ".jpeg"; if (type == "image") { var thumbnail = _fileOptimizationService.CreateImageThumbnail(post.File); await _imageBlobService.UploadFileBlobAsync(post.File, fileNewName); await _imageBlobService.UploadFileBlobAsync(thumbnail, thumbnailNewName); } else if (type == "video") { var thumbnail = await _fileOptimizationService.CreateVideoThumbnailAsync(post.File, thumbnailNewName); await _videoBlobService.UploadFileBlobAsync(post.File, fileNewName); await _imageBlobService.UploadFileBlobAsync(thumbnail, thumbnailNewName); } var postFileModel = new PostFile(fileNewName, type, thumbnailNewName); var userPostModel = new UserPost(userId, post.Caption, postFileModel.Id); await _userPostRepository.CreatePostAsync(userPostModel, postFileModel); return(await _userPostRepository.GetPostByIdAsync(userPostModel.Id)); }
public async Task <ActionResult <UserPostCreateDto> > CreateUserPostAsync([FromForm] UserPostCreateDto post) { var userId = new Guid(User.FindFirstValue(ClaimTypes.NameIdentifier)); var userPostReadDto = await _userPostService.CreatePostAsync(userId, post); return(CreatedAtRoute(nameof(GetUserPostFileByPostFileIdAsync), new { postFileId = userPostReadDto.FileId }, userPostReadDto)); }