mcpField
D
d1-06-crud-endpoints

d1-06-crud-endpoints

github.com/softinter-chiangrai開発046 回インストール9 週間前に更新
リポジトリ

d1-06-crud-endpoints について

移行済みエンティティの CRUD エンドポイントを追加し、アプリケーションを再デプロイする開発スキルです。作業前に対象エンティティの確認が必要です。

主な機能

  1. 01移行済みエンティティの事前確認
  2. 02ASP.NET コントローラーへの CRUD エンドポイント追加
  3. 03変更後の再デプロイ

活用シーン

  1. 01確認済みの移行エンティティ向け API 作成
  2. 02開発手順の続行と再デプロイ

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/softinter-chiangrai/up-ai-skill-training --skill d1-06-crud-endpoints

インストール後、Claude Code で/d1-06-crud-endpointsを入力して読み込まれたか確認します。

詳細

1 日目 · ステップ 6 — CRUD エンドポイントを作成してから再デプロイ

開始前: エンドポイントを作成するエンティティを確認してください(D1_05 で既にマイグレーション済みのものと一致する必要があります)。 確認せずに推測したり、作業を進めたりしないでください。

up-api/Controllers/<Entity>sController.cs:

[ApiController]
[Route("api/[controller]")]
public class <Entity>sController : ControllerBase
{
    private readonly AppDbContext _db;
    public <Entity>sController(AppDbContext db) => _db = db;

    [HttpGet]
    public async Task<IActionResult> All() => Ok(await _db.<Entity>s.ToListAsync());

    [HttpGet("detail/{id}")]
    public async Task<IActionResult> Detail(int id)
    {
        var item = await _db.<Entity>s.FindAsync(id);
        return item is null ? NotFound() : Ok(item);
    }

    [HttpPost("save")]
    public async Task<IActionResult> Save(<Entity> input)
    {
        _db.<Entity>s.Add(input);
        await _db.SaveChangesAsync();
        return Ok(input);
    }

    [HttpPut("update/{id}")]
    public async Task<IActionResult> Update(int id, <Entity> input)
    {
        var item = await _db.<Entity>s.FindAsync(id);
        if (item is null) return NotFound();
        // copy updated fields from input onto item
        await _db.SaveChangesAsync();
        return Ok(item);
    }

    [HttpDelete("{id}")]
    public async Task<IActionResult> Delete(int id)
    {
        var item = await _db.<Entity>s.FindAsync(id);
        if (item is null) return NotFound();
        _db.<Entity>s.Remove(item);
        await _db.SaveChangesAsync();
        return NoContent();
    }
}

コメント