Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dfl 25 add maintenance log #18

Merged
merged 12 commits into from
Mar 15, 2024
Merged
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ The logbook allows for storage and maintenance of the following data:
- Operator details
- Drones, models and manufacturers
- Flights, flight locations and flight properties
- Repair, maintenance and modification records

## Getting Started

Expand Down
4 changes: 2 additions & 2 deletions docker/api/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM mcr.microsoft.com/dotnet/core/aspnet:latest
COPY droneflightlog.api-1.2.1.0 /opt/droneflightlog.api-1.2.1.0
WORKDIR /opt/droneflightlog.api-1.2.1.0/bin
COPY droneflightlog.api-1.3.0.0 /opt/droneflightlog.api-1.3.0.0
WORKDIR /opt/droneflightlog.api-1.3.0.0/bin
ENTRYPOINT [ "./DroneFlightLog.Api" ]
4 changes: 2 additions & 2 deletions docker/ui/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM mcr.microsoft.com/dotnet/core/aspnet:latest
COPY droneflightlog.mvc-1.1.4.0 /opt/droneflightlog.mvc-1.1.4.0
WORKDIR /opt/droneflightlog.mvc-1.1.4.0/bin
COPY droneflightlog.mvc-1.2.0.0 /opt/droneflightlog.mvc-1.2.0.0
WORKDIR /opt/droneflightlog.mvc-1.2.0.0/bin
ENTRYPOINT [ "./DroneFlightLog.Mvc" ]
22 changes: 20 additions & 2 deletions src/DroneFlightLog.Api/Controllers/DronesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,31 @@ public DronesController(IDroneFlightLogFactory<DroneFlightLogDbContext> factory)
_factory = factory;
}

[HttpGet]
[Route("id")]
public async Task<ActionResult<Drone>> GetDroneByIdAsync(int id)
{
Drone drone;

try
{
drone = await _factory.Drones.GetDroneAsync(id);
}
catch (DroneNotFoundException)
{
return NotFound();
}

return drone;
}

