2023-07-16 20:10:02 +02:00
|
|
|
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>))]
|
2023-07-16 21:18:11 +02:00
|
|
|
public ActionResult<ApiResponse<IEnumerable<Category>>> GetCategories()
|
2023-07-16 20:10:02 +02:00
|
|
|
{
|
2023-07-16 21:18:11 +02:00
|
|
|
ApiResponse<IEnumerable<Category>> response = new ApiResponse<IEnumerable<Category>>();
|
2023-07-16 20:10:02 +02:00
|
|
|
IEnumerable<Category> categories = _context.Categories.ToList();
|
|
|
|
if (categories == null || !categories.Any())
|
|
|
|
return NotFound();
|
2023-07-16 21:18:11 +02:00
|
|
|
response.RespsonseData = categories;
|
|
|
|
response.ContinuationToken = "NO_CONTINUATION";
|
|
|
|
return Ok(response);
|
2023-07-16 20:10:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|