Skip to content

Commit

Permalink
chore: resolve miscellaneous issues in Timelines module
Browse files Browse the repository at this point in the history
  • Loading branch information
HunorTotBagi committed Dec 31, 2024
1 parent d607c9b commit 91eaa6f
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 35 deletions.
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
using BuildingBlocks.Domain.ValueObjects.Ids;
using Timelines.Application.Entities.Timelines.Commands.CreateTimeline;

// ReSharper disable ClassNeverInstantiated.Global

namespace Timelines.Api.Endpoints.Timelines;

public class CreateTimeline : ICarterModule
{
public void AddRoutes(IEndpointRouteBuilder app)
{
app.MapPost("/Timelines", async (CreateTimelineRequest request, ISender sender) =>
{
var command = request.Adapt<CreateTimelineCommand>();
var result = await sender.Send(command);
var response = result.Adapt<CreateTimelineResponse>();
{
var command = request.Adapt<CreateTimelineCommand>();
var result = await sender.Send(command);
var response = result.Adapt<CreateTimelineResponse>();

return Results.Created($"/Timelines/{response.Id}", response);
})
.WithName("CreateTimeline")
.Produces<CreateTimelineResponse>(StatusCodes.Status201Created)
.ProducesProblem(StatusCodes.Status400BadRequest)
.WithSummary("Create Timeline")
.WithDescription("Creates a new timeline");
return Results.Created($"/Timelines/{response.Id}", response);
})
.WithName("CreateTimeline")
.Produces<CreateTimelineResponse>(StatusCodes.Status201Created)
.ProducesProblem(StatusCodes.Status400BadRequest)
.WithSummary("Create Timeline")
.WithDescription("Creates a new timeline");
}
}

// ReSharper disable once NotAccessedPositionalProperty.Global
public record CreateTimelineRequest(TimelineDto Timeline);

public record CreateTimelineResponse(TimelineId Id);
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,21 @@ public class GetTimelineById : ICarterModule
public void AddRoutes(IEndpointRouteBuilder app)
{
app.MapGet("/Timelines/{timelineId}", async (string timelineId, ISender sender) =>
{
var result = await sender.Send(new GetTimelineByIdQuery(timelineId));
var response = result.Adapt<GetTimelineByIdResponse>();
{
var result = await sender.Send(new GetTimelineByIdQuery(timelineId));
var response = result.Adapt<GetTimelineByIdResponse>();

return Results.Ok(response);
})
.WithName("GetTimelineById")
.Produces<GetTimelineByIdResponse>()
.ProducesProblem(StatusCodes.Status400BadRequest)
.ProducesProblem(StatusCodes.Status404NotFound)
.WithSummary("Get Timeline by Id")
.WithDescription("Get Timeline by Id");
return Results.Ok(response);
})
.WithName("GetTimelineById")
.Produces<GetTimelineByIdResponse>()
.ProducesProblem(StatusCodes.Status400BadRequest)
.ProducesProblem(StatusCodes.Status404NotFound)
.WithSummary("Get Timeline by Id")
.WithDescription("Get Timeline by Id");
}
}


// ReSharper disable once ClassNeverInstantiated.Global
// ReSharper disable once NotAccessedPositionalProperty.Global
public record GetTimelineByIdResponse([property: JsonPropertyName("timeline")] TimelineDto TimelineDto);
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ public class ListTimelines : ICarterModule
public void AddRoutes(IEndpointRouteBuilder app)
{
app.MapGet("/Timelines", async ([AsParameters] PaginationRequest query, ISender sender) =>
{
var result = await sender.Send(new ListTimelinesQuery(query));
var response = result.Adapt<ListTimelinesResponse>();
{
var result = await sender.Send(new ListTimelinesQuery(query));
var response = result.Adapt<ListTimelinesResponse>();

return Results.Ok(response);
})
.WithName("ListTimelines")
.Produces<ListTimelinesResponse>()
.ProducesProblem(StatusCodes.Status400BadRequest)
.WithSummary("List Timelines")
.WithDescription("List Timelines");
return Results.Ok(response);
})
.WithName("ListTimelines")
.Produces<ListTimelinesResponse>()
.ProducesProblem(StatusCodes.Status400BadRequest)
.WithSummary("List Timelines")
.WithDescription("List Timelines");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

namespace Timelines.Application.Entities.Timelines.Commands.CreateTimeline;

// ReSharper disable once ClassNeverInstantiated.Global
public record CreateTimelineCommand(TimelineDto Timeline) : ICommand<CreateTimelineResult>;

// ReSharper disable once NotAccessedPositionalProperty.Global
public record CreateTimelineResult(TimelineId Id);

public class CreateTimelineCommandValidator : AbstractValidator<CreateTimelineCommand>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
namespace Timelines.Application.Entities.Timelines.Commands.CreateTimeline;

public class CreateTimelineHandler(ITimelinesDbContext dbContext) :
ICommandHandler<CreateTimelineCommand, CreateTimelineResult>
internal class CreateTimelineHandler(ITimelinesDbContext dbContext) : ICommandHandler<CreateTimelineCommand, CreateTimelineResult>
{
public async Task<CreateTimelineResult> Handle(CreateTimelineCommand command, CancellationToken cancellationToken)
{
Expand Down

0 comments on commit 91eaa6f

Please sign in to comment.