Torma Kristóf
634488c2d8
All checks were successful
continuous-integration/drone/push Build is passing
79 lines
2.6 KiB
C#
79 lines
2.6 KiB
C#
using HanyadikHetVan.Data.Entities;
|
|
using HanyadikHetVan.Services;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Identity;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using System;
|
|
using System.Security.Claims;
|
|
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;
|
|
private readonly UserManager<User> _userManager;
|
|
|
|
public HanyadikHetVanController(HanyadikHetVanEntityService hanyadikHetVanEntityService, UserManager<User> userManager)
|
|
{
|
|
_hanyadikHetVanEntityService = hanyadikHetVanEntityService ?? throw new ArgumentNullException(nameof(hanyadikHetVanEntityService));
|
|
_userManager = userManager ?? throw new ArgumentNullException(nameof(userManager));
|
|
}
|
|
|
|
[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();
|
|
}
|
|
}
|
|
|
|
|
|
[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();
|
|
}
|
|
}
|
|
}
|
|
}
|