From f63ac1eb85a1c754df6042e69598cf9896791248 Mon Sep 17 00:00:00 2001 From: UsamaEquinorAFK Date: Mon, 13 Nov 2023 11:59:16 +0100 Subject: [PATCH] Remove response file for inspectionfindings --- .../InspectionFindingsController.cs | 26 ++++++++--------- .../Models/InspectionFindingsQuery.cs | 4 +-- .../Models/InspectionFindingsResponse.cs | 28 ------------------- .../api/Database/Models/InspectionFindings.cs | 8 ++---- backend/api/Services/InspectionService.cs | 1 - 5 files changed, 16 insertions(+), 51 deletions(-) delete mode 100644 backend/api/Controllers/Models/InspectionFindingsResponse.cs diff --git a/backend/api/Controllers/InspectionFindingsController.cs b/backend/api/Controllers/InspectionFindingsController.cs index 2c86de74b..4c3eabcb8 100644 --- a/backend/api/Controllers/InspectionFindingsController.cs +++ b/backend/api/Controllers/InspectionFindingsController.cs @@ -29,31 +29,31 @@ IInspectionService inspectionService /// [HttpPost("add-findings")] [Authorize(Roles = Role.Admin)] - [ProducesResponseType(typeof(InspectionFindingsResponse), StatusCodes.Status200OK)] + [ProducesResponseType(typeof(InspectionFindings), StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status409Conflict)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status403Forbidden)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] - public async Task> AddFindings([FromBody] InspectionFindingsQuery inspectionFinding) + public async Task> AddFindings([FromBody] InspectionFindingsQuery inspectionFinding) { _logger.LogInformation("Updating inspection findings for inspection with isarStepId '{Id}'", inspectionFinding.IsarStepId); try { - var inspection = await _inspectionService.ReadByIsarStepId(inspectionFinding.IsarStepId); + var inspection = await _inspectionService.AddFindings(inspectionFinding); + if (inspection != null) { - inspection = await _inspectionService.AddFindings(inspectionFinding); - return Ok(inspection); + return Ok(inspection.InspectionFindings); } } catch (Exception e) { - _logger.LogError(e, "Error while adding findings to inspection with IsarStepId '{inspectionFinding.IsarStepId}'", inspectionFinding.IsarStepId); - throw; + _logger.LogError(e, "Error while adding findings to inspection with IsarStepId '{Id}'", inspectionFinding.IsarStepId); + return StatusCode(StatusCodes.Status500InternalServerError); } - return NotFound(); + return NotFound($"Could not find any inspection with the provided '{inspectionFinding.IsarStepId}'"); } /// @@ -64,15 +64,15 @@ public async Task> AddFindings([FromBod [HttpGet] [Authorize(Roles = Role.Admin)] [Route("{id}")] - [ProducesResponseType(typeof(AreaResponse), StatusCodes.Status200OK)] + [ProducesResponseType(typeof(Inspection), StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status409Conflict)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status403Forbidden)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] - public async Task> GetInspections([FromRoute] string id) + public async Task> GetInspections([FromRoute] string id) { - _logger.LogInformation("Get inspection by ID '{inspectionFinding.InspectionId}'", id); + _logger.LogInformation("Get inspection by ID '{id}'", id); try { var inspection = await _inspectionService.ReadByIsarStepId(id); @@ -85,9 +85,9 @@ public async Task> GetInspections([FromRoute] s catch (Exception e) { _logger.LogError(e, "Error while finding an inspection with inspection id '{id}'", id); - throw; + return StatusCode(StatusCodes.Status500InternalServerError); } - return NotFound(); + return NotFound("Could not find any inspection with the provided '{id}'"); } } diff --git a/backend/api/Controllers/Models/InspectionFindingsQuery.cs b/backend/api/Controllers/Models/InspectionFindingsQuery.cs index a21001e73..e13d8d184 100644 --- a/backend/api/Controllers/Models/InspectionFindingsQuery.cs +++ b/backend/api/Controllers/Models/InspectionFindingsQuery.cs @@ -3,9 +3,7 @@ public struct InspectionFindingsQuery { - public string RobotName { get; set; } - - public string InspectionDate { get; set; } + public DateTime InspectionDate { get; set; } public string Area { get; set; } diff --git a/backend/api/Controllers/Models/InspectionFindingsResponse.cs b/backend/api/Controllers/Models/InspectionFindingsResponse.cs deleted file mode 100644 index 3765d84b5..000000000 --- a/backend/api/Controllers/Models/InspectionFindingsResponse.cs +++ /dev/null @@ -1,28 +0,0 @@ -using Api.Database.Models; - -namespace Api.Controllers.Models -{ - public struct InspectionFindingsResponse - { - - public string RobotName { get; set; } - - public string InspectionDate { get; set; } - - public string Area { get; set; } - - public string IsarStepId { get; set; } - - public string Findings { get; set; } - - public InspectionFindingsResponse(InspectionFindings inspectionFindings) - { - RobotName = inspectionFindings.RobotName; - InspectionDate = inspectionFindings.InspectionDate; - Area = inspectionFindings.Area; - IsarStepId = inspectionFindings.IsarStepId; - Findings = inspectionFindings.Findings; - } - } -} - diff --git a/backend/api/Database/Models/InspectionFindings.cs b/backend/api/Database/Models/InspectionFindings.cs index 8ebbd39ee..b2d2e348c 100644 --- a/backend/api/Database/Models/InspectionFindings.cs +++ b/backend/api/Database/Models/InspectionFindings.cs @@ -10,9 +10,7 @@ public class InspectionFindings [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public string Id { get; set; } - public string RobotName { get; set; } - - public string InspectionDate { get; set; } + public DateTime InspectionDate { get; set; } public string Area { get; set; } @@ -22,7 +20,6 @@ public class InspectionFindings public InspectionFindings(InspectionFindingsQuery createInspectionFindingQuery) { - RobotName = createInspectionFindingQuery.RobotName; InspectionDate = createInspectionFindingQuery.InspectionDate; Area = createInspectionFindingQuery.Area; IsarStepId = createInspectionFindingQuery.IsarStepId; @@ -31,8 +28,7 @@ public InspectionFindings(InspectionFindingsQuery createInspectionFindingQuery) public InspectionFindings() { - RobotName = "string"; - InspectionDate = "string"; + InspectionDate = DateTime.UtcNow; Area = "string"; IsarStepId = "string"; Findings = "string"; diff --git a/backend/api/Services/InspectionService.cs b/backend/api/Services/InspectionService.cs index ad3c50660..2ca1488aa 100644 --- a/backend/api/Services/InspectionService.cs +++ b/backend/api/Services/InspectionService.cs @@ -78,7 +78,6 @@ private IQueryable GetInspections() var inspectionFindings = new InspectionFindings { - RobotName = inspectionFindingsQuery.RobotName, InspectionDate = inspectionFindingsQuery.InspectionDate, Area = inspectionFindingsQuery.Area, IsarStepId = inspectionFindingsQuery.IsarStepId,