2021-05-19 17:56:56 +02:00
|
|
|
|
using HanyadikHetVan.Data.Entities;
|
|
|
|
|
using HanyadikHetVan.Services;
|
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
2021-05-19 04:33:53 +02:00
|
|
|
|
using Microsoft.AspNetCore.Http;
|
2021-05-19 17:56:56 +02:00
|
|
|
|
using Microsoft.AspNetCore.Identity;
|
2021-05-19 04:33:53 +02:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using System;
|
2021-05-19 17:56:56 +02:00
|
|
|
|
using System.Security.Claims;
|
2021-05-19 04:33:53 +02:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace HanyadikHetVan.Controllers.V2
|
|
|
|
|
{
|
|
|
|
|
[ApiController]
|
|
|
|
|
[ApiVersion("2.0")]
|
|
|
|
|
[Route("api/v{version:apiVersion}/[controller]")]
|
|
|
|
|
public class HanyadikHetVanController : Controller
|
|
|
|
|
{
|
|
|
|
|
private readonly HanyadikHetVanEntityService _hanyadikHetVanEntityService;
|
2021-05-19 17:56:56 +02:00
|
|
|
|
private readonly UserManager<User> _userManager;
|
2021-05-19 04:33:53 +02:00
|
|
|
|
|
2021-05-19 17:56:56 +02:00
|
|
|
|
public HanyadikHetVanController(HanyadikHetVanEntityService hanyadikHetVanEntityService, UserManager<User> userManager)
|
2021-05-19 04:33:53 +02:00
|
|
|
|
{
|
|
|
|
|
_hanyadikHetVanEntityService = hanyadikHetVanEntityService ?? throw new ArgumentNullException(nameof(hanyadikHetVanEntityService));
|
2021-05-19 17:56:56 +02:00
|
|
|
|
_userManager = userManager ?? throw new ArgumentNullException(nameof(userManager));
|
2021-05-19 04:33:53 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet("{weeklytimespanId}")]
|
|
|
|
|
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(int))]
|
|
|
|
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
|
|
|
|
public async Task<IActionResult> GetWeekById(int weeklytimespanId)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var wts = await _hanyadikHetVanEntityService.GetWeekById(weeklytimespanId);
|
|
|
|
|
return Ok(wts);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception)
|
|
|
|
|
{
|
|
|
|
|
return BadRequest();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(int))]
|
|
|
|
|
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
|
|
|
|
public async Task<IActionResult> GetDefaultWeek()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var wts = await _hanyadikHetVanEntityService.GetDefaultWeek();
|
|
|
|
|
return Ok(wts);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception)
|
|
|
|
|
{
|
|
|
|
|
return BadRequest();
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-05-19 17:56:56 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[HttpGet("my")]
|
|
|
|
|
[Authorize]
|
|
|
|
|
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(int))]
|
|
|
|
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
|
|
|
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
|
|
|
|
public async Task<IActionResult> GetUserDefaultWeek()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var wts = await _hanyadikHetVanEntityService.GetUserDefaultWeek(this.User.FindFirst(ClaimTypes.NameIdentifier).Value);
|
|
|
|
|
return Ok(wts);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception)
|
|
|
|
|
{
|
|
|
|
|
return NotFound();
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-05-19 04:33:53 +02:00
|
|
|
|
}
|
|
|
|
|
}
|