diff --git a/Source/BSN.Commons.PresentationInfrastructure/BSN.Commons.PresentationInfrastructure.csproj b/Source/BSN.Commons.PresentationInfrastructure/BSN.Commons.PresentationInfrastructure.csproj index 783839e..5850fc5 100644 --- a/Source/BSN.Commons.PresentationInfrastructure/BSN.Commons.PresentationInfrastructure.csproj +++ b/Source/BSN.Commons.PresentationInfrastructure/BSN.Commons.PresentationInfrastructure.csproj @@ -1,4 +1,4 @@ - + netstandard2.0 diff --git a/Source/BSN.Commons.PresentationInfrastructure/ResponseBase.cs b/Source/BSN.Commons.PresentationInfrastructure/ResponseBase.cs index 53d78b1..83f0d4a 100644 --- a/Source/BSN.Commons.PresentationInfrastructure/ResponseBase.cs +++ b/Source/BSN.Commons.PresentationInfrastructure/ResponseBase.cs @@ -1,24 +1,28 @@ -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; - - -namespace BSN.Commons.PresentationInfrastructure -{ - public class ResponseBase : IResponse - { - /// - /// Gets a value that indicates whether the HTTP response was successful. - /// - /// - /// If the server doesn't return a successful HttpStatusCode in the Successful range (200-299) for the request, then the responseObject.IsSuccess property is set to false - /// - /// 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; } - - public ResponseStatusCode StatusCode { get; set; } - - public IList InvalidItems { get; set; } - } -} +using BSN.Commons.Converters; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Text.Json.Serialization; + +namespace BSN.Commons.PresentationInfrastructure +{ + [Obsolete("Due to incompatability with Grpc this response type is only used for backward compatibility.")] + public class ResponseBase : IResponse + { + /// + /// Gets a value that indicates whether the HTTP response was successful. + /// + /// + /// If the server doesn't return a successful HttpStatusCode in the Successful range (200-299) for the request, then the responseObject.IsSuccess property is set to false + /// + /// 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))] + public ResponseStatusCode StatusCode { get; set; } + + public IList InvalidItems { get; set; } + } +} diff --git a/Source/BSN.Commons.PresentationInfrastructure/Responses/CollectionViewModel.cs b/Source/BSN.Commons.PresentationInfrastructure/Responses/CollectionViewModel.cs new file mode 100644 index 0000000..2bd9b09 --- /dev/null +++ b/Source/BSN.Commons.PresentationInfrastructure/Responses/CollectionViewModel.cs @@ -0,0 +1,21 @@ +using System.Collections.Generic; +using System.Runtime.Serialization; + +namespace BSN.Commons.Responses +{ + /// + /// Collection schema for generating responses.. + /// + /// Elements type. + [DataContract] + public class CollectionViewModel + { + public CollectionViewModel() { } + + /// + /// Elements. + /// + [DataMember(Order = 1)] + public IEnumerable Items { get; set; } + } +} diff --git a/Source/BSN.Commons.PresentationInfrastructure/Responses/GenericResponseBase.cs b/Source/BSN.Commons.PresentationInfrastructure/Responses/GenericResponseBase.cs index aeb0f26..2f26442 100644 --- a/Source/BSN.Commons.PresentationInfrastructure/Responses/GenericResponseBase.cs +++ b/Source/BSN.Commons.PresentationInfrastructure/Responses/GenericResponseBase.cs @@ -1,4 +1,5 @@ -using System; +using BSN.Commons.PresentationInfrastructure; +using System; namespace BSN.Commons.Responses { @@ -7,7 +8,7 @@ namespace BSN.Commons.Responses /// /// The type of object or value handled by the class. [Obsolete("Due to incompatability with Grpc this response type is only used for backward compatibility.")] - public class GenericResponseBase : Response where T : class + public class GenericResponseBase : ResponseBase where T : class { public GenericResponseBase() { } diff --git a/Source/BSN.Commons.PresentationInfrastructure/Responses/GenericResponseBaseWithPagination.cs b/Source/BSN.Commons.PresentationInfrastructure/Responses/GenericResponseBaseWithPagination.cs index a8fa17c..e8a452f 100644 --- a/Source/BSN.Commons.PresentationInfrastructure/Responses/GenericResponseBaseWithPagination.cs +++ b/Source/BSN.Commons.PresentationInfrastructure/Responses/GenericResponseBaseWithPagination.cs @@ -15,7 +15,7 @@ public class GenericResponseBaseWithPagination : GenericResponseBase where public GenericResponseBaseWithPagination() { } /// - /// Pagination metada used by the client as the parameters for navigation through whole records. + /// Pagination metadata used by the client for data navigation purposes. /// public PaginationMetadata Meta { get; set; } } diff --git a/Source/BSN.Commons.PresentationInfrastructure/Responses/InvalidItem.cs b/Source/BSN.Commons.PresentationInfrastructure/Responses/InvalidItem.cs index 006ba66..82ee944 100644 --- a/Source/BSN.Commons.PresentationInfrastructure/Responses/InvalidItem.cs +++ b/Source/BSN.Commons.PresentationInfrastructure/Responses/InvalidItem.cs @@ -8,6 +8,8 @@ namespace BSN.Commons.Responses [DataContract] public class InvalidItem { + public InvalidItem() { } + /// /// Name of the request item. /// diff --git a/Source/BSN.Commons.PresentationInfrastructure/Responses/PaginatedResponse.cs b/Source/BSN.Commons.PresentationInfrastructure/Responses/PaginatedResponse.cs index 19d2631..5ffc6f9 100644 --- a/Source/BSN.Commons.PresentationInfrastructure/Responses/PaginatedResponse.cs +++ b/Source/BSN.Commons.PresentationInfrastructure/Responses/PaginatedResponse.cs @@ -1,7 +1,6 @@ using BSN.Commons.Converters; using BSN.Commons.PresentationInfrastructure; using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; using System.Runtime.Serialization; using System.Text.Json.Serialization; @@ -15,31 +14,44 @@ namespace BSN.Commons.Responses /// /// Data type. [DataContract] - public class PaginatedResponse where T : class + public class PaginatedResponse: IResponse where T : class { + public PaginatedResponse() { } + /// /// Corresponding HttpStatusCode. /// - [DataMember(Order = 2)] + [DataMember(Order = 1)] [JsonConverter(typeof(JsonForceDefaultConverter))] public ResponseStatusCode StatusCode { get; set; } /// /// Data payload (Collection). /// - [DataMember(Order = 1)] - public IEnumerable Data { get; set; } + [DataMember(Order = 2)] + public CollectionViewModel Data { get; set; } + /// + /// Human-readable message for the End-User. + /// [DataMember(Order = 3)] - public string Message { get; set; } - + public string Message { get; set; } + + /// + /// Pagination metadata used by the client for data navigation purposes. + /// [DataMember(Order = 4)] public PaginationMetadata Meta { get; set; } + /// + /// Invalid items of the request object. + /// [DataMember(Order = 5)] - public IList InvalidItems { get; set; } + public IList InvalidItems { get; set; } + /// + /// Distinction between successful and unsuccessful result. + /// public bool IsSuccess => (int)StatusCode >= 200 && (int)StatusCode <= 299; } - } diff --git a/Source/BSN.Commons.PresentationInfrastructure/Responses/PaginationMetadata.cs b/Source/BSN.Commons.PresentationInfrastructure/Responses/PaginationMetadata.cs index 5dd5e62..836e9a8 100644 --- a/Source/BSN.Commons.PresentationInfrastructure/Responses/PaginationMetadata.cs +++ b/Source/BSN.Commons.PresentationInfrastructure/Responses/PaginationMetadata.cs @@ -8,6 +8,8 @@ namespace BSN.Commons.Responses [DataContract] public class PaginationMetadata { + public PaginationMetadata() { } + /// /// Current page number /// diff --git a/Source/BSN.Commons.PresentationInfrastructure/Responses/Response.cs b/Source/BSN.Commons.PresentationInfrastructure/Responses/Response.cs index bb244d7..12364fb 100644 --- a/Source/BSN.Commons.PresentationInfrastructure/Responses/Response.cs +++ b/Source/BSN.Commons.PresentationInfrastructure/Responses/Response.cs @@ -15,8 +15,10 @@ namespace BSN.Commons.Responses /// namely the 'StatusCode' property of the 'ResponseBase' class which should keep it's default numeral value when being converted. /// [DataContract] - public class Response + public class Response: IResponse { + public Response() { } + /// /// Corresponding HttpStatusCode. /// diff --git a/Source/BSN.Commons/BSN.Commons.csproj b/Source/BSN.Commons/BSN.Commons.csproj index 4295f33..9b5712d 100644 --- a/Source/BSN.Commons/BSN.Commons.csproj +++ b/Source/BSN.Commons/BSN.Commons.csproj @@ -1,4 +1,4 @@ - + netstandard2.0