Almost finish implementing client side
This commit is contained in:
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user