✨ Able to transfer post
♻️ Move the publisher name to query string
This commit is contained in:
@@ -165,10 +165,10 @@ public class PostController(
|
|||||||
var query = db.PostReactions
|
var query = db.PostReactions
|
||||||
.Where(e => e.PostId == id);
|
.Where(e => e.PostId == id);
|
||||||
if (symbol is not null) query = query.Where(e => e.Symbol == symbol);
|
if (symbol is not null) query = query.Where(e => e.Symbol == symbol);
|
||||||
|
|
||||||
var totalCount = await query.CountAsync();
|
var totalCount = await query.CountAsync();
|
||||||
Response.Headers.Append("X-Total", totalCount.ToString());
|
Response.Headers.Append("X-Total", totalCount.ToString());
|
||||||
|
|
||||||
var reactions = await query
|
var reactions = await query
|
||||||
.OrderBy(r => r.Symbol)
|
.OrderBy(r => r.Symbol)
|
||||||
.ThenByDescending(r => r.CreatedAt)
|
.ThenByDescending(r => r.CreatedAt)
|
||||||
@@ -281,7 +281,8 @@ public class PostController(
|
|||||||
[RequiredPermission("global", "posts.create")]
|
[RequiredPermission("global", "posts.create")]
|
||||||
public async Task<ActionResult<Post>> CreatePost(
|
public async Task<ActionResult<Post>> CreatePost(
|
||||||
[FromBody] PostRequest request,
|
[FromBody] PostRequest request,
|
||||||
[FromHeader(Name = "X-Pub")] string? publisherName
|
[FromQuery(Name = "pub")] [FromHeader(Name = "X-Pub")]
|
||||||
|
string? publisherName
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
request.Content = TextSanitizer.Sanitize(request.Content);
|
request.Content = TextSanitizer.Sanitize(request.Content);
|
||||||
@@ -433,7 +434,11 @@ public class PostController(
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpPatch("{id:guid}")]
|
[HttpPatch("{id:guid}")]
|
||||||
public async Task<ActionResult<Post>> UpdatePost(Guid id, [FromBody] PostRequest request)
|
public async Task<ActionResult<Post>> UpdatePost(
|
||||||
|
Guid id,
|
||||||
|
[FromBody] PostRequest request,
|
||||||
|
[FromQuery(Name = "pub")] string? pubName
|
||||||
|
)
|
||||||
{
|
{
|
||||||
request.Content = TextSanitizer.Sanitize(request.Content);
|
request.Content = TextSanitizer.Sanitize(request.Content);
|
||||||
if (string.IsNullOrWhiteSpace(request.Content) && request.Attachments is { Count: 0 })
|
if (string.IsNullOrWhiteSpace(request.Content) && request.Attachments is { Count: 0 })
|
||||||
@@ -452,6 +457,16 @@ public class PostController(
|
|||||||
if (!await pub.IsMemberWithRole(post.Publisher.Id, accountId, PublisherMemberRole.Editor))
|
if (!await pub.IsMemberWithRole(post.Publisher.Id, accountId, PublisherMemberRole.Editor))
|
||||||
return StatusCode(403, "You need at least be an editor to edit this publisher's post.");
|
return StatusCode(403, "You need at least be an editor to edit this publisher's post.");
|
||||||
|
|
||||||
|
if (pubName is not null)
|
||||||
|
{
|
||||||
|
var publisher = await pub.GetPublisherByName(pubName);
|
||||||
|
if (publisher is null) return NotFound();
|
||||||
|
if (!await pub.IsMemberWithRole(publisher.Id, accountId, PublisherMemberRole.Editor))
|
||||||
|
return StatusCode(403, "You need at least be an editor to transfer this post to this publisher.");
|
||||||
|
post.PublisherId = publisher.Id;
|
||||||
|
post.Publisher = publisher;
|
||||||
|
}
|
||||||
|
|
||||||
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.Content is not null) post.Content = request.Content;
|
if (request.Content is not null) post.Content = request.Content;
|
||||||
|
Reference in New Issue
Block a user