Skip to content

Commit 9c3a8a7

Browse files
authored
Merge pull request #6 from I-RzR-I/feature/UpgradeRefPack_ResultToProblemDetails
Feature/upgrade ref pack result to problem details
2 parents fde4e98 + 1c5e82d commit 9c3a8a7

17 files changed

+745
-43
lines changed

docs/CHANGELOG.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,14 @@
1111

1212
### **v1.0.4.7652**
1313
-> Update reference package version. <br />
14-
-> Fix some warnings.
14+
-> Fix some warnings.<br />
1515

1616
### **v1.0.5.5444**
17-
-> Update reference package version, fixing CVE (`CVE-2024-43485`).
17+
-> Update reference package version, fixing CVE (`CVE-2024-43485`).<br />
18+
19+
### **v1.1.0.0**
20+
-> Add new/edit data type extensions.<br />
21+
-> Upgrade ref package version.<br />
22+
-> Add and adjust existing message store and HTTP code rfc link.<br />
23+
-> Add new ProblemDetails result model. Extend existing Microsoft.AspNetCore.Mvc.ProblemDetails.<br />
24+
-> Add cast helper from `Result` > `ProblemDetails`. Add API `ObjectResult` extension methods.<br />

src/AggregatedGenericResultMessage.Web/AggregatedGenericResultMessage.Web.csproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netstandard2.1</TargetFramework>
54
<TargetFrameworks>netstandard2.1</TargetFrameworks>
65
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
76
<Authors>RzR</Authors>
@@ -40,7 +39,7 @@
4039
<Compile Include="..\shared\GeneralAssemblyInfo.cs" Link="Properties\GeneralAssemblyInfo.cs" />
4140
</ItemGroup>
4241
<ItemGroup>
43-
<PackageReference Include="AggregatedGenericResultMessage" Version="1.3.4.6865" />
42+
<PackageReference Include="AggregatedGenericResultMessage" Version="1.3.5.4696" />
4443
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.1.3" />
4544
</ItemGroup>
4645

src/AggregatedGenericResultMessage.Web/Extensions/ActionResult/ResultToActionResultByCode.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
using AggregatedGenericResultMessage.Web.Helpers;
2525
using Microsoft.AspNetCore.Mvc;
2626

27+
// ReSharper disable RedundantCast
28+
2729
#endregion
2830

2931
namespace AggregatedGenericResultMessage.Web.Extensions.ActionResult

src/AggregatedGenericResultMessage.Web/Extensions/Internal/DataType/EnumExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ internal static class EnumExtensions
3636
/// <returns></returns>
3737
/// <typeparam name="T"></typeparam>
3838
/// <remarks></remarks>
39-
[CodeSource("https://github.com/I-RzR-I/DomainCommonExtensions", "RzR",
40-
"DomainCommonExtensions.CommonExtensions.EnumExtensions", 1)]
39+
[CodeSource("https://github.com/I-RzR-I/DomainCommonExtensions", "RzR",
40+
"DomainCommonExtensions.CommonExtensions.EnumExtensions.ToInt", 1)]
4141
internal static int ToInt<T>(this T source) where T : IConvertible
4242
=> !typeof(T).IsEnum
4343
? throw new ArgumentException("T must be an enumerated type")
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// ***********************************************************************
2+
// Assembly : RzR.Shared.ResultMessage.AggregatedGenericResultMessage.Web
3+
// Author : RzR
4+
// Created On : 2024-12-25 13:51
5+
//
6+
// Last Modified By : RzR
7+
// Last Modified On : 2024-12-25 14:28
8+
// ***********************************************************************
9+
// <copyright file="EnumerableExtensions.cs" company="RzR SOFT & TECH">
10+
// Copyright © RzR. All rights reserved.
11+
// </copyright>
12+
//
13+
// <summary>
14+
// </summary>
15+
// ***********************************************************************
16+
17+
#region U S A G E S
18+
19+
using CodeSource;
20+
using System.Collections.Generic;
21+
using System.Linq;
22+
23+
#endregion
24+
25+
namespace AggregatedGenericResultMessage.Web.Extensions.Internal.DataType
26+
{
27+
/// -------------------------------------------------------------------------------------------------
28+
/// <summary>
29+
/// An enumerable extensions.
30+
/// </summary>
31+
/// =================================================================================================
32+
internal static class EnumerableExtensions
33+
{
34+
/// -------------------------------------------------------------------------------------------------
35+
/// <summary>
36+
/// An IEnumerable&lt;T&gt; extension method that query if 'source' is null or empty
37+
/// enumerable.
38+
/// </summary>
39+
/// <typeparam name="T">Generic type parameter.</typeparam>
40+
/// <param name="source">The source to act on.</param>
41+
/// <returns>
42+
/// True if null or empty enumerable, false if not.
43+
/// </returns>
44+
/// =================================================================================================
45+
[CodeSource("https://github.com/I-RzR-I/DomainCommonExtensions", "RzR",
46+
"DomainCommonExtensions.ArraysExtensions.EnumerableExtensions.IsNullOrEmptyEnumerable", 1)]
47+
internal static bool IsNullOrEmptyEnumerable<T>(this IEnumerable<T> source)
48+
=> source.IsNull() || !source.Any();
49+
}
50+
}

