Skip to content

Commit

Permalink
feat: improve response types of API
Browse files Browse the repository at this point in the history
  • Loading branch information
romanett committed Nov 6, 2023
1 parent 123d013 commit dcd4d4a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
6 changes: 3 additions & 3 deletions GDSwithREST/Controllers/ApplicationsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ public ApplicationsController(GdsDbContext context, IApplicationsDatabase applic
/// <returns></returns>
// GET: /Applications
[HttpGet]
[ProducesResponseType(Microsoft.AspNetCore.Http.StatusCodes.Status200OK, Type = typeof(ApplicationApiModel))]
[ProducesResponseType(Microsoft.AspNetCore.Http.StatusCodes.Status200OK, Type = typeof(ApplicationApiModel[]))]
[ProducesResponseType(Microsoft.AspNetCore.Http.StatusCodes.Status404NotFound)]
public async Task<ActionResult<IEnumerable<ApplicationApiModel>>> GetApplications()
public async Task<ActionResult<ApplicationApiModel[]>> GetApplications()
{
if (_context.Applications == null)
{
Expand All @@ -50,7 +50,7 @@ public async Task<ActionResult<IEnumerable<ApplicationApiModel>>> GetApplication
var applicationsAsApiModel =
from application in applications
select new ApplicationApiModel(application);
return Ok(applicationsAsApiModel);
return Ok(applicationsAsApiModel.ToArray());
}
/// <summary>
/// Returns the specified Application
Expand Down
17 changes: 8 additions & 9 deletions GDSwithREST/Controllers/CertificateGroupsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ public CertificateGroupsController(ICertificateGroupDb certificates)
/// <returns></returns>
// GET: /CertificateGroups
[HttpGet]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(CertificateGroupApiModel))]
public ActionResult<IEnumerable<CertificateGroupApiModel>> GetCertificateGroups()
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(CertificateGroupApiModel[]))]
public ActionResult<CertificateGroupApiModel[]> GetCertificateGroups()
{
var certificateGroups =
from certificateGroup in _certificatesDatabase.CertificateGroups
select new CertificateGroupApiModel(certificateGroup);
return Ok(certificateGroups);
return Ok(certificateGroups.ToArray());
}
/// <summary>
/// Returns the CA Certificate of the specified Certificate Group
Expand Down Expand Up @@ -63,9 +63,9 @@ public ActionResult<X509CertificateApiModel> GetCertificateGroupCA(uint id)
/// <returns></returns>
// GET: /CertificateGroups/5/trustlist
[HttpGet("{id:int}/trustlist")]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(X509CertificateApiModel))]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(X509CertificateApiModel[]))]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task<ActionResult<IEnumerable<X509CertificateApiModel>>> GetCertificateGroupTrustList(uint id)
public async Task<ActionResult<X509CertificateApiModel[]>> GetCertificateGroupTrustList(uint id)
{
if (_certificatesDatabase == null)
{
Expand All @@ -81,7 +81,7 @@ public async Task<ActionResult<IEnumerable<X509CertificateApiModel>>> GetCertifi
var trustList =
from cert in trustedCertificatesCollection
select new X509CertificateApiModel(cert);
return Ok(trustList);
return Ok(trustList.ToArray());
}
/// <summary>
/// Regenerate the CA Certificate of the specified Certificate Group
Expand All @@ -94,9 +94,8 @@ from cert in trustedCertificatesCollection
[HttpPost("{id:int}/ca")]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(X509CertificateApiModel))]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task<ActionResult<X509CertificateApiModel>> PostCertificateGroupCA(uint id, [FromBody] JsonElement subjectNameRaw)
public async Task<ActionResult<X509CertificateApiModel>> PostCertificateGroupCA(uint id)
{
var subjectName = subjectNameRaw.ToString();
if (_certificatesDatabase == null)
{
return NotFound();
Expand All @@ -106,7 +105,7 @@ public async Task<ActionResult<X509CertificateApiModel>> PostCertificateGroupCA(
{
return NotFound();
}
await certificateGroup.CreateCACertificateAsync(subjectName);
await certificateGroup.CreateCACertificateAsync(certificateGroup.Configuration.SubjectName);

return Ok(new X509CertificateApiModel(certificateGroup.Certificate));
}
Expand Down

0 comments on commit dcd4d4a

Please sign in to comment.