Skip to content

Commit

Permalink
well things work now, lets see how ci goes
Browse files Browse the repository at this point in the history
  • Loading branch information
david-driscoll committed Nov 29, 2024
1 parent c864f71 commit ba0702d
Show file tree
Hide file tree
Showing 69 changed files with 4,856 additions and 6,090 deletions.
14 changes: 1 addition & 13 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -140,18 +140,6 @@ jobs:
id: default
run: |
dotnet .build/bin/Debug/.build.dll --target Default --skip Restore Build Test Pack
- name: 🏺 Publish coverage data
if: always()
uses: actions/[email protected]
with:
name: 'coverage'
path: 'coverage/'
- name: 📫 Publish Coverage
if: (github.event_name != 'pull_request' && github.event_name != 'pull_request_target') || ((github.event_name == 'pull_request' || github.event_name == 'pull_request_target') && github.event.pull_request.user.login != 'renovate[bot]' && github.event.pull_request.user.login != 'dependabot[bot]')
uses: codecov/[email protected]
with:
name: 'actions-${{ matrix.os }}'
token: '${{ secrets.CODECOV_TOKEN }}'
- name: 🏺 Publish logs
if: always()
uses: actions/[email protected]
Expand Down Expand Up @@ -184,7 +172,7 @@ jobs:
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
- name: 📫 Publish Codecov Coverage
if: (github.event_name != 'pull_request' && github.event_name != 'pull_request_target') || ((github.event_name == 'pull_request' || github.event_name == 'pull_request_target') && github.event.pull_request.user.login != 'renovate[bot]' && github.event.pull_request.user.login != 'dependabot[bot]')
uses: codecov/[email protected].3
uses: codecov/[email protected].7
with:
name: 'actions'
token: '${{ secrets.CODECOV_TOKEN }}'
Expand Down
4 changes: 2 additions & 2 deletions sample/Sample.BlazorServer/Pages/Rockets/Delete.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ public partial class Delete : ComponentBase

protected override async Task OnInitializedAsync()
{
Model = await Mediator.Send(new GetRocket.Request { Id = Id });
Model = await Mediator.Send(new GetRocket.Request(Id));
}

public async Task Save()
{
await Mediator.Send(new DeleteRocket.Request { Id = Id });
await Mediator.Send(new DeleteRocket.Request(Id));
NavigationManager.NavigateTo("/rockets");
}
}
4 changes: 2 additions & 2 deletions sample/Sample.BlazorServer/Pages/Rockets/Edit.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ public partial class Edit : ComponentBase

protected override async Task OnInitializedAsync()
{
Model = EditRocket.MapRequest(await Mediator.Send(new GetRocket.Request { Id = Id, }));
Model = EditRocket.MapRequest(await Mediator.Send(new GetRocket.Request(Id)));
}

public async Task Save()
{
await Mediator.Send(Model with { Id = Id, });
NavigationManager.NavigateTo("/rockets");
}
}
}
2 changes: 1 addition & 1 deletion sample/Sample.BlazorServer/Pages/Rockets/View.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ public partial class View : ComponentBase

protected override async Task OnInitializedAsync()
{
Model = await Mediator.Send(new GetRocket.Request { Id = Id });
Model = await Mediator.Send(new GetRocket.Request(Id));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,8 @@ public static partial class DeleteLaunchRecord
/// <summary>
/// The request to delete a launch record
/// </summary>
public record Request : IRequest
{
/// <summary>
/// The launch record to delete
/// </summary>
public LaunchRecordId Id { get; init; }
}
/// <param name="Id">The id of the record to delete</param>
public record Request(LaunchRecordId Id) : IRequest;

[UsedImplicitly]
private class Validator : AbstractValidator<Request>
Expand Down Expand Up @@ -51,4 +46,4 @@ public async Task Handle(Request request, CancellationToken cancellationToken)
await dbContext.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
}
}
}
}
11 changes: 3 additions & 8 deletions sample/Sample.Core/Operations/LaunchRecords/GetLaunchRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,8 @@ public static partial class GetLaunchRecord
/// <summary>
/// The request to get a launch record
/// </summary>
public record Request : IRequest<LaunchRecordModel>
{
/// <summary>
/// The launch record to find
/// </summary>
public LaunchRecordId Id { get; init; }
}
/// <param name="Id">The id of the launch record</param>
public record Request(LaunchRecordId Id) : IRequest<LaunchRecordModel>;

