forked from ddrilling/AsbCloudServer
Merge branch 'feature/WellFinalDocumentsRepository' of http://test.digitaldrilling.ru:8080/DDrilling/AsbCloudServer into feature/WellFinalDocumentsRepository
This commit is contained in:
commit
e4becb18ff
@ -38,14 +38,14 @@ namespace AsbCloudApp.Repositories
|
|||||||
Task<IEnumerable<UserDto>> GetAvailableUsersAsync(int idWell, CancellationToken token);
|
Task<IEnumerable<UserDto>> GetAvailableUsersAsync(int idWell, CancellationToken token);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Сохранение категории файла
|
/// Возвращаент категорию файла
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="idWell"></param>
|
/// <param name="idWell"></param>
|
||||||
/// <param name="idCategory"></param>
|
/// <param name="idCategory"></param>
|
||||||
/// <param name="idUser"></param>
|
/// <param name="idUser"></param>
|
||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<WellFinalDocumentDBDto> SaveCategoryAsync(int idWell, int idCategory, int idUser, CancellationToken token);
|
Task<WellFinalDocumentDBDto> GetCategoryAsync(int idWell, int idCategory, int idUser, CancellationToken token);
|
||||||
}
|
}
|
||||||
#nullable disable
|
#nullable disable
|
||||||
}
|
}
|
||||||
|
@ -33,27 +33,27 @@ namespace AsbCloudInfrastructure.Repository
|
|||||||
///<inheritdoc/>
|
///<inheritdoc/>
|
||||||
public async Task<IEnumerable<WellFinalDocumentDBDto>> UpdateRangeAsync(int idWell, IEnumerable<WellFinalDocumentInputDto>? dtos, CancellationToken token)
|
public async Task<IEnumerable<WellFinalDocumentDBDto>> UpdateRangeAsync(int idWell, IEnumerable<WellFinalDocumentInputDto>? dtos, CancellationToken token)
|
||||||
{
|
{
|
||||||
if (dtos is not null)
|
if (dtos is null)
|
||||||
{
|
throw new ArgumentInvalidException("Данные по категориям отсутствуют.");
|
||||||
var entities = dtos
|
|
||||||
.Where(dto => dto.IdsPublishers?.Any() == true)
|
|
||||||
.SelectMany(dto => dto.IdsPublishers
|
|
||||||
.Select(idUser => new WellFinalDocument
|
|
||||||
{
|
|
||||||
IdCategory = dto.IdCategory,
|
|
||||||
IdWell = idWell,
|
|
||||||
IdUser = idUser
|
|
||||||
}));
|
|
||||||
|
|
||||||
var itemsToDelete = context.WellFinalDocuments.Where(d => d.IdWell == idWell);
|
var entities = dtos
|
||||||
context.WellFinalDocuments.RemoveRange(itemsToDelete);
|
.Where(dto => dto.IdsPublishers?.Any() == true)
|
||||||
|
.SelectMany(dto => dto.IdsPublishers
|
||||||
|
.Select(idUser => new WellFinalDocument
|
||||||
|
{
|
||||||
|
IdCategory = dto.IdCategory,
|
||||||
|
IdWell = idWell,
|
||||||
|
IdUser = idUser
|
||||||
|
}));
|
||||||
|
|
||||||
await context.WellFinalDocuments.AddRangeAsync(entities).ConfigureAwait(false);
|
var itemsToDelete = context.WellFinalDocuments.Where(d => d.IdWell == idWell);
|
||||||
await context.SaveChangesAsync(token).ConfigureAwait(false);
|
context.WellFinalDocuments.RemoveRange(itemsToDelete);
|
||||||
|
|
||||||
|
context.WellFinalDocuments.AddRange(entities);
|
||||||
|
await context.SaveChangesAsync(token).ConfigureAwait(false);
|
||||||
|
|
||||||
|
return entities.Adapt<IEnumerable<WellFinalDocumentDBDto>>();
|
||||||
|
|
||||||
return entities.Adapt<IEnumerable<WellFinalDocumentDBDto>>();
|
|
||||||
}
|
|
||||||
throw new ArgumentInvalidException("Данные по категориям отсутствуют.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
///<inheritdoc/>
|
///<inheritdoc/>
|
||||||
@ -108,6 +108,7 @@ namespace AsbCloudInfrastructure.Repository
|
|||||||
public async Task<IEnumerable<UserDto>> GetAvailableUsersAsync(int idWell, CancellationToken token)
|
public async Task<IEnumerable<UserDto>> GetAvailableUsersAsync(int idWell, CancellationToken token)
|
||||||
{
|
{
|
||||||
var companyIds = await context.RelationCompaniesWells
|
var companyIds = await context.RelationCompaniesWells
|
||||||
|
.AsNoTracking()
|
||||||
.Where(x => x.IdWell == idWell).Select(x => x.IdCompany)
|
.Where(x => x.IdWell == idWell).Select(x => x.IdCompany)
|
||||||
.ToListAsync(token)
|
.ToListAsync(token)
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
@ -123,7 +124,7 @@ namespace AsbCloudInfrastructure.Repository
|
|||||||
}
|
}
|
||||||
|
|
||||||
///<inheritdoc/>
|
///<inheritdoc/>
|
||||||
public async Task<WellFinalDocumentDBDto> SaveCategoryAsync(int idWell, int idCategory, int idUser, CancellationToken token)
|
public async Task<WellFinalDocumentDBDto> GetCategoryAsync(int idWell, int idCategory, int idUser, CancellationToken token)
|
||||||
{
|
{
|
||||||
var entity = await context.WellFinalDocuments
|
var entity = await context.WellFinalDocuments
|
||||||
.AsNoTracking()
|
.AsNoTracking()
|
||||||
|
@ -4,7 +4,6 @@ using AsbCloudApp.Repositories;
|
|||||||
using AsbCloudApp.Requests;
|
using AsbCloudApp.Requests;
|
||||||
using AsbCloudApp.Services;
|
using AsbCloudApp.Services;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@ -51,11 +50,8 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
{
|
{
|
||||||
var data = await wellFinalDocumentsRepository.UpdateRangeAsync(idWell, dtos, token);
|
var data = await wellFinalDocumentsRepository.UpdateRangeAsync(idWell, dtos, token);
|
||||||
|
|
||||||
if (data.Any())
|
var message = "от Вас ожидается загрузка на портал документа «{0}»";
|
||||||
{
|
await GenerateMessageAsync(data, message, token);
|
||||||
var message = "от Вас ожидается загрузка на портал документа «{0}»";
|
|
||||||
await GenerateMessageAsync(data, message, token);
|
|
||||||
}
|
|
||||||
|
|
||||||
return data.Count();
|
return data.Count();
|
||||||
}
|
}
|
||||||
@ -63,13 +59,16 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
///<inheritdoc/>
|
///<inheritdoc/>
|
||||||
public async Task<int> SaveCategoryFileAsync(int idWell, int idCategory, int idUser, Stream fileStream, string fileName, CancellationToken token)
|
public async Task<int> SaveCategoryFileAsync(int idWell, int idCategory, int idUser, Stream fileStream, string fileName, CancellationToken token)
|
||||||
{
|
{
|
||||||
var dto = await wellFinalDocumentsRepository.SaveCategoryAsync(idWell, idCategory, idUser, token)
|
var dto = await wellFinalDocumentsRepository.GetCategoryAsync(idWell, idCategory, idUser, token)
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
|
|
||||||
var file = await fileService.SaveAsync(dto.IdWell, dto.IdUser, dto.IdCategory, fileName,
|
var file = await fileService.SaveAsync(dto.IdWell, dto.IdUser, dto.IdCategory, fileName,
|
||||||
fileStream, token).ConfigureAwait(false);
|
fileStream, token).ConfigureAwait(false);
|
||||||
|
|
||||||
return file?.Id ?? FileServiceThrewException; //TODO: изменить когда файловый сервис будет переведен на nullable
|
if (file is not null)
|
||||||
|
return file.Id;
|
||||||
|
|
||||||
|
return FileServiceThrewException;
|
||||||
}
|
}
|
||||||
|
|
||||||
///<inheritdoc/>
|
///<inheritdoc/>
|
||||||
@ -130,12 +129,12 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
var category = await fileCategoryService.GetOrDefaultAsync(item.IdCategory, token);
|
var category = await fileCategoryService.GetOrDefaultAsync(item.IdCategory, token);
|
||||||
var well = await wellService.GetOrDefaultAsync(item.IdWell, token);
|
var well = await wellService.GetOrDefaultAsync(item.IdWell, token);
|
||||||
|
|
||||||
SendMessage(well, user, category.Name, message, token);
|
SendMessage(well, user, category.Name, message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SendMessage(WellDto? well, UserDto user, string documentCategory, string message, CancellationToken token)
|
private void SendMessage(WellDto? well, UserDto user, string documentCategory, string message)
|
||||||
{
|
{
|
||||||
var factory = new WellFinalDocumentMailBodyFactory(configuration);
|
var factory = new WellFinalDocumentMailBodyFactory(configuration);
|
||||||
var subject = factory.MakeSubject(well, documentCategory);
|
var subject = factory.MakeSubject(well, documentCategory);
|
||||||
|
@ -76,7 +76,7 @@ namespace AsbCloudWebApi.Tests.ServicesTests
|
|||||||
wellFinalDocumentsRepository.Setup(r => r.GetByWellIdAsync(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<CancellationToken>()))
|
wellFinalDocumentsRepository.Setup(r => r.GetByWellIdAsync(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<CancellationToken>()))
|
||||||
.ReturnsAsync(wellCaseDto);
|
.ReturnsAsync(wellCaseDto);
|
||||||
|
|
||||||
wellFinalDocumentsRepository.Setup(r => r.SaveCategoryAsync(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>(), It.IsAny<CancellationToken>()))
|
wellFinalDocumentsRepository.Setup(r => r.GetCategoryAsync(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>(), It.IsAny<CancellationToken>()))
|
||||||
.ReturnsAsync(wellFinalDocumentDBDto);
|
.ReturnsAsync(wellFinalDocumentDBDto);
|
||||||
|
|
||||||
fileRepositoryMock = new Mock<IFileRepository>();
|
fileRepositoryMock = new Mock<IFileRepository>();
|
||||||
|
@ -52,7 +52,7 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
return Forbid();
|
return Forbid();
|
||||||
|
|
||||||
var idUser = User?.GetUserId();
|
var idUser = User?.GetUserId();
|
||||||
var data = await wellFinalDocumentsRepository.GetByWellIdAsync(idWell, idUser ?? default, token);
|
var data = await wellFinalDocumentsRepository.GetByWellIdAsync(idWell, (int)idUser!, token);
|
||||||
return Ok(data);
|
return Ok(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,8 +89,8 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
||||||
return Forbid();
|
return Forbid();
|
||||||
|
|
||||||
var idUser = User.GetUserId() ?? -1;
|
var idUser = User.GetUserId();
|
||||||
var data = await wellFinalDocumentsService.UpdateRangeAsync(idWell, idUser, dtos, token);
|
var data = await wellFinalDocumentsService.UpdateRangeAsync(idWell, (int)idUser!, dtos, token);
|
||||||
return Ok(data);
|
return Ok(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user