Torma Kristóf
8cd1e10cd7
All checks were successful
continuous-integration/drone/push Build is passing
101 lines
3.2 KiB
C#
101 lines
3.2 KiB
C#
using HanyadikHetVan.DTO;
|
|
using HanyadikHetVan.Services;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Net.Mime;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace HanyadikHetVan.Controllers.V2
|
|
{
|
|
[ApiVersion("2.0")]
|
|
[Route("api/v{version:apiVersion}/[controller]")]
|
|
[ApiController]
|
|
public class PauseController : Controller
|
|
{
|
|
private readonly PauseService _pauseService;
|
|
|
|
public PauseController(PauseService pauseService)
|
|
{
|
|
_pauseService = pauseService;
|
|
}
|
|
[HttpPost]
|
|
[Authorize]
|
|
[Consumes(MediaTypeNames.Application.Json)]
|
|
[ProducesResponseType(StatusCodes.Status201Created, Type = typeof(WeeklyTimeSpanDTO))]
|
|
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
|
public async Task<IActionResult> AddPause([FromBody] PauseDTO pause)
|
|
{
|
|
try
|
|
{
|
|
var obj = await _pauseService.AddPause(pause);
|
|
return CreatedAtAction(nameof(GetPauseById),new { pauseId = obj.Id } ,obj);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
|
|
return BadRequest();
|
|
}
|
|
}
|
|
[HttpDelete("{pauseId}")]
|
|
[Authorize(Roles = "admin")]
|
|
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(WeeklyTimeSpanDTO))]
|
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
|
public async Task<IActionResult> DeletePause(int pauseId)
|
|
{
|
|
var result = await _pauseService.DeletePause(pauseId);
|
|
if (result)
|
|
{
|
|
return Ok(result);
|
|
}
|
|
else
|
|
{
|
|
return NotFound();
|
|
}
|
|
}
|
|
[HttpPut]
|
|
[Authorize(Roles = "admin")]
|
|
[Consumes(MediaTypeNames.Application.Json)]
|
|
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(PauseDTO))]
|
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
|
public async Task<IActionResult> UpdatePause([FromBody] PauseDTO pause)
|
|
{
|
|
try
|
|
{
|
|
var obj = await _pauseService.UpdatePause(pause);
|
|
return Ok(obj);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return NotFound();
|
|
}
|
|
}
|
|
[HttpGet]
|
|
public async Task<List<PauseDTO>> GetAllPauses()
|
|
{
|
|
return await _pauseService.GetAllPauses();
|
|
}
|
|
|
|
[HttpGet("{pauseId}")]
|
|
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(PauseDTO))]
|
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
|
public async Task<IActionResult> GetPauseById(int pauseId)
|
|
{
|
|
var pause = await _pauseService.GetPause(pauseId);
|
|
if (pause == null)
|
|
{
|
|
return NotFound();
|
|
}
|
|
else
|
|
{
|
|
return Ok(pause);
|
|
}
|
|
}
|
|
}
|
|
}
|