Add creating bookmark groups
This commit is contained in:
parent
d997655b59
commit
7841d1d1a8
28 changed files with 692 additions and 114 deletions
67
Start/Server/Controllers/BookmarkGroupsController.cs
Normal file
67
Start/Server/Controllers/BookmarkGroupsController.cs
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Start.Server.Data.Services.Interfaces;
|
||||
using Start.Server.Models;
|
||||
using Start.Server.Extensions;
|
||||
using Start.Shared;
|
||||
|
||||
namespace Start.Server.Controllers {
|
||||
[Authorize]
|
||||
[ApiController]
|
||||
[Route("[controller]")]
|
||||
public class BookmarkGroupsController : ControllerBase {
|
||||
private readonly IBookmarkGroupService bookmarkGroupService;
|
||||
|
||||
public BookmarkGroupsController(IBookmarkGroupService bookmarkGroupService) {
|
||||
this.bookmarkGroupService = bookmarkGroupService;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("{bookmarkGroupId}")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(BookmarkGroupDto))]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
public async Task<IActionResult> GetBookmarkGroup(int bookmarkGroupId) {
|
||||
BookmarkGroup? group = await this.bookmarkGroupService
|
||||
.GetBookmarkGroup(this.GetAuthorizedUserId(), bookmarkGroupId);
|
||||
|
||||
if (group == null)
|
||||
return NotFound();
|
||||
|
||||
return Ok(group.MapToDto());
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Route("Create")]
|
||||
[ProducesResponseType(StatusCodes.Status201Created, Type = typeof(BookmarkGroupDto))]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task<IActionResult> CreateBookmarkGroup(string title, string color,
|
||||
int bookmarkContainerId) {
|
||||
BookmarkGroup? newGroup = await this.bookmarkGroupService
|
||||
.CreateBookmarkGroup(this.GetAuthorizedUserId(), title, color, bookmarkContainerId);
|
||||
|
||||
if (newGroup == null)
|
||||
return BadRequest();
|
||||
|
||||
return Created(
|
||||
Url.Action(nameof(GetBookmarkGroup),
|
||||
new { bookmarkGroupId = newGroup.BookmarkGroupId }),
|
||||
newGroup.MapToDto());
|
||||
}
|
||||
|
||||
[HttpDelete]
|
||||
[Route("Delete/{bookmarkGroupId}")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
public async Task<IActionResult> DeleteBookmark(int bookmarkGroupId) {
|
||||
bool res = await this.bookmarkGroupService
|
||||
.DeleteBookmarkGroup(this.GetAuthorizedUserId(), bookmarkGroupId);
|
||||
|
||||
if (!res)
|
||||
return NotFound();
|
||||
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -11,12 +11,9 @@ namespace Start.Server.Controllers {
|
|||
[ApiController]
|
||||
[Route("[controller]")]
|
||||
public class BookmarksController : ControllerBase {
|
||||
private readonly IBookmarkGroupService bookmarkGroupService;
|
||||
private readonly IBookmarkService bookmarkService;
|
||||
|
||||
public BookmarksController(IBookmarkGroupService bookmarkGroupService,
|
||||
IBookmarkService bookmarkService) {
|
||||
this.bookmarkGroupService = bookmarkGroupService;
|
||||
public BookmarksController(IBookmarkService bookmarkService) {
|
||||
this.bookmarkService = bookmarkService;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Linq;
|
||||
using Start.Server.Models;
|
||||
using Start.Shared;
|
||||
|
||||
|
|
@ -12,7 +11,8 @@ namespace Start.Server.Extensions {
|
|||
|
||||
public static BookmarkGroupDto MapToDto(this BookmarkGroup bookmarkGroup) {
|
||||
return new BookmarkGroupDto(bookmarkGroup.BookmarkGroupId, bookmarkGroup.Title,
|
||||
bookmarkGroup.Color, bookmarkGroup.Bookmarks?.Select(b => b.MapToDto()).ToList());
|
||||
bookmarkGroup.Color, bookmarkGroup.BookmarkContainerId,
|
||||
bookmarkGroup.Bookmarks?.Select(b => b.MapToDto()).ToList());
|
||||
}
|
||||
|
||||
public static BookmarkContainerDto MapToDto(this BookmarkContainer bookmarkContainer) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue