-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
131 additions
and
53 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
src/Schemata.Abstractions/Exceptions/InvalidArgumentException.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace Schemata.Abstractions.Exceptions; | ||
|
||
public class InvalidArgumentException : HttpException | ||
{ | ||
public InvalidArgumentException( | ||
int status = 400, | ||
string? message = "An error occurred while processing your request.") : base(status, message) { } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 0 additions & 41 deletions
41
src/Schemata.Resource.Foundation/Converters/ListResponseJsonConverter.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,12 @@ | ||
using System.Collections.Generic; | ||
using System.Text.Json.Serialization; | ||
using Schemata.Resource.Foundation.Converters; | ||
|
||
namespace Schemata.Resource.Foundation.Models; | ||
|
||
public class ListResponse<TSummary> | ||
{ | ||
[JsonConverter(typeof(ListResponseJsonConverter))] | ||
public virtual IEnumerable<TSummary>? Entities { get; set; } | ||
|
||
public virtual long? TotalSize { get; set; } | ||
|
||
public virtual int? PageSize { get; set; } | ||
|
||
public virtual int? Skip { get; set; } | ||
|
||
public virtual string? NextPageToken { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using System; | ||
using System.IO; | ||
using System.IO.Compression; | ||
using System.Text; | ||
using System.Text.Json; | ||
using System.Threading.Tasks; | ||
|
||
namespace Schemata.Resource.Foundation.Models; | ||
|
||
public class PageToken | ||
{ | ||
public virtual string? Filter { get; set; } | ||
|
||
public virtual string? OrderBy { get; set; } | ||
|
||
public virtual bool? ShowDeleted { get; set; } | ||
|
||
public virtual int PageSize { get; set; } | ||
|
||
public virtual int Skip { get; set; } | ||
|
||
public async Task<string> ToStringAsync() { | ||
var json = JsonSerializer.Serialize(this); | ||
var bytes = Encoding.UTF8.GetBytes(json); | ||
|
||
using var ms = new MemoryStream(); | ||
await using var gz = new BrotliStream(ms, CompressionLevel.Optimal); | ||
gz.Write(bytes, 0, bytes.Length); | ||
gz.Close(); | ||
|
||
return Convert.ToBase64String(ms.ToArray()).TrimEnd('=').Replace('+', '-').Replace('/', '_'); | ||
} | ||
|
||
public static async Task<PageToken?> FromStringAsync(string? token) { | ||
if (string.IsNullOrWhiteSpace(token)) { | ||
return null; | ||
} | ||
|
||
var base64 = token.Replace('_', '/').Replace('-', '+'); | ||
switch (base64.Length % 4) { | ||
case 2: | ||
base64 += "=="; | ||
break; | ||
case 3: | ||
base64 += "="; | ||
break; | ||
} | ||
|
||
var bytes = Convert.FromBase64String(base64); | ||
|
||
using var ms = new MemoryStream(bytes); | ||
await using var gz = new BrotliStream(ms, CompressionMode.Decompress); | ||
|
||
try { | ||
return await JsonSerializer.DeserializeAsync<PageToken>(gz); | ||
} catch { | ||
return null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters