Skip to content

Commit

Permalink
Let user configure custom zoom for tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
andchiind committed Dec 6, 2024
1 parent 6dd8eda commit 14c87a3
Show file tree
Hide file tree
Showing 11 changed files with 1,613 additions and 6 deletions.
53 changes: 53 additions & 0 deletions backend/api/Controllers/EchoController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using Api.Controllers.Models;
using Api.Services;
using Api.Services.MissionLoaders;
using Api.Services.Models;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace Api.Controllers
{
[ApiController]
[Route("echo")]
public class EchoController(
ILogger<EchoController> logger,
IEchoService echoService
) : ControllerBase
{
/// <summary>
/// Updates the Flotilla metadata for an Echo tag
/// </summary>
/// <remarks>
/// <para> This query updates the Flotilla metadata for an Echo tag </para>
/// </remarks>
[HttpPost("{tagId}/tag-zoom")]
[Authorize(Roles = Role.Admin)]
[ProducesResponseType(typeof(EchoTagInspectionMetadata), StatusCodes.Status201Created)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<ActionResult<EchoTagInspectionMetadata>> Create([FromRoute] string tagId, [FromBody] IsarZoomDescription zoom)
{
logger.LogInformation($"Updating zoom value for tag with ID {tagId}");

var newMetadata = new EchoTagInspectionMetadata
{
TagId = tagId,
ZoomDescription = zoom
};

try
{
var metadata = await echoService.CreateOrUpdateEchoTagInspectionMetadata(newMetadata);

return metadata;
}
catch (Exception e)
{
logger.LogError(e, "Error while creating or updating Echo tag inspection metadata");
throw;
}
}
}
}
5 changes: 5 additions & 0 deletions backend/api/Controllers/Models/CustomMissionQuery.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Api.Database.Models;
using Api.Services.Models;
namespace Api.Controllers.Models
{
public struct CustomInspectionQuery
Expand All @@ -22,6 +23,8 @@ public struct CustomTaskQuery

public Pose RobotPose { get; set; }

public IsarZoomDescription? IsarZoomDescription { get; set; }

public CustomInspectionQuery? Inspection { get; set; }
}

Expand All @@ -44,5 +47,7 @@ public struct CustomMissionQuery
public string? Comment { get; set; }

public List<CustomTaskQuery> Tasks { get; set; }

public IsarZoomDescription? IsarZoomDescription { get; set; }
}
}
2 changes: 2 additions & 0 deletions backend/api/Database/Context/FlotillaDbContext.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Api.Database.Models;
using Api.Services.MissionLoaders;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.ChangeTracking;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
Expand Down Expand Up @@ -26,6 +27,7 @@ public FlotillaDbContext(DbContextOptions options) : base(options)
public DbSet<DefaultLocalizationPose> DefaultLocalizationPoses => Set<DefaultLocalizationPose>();
public DbSet<AccessRole> AccessRoles => Set<AccessRole>();
public DbSet<UserInfo> UserInfos => Set<UserInfo>();
public DbSet<EchoTagInspectionMetadata> EchoTagInspectionMetadata => Set<EchoTagInspectionMetadata>();

// Timeseries:
public DbSet<RobotPressureTimeseries> RobotPressureTimeseries => Set<RobotPressureTimeseries>();
Expand Down
14 changes: 14 additions & 0 deletions backend/api/Database/Models/EchoTagInspectionMetadata.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#nullable disable
using System.ComponentModel.DataAnnotations;
using Api.Services.Models;

namespace Api.Services.MissionLoaders
{
public class EchoTagInspectionMetadata
{
[Key]
public string TagId { get; set; }

public IsarZoomDescription? ZoomDescription { get; set; }

Check warning on line 12 in backend/api/Database/Models/EchoTagInspectionMetadata.cs

View workflow job for this annotation

GitHub Actions / build_backend

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 12 in backend/api/Database/Models/EchoTagInspectionMetadata.cs

View workflow job for this annotation

GitHub Actions / build_backend

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check failure on line 12 in backend/api/Database/Models/EchoTagInspectionMetadata.cs

View workflow job for this annotation

GitHub Actions / test_backend

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check failure on line 12 in backend/api/Database/Models/EchoTagInspectionMetadata.cs

View workflow job for this annotation

GitHub Actions / test_backend

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
}
}
6 changes: 6 additions & 0 deletions backend/api/Database/Models/MissionTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public MissionTask(
Uri? tagLink,
string? tagId,
int? poseId,
IsarZoomDescription? zoomDescription = null,
TaskStatus status = TaskStatus.NotStarted,
MissionTaskType type = MissionTaskType.Inspection)
{
Expand All @@ -35,6 +36,7 @@ public MissionTask(
TaskOrder = taskOrder;
Status = status;
Type = type;
IsarZoomDescription = zoomDescription;
if (inspection != null) Inspection = new Inspection(inspection);
}

Expand All @@ -45,6 +47,7 @@ public MissionTask(CustomTaskQuery taskQuery)
RobotPose = taskQuery.RobotPose;
TaskOrder = taskQuery.TaskOrder;
Status = TaskStatus.NotStarted;
IsarZoomDescription = taskQuery.IsarZoomDescription;
if (taskQuery.Inspection is not null)
{
Inspection = new Inspection((CustomInspectionQuery)taskQuery.Inspection);
Expand Down Expand Up @@ -98,6 +101,7 @@ public MissionTask(MissionTask copy, TaskStatus? status = null)
RobotPose = new Pose(copy.RobotPose);
PoseId = copy.PoseId;
Status = status ?? copy.Status;
IsarZoomDescription = copy.IsarZoomDescription;
if (copy.Inspection is not null)
{
Inspection = new Inspection(copy.Inspection, InspectionStatus.NotStarted);
Expand Down Expand Up @@ -156,6 +160,8 @@ or TaskStatus.Failed

public DateTime? EndTime { get; private set; }

public IsarZoomDescription? IsarZoomDescription { get; set; }

public Inspection? Inspection { get; set; }

public void UpdateWithIsarInfo(IsarTask isarTask)
Expand Down
Loading

0 comments on commit 14c87a3

Please sign in to comment.