Skip to content

Commit

Permalink
Shady nagy/video comment (DevBetterCom#790)
Browse files Browse the repository at this point in the history
* 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
ShadyNagy authored Jul 11, 2022
1 parent db37479 commit 5578244
Show file tree
Hide file tree
Showing 26 changed files with 3,242 additions and 49 deletions.
11 changes: 10 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ dotnet_naming_style.pascal_case_style.capitalization = pascal_case
# Use PascalCase for constant fields
dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields
dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style
dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style
dotnet_naming_symbols.constant_fields.applicable_kinds = field
dotnet_naming_symbols.constant_fields.applicable_accessibilities = *
dotnet_naming_symbols.constant_fields.required_modifiers = const
Expand All @@ -65,6 +65,11 @@ dotnet_naming_symbols.instance_fields.applicable_kinds = field

dotnet_naming_style.instance_field_style.capitalization = camel_case
dotnet_naming_style.instance_field_style.required_prefix = _
dotnet_style_operator_placement_when_wrapping = beginning_of_line
tab_width = 2
indent_size = 2
end_of_line = crlf
dotnet_style_prefer_simplified_boolean_expressions = true:suggestion
###############################
# C# Coding Conventions #
###############################
Expand Down Expand Up @@ -126,6 +131,10 @@ csharp_space_between_method_call_empty_parameter_list_parentheses = false
# Wrapping preferences
csharp_preserve_single_line_statements = true
csharp_preserve_single_line_blocks = true
csharp_using_directive_placement = outside_namespace:silent
csharp_prefer_simple_using_statement = true:suggestion
csharp_style_expression_bodied_lambdas = true:silent
csharp_style_expression_bodied_local_functions = false:silent
###############################
# VB Coding Conventions #
###############################
Expand Down
16 changes: 16 additions & 0 deletions src/DevBetterWeb.Core/Entities/ArchiveVideo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class ArchiveVideo : BaseEntity, IAggregateRoot
public int Views { get; set; } = 0;

public List<Question> Questions { get; private set; } = new List<Question>();
public List<VideoComment> Comments { get; private set; } = new List<VideoComment>();

private readonly List<MemberFavoriteArchiveVideo> _memberFavorites = new();
public IEnumerable<MemberFavoriteArchiveVideo> MemberFavorites => _memberFavorites.AsReadOnly();
Expand All @@ -30,4 +31,19 @@ public void AddQuestion(Question question)
Guard.Against.Null(question, nameof(question));
Questions.Add(question);
}

public void AddComment(VideoComment comment)
{
Guard.Against.Null(comment, nameof(comment));
Comments.Add(comment);
}

public void CreateMdComments(IMarkdownService markdownService)
{
foreach (var comment in Comments)
{
comment.CreateMdBody(markdownService);

}
}
}
1 change: 1 addition & 0 deletions src/DevBetterWeb.Core/Entities/Member.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ internal Member(string userId, string firstName, string lastName)
public string? DiscordUsername { get; private set; }

public List<Book> BooksRead { get; set; } = new List<Book>();
public List<VideoComment> VideosComments { get; set; } = new List<VideoComment>();

public DateTime DateCreated { get; private set; } = DateTime.UtcNow;
public List<MemberSubscription> MemberSubscriptions { get; set; } = new List<MemberSubscription>();
Expand Down
64 changes: 64 additions & 0 deletions src/DevBetterWeb.Core/Entities/VideoComment.cs
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!;
}
}
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);

}
}

This file was deleted.

16 changes: 16 additions & 0 deletions src/DevBetterWeb.Core/Specs/VideoCommentByVideoIdSpec.cs
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);
}
}
1 change: 1 addition & 0 deletions src/DevBetterWeb.Infrastructure/Data/AppDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
}

public DbSet<ArchiveVideo>? ArchiveVideos { get; set; }
public DbSet<VideoComment>? VideoComments { get; set; }
public DbSet<Question>? Questions { get; set; }
public DbSet<Member>? Members { get; set; }
public DbSet<Book>? Books { get; set; }
Expand Down
34 changes: 34 additions & 0 deletions src/DevBetterWeb.Infrastructure/Data/Config/VideoCommentConfig.cs
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);
}
}
Loading

0 comments on commit 5578244

Please sign in to comment.