src/AggregatedGenericResultMessage.Web/Extensions/Internal/DataType/IntExtensions.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,22 @@
44
// Created On : 2023-10-11 17:41
55
//
66
// Last Modified By : RzR
7-
// Last Modified On : 2023-10-11 17:41
7+
// Last Modified On : 2024-12-25 17:41
88
// ***********************************************************************
9-
// <copyright file="IntExtensions.cs" company="">
10-
// Copyright (c) RzR. All rights reserved.
9+
// <copyright file="IntExtensions.cs" company="RzR SOFT & TECH">
10+
// Copyright © RzR. All rights reserved.
1111
// </copyright>
1212
//
1313
// <summary>
1414
// </summary>
1515
// ***********************************************************************
1616

17+
#region U S A G E S
18+
1719
using Microsoft.AspNetCore.Http;
1820

21+
#endregion
22+
1923
namespace AggregatedGenericResultMessage.Web.Extensions.Internal.DataType
2024
{
2125
/// <summary>

src/AggregatedGenericResultMessage.Web/Extensions/Internal/DataType/NullExtensions.cs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,22 @@
44
// Created On : 2023-06-08 17:21
55
//
66
// Last Modified By : RzR
7-
// Last Modified On : 2023-06-08 17:22
7+
// Last Modified On : 2024-12-25 17:41
88
// ***********************************************************************
9-
// <copyright file="NullExtensions.cs" company="">
10-
// Copyright (c) RzR. All rights reserved.
9+
// <copyright file="NullExtensions.cs" company="RzR SOFT & TECH">
10+
// Copyright © RzR. All rights reserved.
1111
// </copyright>
1212
//
1313
// <summary>
1414
// </summary>
1515
// ***********************************************************************
1616

17+
#region U S A G E S
18+
1719
using CodeSource;
1820

21+
#endregion
22+
1923
namespace AggregatedGenericResultMessage.Web.Extensions.Internal.DataType
2024
{
2125
/// <summary>
@@ -29,8 +33,17 @@ internal static class NullExtensions
2933
/// </summary>
3034
/// <param name="obj">Source data</param>
3135
/// <returns></returns>
32-
[CodeSource("https://github.com/I-RzR-I/DomainCommonExtensions", "RzR",
36+
[CodeSource("https://github.com/I-RzR-I/DomainCommonExtensions", "RzR",
3337
"DomainCommonExtensions.CommonExtensions.NullExtensions.IsNull", 1)]
3438
internal static bool IsNull(this object obj) => obj == null;
39+
40+
/// <summary>
41+
/// Is not null
42+
/// </summary>
43+
/// <param name="obj">Object to be checked</param>
44+
/// <returns></returns>
45+
[CodeSource("https://github.com/I-RzR-I/DomainCommonExtensions", "RzR",
46+
"DomainCommonExtensions.CommonExtensions.NullExtensions.IsNotNull", 1)]
47+
public static bool IsNotNull(this object obj) => obj != null;
3548
}
3649
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// ***********************************************************************
2+
// Assembly : RzR.Shared.ResultMessage.AggregatedGenericResultMessage.Web
3+
// Author : RzR
4+
// Created On : 2024-12-25 13:06
5+
//
6+
// Last Modified By : RzR
7+
// Last Modified On : 2024-12-25 13:40
8+
// ***********************************************************************
9+
// <copyright file="StringExtensions.cs" company="RzR SOFT & TECH">
10+
// Copyright © RzR. All rights reserved.
11+
// </copyright>
12+
//
13+
// <summary>
14+
// </summary>
15+
// ***********************************************************************
16+
17+
#region U S A G E S
18+
19+
using CodeSource;
20+
21+
#endregion
22+
23+
namespace AggregatedGenericResultMessage.Web.Extensions.Internal.DataType
24+
{
25+
/// -------------------------------------------------------------------------------------------------
26+
/// <summary>
27+
/// A string extensions.
28+
/// </summary>
29+
/// =================================================================================================
30+
internal static class StringExtensions
31+
{
32+
/// -------------------------------------------------------------------------------------------------
33+
/// <summary>
34+
/// A string extension method that if is missing.
35+
/// </summary>
36+
/// <param name="source">The source to act on.</param>
37+
/// <param name="defaultValue">The default value.</param>
38+
/// <returns>
39+
/// A string.
40+
/// </returns>
41+
/// =================================================================================================
42+
internal static string IfIsMissing(this string source, string defaultValue)
43+
{
44+
if (source.IsNull() || source.IsMissing())
45+
return defaultValue;
46+
47+
return source;
48+
}
49+
50+
/// -------------------------------------------------------------------------------------------------
51+
/// <summary>
52+
/// A string extension method that query if 'source' is missing.
53+
/// </summary>
54+
/// <param name="source">The source to act on.</param>
55+
/// <returns>
56+
/// True if missing, false if not.
57+
/// </returns>
58+
/// =================================================================================================
59+
[CodeSource("https://github.com/I-RzR-I/DomainCommonExtensions", "RzR",
60+
"DomainCommonExtensions.DataTypeExtensions.StringExtensions.IsMissing", 1)]
61+
internal static bool IsMissing(this string source) => string.IsNullOrWhiteSpace(source);
62+
}
63+
}
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
// ***********************************************************************
2+
// Assembly : RzR.Shared.ResultMessage.AggregatedGenericResultMessage.Web
3+
// Author : RzR
4+
// Created On : 2024-12-24 13:56
5+
//
6+
// Last Modified By : RzR
7+
// Last Modified On : 2024-12-26 18:30
8+
// ***********************************************************************
9+
// <copyright file="ResultToProblemDetails.cs" company="RzR SOFT & TECH">
10+
// Copyright © RzR. All rights reserved.
11+
// </copyright>
12+
//
13+
// <summary>
14+
// </summary>
15+
// ***********************************************************************
16+
17+
#region U S A G E S
18+
19+
using AggregatedGenericResultMessage.Abstractions;
20+
using AggregatedGenericResultMessage.Web.Helpers;
21+
using Microsoft.AspNetCore.Mvc;
22+
using System.Collections.Generic;
23+
using System.Net;
24+
25+
#endregion
26+
27+
namespace AggregatedGenericResultMessage.Web.Extensions.ProblemDetail
28+
{
29+
/// -------------------------------------------------------------------------------------------------
30+
/// <summary>
31+
/// `Result` extension methods that are converted to the `ProblemDetails` model with customization possibilities.
32+
/// </summary>
33+
/// =================================================================================================
34+
public static class ResultToProblemDetails
35+
{
36+
/// -------------------------------------------------------------------------------------------------
37+
/// <summary>
38+
/// An IResult extension method that converts this object to to problem details.
39+
/// </summary>
40+
/// <typeparam name="T">Generic type parameter.</typeparam>
41+
/// <param name="result">The result to act on.</param>
42+
/// <param name="statusCode">The HTTP status code.</param>
43+
/// <param name="message">(Optional) The custom `ProblemDetails` message.</param>
44+
/// <param name="detailMessage">(Optional) The custom message `ProblemDetails` describing the detail.</param>
45+
/// <param name="accessedResourceUri">(Optional) URI of the accessed resource.</param>
46+
/// <param name="additionInformation">(Optional) Information describing the addition `ProblemDetails` objects.</param>
47+
/// <returns>
48+
/// An ObjectResult.
49+
/// </returns>
50+
/// =================================================================================================
51+
public static ObjectResult AsToProblemDetails<T>(
52+
this Result<T> result,
53+
HttpStatusCode statusCode,
54+
string message = null,
55+
string detailMessage = null,
56+
string accessedResourceUri = null,
57+
IDictionary<string, object> additionInformation = null)
58+
=> ResultProblemDetailsHelper.BuildObjectResult(result, statusCode, message, detailMessage, accessedResourceUri, additionInformation);
59+
60+
/// -------------------------------------------------------------------------------------------------
61+
/// <summary>
62+
/// An IResult extension method that converts this object to to problem details.
63+
/// </summary>
64+
/// <typeparam name="T">Generic type parameter.</typeparam>
65+
/// <param name="result">The result to act on.</param>
66+
/// <param name="statusCode">The HTTP status code.</param>
67+
/// <param name="message">(Optional) The custom `ProblemDetails` message.</param>
68+
/// <param name="detailMessage">(Optional) The custom message `ProblemDetails` describing the detail.</param>
69+
/// <param name="accessedResourceUri">(Optional) URI of the accessed resource.</param>
70+
/// <param name="additionInformation">(Optional) Information describing the addition `ProblemDetails` objects.</param>
71+
/// <returns>
72+
/// An ObjectResult.
73+
/// </returns>
74+
/// =================================================================================================
75+
public static ObjectResult AsToProblemDetails(
76+
this Result result,
77+
HttpStatusCode statusCode,
78+
string message = null,
79+
string detailMessage = null,
80+
string accessedResourceUri = null,
81+
IDictionary<string, object> additionInformation = null)
82+
=> ResultProblemDetailsHelper.BuildObjectResult(result, statusCode, message, detailMessage, accessedResourceUri, additionInformation);
83+
84+
/// -------------------------------------------------------------------------------------------------
85+
/// <summary>
86+
/// An IResult extension method that converts this object to to problem details.
87+
/// </summary>
88+
/// <typeparam name="T">Generic type parameter.</typeparam>
89+
/// <param name="result">The result to act on.</param>
90+
/// <param name="statusCode">The HTTP status code.</param>
91+
/// <param name="message">(Optional) The custom `ProblemDetails` message.</param>
92+
/// <param name="detailMessage">(Optional) The custom message `ProblemDetails` describing the detail.</param>
93+
/// <param name="accessedResourceUri">(Optional) URI of the accessed resource.</param>
94+
/// <param name="additionInformation">(Optional) Information describing the addition `ProblemDetails` objects.</param>
95+
/// <returns>
96+
/// An ObjectResult.
97+
/// </returns>
98+
/// =================================================================================================
99+
public static ObjectResult AsToProblemDetails<T>(
100+
this IResult<T> result,
101+
HttpStatusCode statusCode,
102+
string message = null,
103+
string detailMessage = null,
104+
string accessedResourceUri = null,
105+
IDictionary<string, object> additionInformation = null)
106+
=> ResultProblemDetailsHelper.BuildObjectResult(result, statusCode, message, detailMessage, accessedResourceUri, additionInformation);
107+
108+
/// -------------------------------------------------------------------------------------------------
109+
/// <summary>
110+
/// An IResult extension method that converts this object to to problem details.
111+
/// </summary>
112+
/// <typeparam name="T">Generic type parameter.</typeparam>
113+
/// <param name="result">The result to act on.</param>
114+
/// <param name="statusCode">The HTTP status code.</param>
115+
/// <param name="message">(Optional) The custom `ProblemDetails` message.</param>
116+
/// <param name="detailMessage">(Optional) The custom message `ProblemDetails` describing the detail.</param>
117+
/// <param name="accessedResourceUri">(Optional) URI of the accessed resource.</param>
118+
/// <param name="additionInformation">(Optional) Information describing the addition `ProblemDetails` objects.</param>
119+
/// <returns>
120+
/// An ObjectResult.
121+
/// </returns>
122+
/// =================================================================================================
123+
public static ObjectResult AsToProblemDetails(
124+
this IResult result,
125+
HttpStatusCode statusCode,
126+
string message = null,
127+
string detailMessage = null,
128+
string accessedResourceUri = null,
129+
IDictionary<string, object> additionInformation = null)
130+
=> ResultProblemDetailsHelper.BuildObjectResult(result, statusCode, message, detailMessage, accessedResourceUri, additionInformation);
131+
}
132+
}

src/AggregatedGenericResultMessage.Web/Helpers/CheckResultStatusHelper.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
using System.Net;
2121
using AggregatedGenericResultMessage.Abstractions;
2222
using AggregatedGenericResultMessage.Web.Extensions.Internal.DataType;
23+
using AggregatedGenericResultMessage.Web.Helpers.Store;
2324
using AggregatedGenericResultMessage.Web.Models;
2425
using Microsoft.AspNetCore.Http;
2526

0 commit comments

Comments
 (0)