I'm experimenting with a different REST API design. I created a new .Net 5 app with one model and two controllers
public sealed record Todo(string Title, string OwnedBy, bool IsDone = false);
public sealed class TodoQueriesController : ControllerBase
{
[HttpGet("my-todo-by-title/{title}")]
[ActionName(nameof(GetTodoFromAuthenticatedUserByTitle))]
public ActionResult<Todo> GetTodoFromAuthenticatedUserByTitle([FromRoute] string title)
{
string authenticatedUsername = "foo";
return Ok(new Todo(title, authenticatedUsername));
}
}
public sealed class TodoCommandsController : ControllerBase
{
[HttpPost("assign-todo-to-me")]
public ActionResult<Todo> AssignTodoToAuthenticatedUser([FromBody] string title)
{
string authenticatedUsername = "foo";
return CreatedAtAction("???", new { title }, new Todo(title, authenticatedUsername));
}
}
Currently I don't know what to pass in as an action name for the CreatedAtAction (to replace "???")
I tried
nameof(TodoQueriesController.GetTodoFromAuthenticatedUserByTitle)"GetTodoFromAuthenticatedUserByTitle""my-todo-by-title"$"my-todo-by-title/{title}"
but unfortunately I always got a 500 with
System.InvalidOperationException: No route matches the supplied values.
How can I reference the endpoint action from another controller?