Add support for deleting bookmark containers

This commit is contained in:
Neil Brommer 2021-11-22 12:52:41 -08:00
parent 3eb2b2ae98
commit 25fb38baec
2 changed files with 90 additions and 15 deletions

View file

@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Start.Server.Data.Services.Interfaces;
using Start.Server.Extensions;
@ -23,47 +24,96 @@ namespace Start.Server.Controllers {
}
[HttpGet]
public IList<BookmarkContainerDto> GetAllBookmarkContainers() {
return this.bookmarkContainerService.GetUserBookmarkContainers(this.GetAuthorizedUserId())
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(IEnumerable<BookmarkContainerDto>))]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public IActionResult GetAllBookmarkContainers() {
List<BookmarkContainerDto>? containers = this.bookmarkContainerService
.GetUserBookmarkContainers(this.GetAuthorizedUserId())
.Select(bc => bc.MapToDto())
.ToList();
if (containers == null)
return NotFound();
return Ok(containers);
}
[HttpGet]
[Route("{bookmarkContainerId}")]
public BookmarkContainerDto? GetBookmarkContainer(int bookmarkContainerId) {
return this.bookmarkContainerService
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(BookmarkContainerDto))]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public IActionResult GetBookmarkContainer(int bookmarkContainerId) {
BookmarkContainerDto? container = this.bookmarkContainerService
.GetBookmarkContainer(this.GetAuthorizedUserId(), bookmarkContainerId, true, true)
?.MapToDto();
if (container == null)
return NotFound();
return Ok(container);
}
[HttpGet]
[Route("{bookmarkId}")]
public BookmarkDto? GetBookmark(int bookmarkId) {
return this.bookmarkService
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(BookmarkDto))]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public IActionResult GetBookmark(int bookmarkId) {
BookmarkDto? bookmark = this.bookmarkService
.GetBookmark(this.GetAuthorizedUserId(), bookmarkId)
?.MapToDto();
if (bookmark == null)
return NotFound();
return Ok(bookmark);
}
[HttpPost]
public BookmarkDto? CreateBookmark(string title, string url, string? notes,
[ProducesResponseType(StatusCodes.Status201Created, Type = typeof(BookmarkDto))]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
public IActionResult CreateBookmark(string title, string url, string? notes,
int bookmarkGroupId) {
return this.bookmarkService
BookmarkDto? bookmark = this.bookmarkService
.CreateBookmark(this.GetAuthorizedUserId(), title, url, notes, bookmarkGroupId)
?.MapToDto();
if (bookmark == null)
return BadRequest();
return Created(
Url.Action(nameof(this.GetBookmark),new { bookmarkId = bookmark.BookmarkId }),
bookmark);
}
[HttpPost]
public BookmarkContainerDto? CreateBookmarkContainer([FromBody] string title) {
return this.bookmarkContainerService
[ProducesResponseType(StatusCodes.Status201Created, Type = typeof(BookmarkContainerDto))]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
public IActionResult CreateBookmarkContainer([FromBody] string title) {
BookmarkContainerDto? container = this.bookmarkContainerService
.CreateBookmarkContainer(this.GetAuthorizedUserId(), title)
?.MapToDto();
if (container == null)
return BadRequest();
return Created(
Url.Action(nameof(this.GetBookmarkContainer),
new { bookmarkContainerId = container.BookmarkContainerId }),
container);
}
[HttpDelete]
public bool DeleteBookmarkContainer(int bookmarkContainerId) {
return this.bookmarkContainerService
[Route("{bookmarkContainerId}")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public IActionResult DeleteBookmarkContainer(int bookmarkContainerId) {
bool res = this.bookmarkContainerService
.DeleteBookmarkContainer(this.GetAuthorizedUserId(), bookmarkContainerId);
if (!res)
return NotFound();
return Ok();
}
}
}