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 10, 2024
1 parent 97f5afc commit 4e83bb5
Show file tree
Hide file tree
Showing 10 changed files with 1,612 additions and 4 deletions.
53 changes: 53 additions & 0 deletions backend/api/Controllers/InspectionController.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("inspection")]
public class InspectionController(
ILogger<InspectionController> logger,
IEchoService echoService
) : ControllerBase
{
/// <summary>
/// Updates the Flotilla metadata for an inspection tag
/// </summary>
/// <remarks>
/// <para> This query updates the Flotilla metadata for an inpection tag </para>
/// </remarks>
[HttpPost("{tagId}/tag-zoom")]
[Authorize(Roles = Role.Admin)]
[ProducesResponseType(typeof(TagInspectionMetadata), StatusCodes.Status201Created)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<ActionResult<TagInspectionMetadata>> Create([FromRoute] string tagId, [FromBody] IsarZoomDescription zoom)
{
logger.LogInformation($"Updating zoom value for tag with ID {tagId}");

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

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

return metadata;
}
catch (Exception e)
{
logger.LogError(e, "Error while creating or updating inspection tag 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<TagInspectionMetadata> TagInspectionMetadata => Set<TagInspectionMetadata>();

// Timeseries:
public DbSet<RobotPressureTimeseries> RobotPressureTimeseries => Set<RobotPressureTimeseries>();
Expand Down
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
14 changes: 14 additions & 0 deletions backend/api/Database/Models/TagInspectionMetadata.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 TagInspectionMetadata
{
[Key]
public string TagId { get; set; }

public IsarZoomDescription ZoomDescription { get; set; }
}
}
Loading

0 comments on commit 4e83bb5

Please sign in to comment.