From a4fae9c44e245bf6ec16a843b757a522f7164226 Mon Sep 17 00:00:00 2001 From: UsamaEquinorAFK Date: Thu, 9 Nov 2023 16:12:52 +0100 Subject: [PATCH 1/8] Add InspectionService --- backend/api/Services/InspectionService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/api/Services/InspectionService.cs b/backend/api/Services/InspectionService.cs index ea1559a51..4a07ff9e4 100644 --- a/backend/api/Services/InspectionService.cs +++ b/backend/api/Services/InspectionService.cs @@ -1,4 +1,4 @@ -using System.Diagnostics.CodeAnalysis; +using System.Diagnostics.CodeAnalysis; using Api.Database.Context; using Api.Database.Models; using Api.Services.Models; From e8d8972b2a18f8ffc7b20ce6876a4a65455651c2 Mon Sep 17 00:00:00 2001 From: UsamaEquinorAFK Date: Thu, 9 Nov 2023 16:13:44 +0100 Subject: [PATCH 2/8] Modify InspectionFindings table --- .../api/Database/Models/InspectionFindings.cs | 36 ++++++++++++++++--- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/backend/api/Database/Models/InspectionFindings.cs b/backend/api/Database/Models/InspectionFindings.cs index 0243e00c5..a973d0c5c 100644 --- a/backend/api/Database/Models/InspectionFindings.cs +++ b/backend/api/Database/Models/InspectionFindings.cs @@ -1,11 +1,16 @@ using Microsoft.EntityFrameworkCore; - +using Api.Controllers.Models; +using System.ComponentModel.DataAnnotations.Schema; +using System.ComponentModel.DataAnnotations; #pragma warning disable CS8618 namespace Api.Database.Models { [Owned] public class InspectionFindings { + [Key] + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] + public string Id { get; set; } public string RobotName { get; set; } @@ -13,10 +18,31 @@ public class InspectionFindings public string Area { get; set; } - public string InspectionId { get; set; } - - public string FindingsTag { get; set; } - + public string IsarStepId { get; set; } + + public string Findings { get; set; } + + public string MissionRunId { get; set; } + + public InspectionFindings(InspectionFindingsQuery createInspectionFindingQuery) + { + RobotName = createInspectionFindingQuery.RobotName; + InspectionDate = createInspectionFindingQuery.InspectionDate; + Area = createInspectionFindingQuery.Area; + IsarStepId = createInspectionFindingQuery.IsarStepId; + Findings = createInspectionFindingQuery.Findings; + MissionRunId = createInspectionFindingQuery.MissionRunId; + } + + public InspectionFindings() + { + RobotName = "string"; + InspectionDate = "string"; + Area = "string"; + IsarStepId = "string"; + Findings = "string"; + MissionRunId = "string"; + } } } From 4301218b8e82087f8d766d9dce17107f88e038aa Mon Sep 17 00:00:00 2001 From: UsamaEquinorAFK Date: Thu, 9 Nov 2023 16:14:17 +0100 Subject: [PATCH 3/8] Add InspectionFindingsQuery --- .../Models/InspectionFindingsQuery.cs | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 backend/api/Controllers/Models/InspectionFindingsQuery.cs diff --git a/backend/api/Controllers/Models/InspectionFindingsQuery.cs b/backend/api/Controllers/Models/InspectionFindingsQuery.cs new file mode 100644 index 000000000..d4ddb12ed --- /dev/null +++ b/backend/api/Controllers/Models/InspectionFindingsQuery.cs @@ -0,0 +1,23 @@ +using Api.Database.Models; + +namespace Api.Controllers.Models +{ + public struct InspectionFindingsQuery + { + + 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 string MissionRunId { get; set; } + + + } +} + From d21e45aed4d552ee3b67ac7eeb10a382fe9c7401 Mon Sep 17 00:00:00 2001 From: UsamaEquinorAFK Date: Thu, 9 Nov 2023 16:14:36 +0100 Subject: [PATCH 4/8] Add InspectionFindingsController --- .../InspectionFindingsController.cs | 98 +++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 backend/api/Controllers/InspectionFindingsController.cs diff --git a/backend/api/Controllers/InspectionFindingsController.cs b/backend/api/Controllers/InspectionFindingsController.cs new file mode 100644 index 000000000..8cf9948c1 --- /dev/null +++ b/backend/api/Controllers/InspectionFindingsController.cs @@ -0,0 +1,98 @@ +using Api.Controllers.Models; +using Api.Database.Models; +using Api.Services; +using Azure; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; + +namespace Api.Controllers +{ + [ApiController] + [Route("inspection-findings")] + public class InspectionFindingsController : ControllerBase + { + private readonly IInspectionService _inspectionService; + private readonly ILogger _logger; + public InspectionFindingsController( + ILogger logger, + IInspectionService inspectionService + ) + { + _logger = logger; + _inspectionService = inspectionService; + + } + + /// + /// Add a new inspection finding - need isarStepId to run this + /// + /// + /// This query adds a new area to the database + /// + [HttpPost("add-findings")] + [Authorize(Roles = Role.Admin)] + [ProducesResponseType(typeof(AreaResponse), StatusCodes.Status201Created)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + [ProducesResponseType(StatusCodes.Status409Conflict)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status403Forbidden)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task> AddFindings([FromBody] InspectionFindingsQuery inspectionFinding) + { + _logger.LogInformation("Updating inspection findings for inspection with isarStepId '{inspectionFinding.IsarStepId}'", inspectionFinding.IsarStepId); + try + { + var inspection = await _inspectionService.ReadById(inspectionFinding.IsarStepId); + if (inspection != null) + { + inspection = await _inspectionService.AddFindings(inspectionFinding); + return Ok(inspection); + } + + } + catch (Exception e) + { + _logger.LogError(e, "Error while adding findings to inspection with IsarStepId '{inspectionFinding.IsarStepId}'", inspectionFinding.IsarStepId); + throw; + } + return NotFound(); + } + + /// + /// Get the full inspection against an isarStepId + /// + /// + /// This query adds a new area to the database + /// + [HttpGet] + [Authorize(Roles = Role.Admin)] + [Route("{id}")] + [ProducesResponseType(typeof(AreaResponse), StatusCodes.Status201Created)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + [ProducesResponseType(StatusCodes.Status409Conflict)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status403Forbidden)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task> GetInspections([FromRoute] string id) + { + _logger.LogInformation("Get inspection by ID '{inspectionFinding.InspectionId}'", id); + try + { + var inspection = await _inspectionService.ReadById(id); + if (inspection != null) + { + return Ok(inspection); + } + + } + catch (Exception e) + { + _logger.LogError(e, "Error while finding an inspection with inspection id '{id}'", id); + throw; + } + return NotFound(); + } + + } + +} From 7919a966e01a4ffdcde07811d84feaf9fce6a924 Mon Sep 17 00:00:00 2001 From: UsamaEquinorAFK Date: Thu, 9 Nov 2023 16:15:11 +0100 Subject: [PATCH 5/8] Add scope for InspectionFindingsService --- backend/api/Controllers/InspectionFindingsController.cs | 3 +-- backend/api/Controllers/Models/InspectionFindingsQuery.cs | 4 +--- backend/api/Database/Models/InspectionFindings.cs | 6 +++--- backend/api/Program.cs | 2 +- 4 files changed, 6 insertions(+), 9 deletions(-) diff --git a/backend/api/Controllers/InspectionFindingsController.cs b/backend/api/Controllers/InspectionFindingsController.cs index 8cf9948c1..2a9641374 100644 --- a/backend/api/Controllers/InspectionFindingsController.cs +++ b/backend/api/Controllers/InspectionFindingsController.cs @@ -1,7 +1,6 @@ -using Api.Controllers.Models; +using Api.Controllers.Models; using Api.Database.Models; using Api.Services; -using Azure; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; diff --git a/backend/api/Controllers/Models/InspectionFindingsQuery.cs b/backend/api/Controllers/Models/InspectionFindingsQuery.cs index d4ddb12ed..2104dbe42 100644 --- a/backend/api/Controllers/Models/InspectionFindingsQuery.cs +++ b/backend/api/Controllers/Models/InspectionFindingsQuery.cs @@ -1,6 +1,4 @@ -using Api.Database.Models; - -namespace Api.Controllers.Models +namespace Api.Controllers.Models { public struct InspectionFindingsQuery { diff --git a/backend/api/Database/Models/InspectionFindings.cs b/backend/api/Database/Models/InspectionFindings.cs index a973d0c5c..6869c34e2 100644 --- a/backend/api/Database/Models/InspectionFindings.cs +++ b/backend/api/Database/Models/InspectionFindings.cs @@ -1,7 +1,7 @@ -using Microsoft.EntityFrameworkCore; -using Api.Controllers.Models; +using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; -using System.ComponentModel.DataAnnotations; +using Api.Controllers.Models; +using Microsoft.EntityFrameworkCore; #pragma warning disable CS8618 namespace Api.Database.Models { diff --git a/backend/api/Program.cs b/backend/api/Program.cs index e66c224df..e346e1333 100644 --- a/backend/api/Program.cs +++ b/backend/api/Program.cs @@ -73,7 +73,7 @@ builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); - +builder.Services.AddScoped(); bool useInMemoryDatabase = builder.Configuration .GetSection("Database") From 29e37517923c0c70c82fd53978eed3ee74297572 Mon Sep 17 00:00:00 2001 From: UsamaEquinorAFK Date: Fri, 10 Nov 2023 16:26:50 +0100 Subject: [PATCH 6/8] Add InspectionFindings Response --- .../Models/InspectionFindingsResponse.cs | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 backend/api/Controllers/Models/InspectionFindingsResponse.cs diff --git a/backend/api/Controllers/Models/InspectionFindingsResponse.cs b/backend/api/Controllers/Models/InspectionFindingsResponse.cs new file mode 100644 index 000000000..ee3a9bc1a --- /dev/null +++ b/backend/api/Controllers/Models/InspectionFindingsResponse.cs @@ -0,0 +1,31 @@ +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 string MissionRunId { get; set; } + + public InspectionFindingsResponse(InspectionFindings inspectionFindings) + { + RobotName = inspectionFindings.RobotName; + InspectionDate = inspectionFindings.InspectionDate; + Area = inspectionFindings.Area; + IsarStepId = inspectionFindings.IsarStepId; + Findings = inspectionFindings.Findings; + MissionRunId = inspectionFindings.MissionRunId; + } + } +} + From c8812d51738d9ccc12e997ef15c2742c1173ce17 Mon Sep 17 00:00:00 2001 From: UsamaEquinorAFK Date: Wed, 15 Nov 2023 09:42:06 +0100 Subject: [PATCH 7/8] Refactor after making inspection not owned --- .../InspectionFindingsController.cs | 16 ++++----- .../Models/InspectionFindingsQuery.cs | 3 +- .../Models/InspectionFindingsResponse.cs | 5 +-- .../api/Database/Models/InspectionFindings.cs | 6 ---- backend/api/Program.cs | 1 - backend/api/Services/InspectionService.cs | 33 +++++++++++++++++-- 6 files changed, 40 insertions(+), 24 deletions(-) diff --git a/backend/api/Controllers/InspectionFindingsController.cs b/backend/api/Controllers/InspectionFindingsController.cs index 2a9641374..2c86de74b 100644 --- a/backend/api/Controllers/InspectionFindingsController.cs +++ b/backend/api/Controllers/InspectionFindingsController.cs @@ -23,25 +23,24 @@ IInspectionService inspectionService } /// - /// Add a new inspection finding - need isarStepId to run this + /// Associate a new inspection finding with the inspection corresponding to isarStepId /// /// - /// This query adds a new area to the database /// [HttpPost("add-findings")] [Authorize(Roles = Role.Admin)] - [ProducesResponseType(typeof(AreaResponse), StatusCodes.Status201Created)] + [ProducesResponseType(typeof(InspectionFindingsResponse), 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 '{inspectionFinding.IsarStepId}'", inspectionFinding.IsarStepId); + _logger.LogInformation("Updating inspection findings for inspection with isarStepId '{Id}'", inspectionFinding.IsarStepId); try { - var inspection = await _inspectionService.ReadById(inspectionFinding.IsarStepId); + var inspection = await _inspectionService.ReadByIsarStepId(inspectionFinding.IsarStepId); if (inspection != null) { inspection = await _inspectionService.AddFindings(inspectionFinding); @@ -61,12 +60,11 @@ public async Task> AddFindings([FromBody] Inspe /// Get the full inspection against an isarStepId /// /// - /// This query adds a new area to the database /// [HttpGet] [Authorize(Roles = Role.Admin)] [Route("{id}")] - [ProducesResponseType(typeof(AreaResponse), StatusCodes.Status201Created)] + [ProducesResponseType(typeof(AreaResponse), StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status409Conflict)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] @@ -77,7 +75,7 @@ public async Task> GetInspections([FromRoute] s _logger.LogInformation("Get inspection by ID '{inspectionFinding.InspectionId}'", id); try { - var inspection = await _inspectionService.ReadById(id); + var inspection = await _inspectionService.ReadByIsarStepId(id); if (inspection != null) { return Ok(inspection); diff --git a/backend/api/Controllers/Models/InspectionFindingsQuery.cs b/backend/api/Controllers/Models/InspectionFindingsQuery.cs index 2104dbe42..a21001e73 100644 --- a/backend/api/Controllers/Models/InspectionFindingsQuery.cs +++ b/backend/api/Controllers/Models/InspectionFindingsQuery.cs @@ -13,9 +13,8 @@ public struct InspectionFindingsQuery public string Findings { get; set; } - public string MissionRunId { get; set; } - } + } diff --git a/backend/api/Controllers/Models/InspectionFindingsResponse.cs b/backend/api/Controllers/Models/InspectionFindingsResponse.cs index ee3a9bc1a..3765d84b5 100644 --- a/backend/api/Controllers/Models/InspectionFindingsResponse.cs +++ b/backend/api/Controllers/Models/InspectionFindingsResponse.cs @@ -1,4 +1,4 @@ -using Api.Database.Models; +using Api.Database.Models; namespace Api.Controllers.Models { @@ -15,8 +15,6 @@ public struct InspectionFindingsResponse public string Findings { get; set; } - public string MissionRunId { get; set; } - public InspectionFindingsResponse(InspectionFindings inspectionFindings) { RobotName = inspectionFindings.RobotName; @@ -24,7 +22,6 @@ public InspectionFindingsResponse(InspectionFindings inspectionFindings) Area = inspectionFindings.Area; IsarStepId = inspectionFindings.IsarStepId; Findings = inspectionFindings.Findings; - MissionRunId = inspectionFindings.MissionRunId; } } } diff --git a/backend/api/Database/Models/InspectionFindings.cs b/backend/api/Database/Models/InspectionFindings.cs index 6869c34e2..8ebbd39ee 100644 --- a/backend/api/Database/Models/InspectionFindings.cs +++ b/backend/api/Database/Models/InspectionFindings.cs @@ -1,11 +1,9 @@ using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using Api.Controllers.Models; -using Microsoft.EntityFrameworkCore; #pragma warning disable CS8618 namespace Api.Database.Models { - [Owned] public class InspectionFindings { [Key] @@ -22,8 +20,6 @@ public class InspectionFindings public string Findings { get; set; } - public string MissionRunId { get; set; } - public InspectionFindings(InspectionFindingsQuery createInspectionFindingQuery) { RobotName = createInspectionFindingQuery.RobotName; @@ -31,7 +27,6 @@ public InspectionFindings(InspectionFindingsQuery createInspectionFindingQuery) Area = createInspectionFindingQuery.Area; IsarStepId = createInspectionFindingQuery.IsarStepId; Findings = createInspectionFindingQuery.Findings; - MissionRunId = createInspectionFindingQuery.MissionRunId; } public InspectionFindings() @@ -41,7 +36,6 @@ public InspectionFindings() Area = "string"; IsarStepId = "string"; Findings = "string"; - MissionRunId = "string"; } } diff --git a/backend/api/Program.cs b/backend/api/Program.cs index e346e1333..7265e0d5a 100644 --- a/backend/api/Program.cs +++ b/backend/api/Program.cs @@ -73,7 +73,6 @@ builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); -builder.Services.AddScoped(); bool useInMemoryDatabase = builder.Configuration .GetSection("Database") diff --git a/backend/api/Services/InspectionService.cs b/backend/api/Services/InspectionService.cs index 4a07ff9e4..ad3c50660 100644 --- a/backend/api/Services/InspectionService.cs +++ b/backend/api/Services/InspectionService.cs @@ -1,4 +1,5 @@ -using System.Diagnostics.CodeAnalysis; +using System.Diagnostics.CodeAnalysis; +using Api.Controllers.Models; using Api.Database.Context; using Api.Database.Models; using Api.Services.Models; @@ -9,6 +10,9 @@ namespace Api.Services public interface IInspectionService { public Task UpdateInspectionStatus(string isarStepId, IsarStepStatus isarStepStatus); + public Task ReadByIsarStepId(string id); + public Task AddFindings(InspectionFindingsQuery inspectionFindingsQuery); + } [SuppressMessage( @@ -52,7 +56,7 @@ private async Task Update(Inspection inspection) return entry.Entity; } - private async Task ReadByIsarStepId(string id) + public async Task ReadByIsarStepId(string id) { return await GetInspections().FirstOrDefaultAsync(inspection => inspection.IsarStepId != null && inspection.IsarStepId.Equals(id)); } @@ -61,5 +65,30 @@ private IQueryable GetInspections() { return _context.Inspections.Include(inspection => inspection.InspectionFindings); } + + public async Task AddFindings(InspectionFindingsQuery inspectionFindingsQuery) + { + + var inspection = await ReadByIsarStepId(inspectionFindingsQuery.IsarStepId); + + if (inspection is null) + { + return null; + } + + var inspectionFindings = new InspectionFindings + { + RobotName = inspectionFindingsQuery.RobotName, + InspectionDate = inspectionFindingsQuery.InspectionDate, + Area = inspectionFindingsQuery.Area, + IsarStepId = inspectionFindingsQuery.IsarStepId, + Findings = inspectionFindingsQuery.Findings + }; + + inspection.InspectionFindings.Add(inspectionFindings); + inspection = await Update(inspection); + _ = _signalRService.SendMessageAsync("Inspection findings added", inspection); + return inspection; + } } } From 18f4ca6b278c4123f9817451e776c41f6f902717 Mon Sep 17 00:00:00 2001 From: UsamaEquinorAFK Date: Mon, 13 Nov 2023 11:59:16 +0100 Subject: [PATCH 8/8] 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,