PandaTech.ServiceResponse 1.1.4

There is a newer version of this package available.
See the version list below for details.
dotnet add package PandaTech.ServiceResponse --version 1.1.4
NuGet\Install-Package PandaTech.ServiceResponse -Version 1.1.4
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="PandaTech.ServiceResponse" Version="1.1.4" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add PandaTech.ServiceResponse --version 1.1.4
#r "nuget: PandaTech.ServiceResponse, 1.1.4"
#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.
// Install PandaTech.ServiceResponse as a Cake Addin
#addin nuget:?package=PandaTech.ServiceResponse&version=1.1.4

// Install PandaTech.ServiceResponse as a Cake Tool
#tool nuget:?package=PandaTech.ServiceResponse&version=1.1.4

ServiceResponse

Intro

This is service response template for .Net 6+ web api projects. This template is based on the best practices and has goal to harmonize all API I/O operations. The benefit of this template over other templates is that it totally integrates with OpenAPI and Swagger. So, IActionResults and other services, response will be visible in Swagger UI and loads of other features are and is going to be included.

This Template is designed by PandaTech LLC. We build software with the greatest quality! Our website: www.pandatech.it 😃


Example

Model

public class Blog
   {
       public int BlogId { get; set; }
       public string BlogName { get; set; }
       public string BlogDescription { get; set; }
   }

   public class Post
   {
       public int PostId { get; set; }
       public string PostName { get; set; }
       public string PostDescription { get; set; }
       public int BlogId { get; set; }
   }

Interface

public interface IService
{
   public ServiceResponse DeletePost(int postId);
   public ServiceResponse<Post> GetPost(int postId);
   public ServiceResponsePaged<List<Blog>> GetAllBlogs(int page, int pageSize);
}

Program.cs extract

builder.Services.AddTransient<IService, Services>();

#if DEBUG
   builder.Services.AddTransient<IExceptionHandler, DebugExceptionHandler>();
#else
   builder.Services.AddTransient<IExceptionHandler, PublicExceptionHandler>();
#endif

Service

public class Services : IService
{
   public ServiceResponse DeletePost(int postId)
   {
       var serviceResponse = new ServiceResponse();

       if (postId == 0) // just for example, cannot be in real case
       {
           serviceResponse.ResponseStatus = ServiceResponseStatus.NotFound;
           serviceResponse.Message = $"Post with id {postId} not found";
           serviceResponse.Success = false;
       }
       else
       {
           serviceResponse.Message = $"Post with id {postId} deleted";
           serviceResponse.ResponseStatus = ServiceResponseStatus.Ok;
       }

       return serviceResponse;
   }

   public ServiceResponse<Post> GetPost(int postId)
   {
       var serviceResponse = new ServiceResponse<Post>();


       serviceResponse.Data = new Post
       {
           PostId = postId,
           PostName = "Your post name",
           PostDescription = "Post Description",
       };

       return serviceResponse;
   }

   public ServiceResponsePaged<List<Blog>> GetAllBlogs(int page, int pageSize)
   {
       var serviceResponse = new ServiceResponsePaged<List<Blog>>();

       serviceResponse.Page = page;
       serviceResponse.PageSize = pageSize;
       serviceResponse.TotalCount = 1; // just for example

       serviceResponse.Data = new List<Blog>
       {
           new Blog
           {
               BlogId = 1,
               BlogName = "Your blog name",
               BlogDescription = "Blog Description",
           }
       };

       return serviceResponse;
   }
}

Controller

[ApiController]
[Route("[controller]")]
public class DemoController : ExtendedController
{
   private IService _service;

   public DemoController(IExceptionHandler exceptionHandler, IService service) : base(exceptionHandler)
   {
       _service = service;
   }

   [HttpDelete("Post")]
   public ServiceResponse DeletePost(int postId)
   {
       var serviceResponse = new ServiceResponse();
       try
       {
           serviceResponse = _service.DeletePost(postId);
       }
       catch (Exception e)
       {
           serviceResponse = ExceptionHandler.Handle(serviceResponse, e);
       }

       return SetResponse(serviceResponse);
   }

   [HttpGet("Post")]
   public ServiceResponse<Post> GetPost(int postId)
   {
       var serviceResponse = new ServiceResponse<Post>();
       try
       {
           serviceResponse = _service.GetPost(postId);
       }
       catch (Exception e)
       {
           serviceResponse = ExceptionHandler.Handle(serviceResponse, e);
       }

       return SetResponse(serviceResponse);
   }

   [HttpGet("Blogs")]
   public ServiceResponsePaged<List<Blog>> GetAllBlogs(int page, int pageSize)
   {
       var serviceResponse = new ServiceResponsePaged<List<Blog>>();
       try
       {
           serviceResponse = _service.GetAllBlogs(page, pageSize);
       }
       catch (Exception e)
       {
           serviceResponse = ExceptionHandler.Handle(serviceResponse, e);
       }

       return SetResponse(serviceResponse);
   }
}
Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on PandaTech.ServiceResponse:

Package Downloads
Pandatech.ResponseCrafter

Handling exceptions, custom Dtos.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.2.12 440 11/6/2023
1.2.11 93 11/1/2023
1.2.10 110 10/20/2023
1.2.9 114 10/20/2023
1.2.8 175 9/11/2023
1.2.7 104 9/6/2023
1.2.6 149 8/14/2023
1.2.5 158 8/14/2023
1.2.4 121 8/14/2023
1.2.3 124 8/9/2023
1.2.2 133 7/20/2023
1.2.1 157 6/13/2023
1.1.9 144 6/6/2023
1.1.8 129 6/2/2023
1.1.7 102 6/2/2023
1.1.6 98 6/2/2023
1.1.5 112 5/26/2023
1.1.4 319 4/5/2023
1.1.3 245 3/18/2023
1.1.2 191 3/17/2023
1.1.1 200 3/17/2023
1.1.0 200 3/16/2023
1.0.0 200 2/14/2023

Readme demo update only.