using RobotNet10.RobotApp.Interfaces; namespace RobotNet10.RobotApp.Modules; public static class PlcApiEndpoints { // PLC Lift module API (giao diện sửa: homing, velocity, position — 10000 = 0.01m) public static IEndpointRouteBuilder MapPlcApiEndpoints(this IEndpointRouteBuilder app) { var plcApi = app.MapGroup("/api/plc").DisableAntiforgery(); plcApi.MapPost("/lift/homing", (IPlcController plc) => { plc.LiftHoming(); return Results.Ok(new { status = "ok", message = "Lift homing triggered" }); }); plcApi.MapPost("/lift/velocity", async (HttpRequest req, IPlcController plc) => { var body = await req.ReadFromJsonAsync(); if (body == null) return Results.BadRequest(new { status = "error", message = "Body required: { up: bool, down: bool }" }); plc.SetLiftVelocity(body.Up, body.Down); return Results.Ok(new { status = "ok", up = body.Up, down = body.Down }); }); plcApi.MapPost("/lift/position", async (HttpRequest req, IPlcController plc) => { var body = await req.ReadFromJsonAsync(); if (body == null) return Results.BadRequest(new { status = "error", message = "Body required: { position: int } (10000 = 0.01m)" }); plc.SetLiftPositionAndGo(body.Position); return Results.Ok(new { status = "ok", position = body.Position }); }); return app; } } // DTOs for PLC Lift API public record LiftVelocityRequest(bool Up, bool Down); public record LiftPositionRequest(int Position);