I'm trying to create an endpoint supposed to delete multiple ids. It should match deleteRoom(ids: number[]). You can see what I tried below but it doesn't match the request from the angular.
deleteRoom(ids: number[]) {
return this.httpClient.delete(`${this.actionUrl}?id=${ids.toString()}`);
}
public class RoomsController : ApiControllerBase
{
[HttpGet]
public async Task<ActionResult<IList<RoomDto>>> GetRooms()
{
var result = await Mediator.Send(new GetRoomsQuery()).ConfigureAwait(false);
return Ok(result);
}
[HttpGet("available")]
public async Task<ActionResult<IList<RoomDto>>> GetAvailableRooms(
[FromQuery] DateTime from,
[FromQuery] DateTime to,
[FromQuery] int? departmentId,
[FromQuery] RoomType? roomType)
{
var query = new GetAvailableRoomsQuery
{
From = from,
To = to,
DepartmentId = departmentId,
RoomType = roomType
};
var result = await Mediator.Send(query).ConfigureAwait(false);
return Ok(result);
}
[HttpPost]
public async Task<ActionResult<int>> Create(CreateRoomCommand command)
{
return await Mediator.Send(command).ConfigureAwait(false);
}
[HttpPut("{id:int}")]
public async Task<ActionResult> Update(int id, UpdateRoomCommand command)
{
if (id != command.Id) return BadRequest();
await Mediator.Send(command).ConfigureAwait(false);
return NoContent();
}
[HttpDelete("{id:int}")]
public async Task<ActionResult> Delete(int id)
{
await Mediator.Send(new DeleteRoomCommand {Id = id}).ConfigureAwait(false);
return NoContent();
}
[HttpDelete("{ids}")]
public async Task<ActionResult> Delete(int[] ids, DeleteRoomsCommand command)
{
await Mediator.Send(command).ConfigureAwait(false);
return NoContent();
}
}
${this.actionUrl}?id=${ids.toString()}expression?9,10translate to an array at server... you might want to try building your URL likehttp://example.net/api/rooms?ids[0]=9&ids[1]=10Try this first from the post man and see if you are able to call the API. Then you can change the angular code to create URL in tis form for multiple ids.