-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Manage mandates in admin area (#227)
- Loading branch information
Showing
33 changed files
with
1,217 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using Geopilot.Api.Authorization; | ||
using Geopilot.Api.DTOs; | ||
using Geopilot.Api.Models; | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.EntityFrameworkCore; | ||
using Swashbuckle.AspNetCore.Annotations; | ||
|
||
namespace Geopilot.Api.Controllers; | ||
|
||
/// <summary> | ||
/// Controller for organisations. | ||
/// </summary> | ||
[ApiController] | ||
[Route("api/v{version:apiVersion}/[controller]")] | ||
public class OrganisationController : ControllerBase | ||
{ | ||
private readonly ILogger<OrganisationController> logger; | ||
private readonly Context context; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="OrganisationController"/> class. | ||
/// </summary> | ||
/// <param name="logger">Logger for the instance.</param> | ||
/// <param name="context">Database context for getting organisations.</param> | ||
public OrganisationController(ILogger<OrganisationController> logger, Context context) | ||
{ | ||
this.logger = logger; | ||
this.context = context; | ||
} | ||
|
||
/// <summary> | ||
/// Get a list of organisations. | ||
/// </summary> | ||
[HttpGet] | ||
[Authorize(Policy = GeopilotPolicies.Admin)] | ||
[SwaggerResponse(StatusCodes.Status200OK, "Returns list of organisations.", typeof(IEnumerable<Organisation>), new[] { "application/json" })] | ||
public IActionResult Get() | ||
{ | ||
logger.LogInformation("Getting organisations."); | ||
|
||
var organisations = context.Organisations | ||
.Include(o => o.Mandates) | ||
.Include(o => o.Users) | ||
.AsNoTracking() | ||
.Select(OrganisationDto.FromOrganisation) | ||
.ToList(); | ||
|
||
return Ok(organisations); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using NetTopologySuite.Geometries; | ||
|
||
namespace Geopilot.Api.DTOs; | ||
|
||
/// <summary> | ||
/// A coordinate in a two-dimensional space. | ||
/// </summary> | ||
public class CoordinateDto | ||
{ | ||
/// <summary> | ||
/// Create a new <see cref="CoordinateDto"/> from a <see cref="Coordinate"/>. | ||
/// </summary> | ||
/// <param name="coordinate"></param> | ||
/// <returns></returns> | ||
public static CoordinateDto FromCoordinate(Coordinate coordinate) | ||
{ | ||
return new CoordinateDto | ||
{ | ||
X = coordinate.X, | ||
Y = coordinate.Y, | ||
}; | ||
} | ||
|
||
/// <summary> | ||
/// The x-coordinate of the coordinate. | ||
/// </summary> | ||
public double X { get; set; } | ||
|
||
/// <summary> | ||
/// The y-coordinate of the coordinate. | ||
/// </summary> | ||
public double Y { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
using Geopilot.Api.Models; | ||
|
||
namespace Geopilot.Api.DTOs; | ||
|
||
/// <summary> | ||
/// A contract between the system owner and an organisation for data delivery. | ||
/// The mandate describes where and in what format data should be delivered. | ||
/// </summary> | ||
public class MandateDto | ||
{ | ||
/// <summary> | ||
/// Create a new <see cref="MandateDto"/> from a <see cref="Mandate"/>. | ||
/// </summary> | ||
public static MandateDto FromMandate(Mandate mandate) | ||
{ | ||
var wkt = mandate.SpatialExtent.AsText(); | ||
var spatialExtent = new List<CoordinateDto>(); | ||
if (mandate.SpatialExtent.Coordinates.Length == 5) | ||
{ | ||
spatialExtent.Add(CoordinateDto.FromCoordinate(mandate.SpatialExtent.Coordinates[0])); | ||
spatialExtent.Add(CoordinateDto.FromCoordinate(mandate.SpatialExtent.Coordinates[2])); | ||
} | ||
|
||
return new MandateDto | ||
{ | ||
Id = mandate.Id, | ||
Name = mandate.Name, | ||
FileTypes = mandate.FileTypes, | ||
SpatialExtent = spatialExtent, | ||
Organisations = mandate.Organisations.Select(o => o.Id).ToList(), | ||
Deliveries = mandate.Deliveries.Select(d => d.Id).ToList(), | ||
}; | ||
} | ||
|
||
/// <summary> | ||
/// The unique identifier for the mandate. | ||
/// </summary> | ||
public int Id { get; set; } | ||
|
||
/// <summary> | ||
/// The display name of the mandate. | ||
/// </summary> | ||
public string Name { get; set; } = string.Empty; | ||
|
||
/// <summary> | ||
/// List of file types that are allowed to be delivered. Include the period "." and support wildcards "*". | ||
/// </summary> | ||
#pragma warning disable CA1819 // Properties should not return arrays | ||
public string[] FileTypes { get; set; } = Array.Empty<string>(); | ||
#pragma warning restore CA1819 // Properties should not return arrays | ||
|
||
/// <summary> | ||
/// The minimum and maximum coordinates of the spatial extent of the mandate. | ||
/// </summary> | ||
public List<CoordinateDto> SpatialExtent { get; set; } = new List<CoordinateDto>(); | ||
|
||
/// <summary> | ||
/// IDs of the organisations allowed to deliver data fulfilling the mandate. | ||
/// </summary> | ||
public List<int> Organisations { get; set; } = new List<int>(); | ||
|
||
/// <summary> | ||
/// IDs of the data deliveries that have been declared fulfilling the mandate. | ||
/// </summary> | ||
public List<int> Deliveries { get; set; } = new List<int>(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using Geopilot.Api.Models; | ||
|
||
namespace Geopilot.Api.DTOs; | ||
|
||
/// <summary> | ||
/// A company or group of users that may have a mandate for delivering data to the system owner. | ||
/// </summary> | ||
public class OrganisationDto | ||
{ | ||
/// <summary> | ||
/// Create a new <see cref="OrganisationDto"/> from a <see cref="Organisation"/>. | ||
/// </summary> | ||
public static OrganisationDto FromOrganisation(Organisation organisation) | ||
{ | ||
return new OrganisationDto | ||
{ | ||
Id = organisation.Id, | ||
Name = organisation.Name, | ||
Users = organisation.Users.Select(u => u.Id).ToList(), | ||
Mandates = organisation.Mandates.Select(m => m.Id).ToList(), | ||
}; | ||
} | ||
|
||
/// <summary> | ||
/// The unique identifier for the organisation. | ||
/// </summary> | ||
public int Id { get; set; } | ||
|
||
/// <summary> | ||
/// The display name of the organisation. | ||
/// </summary> | ||
public string Name { get; set; } = string.Empty; | ||
|
||
/// <summary> | ||
/// IDs of the users that are members of the organisation. | ||
/// </summary> | ||
public List<int> Users { get; set; } = new List<int>(); | ||
|
||
/// <summary> | ||
/// IDs of the mandates the organisation has for delivering data to the system owner. | ||
/// </summary> | ||
public List<int> Mandates { get; set; } = new List<int>(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
namespace Geopilot.Api.Models; | ||
|
||
/// <summary> | ||
/// An object that can be identified by a numeric ID. | ||
/// </summary> | ||
public interface IIdentifiable | ||
{ | ||
/// <summary> | ||
/// Gets or sets the entity's id. | ||
/// </summary> | ||
public int Id { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.