Moved projects to their own separate subdirectories
This commit is contained in:
146
API/YABA.API/Controllers/BookmarksController.cs
Normal file
146
API/YABA.API/Controllers/BookmarksController.cs
Normal file
@ -0,0 +1,146 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.JsonPatch;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Net;
|
||||
using YABA.API.ViewModels.Bookmarks;
|
||||
using YABA.API.ViewModels.Tags;
|
||||
using YABA.Common.DTOs.Bookmarks;
|
||||
using YABA.Service.Interfaces;
|
||||
|
||||
namespace YABA.API.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[ApiVersion("1")]
|
||||
[Authorize]
|
||||
[Route("api/v{version:apiVersion}/[controller]")]
|
||||
public class BookmarksController : ControllerBase
|
||||
{
|
||||
private readonly IMapper _mapper;
|
||||
private readonly IBookmarkService _bookmarkService;
|
||||
|
||||
public BookmarksController(IMapper mapper, IBookmarkService bookmarkService)
|
||||
{
|
||||
_mapper = mapper;
|
||||
_bookmarkService = bookmarkService;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[ProducesResponseType(typeof(BookmarkResponse), (int)HttpStatusCode.Created)]
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
|
||||
public async Task<IActionResult> Create([FromBody] CreateBookmarkRequestDTO request)
|
||||
{
|
||||
if (!ModelState.IsValid) return BadRequest(ModelState);
|
||||
|
||||
var result = await _bookmarkService.CreateBookmark(request);
|
||||
|
||||
if(result == null) return BadRequest();
|
||||
|
||||
return CreatedAtAction(nameof(Create), _mapper.Map<BookmarkResponse>(result));
|
||||
}
|
||||
|
||||
[HttpPut("{id}")]
|
||||
[ProducesResponseType(typeof(BookmarkResponse), (int)HttpStatusCode.OK)]
|
||||
[ProducesResponseType((int)HttpStatusCode.NotFound)]
|
||||
public async Task<IActionResult> UpdateBookmark(int id, [FromBody] UpdateBookmarkRequestDTO request)
|
||||
{
|
||||
var result = await _bookmarkService.UpdateBookmark(id, request);
|
||||
|
||||
if (result == null) return NotFound();
|
||||
|
||||
return Ok(_mapper.Map<BookmarkResponse>(result));
|
||||
}
|
||||
|
||||
[HttpPatch("{id}")]
|
||||
[ProducesResponseType(typeof(BookmarkResponse), (int)HttpStatusCode.OK)]
|
||||
[ProducesResponseType((int)HttpStatusCode.NotFound)]
|
||||
public async Task<IActionResult> PatchBookmark(int id, [FromBody] JsonPatchDocument<PatchBookmarkRequest> request)
|
||||
{
|
||||
if (request == null || !ModelState.IsValid) return BadRequest(ModelState);
|
||||
|
||||
var entryToEdit = await _bookmarkService.Get(id);
|
||||
if(entryToEdit == null) return NotFound();
|
||||
|
||||
var entryToEditAsPatchRequest = _mapper.Map<PatchBookmarkRequest>(entryToEdit);
|
||||
request.ApplyTo(entryToEditAsPatchRequest, ModelState);
|
||||
|
||||
var updateRequest = _mapper.Map<UpdateBookmarkRequestDTO>(entryToEditAsPatchRequest);
|
||||
var result = await _bookmarkService.UpdateBookmark(id, updateRequest);
|
||||
|
||||
if (result == null) return NotFound();
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[ProducesResponseType(typeof(IEnumerable<BookmarkResponse>), (int)HttpStatusCode.OK)]
|
||||
public IActionResult GetAll(bool showHidden = false)
|
||||
{
|
||||
var result = _bookmarkService.GetAll(showHidden);
|
||||
return Ok(_mapper.Map<IEnumerable<BookmarkResponse>>(result));
|
||||
}
|
||||
|
||||
[HttpGet("{id}")]
|
||||
[ProducesResponseType(typeof(BookmarkResponse), (int)HttpStatusCode.OK)]
|
||||
[ProducesResponseType((int)HttpStatusCode.NotFound)]
|
||||
public async Task<IActionResult> Get(int id)
|
||||
{
|
||||
var result = await _bookmarkService.Get(id);
|
||||
|
||||
if (result == null) return NotFound();
|
||||
|
||||
return Ok(_mapper.Map<BookmarkResponse>(result));
|
||||
}
|
||||
|
||||
[HttpDelete("{id}")]
|
||||
[ProducesResponseType((int)HttpStatusCode.NoContent)]
|
||||
[ProducesResponseType((int)HttpStatusCode.NotFound)]
|
||||
public async Task<IActionResult> Delete(int id)
|
||||
{
|
||||
var result = await _bookmarkService.DeleteBookmark(id);
|
||||
|
||||
if (!result.HasValue) return NotFound();
|
||||
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
[HttpDelete]
|
||||
[ProducesResponseType((int)HttpStatusCode.NoContent)]
|
||||
[ProducesResponseType((int)HttpStatusCode.NotFound)]
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
|
||||
public async Task<IActionResult> DeleteBookmarks([FromBody] DeleteBookmarksRequest request)
|
||||
{
|
||||
if (request.Ids == null || !request.Ids.Any()) return BadRequest();
|
||||
|
||||
var result = await _bookmarkService.DeleteBookmarks(request.Ids);
|
||||
|
||||
if(result == null) return NotFound();
|
||||
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
[HttpPost("Hide")]
|
||||
[ProducesResponseType((int)HttpStatusCode.NoContent)]
|
||||
[ProducesResponseType((int)HttpStatusCode.NotFound)]
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
|
||||
public async Task<IActionResult> HideBookmarks([FromBody] HideBookmarksRequest request)
|
||||
{
|
||||
if (request.Ids == null || !request.Ids.Any()) return BadRequest();
|
||||
|
||||
var result = await _bookmarkService.HideBookmarks(request.Ids);
|
||||
|
||||
if (result == null) return NotFound();
|
||||
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
[HttpGet("Tags")]
|
||||
[ProducesResponseType((int)HttpStatusCode.OK)]
|
||||
public IActionResult GetBookmarkTags(bool showHidden = false)
|
||||
{
|
||||
var result = _bookmarkService.GetAllBookmarkTags(showHidden);
|
||||
return Ok(_mapper.Map<IEnumerable<TagResponse>>(result));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
40
API/YABA.API/Controllers/MiscController.cs
Normal file
40
API/YABA.API/Controllers/MiscController.cs
Normal file
@ -0,0 +1,40 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Net;
|
||||
using YABA.API.Settings;
|
||||
using YABA.API.ViewModels;
|
||||
using YABA.Service.Interfaces;
|
||||
|
||||
namespace YABA.API.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[ApiVersion("1")]
|
||||
[Authorize, Route("api/v{version:apiVersion}/[controller]")]
|
||||
public class MiscController : ControllerBase
|
||||
{
|
||||
private readonly IMapper _mapper;
|
||||
private readonly IMiscService _miscService;
|
||||
|
||||
public MiscController(
|
||||
IMapper mapper,
|
||||
IMiscService miscService)
|
||||
{
|
||||
_mapper = mapper;
|
||||
_miscService = miscService;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[DevOnly]
|
||||
[Route("GetWebsiteMetaData")]
|
||||
[ProducesResponseType(typeof(GetWebsiteMetaDataResponse), (int)HttpStatusCode.OK)]
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
|
||||
public IActionResult GetWebsiteMetaData(string url)
|
||||
{
|
||||
if (string.IsNullOrEmpty(url)) return BadRequest();
|
||||
|
||||
var response = _miscService.GetWebsiteMetaData(url);
|
||||
return Ok(_mapper.Map<GetWebsiteMetaDataResponse>(response));
|
||||
}
|
||||
}
|
||||
}
|
||||
110
API/YABA.API/Controllers/TagsController.cs
Normal file
110
API/YABA.API/Controllers/TagsController.cs
Normal file
@ -0,0 +1,110 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Net;
|
||||
using YABA.API.ViewModels.Tags;
|
||||
using YABA.Common.DTOs.Tags;
|
||||
using YABA.Service.Interfaces;
|
||||
|
||||
namespace YABA.API.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[ApiVersion("1")]
|
||||
[Authorize]
|
||||
[Route("api/v{version:apiVersion}/[controller]")]
|
||||
public class TagsController : ControllerBase
|
||||
{
|
||||
private readonly IMapper _mapper;
|
||||
private readonly ITagsService _tagsService;
|
||||
|
||||
public TagsController(IMapper mapper, ITagsService tagsService)
|
||||
{
|
||||
_mapper = mapper;
|
||||
_tagsService = tagsService;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[ProducesResponseType(typeof(IEnumerable<TagResponse>), (int)HttpStatusCode.OK)]
|
||||
[ProducesResponseType((int)HttpStatusCode.NotFound)]
|
||||
public async Task<IActionResult> GetAll()
|
||||
{
|
||||
var result = await _tagsService.GetAll();
|
||||
|
||||
if (result == null) return NotFound();
|
||||
|
||||
return Ok(_mapper.Map<IEnumerable<TagResponse>>(result));
|
||||
}
|
||||
|
||||
[HttpGet("{id}")]
|
||||
[ProducesResponseType(typeof(TagResponse), (int)HttpStatusCode.OK)]
|
||||
[ProducesResponseType((int)HttpStatusCode.NotFound)]
|
||||
public async Task<IActionResult> Get(int id)
|
||||
{
|
||||
var result = await _tagsService.Get(id);
|
||||
|
||||
if (result == null) return NotFound();
|
||||
|
||||
return Ok(_mapper.Map<TagResponse>(result));
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[ProducesResponseType(typeof(IEnumerable<TagResponse>), (int)HttpStatusCode.OK)]
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
|
||||
public async Task<IActionResult> CreateTag([FromBody]CreateTagDTO request)
|
||||
{
|
||||
if (!ModelState.IsValid) return BadRequest(ModelState);
|
||||
|
||||
var result = await _tagsService.CreateTag(request);
|
||||
|
||||
if (result == null) return BadRequest();
|
||||
|
||||
return Ok(_mapper.Map<TagResponse>(result));
|
||||
}
|
||||
|
||||
[HttpPut("{id}")]
|
||||
[ProducesResponseType(typeof(IEnumerable<TagResponse>), (int)HttpStatusCode.OK)]
|
||||
[ProducesResponseType((int)HttpStatusCode.NotFound)]
|
||||
public async Task<IActionResult> UpdateTag(int id, [FromBody]UpdateTagDTO request)
|
||||
{
|
||||
var result = await _tagsService.UpdateTag(id, request);
|
||||
|
||||
if (result == null) return NotFound();
|
||||
|
||||
return Ok(_mapper.Map<TagResponse>(result));
|
||||
}
|
||||
|
||||
[HttpPatch("{id}")]
|
||||
[ProducesResponseType(typeof(IEnumerable<TagResponse>), (int)HttpStatusCode.OK)]
|
||||
[ProducesResponseType((int)HttpStatusCode.NotFound)]
|
||||
public async Task<IActionResult> PatchTag(int id, [FromBody] UpdateTagDTO request) => await UpdateTag(id, request);
|
||||
|
||||
|
||||
[HttpDelete]
|
||||
[ProducesResponseType((int)HttpStatusCode.NoContent)]
|
||||
[ProducesResponseType ((int)HttpStatusCode.NotFound)]
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
|
||||
public async Task<IActionResult> DeleteTags([FromBody] DeleteTagsRequest request)
|
||||
{
|
||||
if(request.Ids == null || !request.Ids.Any()) return BadRequest();
|
||||
|
||||
var result = await _tagsService.DeleteTags(request.Ids);
|
||||
if (result == null) return NotFound();
|
||||
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
[HttpPost("Hide")]
|
||||
[ProducesResponseType((int)HttpStatusCode.NoContent)]
|
||||
[ProducesResponseType((int)HttpStatusCode.NotFound)]
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
|
||||
public async Task<IActionResult> HideTags([FromBody] HideTagsRequest request)
|
||||
{
|
||||
if (request.Ids == null || !request.Ids.Any()) return BadRequest();
|
||||
|
||||
var result = await _tagsService.HideTags(request.Ids);
|
||||
if (result == null) return NotFound();
|
||||
|
||||
return NoContent();
|
||||
}
|
||||
}
|
||||
}
|
||||
42
API/YABA.API/Controllers/TestController.cs
Normal file
42
API/YABA.API/Controllers/TestController.cs
Normal file
@ -0,0 +1,42 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Net;
|
||||
using YABA.API.Settings;
|
||||
|
||||
namespace YABA.API.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[ApiVersion("1")]
|
||||
[DevOnly]
|
||||
[Route("api/v{version:apiVersion}/[controller]")]
|
||||
public class TestController : ControllerBase
|
||||
{
|
||||
private readonly ILogger<TestController> _logger;
|
||||
|
||||
public TestController(ILogger<TestController> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
[HttpGet("TestLog")]
|
||||
[ProducesResponseType(typeof(string), (int)HttpStatusCode.OK)]
|
||||
[ProducesResponseType((int)HttpStatusCode.NotFound)]
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
|
||||
public IActionResult TestLog()
|
||||
{
|
||||
var testObject = new { id = 1, name = "Test Message" };
|
||||
_logger.LogDebug("Testing debug: {@TestObject}", testObject);
|
||||
return Ok(testObject);
|
||||
}
|
||||
|
||||
[HttpGet("TestLogError")]
|
||||
[ProducesResponseType(typeof(string), (int)HttpStatusCode.OK)]
|
||||
[ProducesResponseType((int)HttpStatusCode.NotFound)]
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
|
||||
public IActionResult TestLogError()
|
||||
{
|
||||
var testObject = new { id = 1, name = "Test Message" };
|
||||
throw new Exception();
|
||||
return Ok(testObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
44
API/YABA.API/Controllers/UsersController.cs
Normal file
44
API/YABA.API/Controllers/UsersController.cs
Normal file
@ -0,0 +1,44 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Net;
|
||||
using YABA.API.Extensions;
|
||||
using YABA.API.ViewModels;
|
||||
using YABA.Service.Interfaces;
|
||||
|
||||
namespace YABA.API.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[ApiVersion("1")]
|
||||
[Authorize]
|
||||
[Route("api/v{version:apiVersion}/[controller]")]
|
||||
public class UsersController : ControllerBase
|
||||
{
|
||||
private readonly IMapper _mapper;
|
||||
private readonly IUserService _userService;
|
||||
|
||||
public UsersController(IMapper mapper, IUserService userService)
|
||||
{
|
||||
_mapper = mapper;
|
||||
_userService = userService;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[ProducesResponseType(typeof(UserResponse), (int)HttpStatusCode.OK)]
|
||||
[ProducesResponseType((int)HttpStatusCode.NotFound)]
|
||||
[ProducesResponseType((int)HttpStatusCode.NoContent)]
|
||||
public async Task<IActionResult> Register()
|
||||
{
|
||||
var authProviderId = this.GetAuthProviderId();
|
||||
|
||||
if (string.IsNullOrEmpty(authProviderId)) return NotFound();
|
||||
|
||||
var isRegistered = _userService.IsUserRegistered(authProviderId);
|
||||
|
||||
if (isRegistered) return NoContent();
|
||||
|
||||
var registedUser = await _userService.RegisterUser(authProviderId);
|
||||
return Ok(_mapper.Map<UserResponse>(registedUser));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user