[CLAUDE] App+Api: 7 Details CRUD endpoints + Changelogs query
All checks were successful
Deploy SOLUTION_ERP / build-deploy (push) Successful in 2m37s
All checks were successful
Deploy SOLUTION_ERP / build-deploy (push) Successful in 2m37s
## DTOs (Application/Contracts/Dtos/ContractDetailDtos.cs)
- 7 typed DTOs (ThauPhuDetailDto, GiaoKhoanDetailDto, NhaCungCapDetailDto,
DichVuDetailDto, MuaBanDetailDto, NguyenTacNccDetailDto,
NguyenTacDvDetailDto) — schema 1-1 với Domain entities
- ContractDetailsBundleDto — wrapper trả về theo Type, chỉ 1 list có data
(FE đọc field tương ứng, tránh polymorphic deserialize phức tạp)
- ContractChangelogDto — full audit entry
## CQRS (Application/Contracts/ContractDetailsFeatures.cs)
- GetContractDetailsQuery — load bundle, switch theo Contract.Type chỉ
query bảng tương ứng (avoid 7 query waste)
- 7 AddXxxDetailCommand handlers — typed payload + EnsureContractType
guard (throw ConflictException nếu Contract.Type sai)
- DeleteContractDetailCommand generic — dispatch xóa theo Type, log change
- Tất cả handler call IChangelogService.LogDetailChangeAsync với summary
human-readable (vd "Thêm hạng mục: Đào móng")
## CQRS (Application/Contracts/ContractChangelogFeatures.cs)
- ListContractChangelogsQuery (read-only) — desc CreatedAt, default top 200
## Controller (Api/Controllers/ContractsController.cs)
8 endpoints mới:
- GET /api/contracts/{id}/details → bundle theo Type
- POST /api/contracts/{id}/details/{thau-phu|giao-khoan|nha-cung-cap|
dich-vu|mua-ban|nguyen-tac-ncc|nguyen-tac-dv} → 7 typed POST
- DELETE /api/contracts/{id}/details/{detailId} → generic delete
- GET /api/contracts/{id}/changelogs → list audit entries
Build: dotnet pass (0 error)
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@ -101,6 +101,74 @@ public class ContractsController(IMediator mediator) : ControllerBase
|
||||
await mediator.Send(new DeleteContractAttachmentCommand(id, attId), ct);
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
// ========== Details (per ContractType) ==========
|
||||
|
||||
[HttpGet("{id:guid}/details")]
|
||||
public async Task<ContractDetailsBundleDto> GetDetails(Guid id, CancellationToken ct)
|
||||
=> await mediator.Send(new GetContractDetailsQuery(id), ct);
|
||||
|
||||
[HttpPost("{id:guid}/details/thau-phu")]
|
||||
public async Task<IActionResult> AddThauPhuDetail(Guid id, [FromBody] ThauPhuDetailDto body, CancellationToken ct)
|
||||
{
|
||||
var newId = await mediator.Send(new AddThauPhuDetailCommand(id, body), ct);
|
||||
return CreatedAtAction(nameof(GetDetails), new { id }, new { id = newId });
|
||||
}
|
||||
|
||||
[HttpPost("{id:guid}/details/giao-khoan")]
|
||||
public async Task<IActionResult> AddGiaoKhoanDetail(Guid id, [FromBody] GiaoKhoanDetailDto body, CancellationToken ct)
|
||||
{
|
||||
var newId = await mediator.Send(new AddGiaoKhoanDetailCommand(id, body), ct);
|
||||
return CreatedAtAction(nameof(GetDetails), new { id }, new { id = newId });
|
||||
}
|
||||
|
||||
[HttpPost("{id:guid}/details/nha-cung-cap")]
|
||||
public async Task<IActionResult> AddNhaCungCapDetail(Guid id, [FromBody] NhaCungCapDetailDto body, CancellationToken ct)
|
||||
{
|
||||
var newId = await mediator.Send(new AddNhaCungCapDetailCommand(id, body), ct);
|
||||
return CreatedAtAction(nameof(GetDetails), new { id }, new { id = newId });
|
||||
}
|
||||
|
||||
[HttpPost("{id:guid}/details/dich-vu")]
|
||||
public async Task<IActionResult> AddDichVuDetail(Guid id, [FromBody] DichVuDetailDto body, CancellationToken ct)
|
||||
{
|
||||
var newId = await mediator.Send(new AddDichVuDetailCommand(id, body), ct);
|
||||
return CreatedAtAction(nameof(GetDetails), new { id }, new { id = newId });
|
||||
}
|
||||
|
||||
[HttpPost("{id:guid}/details/mua-ban")]
|
||||
public async Task<IActionResult> AddMuaBanDetail(Guid id, [FromBody] MuaBanDetailDto body, CancellationToken ct)
|
||||
{
|
||||
var newId = await mediator.Send(new AddMuaBanDetailCommand(id, body), ct);
|
||||
return CreatedAtAction(nameof(GetDetails), new { id }, new { id = newId });
|
||||
}
|
||||
|
||||
[HttpPost("{id:guid}/details/nguyen-tac-ncc")]
|
||||
public async Task<IActionResult> AddNguyenTacNccDetail(Guid id, [FromBody] NguyenTacNccDetailDto body, CancellationToken ct)
|
||||
{
|
||||
var newId = await mediator.Send(new AddNguyenTacNccDetailCommand(id, body), ct);
|
||||
return CreatedAtAction(nameof(GetDetails), new { id }, new { id = newId });
|
||||
}
|
||||
|
||||
[HttpPost("{id:guid}/details/nguyen-tac-dv")]
|
||||
public async Task<IActionResult> AddNguyenTacDvDetail(Guid id, [FromBody] NguyenTacDvDetailDto body, CancellationToken ct)
|
||||
{
|
||||
var newId = await mediator.Send(new AddNguyenTacDvDetailCommand(id, body), ct);
|
||||
return CreatedAtAction(nameof(GetDetails), new { id }, new { id = newId });
|
||||
}
|
||||
|
||||
[HttpDelete("{id:guid}/details/{detailId:guid}")]
|
||||
public async Task<IActionResult> DeleteDetail(Guid id, Guid detailId, CancellationToken ct)
|
||||
{
|
||||
await mediator.Send(new DeleteContractDetailCommand(id, detailId), ct);
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
// ========== Changelogs (read-only) ==========
|
||||
|
||||
[HttpGet("{id:guid}/changelogs")]
|
||||
public async Task<List<ContractChangelogDto>> GetChangelogs(Guid id, CancellationToken ct)
|
||||
=> await mediator.Send(new ListContractChangelogsQuery(id), ct);
|
||||
}
|
||||
|
||||
public record TransitionContractBody(ContractPhase TargetPhase, ApprovalDecision Decision, string? Comment);
|
||||
|
||||
Reference in New Issue
Block a user