forked from DevBetterCom/DevBetterWeb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Shady nagy/video comment (DevBetterCom#790)
* VideoComment created. * changes on ArchiveVideo and Member for Video Comment. * fix video in coment. * db Migrations files added. * video comment relations added. * edit config change the tab to be 2. * db migrations. * Created at added on VideoComment. * video comment specs added. * mapper for video comment added. * video comment dto added. * comments added on OEmbed. * Video details read the comments. * spaces fix. * get member name in the comment. * Video comments on the HTML. * not null * spec try to add replies also. * spaces. * md comment added for video comment. * Migrations * video comments added. * github-code-scanning fixed.
- Loading branch information
Showing
26 changed files
with
3,242 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel.DataAnnotations.Schema; | ||
using Ardalis.GuardClauses; | ||
using DevBetterWeb.Core.Interfaces; | ||
using DevBetterWeb.Core.SharedKernel; | ||
|
||
namespace DevBetterWeb.Core.Entities; | ||
|
||
public class VideoComment : BaseEntity, IAggregateRoot | ||
{ | ||
public int VideoId { get; set; } | ||
public int? ParentCommentId { get; set; } | ||
|
||
[NotMapped] | ||
public string? MdBody { get; set; } | ||
|
||
public string? Body { get; set; } | ||
public int MemberId { get; set; } | ||
public DateTimeOffset CreatedAt { get; set; } | ||
public Member? MemberWhoCreate { get; private set; } | ||
public VideoComment? ParentComment { get; private set; } | ||
public List<VideoComment> Replies { get; private set; } = new List<VideoComment>(); | ||
public ArchiveVideo Video { get; set; } = new ArchiveVideo(); | ||
|
||
public VideoComment() | ||
{ | ||
} | ||
public VideoComment(int memberId, int videoId, string body) | ||
{ | ||
MemberId = memberId; | ||
Body = body; | ||
VideoId = videoId; | ||
CreatedAt = DateTime.Now; | ||
} | ||
|
||
public void AddReplay(VideoComment comment) | ||
{ | ||
Guard.Against.Null(comment, nameof(comment)); | ||
Replies.Add(comment); | ||
} | ||
|
||
public void SetParentComment(VideoComment comment) | ||
{ | ||
Guard.Against.Null(comment, nameof(comment)); | ||
ParentComment = comment; | ||
} | ||
|
||
public void SetCreator(Member member) | ||
{ | ||
Guard.Against.Null(member, nameof(member)); | ||
MemberWhoCreate = member; | ||
} | ||
|
||
public void CreateMdBody(IMarkdownService markdownService) | ||
{ | ||
MdBody = markdownService.RenderHTMLFromMD(Body); | ||
} | ||
|
||
public override string ToString() | ||
{ | ||
return Body!; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/DevBetterWeb.Core/Specs/ArchiveVideoByVideoIdWithMemberFavoritesAndCommentsSpec.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using Ardalis.Specification; | ||
using DevBetterWeb.Core.Entities; | ||
|
||
namespace DevBetterWeb.Core.Specs; | ||
|
||
public sealed class ArchiveVideoByVideoIdWithMemberFavoritesAndCommentsSpec : Specification<ArchiveVideo>, ISingleResultSpecification | ||
{ | ||
public ArchiveVideoByVideoIdWithMemberFavoritesAndCommentsSpec(string videoId) | ||
{ | ||
Query | ||
.Where(x => x.VideoId == videoId) | ||
.Include(X => X.MemberFavorites) | ||
.Include(x => x.Comments) | ||
.ThenInclude(x => x.MemberWhoCreate) | ||
.Include(x => x.Comments) | ||
.ThenInclude(x => x.Replies); | ||
|
||
} | ||
} |
15 changes: 0 additions & 15 deletions
15
src/DevBetterWeb.Core/Specs/ArchiveVideoByVideoIdWithMemberFavoritesSpec.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using Ardalis.Specification; | ||
using DevBetterWeb.Core.Entities; | ||
|
||
namespace DevBetterWeb.Core.Specs; | ||
|
||
public sealed class VideoCommentByVideoIdSpec : Specification<VideoComment> | ||
{ | ||
public VideoCommentByVideoIdSpec(string videoId) | ||
{ | ||
var videoIdToSearchBy = long.Parse(videoId); | ||
Query | ||
.Where(x => x.VideoId == videoIdToSearchBy) | ||
.Include(x => x.Replies) | ||
.OrderByDescending(x => x.CreatedAt); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/DevBetterWeb.Infrastructure/Data/Config/VideoCommentConfig.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using DevBetterWeb.Core.Entities; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Metadata.Builders; | ||
|
||
namespace DevBetterWeb.Infrastructure.Data.Config; | ||
|
||
public class VideoCommentConfig : IEntityTypeConfiguration<VideoComment> | ||
{ | ||
|
||
public void Configure(EntityTypeBuilder<VideoComment> builder) | ||
{ | ||
builder | ||
.Property(x => x.Body) | ||
.HasMaxLength(2000); | ||
|
||
builder | ||
.HasOne(t => t.Video) | ||
.WithMany(p => p.Comments) | ||
.HasForeignKey(d => d.VideoId) | ||
.OnDelete(DeleteBehavior.ClientSetNull); | ||
|
||
builder | ||
.HasOne(t => t.MemberWhoCreate) | ||
.WithMany(p => p.VideosComments) | ||
.HasForeignKey(d => d.MemberId) | ||
.OnDelete(DeleteBehavior.ClientSetNull); | ||
|
||
builder | ||
.HasOne(t => t.ParentComment) | ||
.WithMany(p => p.Replies) | ||
.HasForeignKey(d => d.ParentCommentId) | ||
.OnDelete(DeleteBehavior.ClientSetNull); | ||
} | ||
} |
Oops, something went wrong.