Skip to content

Commit

Permalink
Merge branch 'PromptOperations'
Browse files Browse the repository at this point in the history
  • Loading branch information
altudev committed Dec 1, 2024
2 parents 21b3d17 + 389f483 commit 32500b7
Show file tree
Hide file tree
Showing 30 changed files with 737 additions and 442 deletions.
6 changes: 4 additions & 2 deletions src/AkilliPrompt.Domain/Entities/Prompt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,19 @@ public sealed class Prompt : EntityBase
public ICollection<UserFavoritePrompt> UserFavoritePrompts { get; set; } = [];
public ICollection<UserLikePrompt> UserLikePrompts { get; set; } = [];
public ICollection<Placeholder> Placeholders { get; set; } = [];
public ICollection<PromptComment> PromptComments { get; set; } = [];


public static Prompt Create(string title, string description, string content, bool isActive)
public static Prompt Create(string title, string description, string content, bool isActive, Guid creatorId)
{
return new Prompt
{
Id = Guid.CreateVersion7(),
Title = title,
Description = description,
Content = content,
IsActive = isActive
IsActive = isActive,
CreatorId = creatorId
};
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using System;
using AkilliPrompt.Domain.Common;
using AkilliPrompt.Domain.Identity;

namespace AkilliPrompt.Domain.Entities;

public sealed class UserPromptComment : EntityBase
public sealed class PromptComment : EntityBase
{
public int Level { get; set; }
public string Content { get; set; }
Expand All @@ -16,7 +15,7 @@ public sealed class UserPromptComment : EntityBase
public ApplicationUser User { get; set; }

public Guid? ParentCommentId { get; set; }
public UserPromptComment ParentComment { get; set; }
public PromptComment ParentComment { get; set; }

public ICollection<UserPromptComment> ChildComments { get; set; } = [];
public ICollection<PromptComment> ChildComments { get; set; } = [];
}
2 changes: 1 addition & 1 deletion src/AkilliPrompt.Domain/Identity/ApplicationUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public sealed class ApplicationUser : IdentityUser<Guid>, ICreatedByEntity, IMod
public DateTimeOffset? ModifiedAt { get; set; }

public ICollection<UserSocialMediaAccount> UserSocialMediaAccounts { get; set; } = [];
public ICollection<UserPromptComment> UserPromptComments { get; set; } = [];
public ICollection<PromptComment> PromptComments { get; set; } = [];
public ICollection<UserFavoritePrompt> UserFavoritePrompts { get; set; } = [];
public ICollection<UserLikePrompt> UserLikePrompts { get; set; } = [];
public ICollection<Prompt> CreatedPrompts { get; set; } = [];
Expand Down
4 changes: 0 additions & 4 deletions src/AkilliPrompt.Persistence/AkilliPrompt.Persistence.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,4 @@
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.1" />
</ItemGroup>

<ItemGroup>
<Folder Include="EntityFramework\Configurations\" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

namespace AkilliPrompt.Persistence.EntityFramework.Configurations;

public sealed class UserPromptCommentConfiguration : IEntityTypeConfiguration<UserPromptComment>
public sealed class UserPromptCommentConfiguration : IEntityTypeConfiguration<PromptComment>
{
public void Configure(EntityTypeBuilder<UserPromptComment> builder)
public void Configure(EntityTypeBuilder<PromptComment> builder)
{
// Id
builder.HasKey(x => x.Id);
Expand All @@ -24,7 +24,7 @@ public void Configure(EntityTypeBuilder<UserPromptComment> builder)

// User Relationship
builder.HasOne(x => x.User)
.WithMany(u => u.UserPromptComments)
.WithMany(u => u.PromptComments)
.HasForeignKey(x => x.UserId);

// Parent Comment Relationship
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ public void Configure(EntityTypeBuilder<Prompt> builder)
.WithOne(p => p.Prompt)
.HasForeignKey(p => p.PromptId);

// PromptComments Relationship
builder.HasMany<PromptComment>(x => x.PromptComments)
.WithOne(y => y.Prompt)
.HasForeignKey(y => y.PromptId);


// CreatedAt
builder.Property(p => p.CreatedAt)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
public DbSet<Prompt> Prompts { get; set; }
public DbSet<PromptCategory> PromptCategories { get; set; }
public DbSet<UserSocialMediaAccount> UserSocialMediaAccounts { get; set; }
public DbSet<UserPromptComment> UserPromptComments { get; set; }
public DbSet<PromptComment> PromptComments { get; set; }
public DbSet<UserFavoritePrompt> UserFavoritePrompts { get; set; }
public DbSet<UserLikePrompt> UserLikePrompts { get; set; }
public DbSet<RefreshToken> RefreshTokens { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ private void UpdateEntities(DbContext? context)

if (entry.State == EntityState.Added)
{
entry.Entity.CreatedByUserId = _currentUserService.UserId?.ToString();
entry.Entity.CreatedByUserId = _currentUserService.UserId == Guid.Empty ? null : _currentUserService.UserId.ToString();
entry.Entity.CreatedAt = utcNow;
}

if (entry.State == EntityState.Modified)
{
entry.Entity.ModifiedByUserId = _currentUserService.UserId?.ToString();
entry.Entity.ModifiedByUserId = _currentUserService.UserId == Guid.Empty ? null : _currentUserService.UserId.ToString();
entry.Entity.ModifiedAt = utcNow;
}
}
Expand Down
Loading

0 comments on commit 32500b7

Please sign in to comment.