using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Authorization; using AsbCloudApp.Services; namespace AsbCloudWebApi.Controllers { [ApiController] [Authorize] public abstract class LastDataController : ControllerBase where T : class { private readonly ILastDataService lastDataService; private readonly IWellService wellService; public LastDataController(ILastDataService lastDataService, IWellService wellService) { this.lastDataService = lastDataService; this.wellService = wellService; } [HttpGet] public IActionResult Get([FromRoute] int idWell, [FromQuery] int idCategory) { int? idCompany = User.GetCompanyId(); if (idCompany is null || !wellService.IsCompanyInvolvedInWell((int)idCompany, idWell)) return Forbid(); lastDataService.Get(idWell, idCategory); return Ok(); } [HttpPost] public IActionResult Put([FromRoute] int idWell, [FromQuery] int idCategory, [FromForm] T data) { int? idCompany = User.GetCompanyId(); if (idCompany is null || !wellService.IsCompanyInvolvedInWell((int)idCompany, idWell)) return Forbid(); lastDataService.Upsert(idWell, idCategory, data); return Ok(); } } }