This commit is contained in:
129
HanyadikHetVan/Controllers/V2/WeeklyTimeSpanController.cs
Normal file
129
HanyadikHetVan/Controllers/V2/WeeklyTimeSpanController.cs
Normal file
@@ -0,0 +1,129 @@
|
||||
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 WeeklyTimeSpanController: Controller
|
||||
{
|
||||
private readonly WeeklyTimeSpanService _weeklytimespanService;
|
||||
|
||||
public WeeklyTimeSpanController(WeeklyTimeSpanService weeklytimespanService)
|
||||
{
|
||||
_weeklytimespanService = weeklytimespanService;
|
||||
}
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
[Consumes(MediaTypeNames.Application.Json)]
|
||||
[ProducesResponseType(StatusCodes.Status201Created, Type = typeof(WeeklyTimeSpanDTO))]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||
public async Task<IActionResult> AddWeeklyTimeSpan([FromBody] WeeklyTimeSpanDTO weeklytimespan)
|
||||
{
|
||||
try
|
||||
{
|
||||
var obj = await _weeklytimespanService.AddWeeklyTimeSpan(weeklytimespan);
|
||||
return CreatedAtAction(nameof(GetWeeklyTimeSpanById), new { weeklytimespanId = obj.Id }, obj);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
return BadRequest();
|
||||
}
|
||||
}
|
||||
[HttpDelete("{weeklyTimeSpanId}")]
|
||||
[Authorize]
|
||||
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(bool))]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||
public async Task<IActionResult> DeleteWeeklyTimeSpan(int weeklyTimeSpanId)
|
||||
{
|
||||
var result = await _weeklytimespanService.DeleteWeeklyTimeSpan(weeklyTimeSpanId);
|
||||
if (result)
|
||||
{
|
||||
return Ok(result);
|
||||
}
|
||||
else
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
}
|
||||
[HttpPut]
|
||||
[Authorize]
|
||||
[Consumes(MediaTypeNames.Application.Json)]
|
||||
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(WeeklyTimeSpanDTO))]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||
public async Task<IActionResult> UpdateWeeklyTimeSpan([FromBody] WeeklyTimeSpanDTO weeklytimespan)
|
||||
{
|
||||
try
|
||||
{
|
||||
var wts = await _weeklytimespanService.UpdateWeeklyTimeSpan(weeklytimespan);
|
||||
return Ok(wts);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
}
|
||||
[HttpGet("date/{startTime}")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(WeeklyTimeSpanDTO))]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
public async Task<IActionResult> GetAllWeeklyTimeSpanByStartdate(DateTime startTime)
|
||||
{
|
||||
var wts = await _weeklytimespanService.GetWeeklyTimeSpanByStartdate(startTime);
|
||||
if (wts == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
else
|
||||
{
|
||||
return Ok(wts);
|
||||
}
|
||||
}
|
||||
[HttpGet]
|
||||
public async Task<List<WeeklyTimeSpanDTO>> GetAllWeeklyTimespans()
|
||||
{
|
||||
return await _weeklytimespanService.GetAllWeeklyTimeSpans();
|
||||
}
|
||||
[HttpGet("{weeklytimespanId}")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(WeeklyTimeSpanDTO))]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
public async Task<IActionResult> GetWeeklyTimeSpanById(int weeklytimespanId)
|
||||
{
|
||||
var wts = await _weeklytimespanService.GetWeeklyTimeSpan(weeklytimespanId);
|
||||
if (wts == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
else
|
||||
{
|
||||
return Ok(wts);
|
||||
}
|
||||
}
|
||||
[HttpGet("pauses/{weeklytimespanId}")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(List<PauseDTO>))]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
public async Task<IActionResult> GetAllPausesOfTimeSpan(int weeklytimespanId)
|
||||
{
|
||||
var wts = await _weeklytimespanService.GetPausesOfWeeklyTimeSpan(weeklytimespanId);
|
||||
if (wts == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
else
|
||||
{
|
||||
return Ok(wts);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user