2021-11-14 03:27:01 +00:00
|
|
|
|
using System.Collections.Generic;
|
2021-11-16 05:44:16 +00:00
|
|
|
|
using System.Linq;
|
2021-11-13 03:21:59 +00:00
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Start.Server.Data.Services.Interfaces;
|
2021-11-14 03:27:01 +00:00
|
|
|
|
using Start.Server.Extensions;
|
2021-11-13 03:21:59 +00:00
|
|
|
|
using Start.Server.Models;
|
2021-11-16 05:44:16 +00:00
|
|
|
|
using Start.Shared;
|
2021-11-13 03:21:59 +00:00
|
|
|
|
|
|
|
|
|
namespace Start.Server.Controllers {
|
|
|
|
|
[Authorize]
|
|
|
|
|
[ApiController]
|
|
|
|
|
[Route("[controller]")]
|
|
|
|
|
public class BookmarksController : ControllerBase {
|
2021-11-14 03:27:01 +00:00
|
|
|
|
private readonly IBookmarkContainerService bookmarkContainerService;
|
|
|
|
|
private readonly IBookmarkGroupService bookmarkGroupService;
|
2021-11-13 03:21:59 +00:00
|
|
|
|
private readonly IBookmarkService bookmarkService;
|
|
|
|
|
|
2021-11-14 03:27:01 +00:00
|
|
|
|
private readonly string userId;
|
|
|
|
|
|
|
|
|
|
public BookmarksController(IBookmarkContainerService bookmarkContainerService,
|
|
|
|
|
IBookmarkGroupService bookmarkGroupService, IBookmarkService bookmarkService) {
|
|
|
|
|
this.bookmarkContainerService = bookmarkContainerService;
|
|
|
|
|
this.bookmarkGroupService = bookmarkGroupService;
|
2021-11-13 03:21:59 +00:00
|
|
|
|
this.bookmarkService = bookmarkService;
|
2021-11-14 03:27:01 +00:00
|
|
|
|
|
|
|
|
|
this.userId = this.GetAuthorizedUserId();
|
2021-11-13 03:21:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
2021-11-16 05:44:16 +00:00
|
|
|
|
public IList<BookmarkContainerDto> GetAllBookmarkContainers() {
|
|
|
|
|
return this.bookmarkContainerService.GetUserBookmarkContainers(this.userId)
|
|
|
|
|
.Select(bc => bc.MapToDto())
|
|
|
|
|
.ToList();
|
2021-11-13 03:21:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
2021-11-16 05:44:16 +00:00
|
|
|
|
public (BookmarkStatus, BookmarkContainerDto?) GetBookmarkContainer(int bookmarkContainerId) {
|
|
|
|
|
(BookmarkStatus status, BookmarkContainer? container) = this.bookmarkContainerService
|
|
|
|
|
.GetBookmarkContainer(this.userId, bookmarkContainerId, true, true);
|
|
|
|
|
|
|
|
|
|
return (status, container?.MapToDto());
|
2021-11-13 03:21:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-11-14 01:19:28 +00:00
|
|
|
|
[HttpGet]
|
2021-11-16 05:44:16 +00:00
|
|
|
|
public (BookmarkStatus, BookmarkDto?) GetBookmark(int bookmarkId) {
|
|
|
|
|
(BookmarkStatus status, Bookmark? bookmark) = this.bookmarkService
|
|
|
|
|
.GetBookmark(this.userId, bookmarkId);
|
|
|
|
|
|
|
|
|
|
return (status, bookmark?.MapToDto());
|
2021-11-14 01:19:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-11-13 03:21:59 +00:00
|
|
|
|
[HttpPost]
|
2021-11-16 05:44:16 +00:00
|
|
|
|
public (BookmarkStatus, BookmarkDto?) CreateBookmark(string title, string url, string? notes,
|
2021-11-13 03:21:59 +00:00
|
|
|
|
int bookmarkGroupId) {
|
2021-11-16 05:44:16 +00:00
|
|
|
|
(BookmarkStatus status, Bookmark? bookmark) = this.bookmarkService
|
|
|
|
|
.CreateBookmark(this.userId, title, url, notes, bookmarkGroupId);
|
|
|
|
|
|
|
|
|
|
return (status, bookmark?.MapToDto());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public (BookmarkStatus, BookmarkContainerDto?) CreateBookmarkContainer(string title) {
|
|
|
|
|
(BookmarkStatus status, BookmarkContainer? container) = this
|
|
|
|
|
.bookmarkContainerService.CreateBookmarkContainer(this.userId, title);
|
|
|
|
|
|
|
|
|
|
return (status, container?.MapToDto());
|
2021-11-14 01:19:28 +00:00
|
|
|
|
}
|
2021-11-13 03:21:59 +00:00
|
|
|
|
}
|
|
|
|
|
}
|