Рефакторинг

This commit is contained in:
Olga Nemt 2024-11-29 10:03:52 +05:00
parent 198a65b1d2
commit 25afd50793
2 changed files with 32 additions and 20 deletions

View File

@ -3,6 +3,7 @@ using Microsoft.AspNetCore.Mvc;
using Persistence.Models;
using Persistence.Models.Requests;
using Persistence.Repositories;
using System.Net;
namespace Persistence.API.Controllers;
@ -19,7 +20,8 @@ public class ChangeLogController : ControllerBase, IChangeLogApi
}
[HttpPost]
public async Task<ActionResult<int>> Add(
[ProducesResponseType(typeof(int), (int)HttpStatusCode.OK)]
public async Task<IActionResult> Add(
Guid idDiscriminator,
[FromBody] DataWithWellDepthAndSectionDto dto,
CancellationToken token)
@ -31,7 +33,8 @@ public class ChangeLogController : ControllerBase, IChangeLogApi
}
[HttpPost("range")]
public async Task<ActionResult<int>> AddRange(
[ProducesResponseType(typeof(int), (int)HttpStatusCode.OK)]
public async Task<IActionResult> AddRange(
Guid idDiscriminator,
[FromBody] IEnumerable<DataWithWellDepthAndSectionDto> dtos, CancellationToken token)
{
@ -42,7 +45,8 @@ public class ChangeLogController : ControllerBase, IChangeLogApi
}
[HttpDelete]
public async Task<ActionResult<int>> Delete(Guid id, CancellationToken token)
[ProducesResponseType(typeof(int), (int)HttpStatusCode.OK)]
public async Task<IActionResult> Delete(Guid id, CancellationToken token)
{
var userId = User.GetUserId<Guid>();
var result = await repository.MarkAsDeleted(userId, [id], token);
@ -51,7 +55,8 @@ public class ChangeLogController : ControllerBase, IChangeLogApi
}
[HttpDelete("range")]
public async Task<ActionResult<int>> DeleteRange(IEnumerable<Guid> ids, CancellationToken token)
[ProducesResponseType(typeof(int), (int)HttpStatusCode.OK)]
public async Task<IActionResult> DeleteRange(IEnumerable<Guid> ids, CancellationToken token)
{
var userId = User.GetUserId<Guid>();
var result = await repository.MarkAsDeleted(userId, ids, token);
@ -60,6 +65,7 @@ public class ChangeLogController : ControllerBase, IChangeLogApi
}
[HttpPost("replace")]
[ProducesResponseType(typeof(int), (int)HttpStatusCode.OK)]
public async Task<IActionResult> ClearAndInsertRange(
Guid idDiscriminator,
IEnumerable<DataWithWellDepthAndSectionDto> dtos,
@ -71,7 +77,8 @@ public class ChangeLogController : ControllerBase, IChangeLogApi
}
[HttpPut]
public async Task<ActionResult<int>> Update(
[ProducesResponseType(typeof(int), (int)HttpStatusCode.OK)]
public async Task<IActionResult> Update(
Guid idDiscriminator,
DataWithWellDepthAndSectionDto dto,
CancellationToken token)
@ -83,7 +90,8 @@ public class ChangeLogController : ControllerBase, IChangeLogApi
}
[HttpPut("range")]
public async Task<ActionResult<int>> UpdateRange(
[ProducesResponseType(typeof(int), (int)HttpStatusCode.OK)]
public async Task<IActionResult> UpdateRange(
Guid idDiscriminator,
IEnumerable<DataWithWellDepthAndSectionDto> dtos,
CancellationToken token)
@ -95,7 +103,8 @@ public class ChangeLogController : ControllerBase, IChangeLogApi
}
[HttpGet]
public async Task<ActionResult<PaginationContainer<DataWithWellDepthAndSectionDto>>> GetCurrent(
[ProducesResponseType(typeof(PaginationContainer<DataWithWellDepthAndSectionDto>), (int)HttpStatusCode.OK)]
public async Task<IActionResult> GetCurrent(
Guid idDiscriminator,
[FromQuery]SectionPartRequest request,
CancellationToken token)
@ -107,7 +116,8 @@ public class ChangeLogController : ControllerBase, IChangeLogApi
}
[HttpGet("moment")]
public async Task<ActionResult<PaginationContainer<DataWithWellDepthAndSectionDto>>> GetByDate(
[ProducesResponseType(typeof(PaginationContainer<DataWithWellDepthAndSectionDto>), (int)HttpStatusCode.OK)]
public async Task<IActionResult> GetByDate(
Guid idDiscriminator,
DateTimeOffset moment,
SectionPartRequest request,
@ -119,7 +129,8 @@ public class ChangeLogController : ControllerBase, IChangeLogApi
}
[HttpGet("history")]
public async Task<ActionResult<IEnumerable<ChangeLogDto>>> GetChangeLogForDate(Guid idDiscriminator, DateTimeOffset dateBegin, DateTimeOffset dateEnd, CancellationToken token)
[ProducesResponseType(typeof(IEnumerable<ChangeLogDto>), (int)HttpStatusCode.OK)]
public async Task<IActionResult> GetChangeLogForDate(Guid idDiscriminator, DateTimeOffset dateBegin, DateTimeOffset dateEnd, CancellationToken token)
{
var result = await repository.GetChangeLogForDate(idDiscriminator, dateBegin, dateEnd, token);
@ -127,7 +138,8 @@ public class ChangeLogController : ControllerBase, IChangeLogApi
}
[HttpGet("datesChange")]
public async Task<ActionResult<IEnumerable<DateOnly>>> GetDatesChange(Guid idDiscriminator, CancellationToken token)
[ProducesResponseType(typeof(IEnumerable<DateOnly>), (int)HttpStatusCode.OK)]
public async Task<IActionResult> GetDatesChange(Guid idDiscriminator, CancellationToken token)
{
var result = await repository.GetDatesChange(idDiscriminator, token);

View File

@ -25,7 +25,7 @@ public interface IChangeLogApi
/// <param name="request">параметры запроса</param>
/// <param name="token"></param>
/// <returns></returns>
Task<ActionResult<PaginationContainer<DataWithWellDepthAndSectionDto>>> GetCurrent(Guid idDiscriminator, SectionPartRequest request, CancellationToken token);
Task<IActionResult> GetCurrent(Guid idDiscriminator, SectionPartRequest request, CancellationToken token);
/// <summary>
/// Получение данных на определенную дату (с пагинацией)
@ -35,7 +35,7 @@ public interface IChangeLogApi
/// <param name="request">параметры запроса</param>
/// <param name="token"></param>
/// <returns></returns>
Task<ActionResult<PaginationContainer<DataWithWellDepthAndSectionDto>>> GetByDate(Guid idDiscriminator, DateTimeOffset moment, SectionPartRequest request, CancellationToken token);
Task<IActionResult> GetByDate(Guid idDiscriminator, DateTimeOffset moment, SectionPartRequest request, CancellationToken token);
/// <summary>
/// Получение исторических данных за определенный период времени
@ -45,7 +45,7 @@ public interface IChangeLogApi
/// <param name="dateEnd"></param>
/// <param name="token"></param>
/// <returns></returns>
Task<ActionResult<IEnumerable<ChangeLogDto>>> GetChangeLogForDate(Guid idDiscriminator, DateTimeOffset dateBegin, DateTimeOffset dateEnd, CancellationToken token);
Task<IActionResult> GetChangeLogForDate(Guid idDiscriminator, DateTimeOffset dateBegin, DateTimeOffset dateEnd, CancellationToken token);
/// <summary>
/// Добавить одну запись
@ -54,7 +54,7 @@ public interface IChangeLogApi
/// <param name="dto"></param>
/// <param name="token"></param>
/// <returns></returns>
Task<ActionResult<int>> Add(Guid idDiscriminator, DataWithWellDepthAndSectionDto dto, CancellationToken token);
Task<IActionResult> Add(Guid idDiscriminator, DataWithWellDepthAndSectionDto dto, CancellationToken token);
/// <summary>
/// Добавить несколько записей
@ -63,7 +63,7 @@ public interface IChangeLogApi
/// <param name="dtos"></param>
/// <param name="token"></param>
/// <returns></returns>
Task<ActionResult<int>> AddRange(Guid idDiscriminator, IEnumerable<DataWithWellDepthAndSectionDto> dtos, CancellationToken token);
Task<IActionResult> AddRange(Guid idDiscriminator, IEnumerable<DataWithWellDepthAndSectionDto> dtos, CancellationToken token);
/// <summary>
/// Обновить одну запись
@ -72,7 +72,7 @@ public interface IChangeLogApi
/// <param name="dto"></param>
/// <param name="token"></param>
/// <returns></returns>
Task<ActionResult<int>> Update(Guid idDiscriminator, DataWithWellDepthAndSectionDto dto, CancellationToken token);
Task<IActionResult> Update(Guid idDiscriminator, DataWithWellDepthAndSectionDto dto, CancellationToken token);
/// <summary>
/// Обновить несколько записей
@ -81,7 +81,7 @@ public interface IChangeLogApi
/// <param name="dtos"></param>
/// <param name="token"></param>
/// <returns></returns>
Task<ActionResult<int>> UpdateRange(Guid idDiscriminator, IEnumerable<DataWithWellDepthAndSectionDto> dtos, CancellationToken token);
Task<IActionResult> UpdateRange(Guid idDiscriminator, IEnumerable<DataWithWellDepthAndSectionDto> dtos, CancellationToken token);
/// <summary>
/// Удалить одну запись
@ -89,7 +89,7 @@ public interface IChangeLogApi
/// <param name="id"></param>
/// <param name="token"></param>
/// <returns></returns>
Task<ActionResult<int>> Delete(Guid id, CancellationToken token);
Task<IActionResult> Delete(Guid id, CancellationToken token);
/// <summary>
/// Удалить несколько записей
@ -97,7 +97,7 @@ public interface IChangeLogApi
/// <param name="ids"></param>
/// <param name="token"></param>
/// <returns></returns>
Task<ActionResult<int>> DeleteRange(IEnumerable<Guid> ids, CancellationToken token);
Task<IActionResult> DeleteRange(IEnumerable<Guid> ids, CancellationToken token);
/// <summary>
/// Получение списка дат, в которые происходили изменения (день, месяц, год, без времени)
@ -105,5 +105,5 @@ public interface IChangeLogApi
/// <param name="idDiscriminator"></param>
/// <param name="token"></param>
/// <returns></returns>
Task<ActionResult<IEnumerable<DateOnly>>> GetDatesChange(Guid idDiscriminator, CancellationToken token);
Task<IActionResult> GetDatesChange(Guid idDiscriminator, CancellationToken token);
}