-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
47 lines (35 loc) · 1.07 KB
/
Program.cs
File metadata and controls
47 lines (35 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
using RobotTask;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
var app = builder.Build();
// Configure the HTTP request pipeline.
app.UseHttpsRedirection();
app.MapPost("/api/robot/move", (RobotInputRequest req) =>
{
try
{
var validInput = RobotInput.GetValidatedInput(req.Raw);
var robot = new Robot();
var result = robot.Move(validInput);
var dto = new RobotMoveResultDto(
new PositionDto(
result.Position.Column,
result.Position.Row,
result.Position.Dir.ToString()
)
);
return Results.Ok(dto);
}
catch (ArgumentException ex)
{
return Results.BadRequest(new
{
error = ex.Message,
message = "Invalid input. Expected: 'cols,rows,x,y,dir,actions' f.eks. '8,8,2,2,E,R'."
});
}
});
app.Run();
public record RobotInputRequest(string Raw);
public record PositionDto(int Column, int Row, string Direction);
public record RobotMoveResultDto(PositionDto Position);