Skip to content

Commit

Permalink
Fix formatting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
aeshub authored and andchiind committed Sep 19, 2023
1 parent 1e2b49b commit f78481e
Show file tree
Hide file tree
Showing 7 changed files with 141 additions and 137 deletions.
4 changes: 2 additions & 2 deletions backend/api/Controllers/AreaController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,12 +226,12 @@ public async Task<ActionResult<AreaResponse>> GetAreaById([FromRoute] string id)
[HttpGet]
[Authorize(Roles = Role.Any)]
[Route("{id}/mission-definitions")]
[ProducesResponseType(typeof(MissionDefinitionResponse), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(CondensedMissionDefinitionResponse), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<ActionResult<IList<MissionDefinitionResponse>>> GetMissionDefinitionsInArea([FromRoute] string id)
public async Task<ActionResult<IList<CondensedMissionDefinitionResponse>>> GetMissionDefinitionsInArea([FromRoute] string id)
{
try
{
Expand Down
4 changes: 2 additions & 2 deletions backend/api/Controllers/DeckController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ public async Task<ActionResult<Deck>> GetDeckById([FromRoute] string id)
[HttpGet]
[Authorize(Roles = Role.Any)]
[Route("{id}/mission-definitions")]
[ProducesResponseType(typeof(MissionDefinitionResponse), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(CondensedMissionDefinitionResponse), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<ActionResult<IList<MissionDefinitionResponse>>> GetMissionDefinitionsInDeck([FromRoute] string id)
public async Task<ActionResult<IList<CondensedMissionDefinitionResponse>>> GetMissionDefinitionsInDeck([FromRoute] string id)
{
try
{
Expand Down
247 changes: 123 additions & 124 deletions backend/api/Controllers/MissionController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Globalization;
using System.Text.Json;
using System.Text.Json;
using Api.Controllers.Models;
using Api.Database.Models;
using Api.Services;
Expand Down Expand Up @@ -108,33 +107,33 @@ [FromQuery] MissionRunQueryStringParameters parameters
return Ok(missionRuns);
}

/// <summary>
/// List all mission definitions in the Flotilla database
/// </summary>
/// <remarks>
/// <para> This query gets all mission definitions </para>
/// </remarks>
[HttpGet("definitions")]
[Authorize(Roles = Role.Any)]
[ProducesResponseType(typeof(IList<MissionDefinitionResponse>), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<ActionResult<IList<MissionDefinitionResponse>>> GetMissionDefinitions(
[FromQuery] MissionDefinitionQueryStringParameters parameters
)
{
PagedList<MissionDefinition> missionDefinitions;
try
{
missionDefinitions = await _missionDefinitionService.ReadAll(parameters);
}
catch (InvalidDataException e)
/// <summary>
/// List all mission definitions in the Flotilla database
/// </summary>
/// <remarks>
/// <para> This query gets all mission definitions </para>
/// </remarks>
[HttpGet("definitions")]
[Authorize(Roles = Role.Any)]
[ProducesResponseType(typeof(IList<MissionDefinitionResponse>), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<ActionResult<IList<MissionDefinitionResponse>>> GetMissionDefinitions(
[FromQuery] MissionDefinitionQueryStringParameters parameters
)
{
_logger.LogError(e.Message);
return BadRequest(e.Message);
}
PagedList<MissionDefinition> missionDefinitions;
try
{
missionDefinitions = await _missionDefinitionService.ReadAll(parameters);
}
catch (InvalidDataException e)
{
_logger.LogError(e.Message);
return BadRequest(e.Message);
}

var metadata = new
{
Expand All @@ -151,9 +150,9 @@ [FromQuery] MissionDefinitionQueryStringParameters parameters
JsonSerializer.Serialize(metadata)
);

var missionDefinitionResponses = missionDefinitions.Select(m => new MissionDefinitionResponse(_missionDefinitionService, m));
return Ok(missionDefinitionResponses);
}
var missionDefinitionResponses = missionDefinitions.Select(m => new MissionDefinitionResponse(_missionDefinitionService, m));
return Ok(missionDefinitionResponses);
}

/// <summary>
/// Lookup mission run by specified id.
Expand All @@ -176,45 +175,45 @@ public async Task<ActionResult<MissionRun>> GetMissionRunById([FromRoute] string
return Ok(missioRun);
}

/// <summary>
/// Lookup mission definition by specified id.
/// </summary>
[HttpGet]
[Authorize(Roles = Role.Any)]
[Route("definitions/{id}/condensed")]
[ProducesResponseType(typeof(CondensedMissionDefinitionResponse), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<ActionResult<CondensedMissionDefinitionResponse>> GetCondensedMissionDefinitionById([FromRoute] string id)
{
var missionDefinition = await _missionDefinitionService.ReadById(id);
if (missionDefinition == null)
return NotFound($"Could not find mission definition with id {id}");
var missionDefinitionResponse = new CondensedMissionDefinitionResponse(missionDefinition);
return Ok(missionDefinitionResponse);
}
/// <summary>
/// Lookup mission definition by specified id.
/// </summary>
[HttpGet]
[Authorize(Roles = Role.Any)]
[Route("definitions/{id}/condensed")]
[ProducesResponseType(typeof(CondensedMissionDefinitionResponse), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<ActionResult<CondensedMissionDefinitionResponse>> GetCondensedMissionDefinitionById([FromRoute] string id)
{
var missionDefinition = await _missionDefinitionService.ReadById(id);
if (missionDefinition == null)
return NotFound($"Could not find mission definition with id {id}");
var missionDefinitionResponse = new CondensedMissionDefinitionResponse(missionDefinition);
return Ok(missionDefinitionResponse);
}

/// <summary>
/// Lookup mission definition by specified id.
/// </summary>
[HttpGet]
[Authorize(Roles = Role.Any)]
[Route("definitions/{id}")]
[ProducesResponseType(typeof(MissionDefinitionResponse), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<ActionResult<MissionDefinitionResponse>> GetMissionDefinitionById([FromRoute] string id)
{
var missionDefinition = await _missionDefinitionService.ReadById(id);
if (missionDefinition == null)
return NotFound($"Could not find mission definition with id {id}");
var missionDefinitionResponse = new MissionDefinitionResponse(_missionDefinitionService, missionDefinition);
return Ok(missionDefinitionResponse);
}
/// <summary>
/// Lookup mission definition by specified id.
/// </summary>
[HttpGet]
[Authorize(Roles = Role.Any)]
[Route("definitions/{id}")]
[ProducesResponseType(typeof(MissionDefinitionResponse), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<ActionResult<MissionDefinitionResponse>> GetMissionDefinitionById([FromRoute] string id)
{
var missionDefinition = await _missionDefinitionService.ReadById(id);
if (missionDefinition == null)
return NotFound($"Could not find mission definition with id {id}");
var missionDefinitionResponse = new MissionDefinitionResponse(_missionDefinitionService, missionDefinition);
return Ok(missionDefinitionResponse);
}

/// <summary>
/// Lookup which mission run is scheduled next for the given mission definition
Expand Down Expand Up @@ -294,8 +293,8 @@ [FromBody] ScheduleMissionQuery scheduledMissionQuery
return NotFound("Mission definition not found");
}

List<MissionTask>? missionTasks;
missionTasks = await _missionDefinitionService.GetTasksFromSource(missionDefinition.Source, missionDefinition.InstallationCode);
List<MissionTask>? missionTasks;
missionTasks = await _missionDefinitionService.GetTasksFromSource(missionDefinition.Source, missionDefinition.InstallationCode);

if (missionTasks == null)
{
Expand Down Expand Up @@ -580,65 +579,65 @@ [FromBody] CustomMissionQuery customMissionQuery
}, newMissionRun);
}

/// <summary>
/// Updates a mission definition in the database based on id
/// </summary>
/// <response code="200"> The mission definition was successfully updated </response>
/// <response code="400"> The mission definition data is invalid </response>
/// <response code="404"> There was no mission definition with the given ID in the database </response>
[HttpPut]
[Authorize(Roles = Role.Admin)]
[Route("definitions/{id}")]
[ProducesResponseType(typeof(CondensedMissionDefinitionResponse), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<ActionResult<CondensedMissionDefinitionResponse>> UpdateMissionDefinitionById(
[FromRoute] string id,
[FromBody] UpdateMissionDefinitionQuery missionDefinitionQuery
)
{
_logger.LogInformation("Updating mission definition with id '{id}'", id);
/// <summary>
/// Updates a mission definition in the database based on id
/// </summary>
/// <response code="200"> The mission definition was successfully updated </response>
/// <response code="400"> The mission definition data is invalid </response>
/// <response code="404"> There was no mission definition with the given ID in the database </response>
[HttpPut]
[Authorize(Roles = Role.Admin)]
[Route("definitions/{id}")]
[ProducesResponseType(typeof(CondensedMissionDefinitionResponse), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<ActionResult<CondensedMissionDefinitionResponse>> UpdateMissionDefinitionById(
[FromRoute] string id,
[FromBody] UpdateMissionDefinitionQuery missionDefinitionQuery
)
{
_logger.LogInformation("Updating mission definition with id '{id}'", id);

if (!ModelState.IsValid)
return BadRequest("Invalid data.");
if (!ModelState.IsValid)
return BadRequest("Invalid data.");

var missionDefinition = await _missionDefinitionService.ReadById(id);
if (missionDefinition == null)
return NotFound($"Could not find mission definition with id '{id}'");
var missionDefinition = await _missionDefinitionService.ReadById(id);
if (missionDefinition == null)
return NotFound($"Could not find mission definition with id '{id}'");

if (missionDefinitionQuery.Name == null)
return BadRequest("Name cannot be null.");
if (missionDefinitionQuery.Name == null)
return BadRequest("Name cannot be null.");

missionDefinition.Name = missionDefinitionQuery.Name;
missionDefinition.Comment = missionDefinitionQuery.Comment;
missionDefinition.InspectionFrequency = missionDefinitionQuery.InspectionFrequency;
missionDefinition.Name = missionDefinitionQuery.Name;
missionDefinition.Comment = missionDefinitionQuery.Comment;
missionDefinition.InspectionFrequency = missionDefinitionQuery.InspectionFrequency;

var newMissionDefinition = await _missionDefinitionService.Update(missionDefinition);
return new CondensedMissionDefinitionResponse(newMissionDefinition);
}
var newMissionDefinition = await _missionDefinitionService.Update(missionDefinition);
return new CondensedMissionDefinitionResponse(newMissionDefinition);
}

/// <summary>
/// Deletes the mission definition with the specified id from the database.
/// </summary>
[HttpDelete]
[Authorize(Roles = Role.Admin)]
[Route("definitions/{id}")]
[ProducesResponseType(typeof(MissionDefinitionResponse), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<ActionResult<MissionDefinitionResponse>> DeleteMissionDefinition([FromRoute] string id)
{
var missionDefinition = await _missionDefinitionService.Delete(id);
if (missionDefinition is null)
return NotFound($"Mission definition with id {id} not found");
var missionDefinitionResponse = new MissionDefinitionResponse(_missionDefinitionService, missionDefinition);
return Ok(missionDefinitionResponse);
}
/// <summary>
/// Deletes the mission definition with the specified id from the database.
/// </summary>
[HttpDelete]
[Authorize(Roles = Role.Admin)]
[Route("definitions/{id}")]
[ProducesResponseType(typeof(MissionDefinitionResponse), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<ActionResult<MissionDefinitionResponse>> DeleteMissionDefinition([FromRoute] string id)
{
var missionDefinition = await _missionDefinitionService.Delete(id);
if (missionDefinition is null)
return NotFound($"Mission definition with id {id} not found");
var missionDefinitionResponse = new MissionDefinitionResponse(_missionDefinitionService, missionDefinition);
return Ok(missionDefinitionResponse);
}

/// <summary>
/// Deletes the mission run with the specified id from the database.
Expand Down
2 changes: 1 addition & 1 deletion backend/api/Controllers/Models/AreaResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class AreaResponse
public AreaResponse(Area area)
{
Id = area.Id;
DeckName = area.Deck.Name;
DeckName = area.Deck!.Name;
PlantCode = area.Plant.PlantCode;
InstallationCode = area.Installation.InstallationCode;
AreaName = area.Name;
Expand Down
4 changes: 2 additions & 2 deletions backend/api/Controllers/Models/MissionDefinitionResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public CondensedMissionDefinitionResponse(MissionDefinition missionDefinition)
InstallationCode = missionDefinition.InstallationCode;
Comment = missionDefinition.Comment;
InspectionFrequency = missionDefinition.InspectionFrequency;
Area = new AreaResponse(missionDefinition.Area);
Area = missionDefinition.Area != null ? new AreaResponse(missionDefinition.Area) : null;
LastRun = missionDefinition.LastRun;
IsDeprecated = missionDefinition.IsDeprecated;
SourceType = missionDefinition.Source.Type;
Expand Down Expand Up @@ -88,7 +88,7 @@ public MissionDefinitionResponse(IMissionDefinitionService service, MissionDefin
Comment = missionDefinition.Comment;
InspectionFrequency = missionDefinition.InspectionFrequency;
Area = missionDefinition.Area;
Tasks = service.GetTasksFromSource(missionDefinition.Source, missionDefinition.InstallationCode).Result;
Tasks = service.GetTasksFromSource(missionDefinition.Source, missionDefinition.InstallationCode).Result!;
LastRun = missionDefinition.LastRun;
IsDeprecated = missionDefinition.IsDeprecated;
SourceType = missionDefinition.Source.Type;
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/Pages/FrontPage/FrontPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const refreshInterval = 1000

export function FrontPage() {
const refreshInterval = 1000

return (
<>
<Header page={'root'} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,18 @@ export const ScheduleMissionDialog = (props: IProps): JSX.Element => {

useEffect(() => {
const id = setInterval(() => {
BackendAPICaller.getEnabledRobots().then((robots) => robots.filter(robots => robots.currentInstallation.toLowerCase() === installationCode.toLowerCase()))
.then((robots) => {
setRobotOptions(robots)
})
BackendAPICaller.getEnabledRobots()
.then((robots) =>
robots.filter(
(robots) => robots.currentInstallation.toLowerCase() === installationCode.toLowerCase()
)
)
.then((robots) => {
setRobotOptions(robots)
})
}, props.refreshInterval)
return () => clearInterval(id)
}, [props.refreshInterval])
}, [props.refreshInterval])

let timer: ReturnType<typeof setTimeout>

Expand Down

0 comments on commit f78481e

Please sign in to comment.