diff --git a/CH.CryptoStats.CoinGecko/CoinGeckoService.cs b/CH.CryptoStats.CoinGecko/CoinGeckoService.cs
index 1daecdc..915974e 100644
--- a/CH.CryptoStats.CoinGecko/CoinGeckoService.cs
+++ b/CH.CryptoStats.CoinGecko/CoinGeckoService.cs
@@ -2,7 +2,7 @@
using Microsoft.Extensions.Configuration;
using System.Net.Http.Json;
using System.Text.Json;
-using CH.Energy.Abstractions.Enum;
+using CH.Enum;
namespace CH.CryptoStats.CoinGecko;
diff --git a/CH.CryptoStats.CoinMarketCap/CoinMarketCapService.cs b/CH.CryptoStats.CoinMarketCap/CoinMarketCapService.cs
index fa1c7c2..a1c79cc 100644
--- a/CH.CryptoStats.CoinMarketCap/CoinMarketCapService.cs
+++ b/CH.CryptoStats.CoinMarketCap/CoinMarketCapService.cs
@@ -2,7 +2,7 @@
using Microsoft.Extensions.Configuration;
using System.Net.Http.Json;
using System.Text.Json;
-using CH.Energy.Abstractions.Enum;
+using CH.Enum;
namespace CH.CryptoStats.CoinMarketCap;
diff --git a/CH.CryptoStats/CryptoStats.cs b/CH.CryptoStats/CryptoStats.cs
index f589b0f..6eb90f9 100644
--- a/CH.CryptoStats/CryptoStats.cs
+++ b/CH.CryptoStats/CryptoStats.cs
@@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
-using CH.Energy.Abstractions.Enum;
+using CH.Enum;
namespace CH.CryptoStats.Abstractions;
diff --git a/CH.Dal/CH.Dal.csproj b/CH.Dal/CH.Dal.csproj
index 8220973..953227d 100644
--- a/CH.Dal/CH.Dal.csproj
+++ b/CH.Dal/CH.Dal.csproj
@@ -17,5 +17,8 @@
+
+
+
diff --git a/CH.Dal/CHDbContext.cs b/CH.Dal/CHDbContext.cs
index 1cbec35..c77e635 100644
--- a/CH.Dal/CHDbContext.cs
+++ b/CH.Dal/CHDbContext.cs
@@ -1,18 +1,33 @@
using Microsoft.EntityFrameworkCore;
using Npgsql;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
+using CH.Dal.DbEntity;
+using CH.Enum;
namespace CH.Dal;
public class CHDbContext(DbContextOptions options) : CHDbScaffoldedContext(options)
{
+ static CHDbContext() => NpgsqlConnection.GlobalTypeMapper
+ .MapEnum("currency")
+ .MapEnum("energy_rate_exception_treshold_reset_type");
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
+ modelBuilder.HasPostgresEnum("currency");
+ modelBuilder.HasPostgresEnum("energy_rate_exception_treshold_reset_type");
+
+ modelBuilder.Entity(entity =>
+ {
+ entity.Property(e => e.Currency)
+ .HasColumnName("currency")
+ .HasColumnType("currency");
+ });
+ modelBuilder.Entity(entity =>
+ {
+ entity.Property(e => e.ResetType)
+ .HasColumnName("reset_type")
+ .HasColumnType("energy_rate_exception_treshold_reset_type");
+ });
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
diff --git a/CH.Dal/CHDbScaffoldedContext.cs b/CH.Dal/CHDbScaffoldedContext.cs
index 32bf991..50756ff 100644
--- a/CH.Dal/CHDbScaffoldedContext.cs
+++ b/CH.Dal/CHDbScaffoldedContext.cs
@@ -16,6 +16,12 @@ public partial class CHDbScaffoldedContext : DbContext
{
}
+ public virtual DbSet EnergyProviders { get; set; }
+
+ public virtual DbSet EnergyRates { get; set; }
+
+ public virtual DbSet EnergyRateExceptions { get; set; }
+
public virtual DbSet Locations { get; set; }
public virtual DbSet Machines { get; set; }
@@ -27,6 +33,72 @@ public partial class CHDbScaffoldedContext : DbContext
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
+ modelBuilder
+ .HasPostgresEnum("currency", new[] { "USD", "CAD" })
+ .HasPostgresEnum("energy_rate_exception_treshold_reset_type", new[] { "daily" });
+
+ modelBuilder.Entity(entity =>
+ {
+ entity.HasKey(e => e.Id).HasName("energy_provider_pkey");
+
+ entity.ToTable("energy_provider");
+
+ entity.Property(e => e.Id).HasColumnName("id");
+ entity.Property(e => e.CreatedAt)
+ .HasDefaultValueSql("(CURRENT_TIMESTAMP AT TIME ZONE 'UTC'::text)")
+ .HasColumnName("created_at");
+ entity.Property(e => e.Name)
+ .HasMaxLength(255)
+ .HasColumnName("name");
+ entity.Property(e => e.UpdatedAt).HasColumnName("updated_at");
+ });
+
+ modelBuilder.Entity(entity =>
+ {
+ entity.HasKey(e => e.Id).HasName("energy_rate_pkey");
+
+ entity.ToTable("energy_rate");
+
+ entity.Property(e => e.Id).HasColumnName("id");
+ entity.Property(e => e.CreatedAt)
+ .HasDefaultValueSql("(CURRENT_TIMESTAMP AT TIME ZONE 'UTC'::text)")
+ .HasColumnName("created_at");
+ entity.Property(e => e.Name)
+ .HasMaxLength(255)
+ .HasColumnName("name");
+ entity.Property(e => e.Price).HasColumnName("price");
+ entity.Property(e => e.ProviderId).HasColumnName("provider_id");
+ entity.Property(e => e.UpdatedAt).HasColumnName("updated_at");
+
+ entity.HasOne(d => d.Provider).WithMany(p => p.EnergyRates)
+ .HasForeignKey(d => d.ProviderId)
+ .HasConstraintName("energy_rate_provider_id_fkey");
+ });
+
+ modelBuilder.Entity(entity =>
+ {
+ entity.HasKey(e => e.Id).HasName("energy_rate_exception_pkey");
+
+ entity.ToTable("energy_rate_exception");
+
+ entity.Property(e => e.Id).HasColumnName("id");
+ entity.Property(e => e.CreatedAt)
+ .HasDefaultValueSql("(CURRENT_TIMESTAMP AT TIME ZONE 'UTC'::text)")
+ .HasColumnName("created_at");
+ entity.Property(e => e.EndedAt).HasColumnName("ended_at");
+ entity.Property(e => e.EnergyTreshold).HasColumnName("energy_treshold");
+ entity.Property(e => e.Name)
+ .HasMaxLength(255)
+ .HasColumnName("name");
+ entity.Property(e => e.RateId).HasColumnName("rate_id");
+ entity.Property(e => e.StartedAt).HasColumnName("started_at");
+ entity.Property(e => e.UpdatedAt).HasColumnName("updated_at");
+
+ entity.HasOne(d => d.Rate).WithMany(p => p.EnergyRateExceptions)
+ .HasForeignKey(d => d.RateId)
+ .HasConstraintName("energy_rate_exception_rate_id_fkey");
+ });
+
modelBuilder.Entity(entity =>
{
entity.HasKey(e => e.Id).HasName("location_pkey");
diff --git a/CH.Dal/DbEntity/EnergyProvider.cs b/CH.Dal/DbEntity/EnergyProvider.cs
new file mode 100644
index 0000000..9e558ac
--- /dev/null
+++ b/CH.Dal/DbEntity/EnergyProvider.cs
@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+
+namespace CH.Dal.DbEntity;
+
+public partial class EnergyProvider
+{
+ public long Id { get; set; }
+
+ public string Name { get; set; } = null!;
+
+ public DateTime CreatedAt { get; set; }
+
+ public DateTime? UpdatedAt { get; set; }
+
+ public virtual ICollection EnergyRates { get; set; } = new List();
+}
diff --git a/CH.Dal/DbEntity/EnergyRate.Extension.cs b/CH.Dal/DbEntity/EnergyRate.Extension.cs
new file mode 100644
index 0000000..138f883
--- /dev/null
+++ b/CH.Dal/DbEntity/EnergyRate.Extension.cs
@@ -0,0 +1,10 @@
+using System.ComponentModel.DataAnnotations.Schema;
+using CH.Enum;
+
+namespace CH.Dal.DbEntity;
+
+public partial class EnergyRate
+{
+ [Column(TypeName = "currency")]
+ public Currency Currency { get; set; }
+}
\ No newline at end of file
diff --git a/CH.Dal/DbEntity/EnergyRate.cs b/CH.Dal/DbEntity/EnergyRate.cs
new file mode 100644
index 0000000..0a8c54e
--- /dev/null
+++ b/CH.Dal/DbEntity/EnergyRate.cs
@@ -0,0 +1,23 @@
+using System;
+using System.Collections.Generic;
+
+namespace CH.Dal.DbEntity;
+
+public partial class EnergyRate
+{
+ public long Id { get; set; }
+
+ public long? ProviderId { get; set; }
+
+ public string Name { get; set; } = null!;
+
+ public decimal? Price { get; set; }
+
+ public DateTime CreatedAt { get; set; }
+
+ public DateTime? UpdatedAt { get; set; }
+
+ public virtual ICollection EnergyRateExceptions { get; set; } = new List();
+
+ public virtual EnergyProvider? Provider { get; set; }
+}
diff --git a/CH.Dal/DbEntity/EnergyRateException.Extension.cs b/CH.Dal/DbEntity/EnergyRateException.Extension.cs
new file mode 100644
index 0000000..6c9d7ae
--- /dev/null
+++ b/CH.Dal/DbEntity/EnergyRateException.Extension.cs
@@ -0,0 +1,9 @@
+using System.ComponentModel.DataAnnotations.Schema;
+using CH.Enum;
+namespace CH.Dal.DbEntity;
+
+public partial class EnergyRateException
+{
+ [Column(TypeName = "energy_rate_exception_treshold_reset_type")]
+ public EnergyRateExceptionTresholdResetType ResetType { get; set; }
+}
\ No newline at end of file
diff --git a/CH.Dal/DbEntity/EnergyRateException.cs b/CH.Dal/DbEntity/EnergyRateException.cs
new file mode 100644
index 0000000..fe8291a
--- /dev/null
+++ b/CH.Dal/DbEntity/EnergyRateException.cs
@@ -0,0 +1,25 @@
+using System;
+using System.Collections.Generic;
+
+namespace CH.Dal.DbEntity;
+
+public partial class EnergyRateException
+{
+ public long Id { get; set; }
+
+ public long? RateId { get; set; }
+
+ public string? Name { get; set; }
+
+ public decimal? EnergyTreshold { get; set; }
+
+ public DateTime? StartedAt { get; set; }
+
+ public DateTime? EndedAt { get; set; }
+
+ public DateTime CreatedAt { get; set; }
+
+ public DateTime? UpdatedAt { get; set; }
+
+ public virtual EnergyRate? Rate { get; set; }
+}
diff --git a/CH.Enum/CH.Enum.csproj b/CH.Enum/CH.Enum.csproj
index 3a63532..1dd7abd 100644
--- a/CH.Enum/CH.Enum.csproj
+++ b/CH.Enum/CH.Enum.csproj
@@ -5,5 +5,7 @@
enable
enable
-
+
+
+
diff --git a/CH.Enum/Currency.cs b/CH.Enum/Currency.cs
index 638c271..dab7c32 100644
--- a/CH.Enum/Currency.cs
+++ b/CH.Enum/Currency.cs
@@ -1,7 +1,10 @@
-namespace CH.Energy.Abstractions.Enum;
+using NpgsqlTypes;
+namespace CH.Enum;
public enum Currency
{
+ [PgName("USD")]
USD,
+ [PgName("CAD")]
CAD,
}
\ No newline at end of file
diff --git a/CH.Enum/EnergyRateExceptionTresholdResetType.cs b/CH.Enum/EnergyRateExceptionTresholdResetType.cs
new file mode 100644
index 0000000..915dc1e
--- /dev/null
+++ b/CH.Enum/EnergyRateExceptionTresholdResetType.cs
@@ -0,0 +1,9 @@
+using NpgsqlTypes;
+
+namespace CH.Enum;
+
+public enum EnergyRateExceptionTresholdResetType
+{
+ [PgName("daily")]
+ Daily,
+}
\ No newline at end of file