SharpRSS/SharpSyndicationApi/Controllers/CategoryController.cs
2023-09-03 00:13:02 +02:00

41 lines
1.3 KiB
C#

using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using SharpSyndicationApi.Models;
namespace SharpSyndicationApi.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class CategoryController : ControllerBase
{
private readonly DataContext _context;
public CategoryController(DataContext context)
{
_context = context;
}
[HttpPost]
public async Task PostCategory(Category category)
{
_context.Categories.Add(category);
await _context.SaveChangesAsync();
}
[HttpGet]
[ProducesResponseType(200, Type = typeof(IEnumerable<Category>))]
public ActionResult<ApiResponse<IEnumerable<Category>>> GetCategories()
{
ApiResponse<IEnumerable<Category>> response = new ApiResponse<IEnumerable<Category>>();
IEnumerable<Category> categories = _context.Categories.ToList();
if (categories == null || !categories.Any())
return NotFound();
response.RespsonseData = categories;
response.ContinuationToken = "NO_CONTINUATION";
return Ok(response);
}
}
}