feat: 完成同義詞功能資料流程修復

## 主要修復
- 修復 Flashcard Entity 添加 Synonyms 欄位支援 JSON 格式同義詞存儲
- 更新 CreateFlashcardRequest 支援 Synonyms 陣列傳遞
- 修改 FlashcardsController 處理同義詞序列化到資料庫
- 創建資料庫 Migration 添加 Synonyms 欄位

## 資料流程完善
- AI 分析生成 synonyms → VocabularyAnalysisDto → CreateFlashcardRequest → JSON 序列化 → 資料庫儲存
- 確保 AI 生成的同義詞資料不會遺失
- 支援完整的同義詞 CRUD 操作

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
鄭沛軒 2025-09-28 16:14:20 +08:00
parent 197648f476
commit f5cce0a228
5 changed files with 1544 additions and 0 deletions

View File

@ -260,6 +260,9 @@ public class FlashcardsController : ControllerBase
Pronunciation = request.Pronunciation, Pronunciation = request.Pronunciation,
Example = request.Example, Example = request.Example,
ExampleTranslation = request.ExampleTranslation, ExampleTranslation = request.ExampleTranslation,
Synonyms = request.Synonyms != null && request.Synonyms.Any()
? System.Text.Json.JsonSerializer.Serialize(request.Synonyms)
: null,
MasteryLevel = 0, MasteryLevel = 0,
TimesReviewed = 0, TimesReviewed = 0,
IsFavorite = false, IsFavorite = false,
@ -671,4 +674,5 @@ public class CreateFlashcardRequest
public string Pronunciation { get; set; } = string.Empty; public string Pronunciation { get; set; } = string.Empty;
public string Example { get; set; } = string.Empty; public string Example { get; set; } = string.Empty;
public string? ExampleTranslation { get; set; } public string? ExampleTranslation { get; set; }
public List<string>? Synonyms { get; set; }
} }

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,29 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace DramaLing.Api.Migrations
{
/// <inheritdoc />
public partial class AddSynonymsToFlashcard : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "Synonyms",
table: "flashcards",
type: "TEXT",
maxLength: 2000,
nullable: true);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "Synonyms",
table: "flashcards");
}
}
}

View File

@ -372,6 +372,10 @@ namespace DramaLing.Api.Migrations
b.Property<string>("ReviewHistory") b.Property<string>("ReviewHistory")
.HasColumnType("TEXT"); .HasColumnType("TEXT");
b.Property<string>("Synonyms")
.HasMaxLength(2000)
.HasColumnType("TEXT");
b.Property<int>("TimesCorrect") b.Property<int>("TimesCorrect")
.HasColumnType("INTEGER") .HasColumnType("INTEGER")
.HasColumnName("times_correct"); .HasColumnName("times_correct");

View File

@ -32,6 +32,9 @@ public class Flashcard
[MaxLength(1000)] [MaxLength(1000)]
public string? FilledQuestionText { get; set; } public string? FilledQuestionText { get; set; }
[MaxLength(2000)]
public string? Synonyms { get; set; } // JSON 格式儲存同義詞列表
// SM-2 算法參數 // SM-2 算法參數
public float EasinessFactor { get; set; } = 2.5f; public float EasinessFactor { get; set; } = 2.5f;