Skip to content

Commit

Permalink
fix: creating new FileAsset returns correct response
Browse files Browse the repository at this point in the history
  • Loading branch information
HunorTotBagi committed Dec 30, 2024
1 parent 6bfc4ed commit cda2685
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
14 changes: 5 additions & 9 deletions Backend/src/Modules/Files/Files.Api/Endpoints/CreateFileAsset.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
using BuildingBlocks.Domain.ValueObjects.Ids;
using Carter;
using Files.Application.Dtos;
using Files.Application.Files.Commands.CreateFileAsset;
using Mapster;
using MediatR;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Routing;

// ReSharper disable ClassNeverInstantiated.Global

namespace Files.Api.Endpoints;

Expand All @@ -20,7 +15,7 @@ public void AddRoutes(IEndpointRouteBuilder app)
var result = await sender.Send(command);
var response = result.Adapt<CreateFileAssetResponse>();

return Results.Created($"/Files/{response.AssetId}", response);
return Results.Created($"/Files/{response.Id}", response);
})
.WithName("CreateFileAsset")
.Produces<CreateFileAssetResponse>(StatusCodes.Status201Created)
Expand All @@ -30,6 +25,7 @@ public void AddRoutes(IEndpointRouteBuilder app)
}
}

// ReSharper disable once NotAccessedPositionalProperty.Global
public record CreateFileAssetRequest(FileAssetDto FileAsset);

public record CreateFileAssetResponse(FileAssetId AssetId);
public record CreateFileAssetResponse(FileAssetId Id);
7 changes: 7 additions & 0 deletions Backend/src/Modules/Files/Files.Api/GlobalUsing.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
global using Carter;
global using Mapster;
global using MediatR;
global using Microsoft.AspNetCore.Builder;
global using Microsoft.AspNetCore.Http;
global using Microsoft.AspNetCore.Routing;
global using Files.Application.Dtos;
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Files.Application.Files.Commands.CreateFileAsset;

public record CreateFileAssetCommand(FileAssetDto FileAsset) : ICommand<CreateFileAssetResult>;

public record CreateFileAssetResult(FileAssetId AssetId);
public record CreateFileAssetResult(FileAssetId Id);

public class CreateFileCommandValidator : AbstractValidator<CreateFileAssetCommand>
{
Expand Down
4 changes: 2 additions & 2 deletions Backend/src/Modules/Files/Files.Domain/Models/FileAsset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ public class FileAsset : Aggregate<FileAssetId>

#region File

public static FileAsset Create(FileAssetId fileAssetId, string name, float size, string type, string owner, string description, List<string> sharedWith)
public static FileAsset Create(FileAssetId id, string name, float size, string type, string owner, string description, List<string> sharedWith)
{
var file = new FileAsset
{
Id = fileAssetId,
Id = id,
Name = name,
Size = size,
Type = type,
Expand Down

0 comments on commit cda2685

Please sign in to comment.