♻️ Move most of models to the Shared package

This commit is contained in:
2025-07-06 22:34:52 +08:00
parent cb4acbb3fc
commit 65450e8511
170 changed files with 679 additions and 101121 deletions

View File

@@ -1,6 +1,7 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text.Json.Serialization;
using DysonNetwork.Shared.Models;
using DysonNetwork.Sphere.Activity;
using DysonNetwork.Sphere.Storage;
using NodaTime;
@@ -59,7 +60,7 @@ public class Post : ModelBase, IIdentifiedResource, IActivity
[JsonIgnore] public NpgsqlTsVector SearchVector { get; set; } = null!;
public Guid PublisherId { get; set; }
public Publisher.Publisher Publisher { get; set; } = null!;
public Shared.Models.Publisher Publisher { get; set; } = null!;
public ICollection<PostReaction> Reactions { get; set; } = new List<PostReaction>();
public ICollection<PostTag> Tags { get; set; } = new List<PostTag>();
@@ -109,7 +110,7 @@ public class PostCollection : ModelBase
[MaxLength(256)] public string? Name { get; set; }
[MaxLength(4096)] public string? Description { get; set; }
public Publisher.Publisher Publisher { get; set; } = null!;
public Shared.Models.Publisher Publisher { get; set; } = null!;
public ICollection<Post> Posts { get; set; } = new List<Post>();
}
@@ -130,5 +131,5 @@ public class PostReaction : ModelBase
public Guid PostId { get; set; }
[JsonIgnore] public Post Post { get; set; } = null!;
public Guid AccountId { get; set; }
public Account.Account Account { get; set; } = null!;
public Shared.Models.Account Account { get; set; } = null!;
}

View File

