Use Refit for APIs, make data/API stack async
This commit is contained in:
parent
9c4f01ab13
commit
b00158daa7
17 changed files with 196 additions and 124 deletions
|
|
@ -1,5 +1,6 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
|
@ -22,9 +23,9 @@ namespace Start.Server.Controllers {
|
|||
[ProducesResponseType(StatusCodes.Status200OK,
|
||||
Type = typeof(IEnumerable<BookmarkContainerDto>))]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
public IActionResult GetAllBookmarkContainers() {
|
||||
List<BookmarkContainerDto>? containers = this.bookmarkContainerService
|
||||
.GetUserBookmarkContainers(this.GetAuthorizedUserId())
|
||||
public async Task<IActionResult> GetAllBookmarkContainers() {
|
||||
List<BookmarkContainerDto>? containers = (await this.bookmarkContainerService
|
||||
.GetUserBookmarkContainers(this.GetAuthorizedUserId()))
|
||||
.Select(bc => bc.MapToDto())
|
||||
.ToList();
|
||||
|
||||
|
|
@ -38,9 +39,9 @@ namespace Start.Server.Controllers {
|
|||
[Route("{bookmarkContainerId}")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(BookmarkContainerDto))]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
public IActionResult GetBookmarkContainer(int bookmarkContainerId) {
|
||||
BookmarkContainerDto? container = this.bookmarkContainerService
|
||||
.GetBookmarkContainer(this.GetAuthorizedUserId(), bookmarkContainerId, true, true)
|
||||
public async Task<IActionResult> GetBookmarkContainer(int bookmarkContainerId) {
|
||||
BookmarkContainerDto? container = (await this.bookmarkContainerService
|
||||
.GetBookmarkContainer(this.GetAuthorizedUserId(), bookmarkContainerId, true, true))
|
||||
?.MapToDto();
|
||||
|
||||
if (container == null)
|
||||
|
|
@ -53,9 +54,9 @@ namespace Start.Server.Controllers {
|
|||
[Route("Create")]
|
||||
[ProducesResponseType(StatusCodes.Status201Created, Type = typeof(BookmarkContainerDto))]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public IActionResult CreateBookmarkContainer([FromBody] string title) {
|
||||
BookmarkContainerDto? container = this.bookmarkContainerService
|
||||
.CreateBookmarkContainer(this.GetAuthorizedUserId(), title)
|
||||
public async Task<IActionResult> CreateBookmarkContainer([FromBody] string title) {
|
||||
BookmarkContainerDto? container = (await this.bookmarkContainerService
|
||||
.CreateBookmarkContainer(this.GetAuthorizedUserId(), title))
|
||||
?.MapToDto();
|
||||
|
||||
if (container == null)
|
||||
|
|
@ -71,8 +72,8 @@ namespace Start.Server.Controllers {
|
|||
[Route("Delete/{bookmarkContainerId}")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
public IActionResult DeleteBookmarkContainer(int bookmarkContainerId) {
|
||||
bool res = this.bookmarkContainerService
|
||||
public async Task<IActionResult> DeleteBookmarkContainer(int bookmarkContainerId) {
|
||||
bool res = await this.bookmarkContainerService
|
||||
.DeleteBookmarkContainer(this.GetAuthorizedUserId(), bookmarkContainerId);
|
||||
|
||||
if (!res)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
|
@ -25,9 +24,9 @@ namespace Start.Server.Controllers {
|
|||
[Route("{bookmarkId}")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(BookmarkDto))]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
public IActionResult GetBookmark(int bookmarkId) {
|
||||
BookmarkDto? bookmark = this.bookmarkService
|
||||
.GetBookmark(this.GetAuthorizedUserId(), bookmarkId)
|
||||
public async Task<IActionResult> GetBookmark(int bookmarkId) {
|
||||
BookmarkDto? bookmark = (await this.bookmarkService
|
||||
.GetBookmark(this.GetAuthorizedUserId(), bookmarkId))
|
||||
?.MapToDto();
|
||||
|
||||
if (bookmark == null)
|
||||
|
|
@ -40,10 +39,10 @@ namespace Start.Server.Controllers {
|
|||
[Route("Create")]
|
||||
[ProducesResponseType(StatusCodes.Status201Created, Type = typeof(BookmarkDto))]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public IActionResult CreateBookmark(string title, string url, string? notes,
|
||||
public async Task<IActionResult> CreateBookmark(string title, string url, string? notes,
|
||||
int bookmarkGroupId) {
|
||||
BookmarkDto? bookmark = this.bookmarkService
|
||||
.CreateBookmark(this.GetAuthorizedUserId(), title, url, notes, bookmarkGroupId)
|
||||
BookmarkDto? bookmark = (await this.bookmarkService
|
||||
.CreateBookmark(this.GetAuthorizedUserId(), title, url, notes, bookmarkGroupId))
|
||||
?.MapToDto();
|
||||
|
||||
if (bookmark == null)
|
||||
|
|
@ -58,8 +57,9 @@ namespace Start.Server.Controllers {
|
|||
[Route("Delete/{bookmarkId}")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
public IActionResult DeleteBookmark(int bookmarkId) {
|
||||
var res = this.bookmarkService.DeleteBookmark(this.GetAuthorizedUserId(), bookmarkId);
|
||||
public async Task<IActionResult> DeleteBookmark(int bookmarkId) {
|
||||
var res = await this.bookmarkService
|
||||
.DeleteBookmark(this.GetAuthorizedUserId(), bookmarkId);
|
||||
|
||||
if (!res)
|
||||
return NotFound();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue