Flavio.Santos.NetCore.ApiResponse 1.0.7

There is a newer version of this package available.
See the version list below for details.
dotnet add package Flavio.Santos.NetCore.ApiResponse --version 1.0.7
                    
NuGet\Install-Package Flavio.Santos.NetCore.ApiResponse -Version 1.0.7
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Flavio.Santos.NetCore.ApiResponse" Version="1.0.7" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Flavio.Santos.NetCore.ApiResponse" Version="1.0.7" />
                    
Directory.Packages.props
<PackageReference Include="Flavio.Santos.NetCore.ApiResponse" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Flavio.Santos.NetCore.ApiResponse --version 1.0.7
                    
#r "nuget: Flavio.Santos.NetCore.ApiResponse, 1.0.7"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=Flavio.Santos.NetCore.ApiResponse&version=1.0.7
                    
Install Flavio.Santos.NetCore.ApiResponse as a Cake Addin
#tool nuget:?package=Flavio.Santos.NetCore.ApiResponse&version=1.0.7
                    
Install Flavio.Santos.NetCore.ApiResponse as a Cake Tool

FDS.NetCore.ApiResponse

🚀 FDS.UuidV7.NetCore is a lightweight .NET library for generating UUID v7 (time-based UUIDs) according to the official specification.

NuGet NuGet Downloads License .NET Core

📦 Installation

You can install this package via NuGet Package Manager:

dotnet add package Flavio.Santos.NetCore.ApiResponse --version 1.0.2

Or using Package Manager Console:

Install-Package Flavio.Santos.NetCore.ApiResponse -Version 1.0.2

🚀 Usage

Creating a Standard API Response

Adding a New Client
public async Task<Response<ClientDto>> AddAsync(ClientRequestDto request)
{
    if (await _clientRepository.ExistsByNameAsync(request.Name))
    {
        return Result.Create<ClientDto>(
            actionType: ActionType.VALIDATION_ERROR,
            message: "A client with this name already exists."
        );
    }

    var client = new Client(Guid.NewGuid(), request.Name);
    await _clientRepository.AddAsync(client);
    var clientDto = new ClientDto { Id = client.Id, Name = client.Name };

    return Result.Create(
        actionType: ActionType.CREATE,
        message: "Client created successfully.",
        data: clientDto
    );
}
Deleting a Client
public async Task<Response<bool>> DeleteAsync(Guid id)
{
    var client = await _clientRepository.GetByIdAsync(id);

    if (client is null)
    {
        return Result.Create<bool>(
            actionType: ActionType.NOT_FOUND,
            message: "Client not found."
        );
    }

    await _clientRepository.DeleteAsync(id);

    return Result.Create<bool>(
        actionType: ActionType.DELETE,
        message: "Client deleted successfully."
    );
}

Example of Using the New LogCreateAsync() Method

Now, when creating a new order, we log an audit entry using LogCreateAsync.

Creating a New Order (OrderService)
public class OrderService
{
    private readonly IOrderRepository _orderRepository;
    private readonly IAuditLogService _auditLogService;

    public OrderService(IOrderRepository orderRepository, IAuditLogService auditLogService)
    {
        _orderRepository = orderRepository;
        _auditLogService = auditLogService;
    }

    public async Task<Response<OrderDto>> CreateOrderAsync(OrderRequestDto request)
    {
        try
        {
            if (await _orderRepository.ExistsByReferenceAsync(request.Reference))
            {
                string errorMsg = "An order with this reference already exists.";
                
                await _auditLogService.LogValidationErrorAsync(errorMsg, request);
                
                return Result.Create<OrderDto>(
                    actionType: ActionType.VALIDATION_ERROR,
                    message: errorMsg
                );
            }

            var order = new Order(Guid.NewGuid(), request.Reference, request.Amount);
            await _orderRepository.AddAsync(order);
            var orderDto = new OrderDto { Id = order.Id, Reference = order.Reference, Amount = order.Amount };

            string successMsg = "Order created successfully.";

            // ⬇️ Logging the creation event using LogCreateAsync
            await _auditLogService.LogCreateAsync(successMsg, request, orderDto);

            return Result.CreateSuccess(successMsg, orderDto);
        }
        catch (Exception ex)
        {
            return Result.Create<OrderDto>(
                actionType: ActionType.ERROR,
                message: $"An unexpected error occurred: {ex.Message}"
            );
        }
    }
}
How Is LogCreateAsync() Used?

1️⃣ Before saving the order, we check if it already exists → If so, we log a validation error (LogValidationErrorAsync).

2️⃣ We create the order in the database.

3️⃣ We log the creation event (LogCreateAsync), including both the request and response data.

4️⃣ We return a standardized response (CreateSuccess).

📌 Output Example

Client Not Found (404)
{
  "isSuccess": false,
  "message": "Client not found.",
  "statusCode": 404
}
Client Created Successfully (201)
{
  "isSuccess": true,
  "message": "Client created successfully.",
  "statusCode": 201,
  "data": {
    "id": "bf5d9501-032f-447b-bfaf-8cc4fff19e61",
    "name": "Teste"
  }
}
Client Already Exists (400)
{
  "isSuccess": false,
  "message": "A client with this name already exists.",
  "statusCode": 400
}
Client Deleted Successfully (200)
{
  "isSuccess": true,
  "message": "Client deleted successfully.",
  "statusCode": 200
}

🎯 Features

  • Standardized API response format
  • Built-in status codes and messages
  • Easy integration with Clean Architecture
  • Fully compatible with .NET 8

📜 License

This project is licensed under the MIT License - see the LICENSE file for details.

🔙 Back to Main README

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.16 0 4/21/2025
1.0.15 463 3/25/2025
1.0.14 468 3/25/2025
1.0.13 461 3/25/2025
1.0.12 324 3/24/2025
1.0.11 250 3/24/2025
1.0.10 250 3/23/2025
1.0.9 136 3/16/2025
1.0.8 122 3/16/2025
1.0.7 140 3/14/2025
1.0.6 137 3/14/2025
1.0.5 131 3/13/2025
1.0.4 133 3/13/2025
1.0.3 202 3/3/2025
1.0.2 184 3/3/2025
1.0.1 93 3/2/2025
1.0.0 82 3/2/2025