Almost finish implementing client side

This commit is contained in:
2025-11-06 20:22:16 +02:00
parent a847779582
commit a891a686fd
42 changed files with 6450 additions and 57 deletions

View File

@@ -328,15 +328,15 @@ public class PostController(
/// Get a paginated list of posts.
/// </summary>
/// <param name="query">Query to filter posts by tags. Use +tag-name to require a tag, -tag-name to exclude a tag.</param>
/// <param name="pageNumber">The page number.</param>
/// <param name="page">The page number.</param>
/// <response code="200">The paginated list</response>
/// <response code="400">If request is malformed</response>
[HttpGet]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<ActionResult<PagedList<PostDto>>> GetAll(string? query, [Range(1, int.MaxValue)] int pageNumber = 1)
public async Task<ActionResult<PagedList<PostDto>>> GetAll(string? query, [Range(1, int.MaxValue)] int page = 1)
{
var list = await postService.FindAll(query, pageNumber);
var list = await postService.FindAll(query, page);
var newItems = list.Items.Select(i =>
{
var fileUrl = Url.Action(nameof(PatchFileContent), "Post",
@@ -494,7 +494,7 @@ public class PostController(
/// Get paginated list of specific post comments.
/// </summary>
/// <param name="postId">Post ID</param>
/// <param name="pageNumber">Page number</param>
/// <param name="page">Page number</param>
/// <response code="200">Paginated list of comments</response>
/// <response code="400">If request is malformed</response>
/// <response code="404">If post is not found</response>
@@ -504,13 +504,13 @@ public class PostController(
[ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task<ActionResult<PagedList<CommentDto>>> GetAllComments(
int postId,
[Range(1, int.MaxValue)] int pageNumber = 1
[Range(1, int.MaxValue)] int page = 1
)
{
var post = await postService.GetById(postId);
if (post == null) return NotFound();
var list = await commentService.GetAll(postId, pageNumber);
var list = await commentService.GetAll(postId, page);
var newItems = list.Items.Select(CommentDto.FromComment).ToList();
return Ok(new PagedList<CommentDto>(newItems, list.CurrentPage, list.PageSize, list.TotalCount));
}

View File

@@ -31,7 +31,7 @@ public class TagController(
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
[ProducesResponseType(StatusCodes.Status409Conflict)]
public async Task<ActionResult<Tag>> Create(CreateTagDto dto)
public async Task<ActionResult<TagDto>> Create(CreateTagDto dto)
{
// Check if tag exists, if it does, throw a conflict
var existingTag = await tagService.GetByName(dto.Name);
@@ -44,21 +44,23 @@ public class TagController(
}
var createdTag = await tagService.Create(dto.Type, dto.Name);
return CreatedAtAction(nameof(Get), new { name = createdTag.Name }, createdTag);
return CreatedAtAction(nameof(Get), new { name = createdTag.Name }, TagDto.FromTag(createdTag));
}
/// <summary>
/// Get a paginated list of tags.
/// </summary>
/// <param name="pageNumber">The page number</param>
/// <param name="page">The page number</param>
/// <response code="200">Returns paginated list</response>
/// <response code="400">If request is malformed</response>
[HttpGet]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<ActionResult<PagedList<Tag>>> GetAll(int pageNumber = 1)
public async Task<ActionResult<PagedList<TagDto>>> GetAll(int page = 1)
{
return Ok(await tagService.GetAll(pageNumber));
var list = await tagService.GetAll(page);
var newItems = list.Items.Select(TagDto.FromTag).ToList();
return Ok(new PagedList<TagDto>(newItems, list.CurrentPage, list.PageSize, list.TotalCount));
}
/// <summary>
@@ -72,14 +74,14 @@ public class TagController(
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task<ActionResult<Tag>> Get(string name)
public async Task<ActionResult<TagDto>> Get(string name)
{
var tag = await tagService.GetByName(name);
if (tag == null)
{
return NotFound();
}
return Ok(tag);
return Ok(TagDto.FromTag(tag));
}
/// <summary>
@@ -122,12 +124,12 @@ public class TagController(
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task<ActionResult<Tag>> Update(string name, EditTagDto dto)
public async Task<ActionResult<TagDto>> Update(string name, EditTagDto dto)
{
var tag = await tagService.GetByName(name);
if (tag == null) return NotFound();
var updatedTag = await tagService.Update(tag, dto.Type);
return Ok(updatedTag);
return Ok(TagDto.FromTag(updatedTag));
}