Skip to content

Commit

Permalink
Add endpoint to update robot deprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
Eddasol committed Apr 2, 2024
1 parent 2939135 commit 6869992
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
48 changes: 48 additions & 0 deletions backend/api/Controllers/RobotController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,54 @@ [FromBody] UpdateRobotQuery query
}
}

/// <summary>
/// Updates deprecated field of a robot in the database
/// </summary>
/// <remarks>
/// </remarks>
/// <response code="200"> The robot was successfully updated </response>
/// <response code="404"> There was no robot with the given ID in the database </response>
[HttpPut]
[Authorize(Roles = Role.Admin)]
[Route("{id}/deprecated/{deprecated}")]
[ProducesResponseType(typeof(RobotResponse), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<ActionResult<RobotResponse>> UpdateRobotDeprecated(
[FromRoute] string id,
[FromRoute] bool deprecated
)
{
logger.LogInformation("Updating deprecated on robot with id={Id} to deprecated={Deprecated}", id, deprecated);

try
{
var robot = await robotService.ReadById(id);
if (robot == null)
{
string errorMessage = $"No robot with id: {id} could be found";
logger.LogError("{Message}", errorMessage);
return NotFound(errorMessage);
}

Robot updatedRobot;
updatedRobot = await robotService.UpdateDeprecated(id, deprecated);

var robotResponse = new RobotResponse(updatedRobot);
logger.LogInformation("Successful updated deprecated on robot to database");

return Ok(robotResponse);
}
catch (Exception e)
{
logger.LogError(e, "Error while updating robot with id={Id}", id);
throw;
}
}

/// <summary>
/// Deletes the robot with the specified id from the database
/// </summary>
Expand Down
3 changes: 3 additions & 0 deletions backend/api/Services/RobotService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public interface IRobotService
public Task<Robot> UpdateRobotIsarConnected(string robotId, bool isarConnected);
public Task<Robot> UpdateCurrentMissionId(string robotId, string? missionId);
public Task<Robot> UpdateCurrentArea(string robotId, Area? area);
public Task<Robot> UpdateDeprecated(string robotId, bool deprecated);
public Task<Robot> UpdateMissionQueueFrozen(string robotId, bool missionQueueFrozen);
public Task<Robot?> Delete(string id);
public Task SetRobotToIsarDisconnected(string robotId);
Expand Down Expand Up @@ -218,6 +219,8 @@ public async Task<Robot> UpdateCurrentMissionId(string robotId, string? currentM

public async Task<Robot> UpdateCurrentArea(string robotId, Area? area) { return await UpdateRobotProperty(robotId, "CurrentArea", area); }

public async Task<Robot> UpdateDeprecated(string robotId, bool deprecated) { return await UpdateRobotProperty(robotId, "Deprecated", deprecated); }

public async Task<Robot> UpdateMissionQueueFrozen(string robotId, bool missionQueueFrozen) { return await UpdateRobotProperty(robotId, "MissionQueueFrozen", missionQueueFrozen); }

public async Task<IEnumerable<Robot>> ReadAll() { return await GetRobotsWithSubModels().ToListAsync(); }
Expand Down

0 comments on commit 6869992

Please sign in to comment.