✨ Post featured record
This commit is contained in:
@@ -34,7 +34,8 @@ public class AppDatabase(
|
||||
public DbSet<PostTag> PostTags { get; set; }
|
||||
public DbSet<PostCategory> PostCategories { get; set; }
|
||||
public DbSet<PostCollection> PostCollections { get; set; }
|
||||
|
||||
public DbSet<PostFeaturedRecord> PostFeaturedRecords { get; set; }
|
||||
|
||||
public DbSet<Poll.Poll> Polls { get; set; }
|
||||
public DbSet<Poll.PollQuestion> PollQuestions { get; set; }
|
||||
public DbSet<Poll.PollAnswer> PollAnswers { get; set; }
|
||||
@@ -299,4 +300,4 @@ public static class OptionalQueryExtensions
|
||||
{
|
||||
return condition ? transform(source) : source;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
1930
DysonNetwork.Sphere/Migrations/20250812041519_AddPostFeaturedRecord.Designer.cs
generated
Normal file
1930
DysonNetwork.Sphere/Migrations/20250812041519_AddPostFeaturedRecord.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,51 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using NodaTime;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace DysonNetwork.Sphere.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddPostFeaturedRecord : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "post_featured_records",
|
||||
columns: table => new
|
||||
{
|
||||
id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
post_id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
featured_at = table.Column<Instant>(type: "timestamp with time zone", nullable: true),
|
||||
social_credits = table.Column<int>(type: "integer", nullable: false),
|
||||
created_at = table.Column<Instant>(type: "timestamp with time zone", nullable: false),
|
||||
updated_at = table.Column<Instant>(type: "timestamp with time zone", nullable: false),
|
||||
deleted_at = table.Column<Instant>(type: "timestamp with time zone", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("pk_post_featured_records", x => x.id);
|
||||
table.ForeignKey(
|
||||
name: "fk_post_featured_records_posts_post_id",
|
||||
column: x => x.post_id,
|
||||
principalTable: "posts",
|
||||
principalColumn: "id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_post_featured_records_post_id",
|
||||
table: "post_featured_records",
|
||||
column: "post_id");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "post_featured_records");
|
||||
}
|
||||
}
|
||||
}
|
@@ -724,6 +724,46 @@ namespace DysonNetwork.Sphere.Migrations
|
||||
b.ToTable("post_collections", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DysonNetwork.Sphere.Post.PostFeaturedRecord", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<Instant>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created_at");
|
||||
|
||||
b.Property<Instant?>("DeletedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("deleted_at");
|
||||
|
||||
b.Property<Instant?>("FeaturedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("featured_at");
|
||||
|
||||
b.Property<Guid>("PostId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("post_id");
|
||||
|
||||
b.Property<int>("SocialCredits")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("social_credits");
|
||||
|
||||
b.Property<Instant>("UpdatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("updated_at");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_post_featured_records");
|
||||
|
||||
b.HasIndex("PostId")
|
||||
.HasDatabaseName("ix_post_featured_records_post_id");
|
||||
|
||||
b.ToTable("post_featured_records", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DysonNetwork.Sphere.Post.PostReaction", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
@@ -1637,6 +1677,18 @@ namespace DysonNetwork.Sphere.Migrations
|
||||
b.Navigation("Publisher");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DysonNetwork.Sphere.Post.PostFeaturedRecord", b =>
|
||||
{
|
||||
b.HasOne("DysonNetwork.Sphere.Post.Post", "Post")
|
||||
.WithMany()
|
||||
.HasForeignKey("PostId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_post_featured_records_posts_post_id");
|
||||
|
||||
b.Navigation("Post");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DysonNetwork.Sphere.Post.PostReaction", b =>
|
||||
{
|
||||
b.HasOne("DysonNetwork.Sphere.Post.Post", "Post")
|
||||
|
@@ -114,6 +114,16 @@ public class PostCollection : ModelBase
|
||||
public ICollection<Post> Posts { get; set; } = new List<Post>();
|
||||
}
|
||||
|
||||
public class PostFeaturedRecord : ModelBase
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
|
||||
public Guid PostId { get; set; }
|
||||
public Post Post { get; set; } = null!;
|
||||
public Instant? FeaturedAt { get; set; }
|
||||
public int SocialCredits { get; set; }
|
||||
}
|
||||
|
||||
public enum PostReactionAttitude
|
||||
{
|
||||
Positive,
|
||||
|
@@ -763,6 +763,15 @@ public partial class PostService(
|
||||
featuredIds = reactSocialPoints.Select(e => e.Key).ToList();
|
||||
|
||||
await cache.SetAsync(FeaturedPostCacheKey, featuredIds, TimeSpan.FromHours(24));
|
||||
|
||||
// Create featured record
|
||||
var records = reactSocialPoints.Select(e => new PostFeaturedRecord
|
||||
{
|
||||
PostId = e.Key,
|
||||
SocialCredits = e.Value
|
||||
}).ToList();
|
||||
db.PostFeaturedRecords.AddRange(records);
|
||||
await db.SaveChangesAsync();
|
||||
}
|
||||
|
||||
var posts = await db.Posts
|
||||
|
Reference in New Issue
Block a user