private class Validator : AbstractValidator<Request>
{
Expand All @@ -48,4 +43,4 @@ public async Task<LaunchRecordModel> Handle(Request request, CancellationToken c
return ModelMapper.Map(rocket);
}
}
}
}
11 changes: 3 additions & 8 deletions sample/Sample.Core/Operations/Rockets/DeleteRocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,8 @@ public static partial class DeleteRocket
/// <summary>
/// The request to remove a rocket from the system
/// </summary>
public record Request : IRequest
{
/// <summary>
/// The rocket id
/// </summary>
public RocketId Id { get; init; }
}
/// <param name="Id">The id of the rocket to remove</param>
public record Request(RocketId Id) : IRequest;

private class Validator : AbstractValidator<Request>
{
Expand All @@ -45,4 +40,4 @@ public async Task Handle(Request request, CancellationToken cancellationToken)
await dbContext.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
}
}
}
}
11 changes: 3 additions & 8 deletions sample/Sample.Core/Operations/Rockets/GetRocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,8 @@ public static partial class GetRocket
/// <summary>
/// Request to fetch information about a rocket
/// </summary>
public record Request : IRequest<RocketModel>
{
/// <summary>
/// The rocket id
/// </summary>
public RocketId Id { get; set; }
}
/// <param name="Id">The id of the rocket</param>
public record Request(RocketId Id) : IRequest<RocketModel>;

private class Validator : AbstractValidator<Request>
{
Expand All @@ -41,4 +36,4 @@ public async Task<RocketModel> Handle(Request request, CancellationToken cancell
return ModelMapper.Map(await dbContext.Rockets.FindAsync([request.Id,], cancellationToken).ConfigureAwait(false) ?? throw new NotFoundException());
}
}
}
}
11 changes: 11 additions & 0 deletions sample/Sample.Minimal/CustomHostedService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Microsoft.Extensions.Options;

internal class CustomHostedService(IOptions<CustomHostedServiceOptions> options) : BackgroundService
{
protected override Task ExecuteAsync(CancellationToken stoppingToken)
{
// ReSharper disable once UnusedVariable
var v = options.Value.A;
return Task.CompletedTask;
}
}
15 changes: 15 additions & 0 deletions sample/Sample.Minimal/CustomHostedServiceOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using FluentValidation;

internal class CustomHostedServiceOptions
{
public string? A { get; set; }

[UsedImplicitly]
private sealed class Validator : AbstractValidator<CustomHostedServiceOptions>
{
public Validator()
{
RuleFor(z => z.A).NotNull();
}
}
}
69 changes: 69 additions & 0 deletions sample/Sample.Minimal/LaunchRecordEndpoints.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using MediatR;
using Microsoft.AspNetCore.Http.HttpResults;
using Microsoft.AspNetCore.Mvc;
using Sample.Core.Domain;
using Sample.Core.Models;
using Sample.Core.Operations.LaunchRecords;

internal static partial class LaunchRecordEndpoints
{
public static void UseLaunchRecords(this WebApplication app)
{
app.MapGet("/launch-records", ListLaunchRecords);
app.MapGet("/launch-records/{id:guid}", GetLaunchRecord);
app.MapPost("/launch-records", CreateLaunchRecord);
app.MapPut("/launch-records/{id:guid}", EditLaunchRecord);
app.MapPatch("/launch-records/{id:guid}", PatchLaunchRecord);
app.MapDelete("/launch-records/{id:guid}", DeleteLaunchRecord);
}

[EndpointName(nameof(ListLaunchRecords))]
private static Ok<IAsyncEnumerable<LaunchRecordModel>> ListLaunchRecords(IMediator mediator, RocketType? rocketType) =>
TypedResults.Ok(mediator.CreateStream(new ListLaunchRecords.Request(rocketType)));

[EndpointName(nameof(GetLaunchRecord))]
private static async Task<Results<Ok<LaunchRecordModel>, NotFound, ProblemHttpResult>> GetLaunchRecord(
IMediator mediator,
LaunchRecordId id,
CancellationToken cancellationToken
) => TypedResults.Ok(await mediator.Send(new GetLaunchRecord.Request(id), cancellationToken));

[EndpointName(nameof(CreateLaunchRecord))]
private static async Task<Results<CreatedAtRoute<CreateLaunchRecord.Response>, ProblemHttpResult, BadRequest>> CreateLaunchRecord(
IMediator mediator,
CreateLaunchRecord.Request request
)
{
return TypedResults.CreatedAtRoute(await mediator.Send(request), nameof(GetLaunchRecord));
}

/// <summary>
/// Does this comment get picked up?
/// </summary>
/// <param name="mediator"></param>
/// <param name="id"></param>
/// <param name="model"></param>
/// <returns></returns>
[EndpointName(nameof(EditLaunchRecord))]
private static async Task<Results<Ok<LaunchRecordModel>, NotFound, ProblemHttpResult, BadRequest>> EditLaunchRecord(
IMediator mediator,
[FromRoute]
LaunchRecordId id,
EditLaunchRecord.Request model
) => TypedResults.Ok(await mediator.Send(model with { Id = id }));

[EndpointName(nameof(PatchLaunchRecord))]
private static async Task<Results<Ok<LaunchRecordModel>, NotFound, ProblemHttpResult, BadRequest>> PatchLaunchRecord(
IMediator mediator,
[FromRoute]
LaunchRecordId id,
EditLaunchRecord.PatchRequest model
) => TypedResults.Ok(await mediator.Send(model with { Id = id }));

[EndpointName(nameof(DeleteLaunchRecord))]
private static async Task<Results<NoContent, NotFound>> DeleteLaunchRecord(IMediator mediator, [FromRoute] LaunchRecordId id)
{
await mediator.Send(new DeleteLaunchRecord.Request(id));
return TypedResults.NoContent();
}
}
90 changes: 2 additions & 88 deletions sample/Sample.Minimal/Program.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
using System.Reflection;
using System.Text;
using System.Text.Json;
using FluentValidation;
using Humanizer;
using MediatR;
using Microsoft.AspNetCore.Http.HttpResults;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Diagnostics.HealthChecks;
using Microsoft.Extensions.Options;
using Rocket.Surgery.Hosting;
using Rocket.Surgery.LaunchPad.AspNetCore;
using Sample.Core.Models;
using Sample.Core.Operations.LaunchRecords;
using Sample.Minimal;
using Serilog;

