1
0
DD.WellWorkover.Cloud/AsbCloudWebApi/Controllers/WellSectionController.cs

60 lines
2.0 KiB
C#
Raw Normal View History

2021-08-02 14:45:13 +05:00
using AsbCloudApp.Data;
using AsbCloudApp.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
2021-08-10 14:36:35 +05:00
using System.Threading;
using System.Threading.Tasks;
2021-08-02 14:45:13 +05:00
namespace AsbCloudWebApi.Controllers
{
2021-08-10 14:36:35 +05:00
[Route("api/well/{idWell}/sections")]
2021-08-02 14:45:13 +05:00
[ApiController]
[Authorize]
2021-08-10 14:36:35 +05:00
public class WellSectionController : ControllerBase
2021-08-02 14:45:13 +05:00
{
2021-08-10 14:36:35 +05:00
private readonly IWellSectionService service;
2021-08-02 14:45:13 +05:00
2021-08-10 14:36:35 +05:00
public WellSectionController(IWellSectionService service)
{
this.service = service;
2021-08-02 14:45:13 +05:00
}
[HttpGet]
[Route("")]
2021-08-10 14:36:35 +05:00
public async Task<IActionResult> GetAllAsync(int idWell, int skip = 0, int take = 32, CancellationToken token = default)
{
var result = await service.GetAllByWellIdAsync(idWell, skip, take, token).ConfigureAwait(false);
return Ok(result);
}
2021-08-10 16:37:36 +05:00
[HttpGet]
[Route("{idSection}")]
public async Task<IActionResult> GetAsync(int idSection,CancellationToken token = default)
{
var result = await service.GetAsync(idSection, token).ConfigureAwait(false);
return Ok(result);
}
2021-08-10 14:36:35 +05:00
[HttpPost]
2021-08-10 16:37:36 +05:00
public async Task<IActionResult> Insert([FromBody] WellSectionDto value, int idWell, CancellationToken token = default)
2021-08-10 14:36:35 +05:00
{
2021-08-10 16:37:36 +05:00
var result = await service.InsertAsync(value, idWell, token).ConfigureAwait(false);
2021-08-10 14:36:35 +05:00
return Ok(result);
}
[HttpPut("{id}")]
2021-08-10 16:37:36 +05:00
public async Task<IActionResult> Put(int id, [FromBody] WellSectionDto value, int idWell, CancellationToken token = default)
2021-08-10 14:36:35 +05:00
{
2021-08-10 16:37:36 +05:00
var result = await service.UpdateAsync(value, id, idWell, token).ConfigureAwait(false);
2021-08-10 14:36:35 +05:00
return Ok(result);
}
[HttpDelete("{id}")]
public async Task<IActionResult> Delete(int id, CancellationToken token = default)
2021-08-02 14:45:13 +05:00
{
2021-08-10 14:36:35 +05:00
var result = await service.DeleteAsync(id, token).ConfigureAwait(false);
2021-08-02 14:45:13 +05:00
return Ok(result);
}
}
}