✨ Post slug 🐛 Fix duplicate device id
This commit is contained in:
@@ -101,7 +101,6 @@ public class AuthChallenge : ModelBase
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
[Index(nameof(DeviceId), IsUnique = true)]
|
|
||||||
public class AuthClient : ModelBase
|
public class AuthClient : ModelBase
|
||||||
{
|
{
|
||||||
public Guid Id { get; set; } = Guid.NewGuid();
|
public Guid Id { get; set; } = Guid.NewGuid();
|
||||||
|
1826
DysonNetwork.Pass/Migrations/20250815041723_RemoveAuthClientIndex.Designer.cs
generated
Normal file
1826
DysonNetwork.Pass/Migrations/20250815041723_RemoveAuthClientIndex.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,28 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace DysonNetwork.Pass.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class RemoveAuthClientIndex : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropIndex(
|
||||||
|
name: "ix_auth_clients_device_id",
|
||||||
|
table: "auth_clients");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "ix_auth_clients_device_id",
|
||||||
|
table: "auth_clients",
|
||||||
|
column: "device_id",
|
||||||
|
unique: true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -944,10 +944,6 @@ namespace DysonNetwork.Pass.Migrations
|
|||||||
b.HasIndex("AccountId")
|
b.HasIndex("AccountId")
|
||||||
.HasDatabaseName("ix_auth_clients_account_id");
|
.HasDatabaseName("ix_auth_clients_account_id");
|
||||||
|
|
||||||
b.HasIndex("DeviceId")
|
|
||||||
.IsUnique()
|
|
||||||
.HasDatabaseName("ix_auth_clients_device_id");
|
|
||||||
|
|
||||||
b.ToTable("auth_clients", (string)null);
|
b.ToTable("auth_clients", (string)null);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
1944
DysonNetwork.Sphere/Migrations/20250815041220_AddPostSlug.Designer.cs
generated
Normal file
1944
DysonNetwork.Sphere/Migrations/20250815041220_AddPostSlug.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
40
DysonNetwork.Sphere/Migrations/20250815041220_AddPostSlug.cs
Normal file
40
DysonNetwork.Sphere/Migrations/20250815041220_AddPostSlug.cs
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace DysonNetwork.Sphere.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class AddPostSlug : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "language",
|
||||||
|
table: "posts");
|
||||||
|
|
||||||
|
migrationBuilder.AddColumn<string>(
|
||||||
|
name: "slug",
|
||||||
|
table: "posts",
|
||||||
|
type: "character varying(1024)",
|
||||||
|
maxLength: 1024,
|
||||||
|
nullable: true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "slug",
|
||||||
|
table: "posts");
|
||||||
|
|
||||||
|
migrationBuilder.AddColumn<string>(
|
||||||
|
name: "language",
|
||||||
|
table: "posts",
|
||||||
|
type: "character varying(128)",
|
||||||
|
maxLength: 128,
|
||||||
|
nullable: true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -558,11 +558,6 @@ namespace DysonNetwork.Sphere.Migrations
|
|||||||
.HasColumnType("uuid")
|
.HasColumnType("uuid")
|
||||||
.HasColumnName("forwarded_post_id");
|
.HasColumnName("forwarded_post_id");
|
||||||
|
|
||||||
b.Property<string>("Language")
|
|
||||||
.HasMaxLength(128)
|
|
||||||
.HasColumnType("character varying(128)")
|
|
||||||
.HasColumnName("language");
|
|
||||||
|
|
||||||
b.Property<Dictionary<string, object>>("Meta")
|
b.Property<Dictionary<string, object>>("Meta")
|
||||||
.HasColumnType("jsonb")
|
.HasColumnType("jsonb")
|
||||||
.HasColumnName("meta");
|
.HasColumnName("meta");
|
||||||
@@ -595,6 +590,11 @@ namespace DysonNetwork.Sphere.Migrations
|
|||||||
.HasColumnType("jsonb")
|
.HasColumnType("jsonb")
|
||||||
.HasColumnName("sensitive_marks");
|
.HasColumnName("sensitive_marks");
|
||||||
|
|
||||||
|
b.Property<string>("Slug")
|
||||||
|
.HasMaxLength(1024)
|
||||||
|
.HasColumnType("character varying(1024)")
|
||||||
|
.HasColumnName("slug");
|
||||||
|
|
||||||
b.Property<string>("Title")
|
b.Property<string>("Title")
|
||||||
.HasMaxLength(1024)
|
.HasMaxLength(1024)
|
||||||
.HasColumnType("character varying(1024)")
|
.HasColumnType("character varying(1024)")
|
||||||
|
@@ -28,7 +28,7 @@ public class Post : ModelBase, IIdentifiedResource, IActivity
|
|||||||
public Guid Id { get; set; }
|
public Guid Id { get; set; }
|
||||||
[MaxLength(1024)] public string? Title { get; set; }
|
[MaxLength(1024)] public string? Title { get; set; }
|
||||||
[MaxLength(4096)] public string? Description { get; set; }
|
[MaxLength(4096)] public string? Description { get; set; }
|
||||||
[MaxLength(128)] public string? Language { get; set; }
|
[MaxLength(1024)] public string? Slug { get; set; }
|
||||||
public Instant? EditedAt { get; set; }
|
public Instant? EditedAt { get; set; }
|
||||||
public Instant? PublishedAt { get; set; }
|
public Instant? PublishedAt { get; set; }
|
||||||
public PostVisibility Visibility { get; set; } = PostVisibility.Public;
|
public PostVisibility Visibility { get; set; } = PostVisibility.Public;
|
||||||
|
@@ -124,6 +124,37 @@ public class PostController(
|
|||||||
return Ok(posts);
|
return Ok(posts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpGet("{publisherName}/{slug}")]
|
||||||
|
public async Task<ActionResult<Post>> GetPost(string publisherName, string slug)
|
||||||
|
{
|
||||||
|
HttpContext.Items.TryGetValue("CurrentUser", out var currentUserValue);
|
||||||
|
var currentUser = currentUserValue as Account;
|
||||||
|
List<Guid> userFriends = [];
|
||||||
|
if (currentUser != null)
|
||||||
|
{
|
||||||
|
var friendsResponse = await accounts.ListFriendsAsync(new ListRelationshipSimpleRequest
|
||||||
|
{ AccountId = currentUser.Id });
|
||||||
|
userFriends = friendsResponse.AccountsId.Select(Guid.Parse).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
var userPublishers = currentUser is null ? [] : await pub.GetUserPublishers(Guid.Parse(currentUser.Id));
|
||||||
|
|
||||||
|
var post = await db.Posts
|
||||||
|
.Include(e => e.Publisher)
|
||||||
|
.Where(e => e.Slug == slug && e.Publisher.Name == publisherName)
|
||||||
|
.Include(e => e.Tags)
|
||||||
|
.Include(e => e.Categories)
|
||||||
|
.FilterWithVisibility(currentUser, userFriends, userPublishers)
|
||||||
|
.FirstOrDefaultAsync();
|
||||||
|
if (post is null) return NotFound();
|
||||||
|
post = await ps.LoadPostInfo(post, currentUser);
|
||||||
|
|
||||||
|
// Track view - use the account ID as viewer ID if user is logged in
|
||||||
|
await ps.IncreaseViewCount(post.Id, currentUser?.Id);
|
||||||
|
|
||||||
|
return Ok(post);
|
||||||
|
}
|
||||||
|
|
||||||
[HttpGet("{id:guid}")]
|
[HttpGet("{id:guid}")]
|
||||||
public async Task<ActionResult<Post>> GetPost(Guid id)
|
public async Task<ActionResult<Post>> GetPost(Guid id)
|
||||||
{
|
{
|
||||||
@@ -318,6 +349,7 @@ public class PostController(
|
|||||||
{
|
{
|
||||||
[MaxLength(1024)] public string? Title { get; set; }
|
[MaxLength(1024)] public string? Title { get; set; }
|
||||||
[MaxLength(4096)] public string? Description { get; set; }
|
[MaxLength(4096)] public string? Description { get; set; }
|
||||||
|
[MaxLength(1024)] public string? Slug { get; set; }
|
||||||
public string? Content { get; set; }
|
public string? Content { get; set; }
|
||||||
public PostVisibility? Visibility { get; set; } = PostVisibility.Public;
|
public PostVisibility? Visibility { get; set; } = PostVisibility.Public;
|
||||||
public PostType? Type { get; set; }
|
public PostType? Type { get; set; }
|
||||||
@@ -368,6 +400,7 @@ public class PostController(
|
|||||||
{
|
{
|
||||||
Title = request.Title,
|
Title = request.Title,
|
||||||
Description = request.Description,
|
Description = request.Description,
|
||||||
|
Slug = request.Slug,
|
||||||
Content = request.Content,
|
Content = request.Content,
|
||||||
Visibility = request.Visibility ?? PostVisibility.Public,
|
Visibility = request.Visibility ?? PostVisibility.Public,
|
||||||
PublishedAt = request.PublishedAt,
|
PublishedAt = request.PublishedAt,
|
||||||
@@ -548,6 +581,7 @@ public class PostController(
|
|||||||
|
|
||||||
if (request.Title is not null) post.Title = request.Title;
|
if (request.Title is not null) post.Title = request.Title;
|
||||||
if (request.Description is not null) post.Description = request.Description;
|
if (request.Description is not null) post.Description = request.Description;
|
||||||
|
if (request.Slug is not null) post.Slug = request.Slug;
|
||||||
if (request.Content is not null) post.Content = request.Content;
|
if (request.Content is not null) post.Content = request.Content;
|
||||||
if (request.Visibility is not null) post.Visibility = request.Visibility.Value;
|
if (request.Visibility is not null) post.Visibility = request.Visibility.Value;
|
||||||
if (request.Type is not null) post.Type = request.Type.Value;
|
if (request.Type is not null) post.Type = request.Type.Value;
|
||||||
|
Reference in New Issue
Block a user