Skip to content

Commit

Permalink
Hot-fix/37 merge vns commons (#39)
Browse files Browse the repository at this point in the history
Resolve some missing convention.
  • Loading branch information
Reza-Noei authored Jun 12, 2023
1 parent 513b505 commit 0dce21e
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 39 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
Expand Down
52 changes: 28 additions & 24 deletions Source/BSN.Commons.PresentationInfrastructure/ResponseBase.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;


namespace BSN.Commons.PresentationInfrastructure
{
public class ResponseBase : IResponse<ValidationResult>
{
/// <summary>
/// Gets a value that indicates whether the HTTP response was successful.
/// </summary>
/// <remarks>
/// 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
/// </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; }

public ResponseStatusCode StatusCode { get; set; }

public IList<ValidationResult> 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<ValidationResult>
{
/// <summary>
/// Gets a value that indicates whether the HTTP response was successful.
/// </summary>
/// <remarks>
/// 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
/// </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; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Collections.Generic;
using System.Runtime.Serialization;

namespace BSN.Commons.Responses
{
/// <summary>
/// Collection schema for generating responses..
/// </summary>
/// <typeparam name="T">Elements type.</typeparam>
[DataContract]
public class CollectionViewModel<T>
{
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,4 +1,5 @@
using System;
using BSN.Commons.PresentationInfrastructure;
using System;

namespace BSN.Commons.Responses
{
Expand All @@ -7,7 +8,7 @@ namespace BSN.Commons.Responses
/// </summary>
/// <typeparam name="T"> The type of object or value handled by the class. </typeparam>
[Obsolete("Due to incompatability with Grpc this response type is only used for backward compatibility.")]
public class GenericResponseBase<T> : Response where T : class
public class GenericResponseBase<T> : ResponseBase where T : class
{
public GenericResponseBase() { }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class GenericResponseBaseWithPagination<T> : GenericResponseBase<T> where
public GenericResponseBaseWithPagination() { }

/// <summary>
/// Pagination metada used by the client as the parameters for navigation through whole records.
/// Pagination metadata used by the client for data navigation purposes.
/// </summary>
public PaginationMetadata Meta { get; set; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ namespace BSN.Commons.Responses
[DataContract]
public class InvalidItem
{
public InvalidItem() { }

/// <summary>
/// Name of the request item.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -15,31 +14,44 @@ namespace BSN.Commons.Responses
/// </remarks>
/// <typeparam name="T">Data type.</typeparam>
[DataContract]
public class PaginatedResponse<T> where T : class
public class PaginatedResponse<T>: IResponse<InvalidItem> where T : class
{
public PaginatedResponse() { }

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

/// <summary>
/// Data payload (Collection).
/// </summary>
[DataMember(Order = 1)]
public IEnumerable<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)]
public string Message { get; set; }

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; }

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

/// <summary>
/// Distinction between successful and unsuccessful result.
/// </summary>
public bool IsSuccess => (int)StatusCode >= 200 && (int)StatusCode <= 299;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ namespace BSN.Commons.Responses
[DataContract]
public class PaginationMetadata
{
public PaginationMetadata() { }

/// <summary>
/// Current page number
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
/// </remark>
[DataContract]
public class Response
public class Response: IResponse<InvalidItem>
{
public Response() { }

/// <summary>
/// Corresponding HttpStatusCode.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion Source/BSN.Commons/BSN.Commons.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
Expand Down

0 comments on commit 0dce21e

Please sign in to comment.