feat(prime): add PrimeActionKind to the schedule entity
This commit is contained in:
@@ -1,11 +1,27 @@
|
||||
using ClaudeDo.Data.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
namespace ClaudeDo.Data.Configuration;
|
||||
|
||||
public class PrimeScheduleEntityConfiguration : IEntityTypeConfiguration<PrimeScheduleEntity>
|
||||
{
|
||||
private static string KindToString(PrimeActionKind v)
|
||||
=> v == PrimeActionKind.Ping ? "ping"
|
||||
: v == PrimeActionKind.FillMyDay ? "fill_my_day"
|
||||
: v == PrimeActionKind.Custom ? "custom"
|
||||
: throw new ArgumentOutOfRangeException(nameof(v));
|
||||
|
||||
private static PrimeActionKind KindFromString(string v)
|
||||
=> v == "ping" ? PrimeActionKind.Ping
|
||||
: v == "fill_my_day" ? PrimeActionKind.FillMyDay
|
||||
: v == "custom" ? PrimeActionKind.Custom
|
||||
: throw new ArgumentOutOfRangeException(nameof(v));
|
||||
|
||||
private static readonly ValueConverter<PrimeActionKind, string> KindConverter =
|
||||
new(v => KindToString(v), v => KindFromString(v));
|
||||
|
||||
public void Configure(EntityTypeBuilder<PrimeScheduleEntity> builder)
|
||||
{
|
||||
builder.ToTable("prime_schedules");
|
||||
@@ -15,6 +31,9 @@ public class PrimeScheduleEntityConfiguration : IEntityTypeConfiguration<PrimeSc
|
||||
|
||||
builder.Property(s => s.Days).HasColumnName("days_of_week")
|
||||
.IsRequired().HasDefaultValue(PrimeDays.Weekdays);
|
||||
builder.Property(s => s.Kind).HasColumnName("action_kind")
|
||||
.IsRequired().HasDefaultValue(PrimeActionKind.Ping)
|
||||
.HasConversion(KindConverter);
|
||||
builder.Property(s => s.TimeOfDay).HasColumnName("time_of_day").IsRequired();
|
||||
builder.Property(s => s.Enabled).HasColumnName("enabled").IsRequired().HasDefaultValue(true);
|
||||
builder.Property(s => s.LastRunAt).HasColumnName("last_run_at");
|
||||
|
||||
Reference in New Issue
Block a user