[HttpGet]
[Route("")]
public async Task<ActionResult<List<Drone>>> GetDronesAsync()
{
List<Drone> drones = await _factory.Drones.GetDronesAsync(null).ToListAsync();

if (!drones.Any())
if (drones.Count == 0)
{
return NoContent();
}
Expand All @@ -43,7 +61,7 @@ public async Task<ActionResult<List<Drone>>> GetDronesForModelAsync(int modelId)
{
List<Drone> drones = await _factory.Drones.GetDronesAsync(modelId).ToListAsync();

if (!drones.Any())
if (drones.Count == 0)
{
return NoContent();
}
Expand Down
18 changes: 18 additions & 0 deletions src/DroneFlightLog.Api/Controllers/FlightPropertiesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,24 @@ public FlightPropertiesController(IDroneFlightLogFactory<DroneFlightLogDbContext
_factory = factory;
}

[HttpGet]
[Route("{id}")]
public async Task<ActionResult<FlightProperty>> GetPropertyAsync(int id)
{
FlightProperty property;

try
{
property = await _factory.Properties.GetPropertyAsync(id);
}
catch (PropertyNotFoundException)
{
return NotFound();
}

return property;
}

[HttpGet]
[Route("")]
public async Task<ActionResult<List<FlightProperty>>> GetPropertiesAsync()
Expand Down
28 changes: 23 additions & 5 deletions src/DroneFlightLog.Api/Controllers/FlightsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,31 @@ public FlightsController(IDroneFlightLogFactory<DroneFlightLogDbContext> factory
_factory = factory;
}

[HttpGet]
[Route("{id}")]
public async Task<ActionResult<Flight>> GetFlightByIdAsync(int id)
{
Flight flight;

try
{
flight = await _factory.Flights.GetFlightAsync(id);
}
catch (FlightNotFoundException)
{
return NotFound();
}

return flight;
}

[HttpGet]
[Route("{page}/{pageSize}")]
public async Task<ActionResult<List<Flight>>> GetFlightsAsync(int page, int pageSize)
{
List<Flight> flights = await _factory.Flights.FindFlightsAsync(null, null, null, null, null, page, pageSize).ToListAsync();

if (!flights.Any())
if (flights.Count == 0)
{
return NoContent();
}
Expand All @@ -47,7 +65,7 @@ public async Task<ActionResult<List<Flight>>> FindFlightsByOperatorAsync(int ope
{
List<Flight> flights = await _factory.Flights.FindFlightsAsync(operatorId, null, null, null, null, page, pageSize).ToListAsync();

if (!flights.Any())
if (flights.Count == 0)
{
return NoContent();
}
Expand All @@ -61,7 +79,7 @@ public async Task<ActionResult<List<Flight>>> FindFlightsByDroneAsync(int droneI
{
List<Flight> flights = await _factory.Flights.FindFlightsAsync(null, droneId, null, null, null, page, pageSize).ToListAsync();

if (!flights.Any())
if (flights.Count == 0)
{
return NoContent();
}
Expand All @@ -75,7 +93,7 @@ public async Task<ActionResult<List<Flight>>> FindFlightsByLocationAsync(int loc
{
List<Flight> flights = await _factory.Flights.FindFlightsAsync(null, null, locationId, null, null, page, pageSize).ToListAsync();

if (!flights.Any())
if (flights.Count == 0)
{
return NoContent();
}
Expand All @@ -92,7 +110,7 @@ public async Task<ActionResult<List<Flight>>> FindFlightsByDateAsync(string star

List<Flight> flights = await _factory.Flights.FindFlightsAsync(null, null, null, flightStart, flightEnd, page, pageSize).ToListAsync();

if (!flights.Any())
if (flights.Count == 0)
{
return NoContent();
}
Expand Down
116 changes: 116 additions & 0 deletions src/DroneFlightLog.Api/Controllers/MaintainersController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
using DroneFlightLog.Data.Entities;
using DroneFlightLog.Data.Exceptions;
using DroneFlightLog.Data.Interfaces;
using DroneFlightLog.Data.Sqlite;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Web;

namespace DroneFlightLog.Api.Controllers
{
[Authorize]
[ApiController]
[ApiConventionType(typeof(DefaultApiConventions))]
[Route("[controller]")]
public class MaintainersController : Controller
{
private readonly IDroneFlightLogFactory<DroneFlightLogDbContext> _factory;

public MaintainersController(IDroneFlightLogFactory<DroneFlightLogDbContext> factory)
{
_factory = factory;
}

[HttpGet]
[Route("{id}")]
public async Task<ActionResult<Maintainer>> GetMaintainerAsync(int id)
{
Maintainer maintainer;

try
{
maintainer = await _factory.Maintainers.GetMaintainerAsync(id);
}
catch (MaintainerNotFoundException)
{
return NotFound();
}

return maintainer;
}

[HttpGet]
[Route("")]
public async Task<ActionResult<List<Maintainer>>> GetMaintainersAsync()
{
List<Maintainer> maintainers = await _factory.Maintainers.GetMaintainersAsync().ToListAsync();

if (maintainers.Count == 0)
{
return NoContent();
}

return maintainers;
}

[HttpGet]
[Route("{firstNames}/{surname}")]
public async Task<ActionResult<Maintainer>> FindMaintainerAsync(string firstNames, string surname)
{
string decodedFirstNames = HttpUtility.UrlDecode(firstNames);
string decodedSurname = HttpUtility.UrlDecode(surname);
Maintainer maintainer = await _factory.Maintainers.FindMaintainerAsync(decodedFirstNames, decodedSurname);

if (maintainer == null)
{
return NotFound();
}

return maintainer;
}

[HttpPut]
[Route("")]
public async Task<ActionResult<Maintainer>> UpdateMaintainerAsync([FromBody] Maintainer template)
{
Maintainer maintainer;

try
{
maintainer = await _factory.Maintainers.UpdateMaintainerAsync(template.Id,
template.FirstNames,
template.Surname);
await _factory.Context.SaveChangesAsync();
}
catch (MaintainerNotFoundException)
{
return NotFound();
}

return maintainer;
}

[HttpPost]
[Route("")]
public async Task<ActionResult<Maintainer>> CreateMaintainerAsync([FromBody] Maintainer template)
{
Maintainer maintainer;

try
{
maintainer = await _factory.Maintainers.AddMaintainerAsync(template.FirstNames,
template.Surname);
await _factory.Context.SaveChangesAsync();
}
catch (MaintainerExistsException)
{
return BadRequest();
}

return maintainer;
}
}
}
Loading
Loading