Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add error based response #68

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
**/.classpath
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

سلام؛
آقا ما از پروژه های این مخزن داکر ایمیج میسازیم ؟ فکر کنم به ازای هر Dockerfile باید یدونه از اینا داشته باشیم.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

برای پروژه های تستی نیاز هست که DockerImage داشته باشیم ؟

**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/azds.yaml
**/bin
**/charts
**/docker-compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
LICENSE
README.md
!**/.gitignore
!.git/HEAD
!.git/config
!.git/packed-refs
!.git/refs/heads/**
44 changes: 44 additions & 0 deletions BSN.Commons.sln
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,24 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BSN.Commons.Orm.EntityFrame
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BSN.Commons.Users", "Source\BSN.Commons.Users\BSN.Commons.Users.csproj", "{213ABCEF-7E9A-4CE5-A3EF-289C9781344D}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "GrpcIntegrationTest", "GrpcIntegrationTest", "{54C74546-38B4-4618-AA40-334463F49C54}"
ProjectSection(SolutionItems) = preProject
Test\GrpcIntegrationTest\README.md = Test\GrpcIntegrationTest\README.md
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BSN.Commons.GrpcIntegrationTest.Sample.Service", "Test\GrpcIntegrationTest\BSN.Commons.GrpcIntegrationTest.Sample.Service\BSN.Commons.GrpcIntegrationTest.Sample.Service.csproj", "{08C7C14B-D2E9-4FA0-BD0C-7DDA9582DC6D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BSN.Commons.GrpcIntegrationTest.Sample.AppService.Contract", "Test\GrpcIntegrationTest\BSN.Commons.GrpcIntegrationTest.Sample.AppService.Contract\BSN.Commons.GrpcIntegrationTest.Sample.AppService.Contract.csproj", "{283F2163-BB83-4770-AA1A-F52FEFE8E1CF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BSN.Commons.GrpcIntegrationTest.Sample.Console", "Test\GrpcIntegrationTest\BSN.Commons.GrpcIntegrationTest.Sample.Console\BSN.Commons.GrpcIntegrationTest.Sample.Console.csproj", "{7799FBC7-13EB-4382-83D7-FE9396039C77}"
ProjectSection(ProjectDependencies) = postProject
{08C7C14B-D2E9-4FA0-BD0C-7DDA9582DC6D} = {08C7C14B-D2E9-4FA0-BD0C-7DDA9582DC6D}
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BSN.Commons.TestHelpers", "Source\BSN.Commons.TestHelpers\BSN.Commons.TestHelpers.csproj", "{1ACB3F86-D8AA-4CA4-B0BD-B1833E235F14}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BSN.Commons.Grpc.IntegratonTest", "Test\GrpcIntegrationTest\BSN.Commons.Grpc.IntegratonTest\BSN.Commons.Grpc.IntegratonTest.csproj", "{C5213190-E6BD-4B45-9C09-0951D3387CAD}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -81,6 +99,26 @@ Global
{213ABCEF-7E9A-4CE5-A3EF-289C9781344D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{213ABCEF-7E9A-4CE5-A3EF-289C9781344D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{213ABCEF-7E9A-4CE5-A3EF-289C9781344D}.Release|Any CPU.Build.0 = Release|Any CPU
{08C7C14B-D2E9-4FA0-BD0C-7DDA9582DC6D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{08C7C14B-D2E9-4FA0-BD0C-7DDA9582DC6D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{08C7C14B-D2E9-4FA0-BD0C-7DDA9582DC6D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{08C7C14B-D2E9-4FA0-BD0C-7DDA9582DC6D}.Release|Any CPU.Build.0 = Release|Any CPU
{283F2163-BB83-4770-AA1A-F52FEFE8E1CF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{283F2163-BB83-4770-AA1A-F52FEFE8E1CF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{283F2163-BB83-4770-AA1A-F52FEFE8E1CF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{283F2163-BB83-4770-AA1A-F52FEFE8E1CF}.Release|Any CPU.Build.0 = Release|Any CPU
{7799FBC7-13EB-4382-83D7-FE9396039C77}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7799FBC7-13EB-4382-83D7-FE9396039C77}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7799FBC7-13EB-4382-83D7-FE9396039C77}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7799FBC7-13EB-4382-83D7-FE9396039C77}.Release|Any CPU.Build.0 = Release|Any CPU
{1ACB3F86-D8AA-4CA4-B0BD-B1833E235F14}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1ACB3F86-D8AA-4CA4-B0BD-B1833E235F14}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1ACB3F86-D8AA-4CA4-B0BD-B1833E235F14}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1ACB3F86-D8AA-4CA4-B0BD-B1833E235F14}.Release|Any CPU.Build.0 = Release|Any CPU
{C5213190-E6BD-4B45-9C09-0951D3387CAD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C5213190-E6BD-4B45-9C09-0951D3387CAD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C5213190-E6BD-4B45-9C09-0951D3387CAD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C5213190-E6BD-4B45-9C09-0951D3387CAD}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -94,6 +132,12 @@ Global
{906FEED8-23E0-4EEF-B902-C39325C50480} = {5C6BA7B5-832A-495A-AF5E-C2A74F6A1EF9}
{335F645B-C85F-42C2-9185-A216101F60C7} = {DC377ADC-CC9D-4785-81BE-726DBF5F3096}
{213ABCEF-7E9A-4CE5-A3EF-289C9781344D} = {DC377ADC-CC9D-4785-81BE-726DBF5F3096}
{54C74546-38B4-4618-AA40-334463F49C54} = {5C6BA7B5-832A-495A-AF5E-C2A74F6A1EF9}
{08C7C14B-D2E9-4FA0-BD0C-7DDA9582DC6D} = {54C74546-38B4-4618-AA40-334463F49C54}
{283F2163-BB83-4770-AA1A-F52FEFE8E1CF} = {54C74546-38B4-4618-AA40-334463F49C54}
{7799FBC7-13EB-4382-83D7-FE9396039C77} = {54C74546-38B4-4618-AA40-334463F49C54}
{1ACB3F86-D8AA-4CA4-B0BD-B1833E235F14} = {DC377ADC-CC9D-4785-81BE-726DBF5F3096}
{C5213190-E6BD-4B45-9C09-0951D3387CAD} = {54C74546-38B4-4618-AA40-334463F49C54}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {BCAF76D3-AA3C-4D0F-8D10-34065F8FED09}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="protobuf-net.Grpc" Version="1.1.1" />
<PackageReference Include="System.ComponentModel.Annotations" Version="4.7.0" />
<PackageReference Include="System.Text.Json" Version="7.0.2" />
</ItemGroup>
Expand All @@ -57,6 +58,10 @@
</None>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\BSN.Commons\BSN.Commons.csproj" />
</ItemGroup>

<ItemGroup>
<None Update="README.md">
<Pack>True</Pack>
Expand Down
29 changes: 27 additions & 2 deletions Source/BSN.Commons.PresentationInfrastructure/IResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,36 @@

namespace BSN.Commons.PresentationInfrastructure
{
public interface IResponse<ValidationResultType>
/// <summary>
/// Represents a single response of a command/query service.
/// </summary>
public interface IResponse
{
IList<ValidationResultType> InvalidItems { get; set; }
/// <summary>
/// Distinction between successful and unsuccessful result.
/// </summary>
bool IsSuccess { get; }

/// <summary>
/// Human-readable message for the End-User.
/// </summary>
string Message { get; set; }

/// <summary>
/// Corresponding HttpStatusCode.
/// </summary>
ResponseStatusCode StatusCode { get; set; }
}

/// <summary>
/// Represents a single response of a command/query service with additional informations about invalid items.
/// </summary>
/// <typeparam name="ValidationResultType"></typeparam>
public interface IResponse<ValidationResultType> : IResponse
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

بهتر نیست اسم این واسط بشود
IValidatedResponse

{
/// <summary>
/// Invalid items of the request object.
/// </summary>
IList<ValidationResultType> InvalidItems { get; set; }
}
}
23 changes: 17 additions & 6 deletions Source/BSN.Commons.PresentationInfrastructure/ResponseBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,25 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Runtime.Serialization;
using System.Text.Json.Serialization;

namespace BSN.Commons.PresentationInfrastructure
{
[Obsolete("Due to incompatability with Grpc this response type is only used for backward compatibility.")]
[DataContract]
public class ResponseBase : IResponse<ValidationResult>
{
[DataMember(Order = 1)]
[JsonConverter(typeof(JsonForceDefaultConverter<ResponseStatusCode>))]
public ResponseStatusCode StatusCode { get; set; }

[DataMember(Order = 2)]
public string Message { get; set; }

[DataMember(Order = 3)]
public IList<ValidationResult> InvalidItems { get; set; }

/// <summary>
/// Gets a value that indicates whether the HTTP response was successful.
/// </summary>
Expand All @@ -17,12 +29,11 @@ public class ResponseBase : IResponse<ValidationResult>
/// </remarks>
/// More info: https://docs.microsoft.com/en-us/uwp/api/windows.web.http.httpresponsemessage.issuccessstatuscode?view=winrt-19041
public bool IsSuccess => (int)StatusCode >= 200 && (int)StatusCode <= 299;
}

public string Message { get; set; }

[JsonConverter(typeof(JsonForceDefaultConverter<ResponseStatusCode>))]
public ResponseStatusCode StatusCode { get; set; }

public IList<ValidationResult> InvalidItems { get; set; }
[Obsolete("Due to incompatability with Grpc this response type is only used for backward compatibility.")]
[DataContract]
public class ErrorResponseBase : ResponseBase
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

این کلاس لازم است ؟

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

البته منم موافقم اینطور بشود.
یه کدهایی در PR خانوم سلطانزاده دیدم بنظرم مفید است.

در سرویس ها لازم نیست همه Return Typeها از جنس Response<> باشد. البته با حفظ سلسله مراتب ارث بری

در تولید ExampleResponse خیلی بچه ها را کمک میکند

{
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
namespace BSN.Commons.PresentationInfrastructure
{
/// <summary>
/// Response status codes based on the HTTP status codes.
/// </summary>
public enum ResponseStatusCode
{
//
// Summary:
// Equivalent to HTTP status 200. System.Net.HttpStatusCode.OK indicates that the
// request succeeded and that the requested information is in the response. This
// is the most common status code to receive.
/// <summary>
/// Equivalent to HTTP status 200. System.Net.HttpStatusCode.OK indicates that the
/// request succeeded and that the requested information is in the response. This
/// is the most common status code to receive.
/// </summary>
OK = 200,
//
// Summary:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
using System.Collections.Generic;
using System.Runtime.Serialization;

namespace BSN.Commons.Responses
namespace BSN.Commons.Responses
{
/// <summary>
/// Collection schema for generating responses..
/// </summary>
/// <typeparam name="T">Elements type.</typeparam>
[DataContract]
[DataContract]
public class CollectionViewModel<T>
{
/// <summary>
/// Default constructor.
/// </summary>
public CollectionViewModel() { }

/// <summary>
/// Elements.
/// </summary>
[DataMember(Order = 1)]
public IEnumerable<T> Items { get; set; }
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System.Runtime.Serialization;

namespace BSN.Commons.Responses
{
namespace BSN.Commons.Responses
{
/// <summary>
/// Represents a request validation issue for the API consumers.
/// </summary>
/// </summary>
[DataContract]
public class InvalidItem
{
Expand All @@ -22,4 +22,4 @@ public class InvalidItem
[DataMember(Order = 2)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Order = 1
نباید باشد ؟

public string Reason { get; set; }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,54 +4,57 @@
using System.Runtime.Serialization;
using System.Text.Json.Serialization;

namespace BSN.Commons.Responses
namespace BSN.Commons.Responses
{
/// <summary>
/// Generic response base for paginated data.
/// </summary>
/// <remarks>
/// Paginated response provides metadata for navigation purposes.
/// </remarks>
/// <typeparam name="T">Data type.</typeparam>
[DataContract]
public class PaginatedResponse<T>: IResponse<InvalidItem> where T : class
/// <summary>
/// Generic response base for paginated data.
/// </summary>
/// <remarks>
/// Paginated response provides metadata for navigation purposes.
/// </remarks>
/// <typeparam name="T">Data type.</typeparam>
[DataContract]
public class PaginatedResponse<T> : IResponse<InvalidItem> where T : class
{
/// <summary>
/// Default constructor.
/// </summary>
public PaginatedResponse() { }

/// <summary>
/// Corresponding HttpStatusCode.
/// </summary>
[DataMember(Order = 1)]
[JsonConverter(typeof(JsonForceDefaultConverter<ResponseStatusCode>))]
public ResponseStatusCode StatusCode { get; set; }

[DataMember(Order = 1)]
[JsonConverter(typeof(JsonForceDefaultConverter<ResponseStatusCode>))]
public ResponseStatusCode StatusCode { get; set; }
/// <summary>
/// Data payload (Collection).
/// </summary>
[DataMember(Order = 2)]
public CollectionViewModel<T> Data { get; set; }

[DataMember(Order = 2)]
public CollectionViewModel<T> Data { get; set; }
/// <summary>
/// Human-readable message for the End-User.
/// </summary>
[DataMember(Order = 3)]
[DataMember(Order = 3)]
public string Message { get; set; }

/// <summary>
/// Pagination metadata used by the client for data navigation purposes.
/// </summary>
[DataMember(Order = 4)]
public PaginationMetadata Meta { get; set; }

[DataMember(Order = 4)]
public PaginationMetadata Meta { get; set; }
/// <summary>
/// Invalid items of the request object.
/// </summary>
[DataMember(Order = 5)]
public IList<InvalidItem> InvalidItems { get; set; }

[DataMember(Order = 5)]
public IList<InvalidItem> InvalidItems { get; set; }
/// <summary>
/// Distinction between successful and unsuccessful result.
/// </summary>
public bool IsSuccess => (int)StatusCode >= 200 && (int)StatusCode <= 299;
}
}
public bool IsSuccess => (int)StatusCode >= 200 && (int)StatusCode <= 299;
}
}
Loading
Loading