Skip to content

Commit

Permalink
Include robot in report API response
Browse files Browse the repository at this point in the history
  • Loading branch information
GodVenn committed Jul 14, 2022
1 parent 9340785 commit cda8d47
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 9 deletions.
4 changes: 2 additions & 2 deletions backend/api.test/Services/RobotService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public async Task Read()
var robotService = new RobotService(_fixture.Context);
var robots = await robotService.ReadAll();
var firstRobot = robots.First();
var robotById = await robotService.Read(firstRobot.Id);
var robotById = await robotService.ReadById(firstRobot.Id);

Assert.Equal(firstRobot, robotById);
}
Expand All @@ -40,7 +40,7 @@ public async Task Read()
public async Task ReadIdDoesNotExist()
{
var robotService = new RobotService(_fixture.Context);
var robot = await robotService.Read("some_id_that_does_not_exist");
var robot = await robotService.ReadById("some_id_that_does_not_exist");
Assert.Null(robot);
}

Expand Down
2 changes: 1 addition & 1 deletion backend/api.test/Services/ScheduledMissionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public async Task Create()
await scheduledMissionService.Create(new ScheduledMission()
{
Robot = robot,
IsarMissionId = "",
EchoMissionId = "",
StartTime = System.DateTimeOffset.UtcNow
});
int nScheduledMissionsAfter = scheduledMissionService.ReadAll().Result.Count();
Expand Down
3 changes: 0 additions & 3 deletions backend/api.test/TestRobotController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using Api.Database.Models;
using Api.Services;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Moq;
using Xunit;
Expand All @@ -21,8 +20,6 @@ public TestRobotController(DatabaseFixture fixture)
var isarLogger = new Mock<ILogger<IsarService>>();
var reportServiceLogger = new Mock<ILogger<ReportService>>();

var config = new ConfigurationBuilder().AddJsonFile("appsettings.json").Build();

var context = fixture.Context;

var reportService = new ReportService(context, reportServiceLogger.Object);
Expand Down
4 changes: 3 additions & 1 deletion backend/api/Services/ReportService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Robot robot
public async Task<IEnumerable<Report>> ReadAll()
{
return await _context.Reports
.Include(r => r.Robot)
.Include(report => report.Tasks)
.ThenInclude(task => task.Steps)
.ToListAsync();
Expand All @@ -59,14 +60,15 @@ public async Task<IEnumerable<Report>> ReadAll()
public async Task<Report?> Read(string id)
{
return await _context.Reports
.Include(r => r.Robot)
.Include(report => report.Tasks)
.ThenInclude(task => task.Steps)
.FirstOrDefaultAsync(report => report.Id.Equals(id));
}

public async Task<Report?> ReadByIsarMissionId(string isarMissionId)
{
return await _context.Reports.FirstOrDefaultAsync(
return await _context.Reports.Include(r => r.Robot).FirstOrDefaultAsync(
report => report.IsarMissionId.Equals(isarMissionId)
);
}
Expand Down
6 changes: 4 additions & 2 deletions backend/api/Services/ScheduledMissionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,13 @@ public void Update(ScheduledMission scheduledMission)

public async Task<List<ScheduledMission>> GetScheduledMissionsByStatus(ScheduledMissionStatus status)
{
return await _context.ScheduledMissions
// EF Core cannot translate DateTimeOffset ordering to SQL,
// so we need to do this on the client side (After getting list from database)
var list = await _context.ScheduledMissions
.Include(sm => sm.Robot)
.Where(sm => sm.Status.Equals(status))
.OrderBy(sm => sm.StartTime)
.ToListAsync();
return list.OrderBy(sm => sm.StartTime).ToList();
}

public async Task<ScheduledMission?> Delete(string id)
Expand Down

0 comments on commit cda8d47

Please sign in to comment.