Skip to content

Commit

Permalink
Add json constructor for robotResponse.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
prasm313 committed Nov 24, 2023
1 parent e95c7aa commit 295a8c2
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 22 deletions.
2 changes: 1 addition & 1 deletion backend/api/Controllers/Models/MissionRunResponse.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.Text.Json.Serialization;
using Api.Database.Models;
using System.Text.Json.Serialization;
namespace Api.Controllers.Models
{
public class MissionRunResponse
Expand Down
69 changes: 48 additions & 21 deletions backend/api/Controllers/Models/RobotResponse.cs
Original file line number Diff line number Diff line change
@@ -1,43 +1,70 @@
using Api.Database.Models;
#pragma warning disable CS8618
using System.Text.Json.Serialization;
using Api.Database.Models;
namespace Api.Controllers.Models
{
public class RobotResponse(Robot robot)
public class RobotResponse
{
public string Id { get; } = robot.Id;
public string Id { get; set; }

public string Name { get; } = robot.Name;
public string Name { get; set; }

public string IsarId { get; } = robot.IsarId;
public string IsarId { get; set; }

public virtual RobotModel Model { get; } = robot.Model;
public virtual RobotModel Model { get; set; }

public string SerialNumber { get; } = robot.SerialNumber;
public string SerialNumber { get; set; }

public string CurrentInstallation { get; } = robot.CurrentInstallation;
public string CurrentInstallation { get; set; }

public AreaResponse? CurrentArea { get; } = robot.CurrentArea != null ? new AreaResponse(robot.CurrentArea) : null;
public AreaResponse? CurrentArea { get; set; }

public float BatteryLevel { get; } = robot.BatteryLevel;
public float BatteryLevel { get; set; }

public float? PressureLevel { get; } = robot.PressureLevel;
public float? PressureLevel { get; set; }

public IList<VideoStream> VideoStreams { get; } = robot.VideoStreams;
public IList<VideoStream> VideoStreams { get; set; }

public string Host { get; } = robot.Host;
public string Host { get; set; }

public int Port { get; } = robot.Port;
public int Port { get; set; }

public bool Enabled { get; } = robot.Enabled;
public bool Enabled { get; set; }

public bool MissionQueueFrozen { get; } = robot.MissionQueueFrozen;
public bool MissionQueueFrozen { get; set; }

public RobotStatus Status { get; } = robot.Status;
public RobotStatus Status { get; set; }

public Pose Pose { get; } = robot.Pose;
public Pose Pose { get; set; }

public string? CurrentMissionId { get; } = robot.CurrentMissionId;
public string? CurrentMissionId { get; set; }

public string IsarUri { get; } = robot.IsarUri;
public string IsarUri { get; set; }

[JsonConstructor]
#nullable disable
public RobotResponse() { }
#nullable enable

public RobotResponse(Robot robot)
{
Id = robot.Id;
Name = robot.Name;
IsarId = robot.IsarId;
Model = robot.Model;
SerialNumber = robot.SerialNumber;
CurrentInstallation = robot.CurrentInstallation;
CurrentArea = robot.CurrentArea != null ? new AreaResponse(robot.CurrentArea) : null;
BatteryLevel = robot.BatteryLevel;
PressureLevel = robot.PressureLevel;
VideoStreams = robot.VideoStreams;
Host = robot.Host;
Port = robot.Port;
Enabled = robot.Enabled;
MissionQueueFrozen = robot.MissionQueueFrozen;
Status = robot.Status;
Pose = robot.Pose;
CurrentMissionId = robot.CurrentMissionId;
IsarUri = robot.IsarUri;
}
}
}

0 comments on commit 295a8c2

Please sign in to comment.