-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add possibility to returning the robot home in robot page
- Loading branch information
1 parent
60e9912
commit da7e58e
Showing
3 changed files
with
72 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using Api.Controllers.Models; | ||
using Api.Database.Models; | ||
using Api.Services; | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Mvc; | ||
namespace Api.Controllers | ||
{ | ||
[ApiController] | ||
[Route("return-to-home")] | ||
public class ReturnToHomeController( | ||
ILogger<RobotController> logger, | ||
IReturnToHomeService returnToHomeService, | ||
IRobotService robotService | ||
) : ControllerBase | ||
{ | ||
/// <summary> | ||
/// Sends the robots to their home. | ||
/// </summary> | ||
[HttpPost("schedule-return-to-home/{robotId}")] | ||
[Authorize(Roles = Role.User)] | ||
[ProducesResponseType(typeof(MissionRun), StatusCodes.Status200OK)] | ||
[ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||
[ProducesResponseType(StatusCodes.Status403Forbidden)] | ||
[ProducesResponseType(StatusCodes.Status404NotFound)] | ||
[ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||
public async Task<ActionResult<IList<MissionRun>>> ScheduleReturnToHomeMission( | ||
[FromRoute] string robotId | ||
) | ||
{ | ||
var robot = await robotService.ReadById(robotId); | ||
if (robot is null) | ||
{ | ||
logger.LogWarning("Could not find robot with id={Id}", robotId); | ||
return NotFound(); | ||
} | ||
|
||
var returnToHomeMission = await returnToHomeService.ScheduleReturnToHomeMissionRunIfNotAlreadyScheduledOrRobotIsHome(robot.Id); | ||
if (returnToHomeMission is null) | ||
{ | ||
string errorMessage = "Error while scheduling Return to Home mission"; | ||
logger.LogError(errorMessage); | ||
return StatusCode(StatusCodes.Status502BadGateway, $"{errorMessage}"); | ||
} | ||
|
||
return Ok(returnToHomeMission); | ||
|
||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters