-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathQueryParameters.cs
More file actions
123 lines (109 loc) · 3.97 KB
/
Copy pathQueryParameters.cs
File metadata and controls
123 lines (109 loc) · 3.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// -------------------------------------------------------------------------------------------------
// <copyright file="QueryParameters.cs" company="Starion Group S.A.">
//
// Copyright 2022-2025 Starion Group S.A.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// </copyright>
// ------------------------------------------------------------------------------------------------
namespace SysML2.NET.PIM
{
using System;
using System.Collections.Generic;
using System.Linq;
/// <summary>
/// Provide object structure for parameters than could be defined inside a queyr
/// </summary>
public class QueryParameters
{
/// <summary>
/// specifies the maximum number of records that will be returned per page in the response
/// </summary>
public int PageSize { get; set; } = 0;
/// <summary>
/// specifies the URL of the page succeeding the page being requested
/// </summary>
/// <remarks>
/// format: epoch|GUID, where epoch is Unix epoch: DateTime(1970, 1, 1, 0, 0, 0, 0)
/// </remarks>
public Page? PageAfter { get; set; } = null;
/// <summary>
/// specifies the URL of a page preceding the page being requested
/// </summary>
/// <remarks>
/// format: epoch|GUID, where epoch is Unix epoch: DateTime(1970, 1, 1, 0, 0, 0, 0)
/// </remarks>
public Page? PageBefore { get; set; } = null;
/// <summary>
/// Returns a string that represents the <see cref="QueryParameters"/>
/// </summary>
/// <returns>
/// a string representation
/// </returns>
public override string ToString()
{
var queryParameters = new List<string>();
if (this.PageSize > 0)
{
queryParameters.Add($"page[size]={this.PageSize}");
}
if (this.PageAfter != null)
{
queryParameters.Add($"page[after]={this.PageAfter}");
}
if (this.PageBefore != null)
{
queryParameters.Add($"page[before]={this.PageBefore}");
}
if (!queryParameters.Any())
{
return string.Empty;
}
return "?" + string.Join("&", queryParameters);
}
/// <summary>
/// Creates an instance
/// </summary>
/// <returns>A <see cref="QueryParameters"/></returns>
/// <exception cref="NotImplementedException"></exception>
public static QueryParameters FromString()
{
throw new NotImplementedException();
}
}
/// <summary>
/// Defines the structure of the page for the pagination process
/// </summary>
public struct Page
{
/// <summary>
/// the epoch time
/// </summary>
public int Epoch { get; set; }
/// <summary>
/// The page identifier
/// </summary>
public Guid Identifier { get; set; }
/// <summary>
/// Returns a string that represents the <see cref="Page"/>
/// </summary>
/// <returns>
/// a string representation
/// </returns>
public override string ToString()
{
return $"{this.Epoch}|{this.Identifier}";
}
}
}