hanyadikhetvan-dotnethf/HanyadikHetVan/Controllers/V2/FunFactController.cs

95 lines
3.3 KiB
C#
Raw Permalink Normal View History

2021-05-19 17:56:56 +02:00
using HanyadikHetVan.DTO;
using HanyadikHetVan.Services;
2021-05-20 01:36:54 +02:00
using Microsoft.AspNetCore.Authentication.JwtBearer;
2021-05-19 17:56:56 +02:00
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
2021-05-19 23:14:57 +02:00
using System.Collections.Generic;
2021-05-20 01:36:54 +02:00
using System.Net.Mime;
2021-05-19 17:56:56 +02:00
using System.Threading.Tasks;
namespace HanyadikHetVan.Controllers.V2
{
[ApiVersion("2.0")]
[Route("api/v{version:apiVersion}/[controller]")]
[ApiController]
public class FunFactController : Controller
{
private readonly FunFactService _funfactService;
public FunFactController(FunFactService funfactService)
{
_funfactService = funfactService ?? throw new ArgumentNullException(nameof(funfactService));
}
2021-05-19 23:14:57 +02:00
[HttpGet("WeeklyTimeSpan/{weeklytimespanId}")]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(List<FunFactDTO>))]
2021-05-19 17:56:56 +02:00
[ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task<IActionResult> GetFunFactOfWeeklyTimeSpan(int weeklytimespanId)
{
try
{
var obj = await _funfactService.GetFunFactOfWeeklyTimeSpan(weeklytimespanId);
return Ok(obj);
}
catch (Exception)
{
return NotFound();
}
}
[HttpGet("{funfactId}")]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(FunFactDTO))]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task<IActionResult> GetFunFactorOfFunFact(int funfactId)
{
try
{
var obj = await _funfactService.GetFunFactorOfFunFact(funfactId);
return Ok(obj);
}
catch (Exception)
{
return NotFound();
}
}
2021-05-20 01:36:54 +02:00
[HttpDelete("{funfactId}")]
[Authorize(Policy = "AdminPolicy", AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(bool))]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
public async Task<IActionResult> DeleteFunFact(int funfactId)
{
var result = await _funfactService.DeleteFunFact(funfactId);
if (result)
{
return Ok(result);
}
else
{
return NotFound();
}
}
[HttpPut("{funfactId}")]
[Authorize(Policy = "AdminPolicy", AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
[Consumes(MediaTypeNames.Application.Json)]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(FunFactDTO))]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
public async Task<IActionResult> UpdatePause(int funfactId, [FromBody] FunFactDTO funfact)
{
try
{
var obj = await _funfactService.UpdateFunFact(funfactId, funfact);
return Ok(obj);
}
catch (Exception)
{
return NotFound();
}
}
2021-05-19 17:56:56 +02:00
}
}