@@ -1,5 +1,6 @@
using System.ComponentModel.DataAnnotations;
using System.Text.Json;
using DysonNetwork.Shared.Models;
using DysonNetwork.Sphere.Account;
using DysonNetwork.Sphere.Permission;
using DysonNetwork.Sphere.Publisher;
@@ -31,7 +32,7 @@ public class PostController(
)
{
HttpContext.Items.TryGetValue("CurrentUser", out var currentUserValue);
var currentUser = currentUserValue as Account.Account;
var currentUser = currentUserValue as Shared.Models.Account;
var userFriends = currentUser is null ? [] : await rels.ListAccountFriends(currentUser);
var userPublishers = currentUser is null ? [] : await pub.GetUserPublishers(currentUser.Id);
@@ -66,7 +67,7 @@ public class PostController(
public async Task<ActionResult<Post>> GetPost(Guid id)
{
HttpContext.Items.TryGetValue("CurrentUser", out var currentUserValue);
var currentUser = currentUserValue as Account.Account;
var currentUser = currentUserValue as Shared.Models.Account;
var userFriends = currentUser is null ? [] : await rels.ListAccountFriends(currentUser);
var userPublishers = currentUser is null ? [] : await pub.GetUserPublishers(currentUser.Id);
@@ -98,7 +99,7 @@ public class PostController(
return BadRequest("Search query cannot be empty");
HttpContext.Items.TryGetValue("CurrentUser", out var currentUserValue);
var currentUser = currentUserValue as Account.Account;
var currentUser = currentUserValue as Shared.Models.Account;
var userFriends = currentUser is null ? [] : await rels.ListAccountFriends(currentUser);
var userPublishers = currentUser is null ? [] : await pub.GetUserPublishers(currentUser.Id);
@@ -135,7 +136,7 @@ public class PostController(
[FromQuery] int take = 20)
{
HttpContext.Items.TryGetValue("CurrentUser", out var currentUserValue);
var currentUser = currentUserValue as Account.Account;
var currentUser = currentUserValue as Shared.Models.Account;
var userFriends = currentUser is null ? [] : await rels.ListAccountFriends(currentUser);
var userPublishers = currentUser is null ? [] : await pub.GetUserPublishers(currentUser.Id);
@@ -197,9 +198,9 @@ public class PostController(
request.Content = TextSanitizer.Sanitize(request.Content);
if (string.IsNullOrWhiteSpace(request.Content) && request.Attachments is { Count: 0 })
return BadRequest("Content is required.");
if (HttpContext.Items["CurrentUser"] is not Account.Account currentUser) return Unauthorized();
if (HttpContext.Items["CurrentUser"] is not Shared.Models.Account currentUser) return Unauthorized();
Publisher.Publisher? publisher;
Shared.Models.Publisher? publisher;
if (publisherName is null)
{
// Use the first personal publisher
@@ -283,7 +284,7 @@ public class PostController(
public async Task<ActionResult<PostReaction>> ReactPost(Guid id, [FromBody] PostReactionRequest request)
{
HttpContext.Items.TryGetValue("CurrentUser", out var currentUserValue);
if (currentUserValue is not Account.Account currentUser) return Unauthorized();
if (currentUserValue is not Shared.Models.Account currentUser) return Unauthorized();
var userFriends = await rels.ListAccountFriends(currentUser);
var userPublishers = await pub.GetUserPublishers(currentUser.Id);
@@ -332,7 +333,7 @@ public class PostController(
request.Content = TextSanitizer.Sanitize(request.Content);
if (string.IsNullOrWhiteSpace(request.Content) && request.Attachments is { Count: 0 })
return BadRequest("Content is required.");
if (HttpContext.Items["CurrentUser"] is not Account.Account currentUser) return Unauthorized();
if (HttpContext.Items["CurrentUser"] is not Shared.Models.Account currentUser) return Unauthorized();
var post = await db.Posts
.Where(e => e.Id == id)
@@ -378,7 +379,7 @@ public class PostController(
[HttpDelete("{id:guid}")]
public async Task<ActionResult<Post>> DeletePost(Guid id)
{
if (HttpContext.Items["CurrentUser"] is not Account.Account currentUser) return Unauthorized();
if (HttpContext.Items["CurrentUser"] is not Shared.Models.Account currentUser) return Unauthorized();
var post = await db.Posts
.Where(e => e.Id == id)

View File

@@ -69,7 +69,7 @@ public partial class PostService(
}
public async Task<Post> PostAsync(
Account.Account user,
Shared.Models.Account user,
Post post,
List<string>? attachments = null,
List<string>? tags = null,
@@ -391,7 +391,7 @@ public partial class PostService(
public async Task<bool> ModifyPostVotes(
Post post,
PostReaction reaction,
Account.Account sender,
Shared.Models.Account sender,
bool isRemoving,
bool isSelfReact
)
@@ -563,7 +563,7 @@ public partial class PostService(
return posts;
}
public async Task<List<Post>> LoadInteractive(List<Post> posts, Account.Account? currentUser = null)
public async Task<List<Post>> LoadInteractive(List<Post> posts, Shared.Models.Account? currentUser = null)
{
if (posts.Count == 0) return posts;
@@ -605,7 +605,7 @@ public partial class PostService(
);
}
public async Task<List<Post>> LoadPostInfo(List<Post> posts, Account.Account? currentUser = null,
public async Task<List<Post>> LoadPostInfo(List<Post> posts, Shared.Models.Account? currentUser = null,
bool truncate = false)
{
if (posts.Count == 0) return posts;
@@ -619,7 +619,7 @@ public partial class PostService(
return posts;
}
public async Task<Post> LoadPostInfo(Post post, Account.Account? currentUser = null, bool truncate = false)
public async Task<Post> LoadPostInfo(Post post, Shared.Models.Account? currentUser = null, bool truncate = false)
{
// Convert single post to list, process it, then return the single post
var posts = await LoadPostInfo([post], currentUser, truncate);
@@ -631,9 +631,9 @@ public static class PostQueryExtensions
{
public static IQueryable<Post> FilterWithVisibility(
this IQueryable<Post> source,
Account.Account? currentUser,
Shared.Models.Account? currentUser,
List<Guid> userFriends,
List<Publisher.Publisher> publishers,
List<Shared.Models.Publisher> publishers,
bool isListing = false
)
{