diff --git a/src/Service/MeTube.Service/Videos/VideoService.cs b/src/Service/MeTube.Service/Videos/VideoService.cs index 22af874..5e4f1ee 100644 --- a/src/Service/MeTube.Service/Videos/VideoService.cs +++ b/src/Service/MeTube.Service/Videos/VideoService.cs @@ -74,7 +74,10 @@ public async Task CreateAsync(VideoDto videoDto, string userId) public async Task EditAsync(VideoDto videoDto) { - Video video = videoDto.ToVideoEntity(); + Video video = await this.GetByIdInternalAsync(videoDto.Id); + + video.Title = videoDto.Title; + video.Description = videoDto.Description; return (await _videoRepository.EditAsync(video)).ToVideoDto(); } diff --git a/src/Web/MeTube.Web.Models/Video/VideoEditModel.cs b/src/Web/MeTube.Web.Models/Video/VideoEditModel.cs new file mode 100644 index 0000000..4f633a3 --- /dev/null +++ b/src/Web/MeTube.Web.Models/Video/VideoEditModel.cs @@ -0,0 +1,7 @@ +namespace MeTube.Web.Models.Video; + +public class VideoEditModel +{ + public string Title { get; set; } + public string Description { get;set; } +} \ No newline at end of file diff --git a/src/Web/MeTube.Web/Controllers/VideoController.cs b/src/Web/MeTube.Web/Controllers/VideoController.cs index d26ff11..10c909a 100644 --- a/src/Web/MeTube.Web/Controllers/VideoController.cs +++ b/src/Web/MeTube.Web/Controllers/VideoController.cs @@ -1,5 +1,6 @@ using MeTube.Data.Models; using MeTube.Service.Channels; +using MeTube.Service.Models.Videos; using MeTube.Service.Playlists; using MeTube.Service.Reactions; using MeTube.Service.Videos; @@ -96,5 +97,37 @@ public async Task Comment([FromQuery] string videoId, [FromBody] return Ok(await this._videoService.Comment(videoId, commentCreateModel.Content, currentUser.Id)); } + + [HttpGet] + public async Task Edit([FromQuery(Name = "v")] string videoId) + { + MeTubeUser currentUser = await this._userManager.GetUserAsync(this.User); + + if (this.User.Identity.IsAuthenticated) + { + this.ViewData["Channel"] = await this._channelService.GetByUserIdAsync(currentUser.Id); + } + + this.ViewData["ReactionTypes"] = await this._reactionTypeService.GetAll().ToListAsync(); + + var video = await this._videoService.ViewVideoByIdAsync(videoId); + + return View(video); + } + + [HttpPost] + public async Task Edit([FromQuery(Name = "v")] string videoId, [FromForm] VideoEditModel videoEditModel) + { + VideoDto videoModifiedDto = new VideoDto + { + Id = videoId, + Title = videoEditModel.Title, + Description = videoEditModel.Description + }; + + await this._videoService.EditAsync(videoModifiedDto); + + return Redirect("/Video/Details?v=" + videoId); + } } } \ No newline at end of file diff --git a/src/Web/MeTube.Web/Views/Video/Details.cshtml b/src/Web/MeTube.Web/Views/Video/Details.cshtml index 43c2382..9c4e533 100644 --- a/src/Web/MeTube.Web/Views/Video/Details.cshtml +++ b/src/Web/MeTube.Web/Views/Video/Details.cshtml @@ -33,12 +33,21 @@