Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion SnakeAid.Core/Domains/FirstAidGuideline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class FirstAidGuideline : BaseEntity

[Required]
[Column(TypeName = "jsonb")]
public string Content { get; set; }
public FirstAidContent Content { get; set; }

[Required]
public GuidelineType Type { get; set; } = GuidelineType.General;
Expand All @@ -29,4 +29,18 @@ public class FirstAidGuideline : BaseEntity
public string? Summary { get; set; } // Tóm tắt ngắn

}

public class FirstAidContent
{
public List<FirstAidStep> Steps { get; set; } = new();
public List<FirstAidStep> Dos { get; set; } = new();
public List<FirstAidStep> Donts { get; set; } = new();
public List<string> Notes { get; set; } = new();
}

public class FirstAidStep
{
public string Text { get; set; }
public string MediaUrl { get; set; }
}
}
2 changes: 2 additions & 0 deletions SnakeAid.Core/Domains/SpeciesVenom.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text.Json.Serialization;
using System.Threading.Tasks;

namespace SnakeAid.Core.Domains
Expand All @@ -19,6 +20,7 @@ public class SpeciesVenom


public VenomType VenomType { get; set; }
[JsonIgnore]
public SnakeSpecies SnakeSpecies { get; set; }
}
}
3 changes: 3 additions & 0 deletions SnakeAid.Core/Domains/VenomType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text.Json.Serialization;
using System.Threading.Tasks;

namespace SnakeAid.Core.Domains
Expand Down Expand Up @@ -35,7 +36,9 @@ public class VenomType : BaseEntity
public int FirstAidGuidelineId { get; set; }

// Navigation properties
[JsonIgnore]
public ICollection<SpeciesVenom> SpeciesVenoms { get; set; } = new List<SpeciesVenom>();
[JsonIgnore]
public ICollection<SymptomConfig> SymptomConfigs { get; set; } = new List<SymptomConfig>();

public FirstAidGuideline FirstAidGuideline { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class CreateFirstAidGuidelineRequest
/// Nội dung chi tiết (JSON format)
/// </summary>
[Required(ErrorMessage = "Content is required")]
public object Content { get; set; }
public FirstAidContent Content { get; set; }

/// <summary>
/// Loại hướng dẫn: General (0) hoặc SpeciesSpecific (1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class UpdateFirstAidGuidelineRequest
/// <summary>
/// Nội dung chi tiết (JSON format)
/// </summary>
public object? Content { get; set; }
public FirstAidContent? Content { get; set; }

/// <summary>
/// Loại hướng dẫn: General (0) hoặc SpeciesSpecific (1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class FirstAidGuidelineResponse
{
public int Id { get; set; }
public string Name { get; set; }
public string Content { get; set; }
public FirstAidContent Content { get; set; }
public GuidelineType Type { get; set; }
public string? Summary { get; set; }
public DateTime CreatedAt { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using SnakeAid.Core.Domains;
using System.Text.Json;

namespace SnakeAid.Repository.Data.Configurations
{
Expand All @@ -10,6 +11,20 @@ public void Configure(EntityTypeBuilder<FirstAidGuideline> builder)
{
builder.ToTable("FirstAidGuidelines");

// JSON conversion for Content
var jsonOptions = new JsonSerializerOptions
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
WriteIndented = false
};

builder.Property(g => g.Content)
.HasConversion(
v => JsonSerializer.Serialize(v, jsonOptions),
v => JsonSerializer.Deserialize<FirstAidContent>(v, jsonOptions))
.HasColumnType("jsonb")
.IsRequired();

// Enum conversion
builder.Property(g => g.Type)
.HasConversion<int>()
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
namespace SnakeAid.Repository.Migrations
{
/// <inheritdoc />
public partial class SnakeAidMigration : Migration
public partial class SnakeAidMigratione : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
Expand Down Expand Up @@ -67,9 +67,6 @@ protected override void Up(MigrationBuilder migrationBuilder)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Version = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
Description = table.Column<string>(type: "character varying(1000)", maxLength: 1000, nullable: true),
EndpointUrl = table.Column<string>(type: "character varying(500)", maxLength: 500, nullable: false),
ApiKey = table.Column<string>(type: "character varying(200)", maxLength: 200, nullable: true),
ModelParameters = table.Column<string>(type: "jsonb", nullable: true),
IsActive = table.Column<bool>(type: "boolean", nullable: false),
IsDefault = table.Column<bool>(type: "boolean", nullable: false),
DeployedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
Expand Down Expand Up @@ -785,7 +782,6 @@ protected override void Up(MigrationBuilder migrationBuilder)
SnakeSpeciesId = table.Column<int>(type: "integer", nullable: false),
YoloClassName = table.Column<string>(type: "text", nullable: false),
YoloClassId = table.Column<int>(type: "integer", nullable: false),
Confidence = table.Column<decimal>(type: "numeric", nullable: false),
IsActive = table.Column<bool>(type: "boolean", nullable: false)
},
constraints: table =>
Expand Down
15 changes: 0 additions & 15 deletions SnakeAid.Repository/Migrations/SnakeAidDbContextModelSnapshot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,6 @@ protected override void BuildModel(ModelBuilder modelBuilder)

NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));

b.Property<string>("ApiKey")
.HasMaxLength(200)
.HasColumnType("character varying(200)");

b.Property<DateTime>("CreatedAt")
.HasColumnType("timestamp with time zone");

Expand All @@ -111,20 +107,12 @@ protected override void BuildModel(ModelBuilder modelBuilder)
.HasMaxLength(1000)
.HasColumnType("character varying(1000)");

b.Property<string>("EndpointUrl")
.IsRequired()
.HasMaxLength(500)
.HasColumnType("character varying(500)");

b.Property<bool>("IsActive")
.HasColumnType("boolean");

b.Property<bool>("IsDefault")
.HasColumnType("boolean");

b.Property<string>("ModelParameters")
.HasColumnType("jsonb");

b.Property<DateTime?>("RetiredAt")
.HasColumnType("timestamp with time zone");

Expand Down Expand Up @@ -160,9 +148,6 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.Property<int>("AIModelId")
.HasColumnType("integer");

b.Property<decimal>("Confidence")
.HasColumnType("numeric");

b.Property<bool>("IsActive")
.HasColumnType("boolean");

Expand Down
Loading