forked from ddrilling/AsbCloudServer
Add ScheduleController.GetByIdWellAsync(..)
This commit is contained in:
parent
3671dc12a1
commit
c568fafa8f
@ -8,6 +8,7 @@ namespace AsbCloudApp.Services
|
|||||||
{
|
{
|
||||||
public interface IScheduleService : ICrudService<ScheduleDto>
|
public interface IScheduleService : ICrudService<ScheduleDto>
|
||||||
{
|
{
|
||||||
|
Task<IEnumerable<ScheduleDto>> GetByIdWellAsync(int idWell, CancellationToken token = default);
|
||||||
Task<DrillerDto> GetDrillerAsync(int idWell, DateTime workTime, CancellationToken token = default);
|
Task<DrillerDto> GetDrillerAsync(int idWell, DateTime workTime, CancellationToken token = default);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ using AsbCloudDb.Model;
|
|||||||
using Mapster;
|
using Mapster;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -21,6 +22,15 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
this.wellService = wellService;
|
this.wellService = wellService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<IEnumerable<ScheduleDto>> GetByIdWellAsync(int idWell, CancellationToken token = default)
|
||||||
|
{
|
||||||
|
var entities = await GetQueryWithIncludes()
|
||||||
|
.Where(s => s.IdWell == idWell)
|
||||||
|
.ToListAsync(token);
|
||||||
|
var dtos = entities.Select(Convert);
|
||||||
|
return dtos;
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<DrillerDto?> GetDrillerAsync(int idWell, DateTime workTime, CancellationToken token = default)
|
public async Task<DrillerDto?> GetDrillerAsync(int idWell, DateTime workTime, CancellationToken token = default)
|
||||||
{
|
{
|
||||||
var hoursOffset = wellService.GetTimezone(idWell).Hours;
|
var hoursOffset = wellService.GetTimezone(idWell).Hours;
|
||||||
|
@ -3,6 +3,7 @@ using AsbCloudApp.Services;
|
|||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
@ -14,12 +15,34 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
public class ScheduleController : CrudController<ScheduleDto, IScheduleService>
|
public class ScheduleController : CrudController<ScheduleDto, IScheduleService>
|
||||||
{
|
{
|
||||||
private readonly IScheduleService scheduleService;
|
private readonly IScheduleService scheduleService;
|
||||||
public ScheduleController(IScheduleService scheduleService)
|
private readonly IWellService wellService;
|
||||||
|
|
||||||
|
public ScheduleController(IScheduleService scheduleService, IWellService wellService)
|
||||||
:base(scheduleService)
|
:base(scheduleService)
|
||||||
{
|
{
|
||||||
this.scheduleService = service;
|
this.scheduleService = service;
|
||||||
|
this.wellService = wellService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// список расписаний бурильщиков по скважине
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="idWell"></param>
|
||||||
|
/// <param name="token"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpGet("byWellId/{idWell}")]
|
||||||
|
[ProducesResponseType(typeof(IEnumerable<ScheduleDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||||
|
public async Task<IActionResult> GetByIdWellAsync(int idWell, CancellationToken token)
|
||||||
|
{
|
||||||
|
var idCompany = User.GetCompanyId();
|
||||||
|
if(idCompany is null || !wellService.IsCompanyInvolvedInWell((int)idCompany, idWell))
|
||||||
|
return Forbid();
|
||||||
|
|
||||||
|
var result = await scheduleService.GetByIdWellAsync(idWell, token);
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Получить бурильщика работавшего на скважине в определенное время.
|
/// Получить бурильщика работавшего на скважине в определенное время.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -28,8 +51,12 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns>бурильщик</returns>
|
/// <returns>бурильщик</returns>
|
||||||
[HttpGet("driller")]
|
[HttpGet("driller")]
|
||||||
public async Task<ActionResult<DrillerDto>> GetDrillerAsync(int idWell, DateTime workTime, CancellationToken token = default)
|
public async Task<ActionResult<DrillerDto>> GetDrillerAsync(int idWell, DateTime workTime, CancellationToken token)
|
||||||
{
|
{
|
||||||
|
var idCompany = User.GetCompanyId();
|
||||||
|
if (idCompany is null || !wellService.IsCompanyInvolvedInWell((int)idCompany, idWell))
|
||||||
|
return Forbid();
|
||||||
|
|
||||||
var result = await scheduleService.GetDrillerAsync(idWell,workTime, token);
|
var result = await scheduleService.GetDrillerAsync(idWell,workTime, token);
|
||||||
return Ok(result);
|
return Ok(result);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user