-
Notifications
You must be signed in to change notification settings - Fork 8
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
base: master
Are you sure you want to change the base?
Changes from 7 commits
9ccbe32
9767c04
b88b27e
615fccf
57ac221
b645471
3ad2347
9db4d26
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
**/.classpath | ||
**/.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/** |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. بهتر نیست اسم این واسط بشود |
||
{ | ||
/// <summary> | ||
/// Invalid items of the request object. | ||
/// </summary> | ||
IList<ValidationResultType> InvalidItems { get; set; } | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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> | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. این کلاس لازم است ؟ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. البته منم موافقم اینطور بشود. در سرویس ها لازم نیست همه Return Typeها از جنس Response<> باشد. البته با حفظ سلسله مراتب ارث بری در تولید ExampleResponse خیلی بچه ها را کمک میکند |
||
{ | ||
} | ||
} |
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 | ||
{ | ||
|
@@ -22,4 +22,4 @@ public InvalidItem() { } | |
[DataMember(Order = 2)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Order = 1 |
||
public string Reason { get; set; } | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
سلام؛
آقا ما از پروژه های این مخزن داکر ایمیج میسازیم ؟ فکر کنم به ازای هر Dockerfile باید یدونه از اینا داشته باشیم.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
برای پروژه های تستی نیاز هست که DockerImage داشته باشیم ؟