Compare commits
No commits in common. "5f2535b51790508bdc92be464cb39a77f54f2fe0" and "9e375b48319b642ee71f76d7b28949ebfe18d988" have entirely different histories.
5f2535b517
...
9e375b4831
@ -1,4 +1,5 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Persistence.API;
|
||||
using Persistence.Repositories;
|
||||
using Persistence.Repository.Data;
|
||||
|
||||
@ -10,5 +11,5 @@ public class DataSaubController : TimeSeriesController<DataSaubDto>
|
||||
public DataSaubController(ITimeSeriesDataRepository<DataSaubDto> timeSeriesDataRepository) : base(timeSeriesDataRepository)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,10 +24,9 @@ public class TimeSeriesController<TDto> : ControllerBase, ITimeSeriesDataApi<TDt
|
||||
}
|
||||
|
||||
[HttpGet("datesRange")]
|
||||
public async Task<IActionResult> GetDatesRangeAsync(CancellationToken token)
|
||||
public Task<IActionResult> GetDatesRangeAsync(CancellationToken token)
|
||||
{
|
||||
var result = await this.timeSeriesDataRepository.GetDatesRangeAsync(token);
|
||||
return Ok(result);
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
|
12
Persistence.API/WeatherForecast.cs
Normal file
12
Persistence.API/WeatherForecast.cs
Normal file
@ -0,0 +1,12 @@
|
||||
namespace Persistence.API;
|
||||
|
||||
public class WeatherForecast
|
||||
{
|
||||
public DateOnly Date { get; set; }
|
||||
|
||||
public int TemperatureC { get; set; }
|
||||
|
||||
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
|
||||
|
||||
public string? Summary { get; set; }
|
||||
}
|
@ -1,6 +1,8 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Persistence.Database;
|
||||
using Persistence.Database.Model;
|
||||
|
||||
namespace Persistence.Database.Model;
|
||||
|
||||
|
@ -12,7 +12,7 @@ using Persistence.Database.Model;
|
||||
namespace Persistence.Database.Postgres.Migrations
|
||||
{
|
||||
[DbContext(typeof(PersistenceDbContext))]
|
||||
[Migration("20241118091712_InitialCreate")]
|
||||
[Migration("20241115105149_InitialCreate")]
|
||||
partial class InitialCreate
|
||||
{
|
||||
/// <inheritdoc />
|
||||
@ -52,10 +52,6 @@ namespace Persistence.Database.Postgres.Migrations
|
||||
.HasColumnType("double precision")
|
||||
.HasColumnName("blockSpeed");
|
||||
|
||||
b.Property<DateTimeOffset>("Date")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("date");
|
||||
|
||||
b.Property<double?>("Flow")
|
||||
.HasColumnType("double precision")
|
||||
.HasColumnName("flow");
|
||||
@ -104,6 +100,10 @@ namespace Persistence.Database.Postgres.Migrations
|
||||
.HasColumnType("double precision")
|
||||
.HasColumnName("rotorTorque");
|
||||
|
||||
b.Property<int>("TimeStamp")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("timestamp");
|
||||
|
||||
b.Property<string>("User")
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("user");
|
@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
@ -21,7 +20,7 @@ namespace Persistence.Database.Postgres.Migrations
|
||||
{
|
||||
id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
date = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
|
||||
timestamp = table.Column<int>(type: "integer", nullable: false),
|
||||
mode = table.Column<int>(type: "integer", nullable: true),
|
||||
user = table.Column<string>(type: "text", nullable: true),
|
||||
wellDepth = table.Column<double>(type: "double precision", nullable: true),
|
@ -49,10 +49,6 @@ namespace Persistence.Database.Postgres.Migrations
|
||||
.HasColumnType("double precision")
|
||||
.HasColumnName("blockSpeed");
|
||||
|
||||
b.Property<DateTimeOffset>("Date")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("date");
|
||||
|
||||
b.Property<double?>("Flow")
|
||||
.HasColumnType("double precision")
|
||||
.HasColumnName("flow");
|
||||
@ -101,6 +97,10 @@ namespace Persistence.Database.Postgres.Migrations
|
||||
.HasColumnType("double precision")
|
||||
.HasColumnName("rotorTorque");
|
||||
|
||||
b.Property<int>("TimeStamp")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("timestamp");
|
||||
|
||||
b.Property<string>("User")
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("user");
|
||||
|
@ -18,8 +18,4 @@
|
||||
<ProjectReference Include="..\Persistence.Database\Persistence.Database.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Migrations\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -4,6 +4,7 @@ using System.Data.Common;
|
||||
namespace Persistence.Database.Model;
|
||||
public partial class PersistenceDbContext : DbContext, IPersistenceDbContext
|
||||
{
|
||||
private readonly DbConnection connection = null!;
|
||||
public DbSet<DataSaub> DataSaub => Set<DataSaub>();
|
||||
|
||||
public DbSet<Setpoint> Setpoint => Set<Setpoint>();
|
||||
@ -20,6 +21,16 @@ public partial class PersistenceDbContext : DbContext, IPersistenceDbContext
|
||||
|
||||
}
|
||||
|
||||
public PersistenceDbContext(DbConnection connection)
|
||||
{
|
||||
this.connection = connection;
|
||||
}
|
||||
|
||||
protected virtual DbConnection GetConnection()
|
||||
{
|
||||
return connection;
|
||||
}
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
if (!optionsBuilder.IsConfigured)
|
||||
|
@ -6,8 +6,8 @@ public class DataSaub : ITimestampedData
|
||||
[Column("id")]
|
||||
public int Id { get; set; }
|
||||
|
||||
[Column("date")]
|
||||
public DateTimeOffset Date { get; set; }
|
||||
[Column("timestamp")]
|
||||
public int TimeStamp { get; set; }
|
||||
|
||||
[Column("mode")]
|
||||
public int? Mode { get; set; }
|
||||
|
@ -7,8 +7,5 @@ using System.Threading.Tasks;
|
||||
namespace Persistence.Database.Model;
|
||||
public interface ITimestampedData
|
||||
{
|
||||
/// <summary>
|
||||
/// Дата (должна быть обязательно в UTC)
|
||||
/// </summary>
|
||||
DateTimeOffset Date { get; set; }
|
||||
int TimeStamp { get; set; }
|
||||
}
|
||||
|
@ -1,5 +1,11 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Persistence.Repository.Data;
|
||||
using Refit;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Persistence.IntegrationTests.Clients;
|
||||
public interface ITimeSeriesClient<TDto>
|
||||
@ -7,7 +13,4 @@ public interface ITimeSeriesClient<TDto>
|
||||
{
|
||||
[Post("/api/dataSaub")]
|
||||
Task<IApiResponse<int>> InsertRangeAsync(IEnumerable<TDto> dtos);
|
||||
|
||||
[Get("/api/dataSaub")]
|
||||
Task<IApiResponse<IEnumerable<TDto>>> GetAsync(DateTimeOffset dateBegin, DateTimeOffset dateEnd);
|
||||
}
|
||||
|
@ -1,56 +1,36 @@
|
||||
using Persistence.Database.Model;
|
||||
using Persistence.Repository.Data;
|
||||
using Persistence.Repository.Data;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
|
||||
namespace Persistence.IntegrationTests.Controllers;
|
||||
public class DataSaubControllerTest : TimeSeriesBaseControllerTest<DataSaub, DataSaubDto>
|
||||
public class DataSaubControllerTest : TimeSeriesBaseControllerTest<DataSaubDto>
|
||||
{
|
||||
private readonly DataSaubDto dto = new DataSaubDto()
|
||||
{
|
||||
AxialLoad = 1,
|
||||
BitDepth = 2,
|
||||
BlockPosition = 3,
|
||||
BlockSpeed = 4,
|
||||
Date = DateTimeOffset.Now,
|
||||
Flow = 5,
|
||||
HookWeight = 6,
|
||||
Id = 7,
|
||||
IdFeedRegulator = 8,
|
||||
Mode = 9,
|
||||
Mse = 10,
|
||||
MseState = 11,
|
||||
Pressure = 12,
|
||||
Pump0Flow = 13,
|
||||
Pump1Flow = 14,
|
||||
Pump2Flow = 15,
|
||||
RotorSpeed = 16,
|
||||
RotorTorque = 17,
|
||||
User = string.Empty,
|
||||
WellDepth = 18,
|
||||
};
|
||||
|
||||
private readonly DataSaub entity = new DataSaub()
|
||||
{
|
||||
AxialLoad = 1,
|
||||
BitDepth = 2,
|
||||
BlockPosition = 3,
|
||||
BlockSpeed = 4,
|
||||
Date = DateTimeOffset.UtcNow,
|
||||
Flow = 5,
|
||||
HookWeight = 6,
|
||||
Id = 7,
|
||||
IdFeedRegulator = 8,
|
||||
Mode = 9,
|
||||
Mse = 10,
|
||||
MseState = 11,
|
||||
Pressure = 12,
|
||||
Pump0Flow = 13,
|
||||
Pump1Flow = 14,
|
||||
Pump2Flow = 15,
|
||||
RotorSpeed = 16,
|
||||
RotorTorque = 17,
|
||||
User = string.Empty,
|
||||
WellDepth = 18,
|
||||
AxialLoad = 1,
|
||||
BitDepth = 2,
|
||||
BlockPosition = 3,
|
||||
BlockSpeed = 4,
|
||||
Date = DateTimeOffset.Now,
|
||||
Flow = 5,
|
||||
HookWeight = 6,
|
||||
Id = 7,
|
||||
IdFeedRegulator = 8,
|
||||
Mode = 9,
|
||||
Mse = 10,
|
||||
MseState = 11,
|
||||
Pressure = 12,
|
||||
Pump0Flow = 13,
|
||||
Pump1Flow = 14,
|
||||
Pump2Flow = 15,
|
||||
RotorSpeed = 16,
|
||||
RotorTorque = 17,
|
||||
User = string.Empty,
|
||||
WellDepth = 18,
|
||||
};
|
||||
|
||||
public DataSaubControllerTest(WebAppFactoryFixture factory) : base(factory)
|
||||
@ -62,12 +42,4 @@ public class DataSaubControllerTest : TimeSeriesBaseControllerTest<DataSaub, Dat
|
||||
{
|
||||
await InsertRangeSuccess(dto);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Get_returns_success()
|
||||
{
|
||||
var beginDate = DateTimeOffset.UtcNow.AddDays(-1);
|
||||
var endDate = DateTimeOffset.UtcNow;
|
||||
await GetSuccess(beginDate, endDate, entity);
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
using Mapster;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration.UserSecrets;
|
||||
using Persistence.IntegrationTests.Clients;
|
||||
using Persistence.Models;
|
||||
using System;
|
||||
@ -13,15 +12,14 @@ using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
|
||||
namespace Persistence.IntegrationTests.Controllers;
|
||||
public abstract class TimeSeriesBaseControllerTest<TEntity, TDto> : BaseIntegrationTest
|
||||
where TEntity : class
|
||||
public abstract class TimeSeriesBaseControllerTest<TDto> : BaseIntegrationTest
|
||||
where TDto : class, new()
|
||||
{
|
||||
private ITimeSeriesClient<TDto> client;
|
||||
|
||||
public TimeSeriesBaseControllerTest(WebAppFactoryFixture factory) : base(factory)
|
||||
{
|
||||
dbContext.CleanupDbSet<TEntity>();
|
||||
//dbContext.CleanupDbSet<TEntity>();
|
||||
client = factory.GetHttpClient<ITimeSeriesClient<TDto>>(string.Empty);
|
||||
}
|
||||
|
||||
@ -36,22 +34,18 @@ public abstract class TimeSeriesBaseControllerTest<TEntity, TDto> : BaseIntegrat
|
||||
//assert
|
||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||
Assert.Equal(1, response.Content);
|
||||
}
|
||||
|
||||
public async Task GetSuccess(DateTimeOffset beginDate, DateTimeOffset endDate, TEntity entity)
|
||||
{
|
||||
//arrange
|
||||
var dbset = dbContext.Set<TEntity>();
|
||||
//var entity = GetByWellId();
|
||||
|
||||
dbset.Add(entity);
|
||||
//Assert.NotNull(entity);
|
||||
|
||||
dbContext.SaveChanges();
|
||||
//var actual = entity.Adapt<ChangeLogDto<TDto>>();
|
||||
//Assert.Equal(ProcessMapPlanBase.IdStateActual, actual.IdState);
|
||||
|
||||
var response = await client.GetAsync(beginDate, endDate);
|
||||
|
||||
//assert
|
||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||
Assert.NotNull(response.Content);
|
||||
Assert.Single(response.Content);
|
||||
//var excludeProps = new[] {
|
||||
// nameof(ProcessMapPlanBaseDto.Id),
|
||||
// nameof(ProcessMapPlanBaseDto.Section)
|
||||
//};
|
||||
//MatchHelper.Match(expected, actual.Item, excludeProps);
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +0,0 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Persistence.Database.Model;
|
||||
|
||||
namespace Persistence.IntegrationTests;
|
||||
public static class EFCoreExtensions
|
||||
{
|
||||
public static void CleanupDbSet<T>(this DbContext dbContext)
|
||||
where T : class
|
||||
{
|
||||
var dbset = dbContext.Set<T>();
|
||||
dbset.RemoveRange(dbset);
|
||||
dbContext.SaveChanges();
|
||||
}
|
||||
}
|
@ -4,9 +4,9 @@ using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Persistence.Database.Model;
|
||||
using Persistence.Database.Postgres;
|
||||
using Persistence.API;
|
||||
using Refit;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Text.Json;
|
||||
using Persistence.Database.Postgres;
|
||||
|
||||
|
@ -1,12 +1,14 @@
|
||||
using Mapster;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Persistence.Database.Model;
|
||||
using Persistence.Models;
|
||||
using Persistence.Repositories;
|
||||
using Persistence.Database.Model;
|
||||
using Persistence.Repository.Data;
|
||||
using Persistence.Database;
|
||||
|
||||
namespace Persistence.Repository.Repositories;
|
||||
public class TimeSeriesDataRepository<TEntity, TDto> : ITimeSeriesDataRepository<TDto>
|
||||
where TEntity : class, ITimestampedData, new()
|
||||
where TEntity : class
|
||||
where TDto : class, ITimeSeriesAbstractDto, new()
|
||||
{
|
||||
private DbContext db;
|
||||
@ -27,27 +29,14 @@ public class TimeSeriesDataRepository<TEntity, TDto> : ITimeSeriesDataRepository
|
||||
return dtos;
|
||||
}
|
||||
|
||||
public async Task<DatesRangeDto> GetDatesRangeAsync(CancellationToken token)
|
||||
public Task<DatesRangeDto> GetDatesRangeAsync(CancellationToken token)
|
||||
{
|
||||
var query = GetQueryReadOnly();
|
||||
var minDate = await query.MinAsync(o => o.Date, token);
|
||||
var maxDate = await query.MaxAsync(o => o.Date, token);
|
||||
|
||||
return new DatesRangeDto
|
||||
{
|
||||
From = minDate,
|
||||
To = maxDate
|
||||
};
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<TDto>> GetGtDate(DateTimeOffset date, CancellationToken token)
|
||||
public Task<IEnumerable<TDto>> GetGtDate(DateTimeOffset date, CancellationToken token)
|
||||
{
|
||||
var query = this.db.Set<TEntity>().Where(e => e.Date > date);
|
||||
var entities = await query.ToArrayAsync(token);
|
||||
|
||||
var dtos = entities.Select(e => e.Adapt<TDto>());
|
||||
|
||||
return dtos;
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public async Task<int> InsertRange(IEnumerable<TDto> dtos, CancellationToken token)
|
||||
|
@ -5,19 +5,9 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Persistence.Models;
|
||||
|
||||
/// <summary>
|
||||
/// Диапазон дат
|
||||
/// </summary>
|
||||
public class DatesRangeDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Дата начала диапазона
|
||||
/// </summary>
|
||||
public DateTimeOffset From { get; set; }
|
||||
public DateTimeOffset dateBegin { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Дата окончания диапазона
|
||||
/// </summary>
|
||||
public DateTimeOffset To { get; set; }
|
||||
public DateTimeOffset dateEnd { get; set; }
|
||||
}
|
||||
|
@ -1,4 +1,10 @@
|
||||
namespace Persistence.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Persistence.Models;
|
||||
|
||||
/// <summary>
|
||||
/// Интерфейс, описывающий временные данные
|
||||
|
@ -1,23 +1,10 @@
|
||||
namespace Persistence.Models;
|
||||
|
||||
/// <summary>
|
||||
/// Контейнер для поддержки постраничного просмотра таблиц
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
public class RequestDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Кол-во записей пропущенных с начала таблицы в запросе от api
|
||||
/// </summary>
|
||||
public int Skip { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Кол-во записей в запросе от api
|
||||
/// </summary>
|
||||
public int Take { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Настройки сортировки
|
||||
/// </summary>
|
||||
public string SortSettings { get; set; } = string.Empty;
|
||||
}
|
||||
|
@ -1,17 +1,12 @@
|
||||
namespace Persistence.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
/// <summary>
|
||||
/// Модель для описания лога уставки
|
||||
/// </summary>
|
||||
namespace Persistence.Models;
|
||||
public class SetpointLogDto : SetpointValueDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Дата сохранения уставки
|
||||
/// </summary>
|
||||
public DateTimeOffset Created { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Ключ пользователя
|
||||
/// </summary>
|
||||
public int IdUser { get; set; }
|
||||
}
|
||||
|
@ -1,18 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Persistence.Models;
|
||||
|
||||
/// <summary>
|
||||
/// Модель для хранения значения уставки
|
||||
/// </summary>
|
||||
public class SetpointValueDto
|
||||
{
|
||||
/// Идентификатор уставки
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public Guid Key { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Значение уставки
|
||||
/// </summary>
|
||||
public required object Value { get; set; }
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,11 @@
|
||||
namespace Persistence.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
/// <summary>
|
||||
/// Модель, описывающая пользователя
|
||||
/// </summary>
|
||||
namespace Persistence.Models;
|
||||
public class UserDto
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
|
@ -1,4 +1,4 @@
|
||||
using Persistence.Models;
|
||||
using Persistence.Models;
|
||||
|
||||
namespace Persistence.Repositories;
|
||||
|
||||
|
@ -1,12 +1,12 @@
|
||||
namespace Persistence.Services;
|
||||
|
||||
/// <summary>
|
||||
/// Сервис по работе с БД
|
||||
///
|
||||
/// </summary>
|
||||
internal interface IArchiveService
|
||||
{
|
||||
/// <summary>
|
||||
/// Переименование БД
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="connectionString"></param>
|
||||
/// <param name="databaseName"></param>
|
||||
@ -15,7 +15,7 @@ internal interface IArchiveService
|
||||
Task RenameDatabase(string connectionString, string databaseName, CancellationToken token);
|
||||
|
||||
/// <summary>
|
||||
/// Создание БД
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="connectionString"></param>
|
||||
/// <param name="databaseName"></param>
|
||||
|
@ -1,5 +1,4 @@
|
||||
namespace Persistence.Services;
|
||||
|
||||
public interface ITimeSeriesDataObserverService
|
||||
{
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user