Expand Down Expand Up @@ -40,6 +33,8 @@
app
.UseSwaggerUI()
.UseReDoc();
app.UseLaunchRecords();
app.UseRockets();

app.UseAuthorization();
app.MapHealthChecks(
Expand All @@ -56,87 +51,6 @@
}
);

app.MapGet("/launch-records", LaunchPadApi.ListLaunchRecords);
app.MapGet("/launch-records/{id:guid}", LaunchPadApi.GetLaunchRecord);
//[Route("[controller]")]
//public partial class LaunchRecordController : RestfulApiController
//{
// /// <summary>
// /// Create a new launch record
// /// </summary>
// /// <param name="request">The launch record details</param>
// /// <returns></returns>
// [HttpPost]
// [Created(nameof(GetLaunchRecord))]
// public partial Task<ActionResult<CreateLaunchRecord.Response>> CreateLaunchRecord(CreateLaunchRecord.Request request);
//
// /// <summary>
// /// Update a given launch record
// /// </summary>
// /// <param name="id">The id of the launch record</param>
// /// <param name="model">The request details</param>
// /// <returns></returns>
// [HttpPut("{id:guid}")]
// // ReSharper disable once RouteTemplates.ParameterTypeAndConstraintsMismatch
// public partial Task<ActionResult> EditLaunchRecord([BindRequired] [FromRoute] LaunchRecordId id, EditLaunchRecord.Request model);
//
// /// <summary>
// /// Update a given launch record
// /// </summary>
// /// <param name="id">The id of the launch record</param>
// /// <param name="model">The request details</param>
// /// <returns></returns>
// [HttpPatch("{id:guid}")]
// // ReSharper disable once RouteTemplates.ParameterTypeAndConstraintsMismatch
// public partial Task<ActionResult> PatchLaunchRecord([BindRequired] [FromRoute] LaunchRecordId id, EditLaunchRecord.PatchRequest model);
//
// /// <summary>
// /// Remove a launch record
// /// </summary>
// /// <param name="request"></param>
// /// <returns></returns>
// [HttpDelete("{id:guid}")]
// public partial Task<ActionResult> DeleteLaunchRecord(DeleteLaunchRecord.Request request);


app.Run();

public partial class Program;

internal class CustomHostedServiceOptions
{
public string? A { get; set; }

[UsedImplicitly]
private sealed class Validator : AbstractValidator<CustomHostedServiceOptions>
{
public Validator()
{
RuleFor(z => z.A).NotNull();
}
}
}

internal class CustomHostedService(IOptions<CustomHostedServiceOptions> options) : BackgroundService
{
protected override Task ExecuteAsync(CancellationToken stoppingToken)
{
// ReSharper disable once UnusedVariable
var v = options.Value.A;
return Task.CompletedTask;
}
}


public static partial class LaunchPadApi
{
public static Ok<IAsyncEnumerable<LaunchRecordModel>> ListLaunchRecords(IMediator mediator, ListLaunchRecords.Request request) =>
TypedResults.Ok(mediator.CreateStream(request));

public static async Task<Ok<LaunchRecordModel>> GetLaunchRecord(
IMediator mediator,
[FromRoute]
GetLaunchRecord.Request request,
CancellationToken cancellationToken
) => TypedResults.Ok(await mediator.Send(request, cancellationToken));
}
Loading

0 comments on commit ba0702d

Please sign in to comment.