forked from ddrilling/AsbCloudServer
DrillingProgram replace idPart by idFileCategory.
This commit is contained in:
parent
7a77ff7904
commit
4863b69cfe
@ -8,16 +8,16 @@ namespace AsbCloudApp.Services
|
||||
{
|
||||
public interface IDrillingProgramService
|
||||
{
|
||||
Task<IEnumerable<UserDto>> GetAvailableUsers(int idWell, CancellationToken token = default);
|
||||
Task<IEnumerable<FileCategoryDto>> GetCategoriesAsync(CancellationToken token = default);
|
||||
Task<DrillingProgramStateDto> GetStateAsync(int idWell, int fileChangerId,
|
||||
Task<DrillingProgramStateDto> GetStateAsync(int idWell, int idUser,
|
||||
CancellationToken token = default);
|
||||
Task<int> AddOrReplaceFileMarkAsync(FileMarkDto fileMarkDto, int idUser, CancellationToken token);
|
||||
Task<int> MarkAsDeletedFileMarkAsync(int idFileMark, CancellationToken token);
|
||||
Task<int> AddFile(int idWell, int idFileCategory, int idUser, string fileFullName, System.IO.Stream fileStream, CancellationToken token = default);
|
||||
Task<int> AddPartsAsync(int idWell, IEnumerable<int> idFileCategories, CancellationToken token = default);
|
||||
Task<int> RemovePartsAsync(int idWell, IEnumerable<int> idFileCategories, CancellationToken token = default);
|
||||
Task<int> AddUserAsync(int idUser, int idPart, int idUserRole, CancellationToken token = default);
|
||||
Task<int> RemoveUserAsync(int idUser, int idPart, int idUserRole, CancellationToken token = default);
|
||||
Task<int> AddFile(int idPart, int idUser, string fileFullName, Stream fileStream, CancellationToken token = default);
|
||||
Task<IEnumerable<UserDto>> GetAvailableUsers(int idWell, CancellationToken token = default);
|
||||
Task<int> AddUserAsync(int idWell, int idFileCategory, int idUser, int idUserRole, CancellationToken token = default);
|
||||
Task<int> RemoveUserAsync(int idWell, int idFileCategory, int idUser, int idUserRole, CancellationToken token = default);
|
||||
Task<int> AddOrReplaceFileMarkAsync(FileMarkDto fileMarkDto, int idUser, CancellationToken token);
|
||||
Task<int> MarkAsDeletedFileMarkAsync(int idFileMark, CancellationToken token);
|
||||
}
|
||||
}
|
@ -138,14 +138,14 @@ namespace AsbCloudInfrastructure.Services.DrillingProgram
|
||||
return state;
|
||||
}
|
||||
|
||||
public async Task<int> AddFile(int idPart, int idUser, string fileFullName, System.IO.Stream fileStream, CancellationToken token = default)
|
||||
public async Task<int> AddFile(int idWell, int idFileCategory, int idUser, string fileFullName, System.IO.Stream fileStream, CancellationToken token = default)
|
||||
{
|
||||
var part = await context.DrillingProgramParts
|
||||
.Include(p => p.RelatedUsers)
|
||||
.FirstOrDefaultAsync(p => p.Id == idPart, token);
|
||||
.FirstOrDefaultAsync(p => p.IdWell == idWell && p.IdFileCategory == idFileCategory, token);
|
||||
|
||||
if (part == null)
|
||||
throw new ArgumentInvalidException($"DrillingProgramPart id == {idPart} does not exist", nameof(idPart));
|
||||
throw new ArgumentInvalidException($"DrillingProgramPart id == {idFileCategory} does not exist", nameof(idFileCategory));
|
||||
|
||||
if (! part.RelatedUsers.Any(r => r.IdUser == idUser && r.IdUserRole == idUserRolePublisher))
|
||||
throw new ForbidException($"User {idUser} is not in the publisher list.");
|
||||
@ -198,45 +198,51 @@ namespace AsbCloudInfrastructure.Services.DrillingProgram
|
||||
return await context.SaveChangesAsync(token);
|
||||
}
|
||||
|
||||
public async Task<int> AddUserAsync(int idUser, int idPart, int idUserRole, CancellationToken token = default)
|
||||
public async Task<int> AddUserAsync(int idWell, int idFileCategory, int idUser, int idUserRole, CancellationToken token = default)
|
||||
{
|
||||
var user = await userService.GetAsync(idUser, token);
|
||||
if (user is null)
|
||||
throw new ArgumentInvalidException($"User id == {idUser} does not exist", nameof(idUser));
|
||||
|
||||
var drillingProgramPart = await context.DrillingProgramParts.FirstOrDefaultAsync(p => p.Id == idPart, token);
|
||||
if (drillingProgramPart is null)
|
||||
throw new ArgumentInvalidException($"DrillingProgramPart id == {idPart} does not exist", nameof(idPart));
|
||||
var part = await context.DrillingProgramParts
|
||||
.FirstOrDefaultAsync(p => p.IdWell == idWell && p.IdFileCategory == idFileCategory, token);
|
||||
|
||||
if (part is null)
|
||||
throw new ArgumentInvalidException($"DrillingProgramPart idFileCategory == {idFileCategory} does not exist", nameof(idFileCategory));
|
||||
|
||||
if (idUserRole != idUserRoleApprover && idUserRole != idUserRolePublisher)
|
||||
throw new ArgumentInvalidException($"idUserRole ({idPart}), should be approver ({idUserRoleApprover}) or publisher ({idUserRolePublisher})", nameof(idPart));
|
||||
throw new ArgumentInvalidException($"idUserRole ({idUserRole}), should be approver ({idUserRoleApprover}) or publisher ({idUserRolePublisher})", nameof(idUserRole));
|
||||
|
||||
var oldRelation = await context.RelationDrillingProgramPartUsers
|
||||
.FirstOrDefaultAsync(r => r.IdUser == idUser && r.IdDrillingProgramPart == part.Id, token);
|
||||
|
||||
if(oldRelation is not null)
|
||||
context.RelationDrillingProgramPartUsers.Remove(oldRelation);
|
||||
|
||||
var newRelation = new RelationUserDrillingProgramPart
|
||||
{
|
||||
IdUser = idUser,
|
||||
IdDrillingProgramPart = idPart,
|
||||
IdDrillingProgramPart = part.Id,
|
||||
IdUserRole = idUserRole,
|
||||
};
|
||||
|
||||
context.RelationDrillingProgramPartUsers.Add(newRelation);
|
||||
if(idUserRole == idUserRoleApprover)
|
||||
await RemoveDrillingProgramAsync(drillingProgramPart.IdWell, token);
|
||||
await RemoveDrillingProgramAsync(part.IdWell, token);
|
||||
return await context.SaveChangesAsync(token);
|
||||
}
|
||||
|
||||
public async Task<int> RemoveUserAsync(int idUser, int idPart, int idUserRole, CancellationToken token = default)
|
||||
public async Task<int> RemoveUserAsync(int idWell, int idFileCategory, int idUser, int idUserRole, CancellationToken token = default)
|
||||
{
|
||||
var whereQuery = context.RelationDrillingProgramPartUsers
|
||||
.Include(r => r.DrillingProgramPart)
|
||||
.Where(r => r.IdUser == idUser &&
|
||||
r.IdDrillingProgramPart == idPart &&
|
||||
r.IdUserRole == idUserRole);
|
||||
r.IdUserRole == idUserRole &&
|
||||
r.DrillingProgramPart.IdWell == idWell &&
|
||||
r.DrillingProgramPart.IdFileCategory == idFileCategory);
|
||||
|
||||
context.RelationDrillingProgramPartUsers.RemoveRange(whereQuery);
|
||||
if (idUserRole == idUserRoleApprover)
|
||||
{
|
||||
var part = await context.DrillingProgramParts.FirstOrDefaultAsync(p => p.Id == idPart, token);
|
||||
}
|
||||
|
||||
|
||||
return await context.SaveChangesAsync(token);
|
||||
}
|
||||
|
||||
|
@ -82,17 +82,17 @@ namespace AsbCloudWebApi.Controllers
|
||||
/// <summary>
|
||||
/// Загрузка файла для части программы бурения
|
||||
/// </summary>
|
||||
/// <param name="idPart">ID части программы. Не путать с категорией файла</param>
|
||||
/// <param name="idWell"></param>
|
||||
/// <param name="idFileCategory">ID части программы. Не путать с категорией файла</param>
|
||||
/// <param name="files"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("part/{idPart}")]
|
||||
[HttpPost("part/{idFileCategory}")]
|
||||
[Permission]
|
||||
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
||||
public async Task<IActionResult> AddFile(
|
||||
int idPart,
|
||||
int idWell,
|
||||
int idFileCategory,
|
||||
[FromForm] IFormFileCollection files,
|
||||
CancellationToken token)
|
||||
{
|
||||
@ -118,7 +118,7 @@ namespace AsbCloudWebApi.Controllers
|
||||
return BadRequest(ArgumentInvalidException.MakeValidationError("file", "Файл должен быть xlsx"));
|
||||
|
||||
var fileStream = files[0].OpenReadStream();
|
||||
var result = await drillingProgramService.AddFile(idPart, (int)idUser, fileName, fileStream, token);
|
||||
var result = await drillingProgramService.AddFile(idWell, idFileCategory, (int)idUser, fileName, fileStream, token);
|
||||
|
||||
return Ok(result);
|
||||
}
|
||||
@ -180,14 +180,14 @@ namespace AsbCloudWebApi.Controllers
|
||||
/// </summary>
|
||||
/// <param name="idWell"></param>
|
||||
/// <param name="idUser"></param>
|
||||
/// <param name="idPart"></param>
|
||||
/// <param name="idFileCategory"></param>
|
||||
/// <param name="idUserRole"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("part/{idPart}/user")]
|
||||
[HttpPost("part/{idFileCategory}/user")]
|
||||
[Permission]
|
||||
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
||||
public async Task<IActionResult> AddUserAsync(int idWell, [Required] int idUser, int idPart, [Required] int idUserRole, CancellationToken token = default)
|
||||
public async Task<IActionResult> AddUserAsync(int idWell, [Required] int idUser, int idFileCategory, [Required] int idUserRole, CancellationToken token = default)
|
||||
{
|
||||
int? idCompany = User.GetCompanyId();
|
||||
int? idUserEditor = User.GetUserId();
|
||||
@ -199,7 +199,7 @@ namespace AsbCloudWebApi.Controllers
|
||||
idWell, token).ConfigureAwait(false))
|
||||
return Forbid();
|
||||
|
||||
var result = await drillingProgramService.AddUserAsync(idUser, idPart, idUserRole, token);
|
||||
var result = await drillingProgramService.AddUserAsync(idWell, idFileCategory, idUser, idUserRole, token);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
@ -208,14 +208,14 @@ namespace AsbCloudWebApi.Controllers
|
||||
/// </summary>
|
||||
/// <param name="idWell"></param>
|
||||
/// <param name="idUser"></param>
|
||||
/// <param name="idPart"></param>
|
||||
/// <param name="idFileCategory"></param>
|
||||
/// <param name="idUserRole"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
[HttpDelete("part/{idPart}/user/{idUser}")]
|
||||
[HttpDelete("part/{idFileCategory}/user/{idUser}")]
|
||||
[Permission]
|
||||
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
||||
public async Task<IActionResult> RemoveUserAsync(int idWell, int idUser, int idPart, [Required]int idUserRole, CancellationToken token = default)
|
||||
public async Task<IActionResult> RemoveUserAsync(int idWell, int idUser, int idFileCategory, [Required]int idUserRole, CancellationToken token = default)
|
||||
{
|
||||
int? idCompany = User.GetCompanyId();
|
||||
int? idUserEditor = User.GetUserId();
|
||||
@ -227,7 +227,7 @@ namespace AsbCloudWebApi.Controllers
|
||||
idWell, token).ConfigureAwait(false))
|
||||
return Forbid();
|
||||
|
||||
var result = await drillingProgramService.RemoveUserAsync(idUser, idPart, idUserRole, token);
|
||||
var result = await drillingProgramService.RemoveUserAsync(idWell, idFileCategory,idUser, idUserRole, token);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user