Skip to content

Commit

Permalink
Updated models with updated serialization declarations to avoid seria…
Browse files Browse the repository at this point in the history
…lizing incompatible types. (#141)
  • Loading branch information
jasonmwebb-lv authored Nov 22, 2024
1 parent 13855f7 commit a83fdce
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ protected override void OnBuildInitialized()
{
Log.Information("Generating NuGet packages for projects in solution");
int commitNum = 0;
string NuGetVersionCustom = "2.1.1";
string NuGetVersionCustom = "2.1.1.1";


//if it's not a tagged release - append the commit number to the package version
Expand Down
3 changes: 3 additions & 0 deletions Src/RCommon.Models/Commands/CommandResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;

namespace RCommon.Models.Commands
{
[DataContract]
public record CommandResult<TExecutionResult> : ICommandResult<TExecutionResult>
where TExecutionResult : IExecutionResult
{
[DataMember]
public TExecutionResult Result { get; }

public CommandResult(TExecutionResult result)
Expand Down
3 changes: 3 additions & 0 deletions Src/RCommon.Models/ExecutionResults/ExecutionResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@

using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;

namespace RCommon.Models.ExecutionResults
{
[DataContract]
public abstract record ExecutionResult : IExecutionResult
{
private static readonly IExecutionResult SuccessResult = new SuccessExecutionResult();
Expand All @@ -36,6 +38,7 @@ public abstract record ExecutionResult : IExecutionResult
public static IExecutionResult Failed(IEnumerable<string> errors) => new FailedExecutionResult(errors);
public static IExecutionResult Failed(params string[] errors) => new FailedExecutionResult(errors);

[DataMember]
public abstract bool IsSuccess { get; }

public override string ToString()
Expand Down
3 changes: 3 additions & 0 deletions Src/RCommon.Models/ExecutionResults/FailedExecutionResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@

using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;

namespace RCommon.Models.ExecutionResults
{
[DataContract]
public record FailedExecutionResult : ExecutionResult
{
public IReadOnlyCollection<string> Errors { get; }
Expand All @@ -36,6 +38,7 @@ public FailedExecutionResult(
Errors = (errors ?? Enumerable.Empty<string>()).ToList();
}

[DataMember]
public override bool IsSuccess { get; } = false;

public override string ToString()
Expand Down
4 changes: 4 additions & 0 deletions Src/RCommon.Models/ExecutionResults/SuccessExecutionResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,14 @@
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

using System.Runtime.Serialization;

namespace RCommon.Models.ExecutionResults
{
[DataContract]
public record SuccessExecutionResult : ExecutionResult
{
[DataMember]
public override bool IsSuccess { get; } = true;

public override string ToString()
Expand Down
25 changes: 25 additions & 0 deletions Src/RCommon.Models/PaginatedListModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Runtime.Serialization;
using System.Text;
using RCommon.Collections;

Expand All @@ -11,6 +12,7 @@ namespace RCommon.Models
/// Represents a Data Transfer Object (DTO) that is typically used to encapsulate a PaginatedList so that it can be
/// delivered to the application layer. This should be an immutable object.
/// </summary>
[DataContract]
public abstract record PaginatedListModel<TSource, TOut> : IModel
where TSource : class
where TOut : class
Expand Down Expand Up @@ -131,18 +133,28 @@ protected void PaginateList(IPaginatedList<TSource> source, PaginatedListRequest

public virtual Expression<Func<TSource, object>> SortExpression { get => _sortExpression; set => _sortExpression = value; }

[DataMember]
public List<TOut> Items { get; set; }

[DataMember]
public int? PageSize { get; set; }

[DataMember]
public int PageNumber { get; set; }

[DataMember]
public int TotalPages { get; set; }

[DataMember]
public int TotalCount { get; set; }

[DataMember]
public string SortBy { get; set; }

[DataMember]
public SortDirectionEnum SortDirection { get; set; }

[DataMember]
public bool HasPreviousPage
{
get
Expand All @@ -151,6 +163,7 @@ public bool HasPreviousPage
}
}

[DataMember]
public bool HasNextPage
{
get
Expand All @@ -164,6 +177,7 @@ public bool HasNextPage
/// Represents a Data Transfer Object (DTO) that is typically used to encapsulate a PaginatedList so that it can be
/// delivered to the application layer. This should be an immutable object.
/// </summary>
[DataContract]
public abstract record PaginatedListModel<TSource> : IModel
where TSource : class
{
Expand Down Expand Up @@ -281,18 +295,28 @@ protected void PaginateList(IPaginatedList<TSource> source, PaginatedListRequest

public virtual Expression<Func<TSource, object>> SortExpression { get => _sortExpression; set => _sortExpression = value; }

[DataMember]
public List<TSource> Items { get; set; }

[DataMember]
public int? PageSize { get; set; }

[DataMember]
public int PageNumber { get; set; }

[DataMember]
public int TotalPages { get; set; }

[DataMember]
public int TotalCount { get; set; }

[DataMember]
public string SortBy { get; set; }

[DataMember]
public SortDirectionEnum SortDirection { get; set; }

[DataMember]
public bool HasPreviousPage
{
get
Expand All @@ -301,6 +325,7 @@ public bool HasPreviousPage
}
}

[DataMember]
public bool HasNextPage
{
get
Expand Down
7 changes: 7 additions & 0 deletions Src/RCommon.Models/PaginatedListRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,16 @@ public PaginatedListRequest()
SortDirection = SortDirectionEnum.None;
}

[DataMember]
public virtual int PageNumber { get; set; }

[DataMember]
public virtual int? PageSize { get; set; }

[DataMember]
public virtual string SortBy { get; set; }

[DataMember]
public virtual SortDirectionEnum SortDirection { get; set; }
}
}
4 changes: 4 additions & 0 deletions Src/RCommon.Models/SearchPaginatedListRequest.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;

namespace RCommon.Models
{
[DataContract]
public record SearchPaginatedListRequest : PaginatedListRequest, ISearchPaginatedListRequest
{
public SearchPaginatedListRequest()
{

}

[DataMember]
public string SearchString { get; set; }
}
}
2 changes: 2 additions & 0 deletions Src/RCommon.Models/SortDirectionEnum.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;

namespace RCommon.Models
{
[DataContract]
public enum SortDirectionEnum : byte
{
Ascending = 1,
Expand Down

0 comments on commit a83fdce

Please sign in to comment.