forked from ddrilling/AsbCloudServer
правки по результатам ревью
This commit is contained in:
parent
9806df01ae
commit
81ab77cdfc
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
namespace AsbCloudApp.Data
|
namespace AsbCloudApp.Data
|
||||||
{
|
{
|
||||||
#nullable enable
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// DTO для faq-вопроса
|
/// DTO для faq-вопроса
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -13,11 +12,6 @@ namespace AsbCloudApp.Data
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// ключ скважины
|
|
||||||
/// </summary>
|
|
||||||
public int? IdWell { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// ключ автора вопроса
|
/// ключ автора вопроса
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -47,17 +41,16 @@ namespace AsbCloudApp.Data
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// статус вопроса
|
/// статус вопроса
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int? State { get; set; } = 0!;
|
public int State { get; set; } = 0;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Счетчик повторений вопроса
|
/// Счетчик повторений вопроса
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int? CounterQuestion { get; set; } = 0!;
|
public int CounterQuestion { get; set; } = 1;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Частый вопрос
|
/// Частый вопрос
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool? IsFrequently { get; set; } = false!;
|
public bool IsFrequently { get; set; } = false;
|
||||||
}
|
}
|
||||||
#nullable disable
|
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,6 @@ using AsbCloudApp.Services;
|
|||||||
|
|
||||||
namespace AsbCloudApp.Repositories
|
namespace AsbCloudApp.Repositories
|
||||||
{
|
{
|
||||||
#nullable enable
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// репозиторий по работе с faq-вопросами
|
/// репозиторий по работе с faq-вопросами
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -19,7 +18,7 @@ namespace AsbCloudApp.Repositories
|
|||||||
/// <param name="request"></param>
|
/// <param name="request"></param>
|
||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<IEnumerable<FaqDto>> GetAllAsync(FaqRequest request, CancellationToken token);
|
Task<IEnumerable<FaqDto>> GetFilteredAsync(FaqRequest request, CancellationToken token);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Добавить вопрос
|
/// Добавить вопрос
|
||||||
@ -40,20 +39,27 @@ namespace AsbCloudApp.Repositories
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Объединить 2 вопроса в 1
|
/// Объединить 2 вопроса в 1
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sourceIds">Ключи вопросов, подлежащих объединению</param>
|
/// <param name="sourceId1">ключ первого вопроса, подлежащего объединению</param>
|
||||||
/// <param name="mergeTexts">Флаг, объединять текст вопросов или нет</param>
|
/// <param name="sourceId2">ключ второго вопроса, подлежащего объединению</param>
|
||||||
|
/// <param name="mergeQuestions">Флаг, объединять текст вопросов или нет</param>
|
||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<int> MergeAsync(IEnumerable<int> sourceIds, bool mergeTexts, CancellationToken token);
|
Task<int> MergeAsync(int sourceId1, int sourceId2, bool mergeQuestions, CancellationToken token);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Пометить вопрос по id как удаленный
|
/// Пометить вопрос по id как удаленный
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="idWell"></param>
|
|
||||||
/// <param name="id"></param>
|
/// <param name="id"></param>
|
||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<int> MarkAsDeletedAsync(int idWell, int id, CancellationToken token);
|
Task<int> MarkAsDeletedAsync(int id, CancellationToken token);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Удалить вопрос по ключу
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="token"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<int> DeleteAsync(int id, CancellationToken token);
|
||||||
}
|
}
|
||||||
#nullable disable
|
|
||||||
}
|
}
|
||||||
|
@ -7,11 +7,10 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace AsbCloudApp.Requests
|
namespace AsbCloudApp.Requests
|
||||||
{
|
{
|
||||||
#nullable enable
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Параметры запроса для фильтрации faq-вопросов
|
/// Параметры запроса для фильтрации faq-вопросов
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class FaqRequestBase : RequestBase
|
public class FaqRequest
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Есть ли ответ на вопрос
|
/// Есть ли ответ на вопрос
|
||||||
@ -28,30 +27,4 @@ namespace AsbCloudApp.Requests
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public bool IncludeDeleted { get; set; } = false;
|
public bool IncludeDeleted { get; set; } = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Параметры запроса для фильтрации faq-вопросов (с id скважины)
|
|
||||||
/// </summary>
|
|
||||||
public class FaqRequest : FaqRequestBase
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// копирующий конструктор
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="request"></param>
|
|
||||||
/// <param name="idWell"></param>
|
|
||||||
public FaqRequest(FaqRequestBase request, int idWell)
|
|
||||||
{
|
|
||||||
IdWell = idWell;
|
|
||||||
this.IncludeDeleted = request.IncludeDeleted;
|
|
||||||
this.HasAnswer = request.HasAnswer;
|
|
||||||
this.IsFrequently = request.IsFrequently;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// id скважины
|
|
||||||
/// </summary>
|
|
||||||
public int IdWell { get; set; }
|
|
||||||
|
|
||||||
}
|
|
||||||
#nullable disable
|
|
||||||
}
|
}
|
||||||
|
@ -72,7 +72,7 @@ namespace AsbCloudDb.Model
|
|||||||
private static int referenceCount;
|
private static int referenceCount;
|
||||||
public static int ReferenceCount => referenceCount;
|
public static int ReferenceCount => referenceCount;
|
||||||
|
|
||||||
public DbSet<Faq> FAQs => Set<Faq>();
|
public DbSet<Faq> Faqs => Set<Faq>();
|
||||||
|
|
||||||
public AsbCloudDbContext() : base()
|
public AsbCloudDbContext() : base()
|
||||||
{
|
{
|
||||||
|
@ -6,7 +6,6 @@ using System.Text.Json.Serialization;
|
|||||||
|
|
||||||
namespace AsbCloudDb.Model
|
namespace AsbCloudDb.Model
|
||||||
{
|
{
|
||||||
#nullable enable
|
|
||||||
[Table("t_faq"), Comment("вопросы пользователей")]
|
[Table("t_faq"), Comment("вопросы пользователей")]
|
||||||
public class Faq : IId
|
public class Faq : IId
|
||||||
{
|
{
|
||||||
@ -17,16 +16,6 @@ namespace AsbCloudDb.Model
|
|||||||
[Column("id"), Comment("Идентификатор")]
|
[Column("id"), Comment("Идентификатор")]
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// ключ скважины, к которой пивязан вопрос
|
|
||||||
/// </summary>
|
|
||||||
[Column("id_well"), Comment("id скважины")]
|
|
||||||
public int IdWell { get; set; }
|
|
||||||
|
|
||||||
[JsonIgnore]
|
|
||||||
[ForeignKey(nameof(IdWell))]
|
|
||||||
public virtual Well Well { get; set; } = null!;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// автор вопроса
|
/// автор вопроса
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -45,7 +34,7 @@ namespace AsbCloudDb.Model
|
|||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
[ForeignKey(nameof(IdAuthorAnswer))]
|
[ForeignKey(nameof(IdAuthorAnswer))]
|
||||||
public virtual User AuthorAnswer { get; set; } = null!;
|
public virtual User? AuthorAnswer { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// дата создания вопроса
|
/// дата создания вопроса
|
||||||
@ -87,7 +76,7 @@ namespace AsbCloudDb.Model
|
|||||||
/// Счетчик повторений вопроса
|
/// Счетчик повторений вопроса
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Column("counter_question"), Comment("Счетчик повторений вопроса")]
|
[Column("counter_question"), Comment("Счетчик повторений вопроса")]
|
||||||
public int CounterQuestion { get; set; }
|
public int CounterQuestion { get; set; } = 1;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ключ заменяющего вопроса
|
/// Ключ заменяющего вопроса
|
||||||
@ -102,5 +91,4 @@ namespace AsbCloudDb.Model
|
|||||||
public bool IsFrequently { get; set; } = false;
|
public bool IsFrequently { get; set; } = false;
|
||||||
|
|
||||||
}
|
}
|
||||||
#nullable disable
|
|
||||||
}
|
}
|
||||||
|
@ -57,7 +57,7 @@ namespace AsbCloudDb.Model
|
|||||||
DbSet<WellFinalDocument> WellFinalDocuments { get; }
|
DbSet<WellFinalDocument> WellFinalDocuments { get; }
|
||||||
DbSet<LimitingParameter> LimitingParameter { get; }
|
DbSet<LimitingParameter> LimitingParameter { get; }
|
||||||
DbSet<TelemetryWirelineRunOut> TelemetryWirelineRunOut { get; }
|
DbSet<TelemetryWirelineRunOut> TelemetryWirelineRunOut { get; }
|
||||||
DbSet<Faq> FAQs { get; }
|
DbSet<Faq> Faqs { get; }
|
||||||
|
|
||||||
DbSet<Record1> Record1 { get; }
|
DbSet<Record1> Record1 { get; }
|
||||||
DbSet<Record7> Record7 { get; }
|
DbSet<Record7> Record7 { get; }
|
||||||
|
@ -15,7 +15,6 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace AsbCloudInfrastructure.Repository
|
namespace AsbCloudInfrastructure.Repository
|
||||||
{
|
{
|
||||||
#nullable enable
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// сервис по работе с faq-вопросами
|
/// сервис по работе с faq-вопросами
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -30,10 +29,9 @@ namespace AsbCloudInfrastructure.Repository
|
|||||||
this.wellService = wellService;
|
this.wellService = wellService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IEnumerable<FaqDto>> GetAllAsync(FaqRequest request, CancellationToken token)
|
public async Task<IEnumerable<FaqDto>> GetFilteredAsync(FaqRequest request, CancellationToken token)
|
||||||
{
|
{
|
||||||
var query = db.FAQs
|
var query = db.Faqs.AsNoTracking();
|
||||||
.Where(o => o.IdWell == request.IdWell);
|
|
||||||
|
|
||||||
if (request.IsFrequently)
|
if (request.IsFrequently)
|
||||||
{
|
{
|
||||||
@ -48,7 +46,9 @@ namespace AsbCloudInfrastructure.Repository
|
|||||||
query = query.Where(o => o.State != Faq.StateDeleted);
|
query = query.Where(o => o.State != Faq.StateDeleted);
|
||||||
}
|
}
|
||||||
|
|
||||||
var entities = query.Select(o => new FaqDto()
|
var entities = query
|
||||||
|
.OrderByDescending(e => e.DateCreatedQuestion)
|
||||||
|
.Select(o => new FaqDto()
|
||||||
{
|
{
|
||||||
Id = o.Id,
|
Id = o.Id,
|
||||||
Question = o.Question,
|
Question = o.Question,
|
||||||
@ -59,15 +59,6 @@ namespace AsbCloudInfrastructure.Repository
|
|||||||
DateCreatedQuestion = o.DateCreatedQuestion,
|
DateCreatedQuestion = o.DateCreatedQuestion,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (request.SortFields?.Any() == true)
|
|
||||||
{
|
|
||||||
entities = entities.SortBy(request.SortFields);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
entities = entities.OrderByDescending(e => e.DateCreatedQuestion);
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
var result = await entities.AsNoTracking()
|
var result = await entities.AsNoTracking()
|
||||||
.ToArrayAsync(token)
|
.ToArrayAsync(token)
|
||||||
@ -81,22 +72,20 @@ namespace AsbCloudInfrastructure.Repository
|
|||||||
{
|
{
|
||||||
var entity = faqDto.Adapt<Faq>();
|
var entity = faqDto.Adapt<Faq>();
|
||||||
entity.DateCreatedQuestion = entity.DateLastEditedQuestion = DateTimeOffset.UtcNow;
|
entity.DateCreatedQuestion = entity.DateLastEditedQuestion = DateTimeOffset.UtcNow;
|
||||||
entity.CounterQuestion = 0;
|
entity.CounterQuestion = 1;
|
||||||
entity.State = Faq.StateOpened;
|
entity.State = Faq.StateOpened;
|
||||||
|
|
||||||
db.FAQs.Add(entity);
|
db.Faqs.Add(entity);
|
||||||
|
|
||||||
await db.SaveChangesAsync(token).ConfigureAwait(false);
|
await db.SaveChangesAsync(token).ConfigureAwait(false);
|
||||||
return entity.Id;
|
return entity.Id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<int> MergeAsync(IEnumerable<int> sourceIds, bool mergeTexts, CancellationToken token)
|
public async Task<int> MergeAsync(int sourceId1, int sourceId2, bool mergeQuestions, CancellationToken token)
|
||||||
{
|
{
|
||||||
var sourceFaqs = db.FAQs.Where(e => sourceIds.Contains(e.Id)).ToArray();
|
var sourceFaqs = db.Faqs.Where(e => e.Id == sourceId1 || e.Id == sourceId2).ToArray();
|
||||||
if (sourceFaqs.Count() < 2)
|
if (sourceFaqs.Count() < 2)
|
||||||
throw new ArgumentInvalidException("Questions with target ids don't exist", nameof(sourceIds));
|
throw new ArgumentInvalidException("Questions with target ids don't exist", nameof(sourceFaqs));
|
||||||
if (sourceFaqs.Select(e => e.IdWell).Distinct().Count() > 1)
|
|
||||||
throw new ArgumentInvalidException("Questions with different idWell are not merged", nameof(sourceIds));
|
|
||||||
|
|
||||||
var newFaq = new Faq()
|
var newFaq = new Faq()
|
||||||
{
|
{
|
||||||
@ -106,16 +95,15 @@ namespace AsbCloudInfrastructure.Repository
|
|||||||
IdAuthorQuestion = sourceFaqs.Last().IdAuthorQuestion,
|
IdAuthorQuestion = sourceFaqs.Last().IdAuthorQuestion,
|
||||||
DateCreatedQuestion = DateTimeOffset.UtcNow,
|
DateCreatedQuestion = DateTimeOffset.UtcNow,
|
||||||
DateLastEditedQuestion = DateTimeOffset.UtcNow,
|
DateLastEditedQuestion = DateTimeOffset.UtcNow,
|
||||||
IdWell = sourceFaqs.Last().IdWell,
|
Answer = mergeQuestions == true
|
||||||
Answer = mergeTexts == true
|
|
||||||
? string.Join(Environment.NewLine, sourceFaqs.Select(e => e.Answer))
|
? string.Join(Environment.NewLine, sourceFaqs.Select(e => e.Answer))
|
||||||
: sourceFaqs.Last().Answer,
|
: sourceFaqs.Last().Answer,
|
||||||
Question = mergeTexts == true
|
Question = mergeQuestions == true
|
||||||
? string.Join(Environment.NewLine, sourceFaqs.Select(e => e.Question))
|
? string.Join(Environment.NewLine, sourceFaqs.Select(e => e.Question))
|
||||||
: sourceFaqs.Last().Question,
|
: sourceFaqs.Last().Question,
|
||||||
};
|
};
|
||||||
|
|
||||||
db.FAQs.Add(newFaq);
|
db.Faqs.Add(newFaq);
|
||||||
await db.SaveChangesAsync(token).ConfigureAwait(false);
|
await db.SaveChangesAsync(token).ConfigureAwait(false);
|
||||||
|
|
||||||
if (newFaq.Id == 0)
|
if (newFaq.Id == 0)
|
||||||
@ -135,18 +123,16 @@ namespace AsbCloudInfrastructure.Repository
|
|||||||
{
|
{
|
||||||
var entity = dto.Adapt<Faq>();
|
var entity = dto.Adapt<Faq>();
|
||||||
entity.DateLastEditedQuestion = DateTimeOffset.UtcNow;
|
entity.DateLastEditedQuestion = DateTimeOffset.UtcNow;
|
||||||
db.FAQs.Update(entity);
|
db.Faqs.Update(entity);
|
||||||
return await db.SaveChangesAsync(token)
|
return await db.SaveChangesAsync(token)
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<int> MarkAsDeletedAsync(int idWell, int id, CancellationToken token)
|
public async Task<int> MarkAsDeletedAsync(int id, CancellationToken token)
|
||||||
{
|
{
|
||||||
var entity = db.FAQs.FirstOrDefault(e => e.Id == id);
|
var entity = db.Faqs.FirstOrDefault(e => e.Id == id);
|
||||||
if (entity is null)
|
if (entity is null)
|
||||||
throw new ArgumentInvalidException("Question doesn't exist", nameof(id));
|
throw new ArgumentInvalidException("Question doesn't exist", nameof(id));
|
||||||
if (entity.IdWell != idWell)
|
|
||||||
throw new ArgumentInvalidException("Question's well and idWell don't match", nameof(idWell));
|
|
||||||
|
|
||||||
entity.State = Faq.StateDeleted;
|
entity.State = Faq.StateDeleted;
|
||||||
entity.DateLastEditedQuestion = DateTimeOffset.UtcNow;
|
entity.DateLastEditedQuestion = DateTimeOffset.UtcNow;
|
||||||
@ -154,6 +140,15 @@ namespace AsbCloudInfrastructure.Repository
|
|||||||
return await db.SaveChangesAsync(token)
|
return await db.SaveChangesAsync(token)
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<int> DeleteAsync(int id, CancellationToken token)
|
||||||
|
{
|
||||||
|
var faq = db.Faqs.FirstOrDefault(f => f.Id == id);
|
||||||
|
if (faq is null)
|
||||||
|
throw new ArgumentInvalidException("Question doesn't exist", nameof(id));
|
||||||
|
|
||||||
|
db.Faqs.Remove(faq);
|
||||||
|
return await db.SaveChangesAsync(token);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#nullable disable
|
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,6 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace AsbCloudWebApi.Controllers
|
namespace AsbCloudWebApi.Controllers
|
||||||
{
|
{
|
||||||
#nullable enable
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// контроллер по работе с faq-вопросами
|
/// контроллер по работе с faq-вопросами
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -35,34 +34,23 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// получение списка faq-вопросов
|
/// получение списка faq-вопросов
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="idWell"></param>
|
|
||||||
/// <param name="request"></param>
|
/// <param name="request"></param>
|
||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[Permission]
|
[Permission]
|
||||||
[ProducesResponseType(typeof(IEnumerable<FaqDto>), (int)System.Net.HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(IEnumerable<FaqDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||||
public async Task<IActionResult> GetAllAsync(
|
public async Task<IActionResult> GetFilteredAsync(
|
||||||
[FromRoute] int idWell,
|
[FromQuery] FaqRequest request,
|
||||||
[FromQuery] FaqRequestBase request,
|
|
||||||
CancellationToken token)
|
CancellationToken token)
|
||||||
{
|
{
|
||||||
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
var result = await faqRepository.GetFilteredAsync(request, token).ConfigureAwait(false);
|
||||||
return Forbid();
|
|
||||||
|
|
||||||
var requestToRepository = new FaqRequest(request, idWell);
|
|
||||||
|
|
||||||
var result = await faqRepository.GetAllAsync(
|
|
||||||
requestToRepository,
|
|
||||||
token)
|
|
||||||
.ConfigureAwait(false);
|
|
||||||
return Ok(result);
|
return Ok(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// добавление нового вопроса
|
/// добавление нового вопроса
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="idWell">ключ скважины</param>
|
|
||||||
/// <param name="faqDto">вопрос</param>
|
/// <param name="faqDto">вопрос</param>
|
||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
@ -70,14 +58,9 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
[Permission]
|
[Permission]
|
||||||
[ProducesResponseType(typeof(FaqDto), (int)System.Net.HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(FaqDto), (int)System.Net.HttpStatusCode.OK)]
|
||||||
public async Task<IActionResult> InsertAsync(
|
public async Task<IActionResult> InsertAsync(
|
||||||
[Range(1, int.MaxValue, ErrorMessage = "Id скважины не может быть меньше 1")] int idWell,
|
|
||||||
[FromBody] FaqDto faqDto,
|
[FromBody] FaqDto faqDto,
|
||||||
CancellationToken token)
|
CancellationToken token)
|
||||||
{
|
{
|
||||||
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
|
||||||
return Forbid();
|
|
||||||
|
|
||||||
faqDto.IdWell = idWell;
|
|
||||||
faqDto.IdAuthorQuestion = User.GetUserId()!.Value;
|
faqDto.IdAuthorQuestion = User.GetUserId()!.Value;
|
||||||
|
|
||||||
var result = await faqRepository.InsertAsync(faqDto, token)
|
var result = await faqRepository.InsertAsync(faqDto, token)
|
||||||
@ -88,11 +71,8 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
|
|
||||||
[HttpPut]
|
[HttpPut]
|
||||||
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
||||||
public async Task<IActionResult> UpdateAsync(int idWell, [FromBody] FaqDto faqDto, CancellationToken token)
|
public async Task<IActionResult> UpdateAsync([FromBody] FaqDto faqDto, CancellationToken token)
|
||||||
{
|
{
|
||||||
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
|
||||||
return Forbid();
|
|
||||||
|
|
||||||
faqDto.IdAuthorAnswer = User.GetUserId()!.Value;
|
faqDto.IdAuthorAnswer = User.GetUserId()!.Value;
|
||||||
|
|
||||||
var result = await faqRepository.UpdateAsync(faqDto, token)
|
var result = await faqRepository.UpdateAsync(faqDto, token)
|
||||||
@ -103,8 +83,8 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Объединение 2 вопросов в один
|
/// Объединение 2 вопросов в один
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="idWell">ключ скважины</param>
|
/// <param name="sourceId1"></param>
|
||||||
/// <param name="sourceIds">ключи вопросов, подлежащих объединению</param>
|
/// <param name="sourceId2"></param>
|
||||||
/// <param name="mergeTexts">настройка, объединять ли текст 2-х вопросов в один или нет</param>
|
/// <param name="mergeTexts">настройка, объединять ли текст 2-х вопросов в один или нет</param>
|
||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
@ -112,17 +92,12 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
[HttpGet("merge")]
|
[HttpGet("merge")]
|
||||||
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
||||||
public async Task<IActionResult> MergeAsync(
|
public async Task<IActionResult> MergeAsync(
|
||||||
int idWell,
|
[FromQuery] int sourceId1,
|
||||||
[FromQuery] IEnumerable<int> sourceIds,
|
[FromQuery] int sourceId2,
|
||||||
[FromQuery] bool mergeTexts,
|
[FromQuery] bool mergeTexts,
|
||||||
CancellationToken token)
|
CancellationToken token)
|
||||||
{
|
{
|
||||||
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
var result = await faqRepository.MergeAsync(sourceId1, sourceId2, mergeTexts, token)
|
||||||
return Forbid();
|
|
||||||
if (sourceIds.Count() < 2)
|
|
||||||
throw new ArgumentInvalidException("Count of questions must be more than 1", nameof(sourceIds));
|
|
||||||
|
|
||||||
var result = await faqRepository.MergeAsync(sourceIds, mergeTexts, token)
|
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
return Ok(result);
|
return Ok(result);
|
||||||
}
|
}
|
||||||
@ -130,31 +105,35 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Помечает вопрос как удаленный
|
/// Помечает вопрос как удаленный
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="idWell">id скважины</param>
|
|
||||||
/// <param name="id">id вопроса</param>
|
/// <param name="id">id вопроса</param>
|
||||||
/// <param name="token">Токен отмены задачи</param>
|
/// <param name="token">Токен отмены задачи</param>
|
||||||
/// <returns>Количество удаленных из БД строк</returns>
|
/// <returns>Количество удаленных из БД строк</returns>
|
||||||
[HttpPut("{id}")]
|
[HttpPut("{id}")]
|
||||||
[Permission]
|
[Permission]
|
||||||
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
||||||
public async Task<IActionResult> MarkAsDeletedAsync(int idWell, int id, CancellationToken token)
|
public async Task<IActionResult> MarkAsDeletedAsync(int id, CancellationToken token)
|
||||||
{
|
{
|
||||||
if (!await CanUserAccessToWellAsync(idWell,
|
var result = await faqRepository.MarkAsDeletedAsync(id, token)
|
||||||
token).ConfigureAwait(false))
|
|
||||||
return Forbid();
|
|
||||||
|
|
||||||
var result = await faqRepository.MarkAsDeletedAsync(idWell, id, token)
|
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
|
|
||||||
return Ok(result);
|
return Ok(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<bool> CanUserAccessToWellAsync(int idWell, CancellationToken token)
|
/// <summary>
|
||||||
|
/// Удаление вопроса
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">id вопроса</param>
|
||||||
|
/// <param name="token">Токен отмены задачи</param>
|
||||||
|
/// <returns>Количество удаленных из БД строк</returns>
|
||||||
|
[HttpDelete("{id}")]
|
||||||
|
[Permission]
|
||||||
|
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
||||||
|
public async Task<IActionResult> DeleteAsync(int id, CancellationToken token)
|
||||||
{
|
{
|
||||||
int? idCompany = User.GetCompanyId();
|
var result = await faqRepository.DeleteAsync(id, token)
|
||||||
return idCompany is not null && await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
.ConfigureAwait(false);
|
||||||
idWell, token).ConfigureAwait(false);
|
|
||||||
|
return Ok(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#nullable disable
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user