Skip to content

Commit 1ebdfc7

Browse files
Add comments, query parameters
1 parent 2fc9781 commit 1ebdfc7

5 files changed

Lines changed: 218 additions & 4 deletions

File tree

CSAPI-lib/CSAPI-lib.vcxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,8 @@
181181
<ClInclude Include="ObservationsAPI.h" />
182182
<ClInclude Include="Query\DataStreamsOfSystemQuery.h" />
183183
<ClInclude Include="Query\DataStreamsQuery.h" />
184+
<ClInclude Include="Query\ObservationsOfDataStreamQuery.h" />
185+
<ClInclude Include="Query\ObservationsQuery.h" />
184186
<ClInclude Include="Query\QueryParameters.h" />
185187
<ClInclude Include="Query\SystemsQuery.h" />
186188
<ClInclude Include="RegistryInit.h" />

CSAPI-lib/CSAPI-lib.vcxproj.filters

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,5 +195,11 @@
195195
<ClInclude Include="DataModels\ObservationBuilder.h">
196196
<Filter>Header Files\DataModels</Filter>
197197
</ClInclude>
198+
<ClInclude Include="Query\ObservationsQuery.h">
199+
<Filter>Header Files\Query</Filter>
200+
</ClInclude>
201+
<ClInclude Include="Query\ObservationsOfDataStreamQuery.h">
202+
<Filter>Header Files\Query</Filter>
203+
</ClInclude>
198204
</ItemGroup>
199205
</Project>

CSAPI-lib/ObservationsAPI.h

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#include "APIRequest.h"
66
#include "APIResponse.h"
77
#include "DataModels/Observation.h"
8+
#include "Query/ObservationsQuery.h"
9+
#include "Query/ObservationsOfDataStreamQuery.h"
810

911
namespace ConnectedSystemsAPI {
1012
class ObservationsAPI {
@@ -18,28 +20,61 @@ namespace ConnectedSystemsAPI {
1820
: apiRoot(apiRoot), authHeader(authHeader) {
1921
}
2022

21-
APIResponse<DataModels::Observation> getObservations() {
23+
/// <summary>
24+
/// List or search all observations available from this server endpoint.
25+
/// </summary>
26+
/// <param name="query">The query string parameters.</param>
27+
/// <returns>A response object containing a list of observations.</returns>
28+
APIResponse<DataModels::Observation> getObservations(const Query::ObservationsQuery& query) {
29+
return getObservations(query.toString());
30+
}
31+
32+
/// <summary>
33+
/// List or search all observations available from this server endpoint.
34+
/// </summary>
35+
/// <param name="query">The query string.</param>
36+
/// <returns>A response object containing a list of observations.</returns>
37+
APIResponse<DataModels::Observation> getObservations(std::string queryString = "") {
2238
auto response = APIRequest::Builder()
2339
.setApiRoot(apiRoot)
2440
.setMethod("GET")
2541
.setAuthHeader(authHeader)
26-
.setResourcePath("/observations")
42+
.setResourcePath("/observations" + queryString)
2743
.build()
2844
.execute<DataModels::Observation>();
2945
return response;
3046
}
3147

32-
APIResponse<DataModels::Observation> getObservationsOfDataStream(const std::string& dataStreamId) {
48+
/// <summary>
49+
/// List or search all observations available from a datastream.
50+
/// </summary>
51+
/// <param name="query">The query string parameters.</param>
52+
/// <returns>A response object containing a list of observations.</returns>
53+
APIResponse<DataModels::Observation> getObservationsOfDataStream(const std::string& dataStreamId, const Query::ObservationsOfDataStreamQuery& query) {
54+
return getObservationsOfDataStream(dataStreamId, query.toString());
55+
}
56+
57+
/// <summary>
58+
/// List or search all observations available from a datastream.
59+
/// </summary>
60+
/// <param name="query">The query string.</param>
61+
/// <returns>A response object containing a list of observations.</returns>
62+
APIResponse<DataModels::Observation> getObservationsOfDataStream(const std::string& dataStreamId, std::string queryString = "") {
3363
auto response = APIRequest::Builder()
3464
.setApiRoot(apiRoot)
3565
.setMethod("GET")
3666
.setAuthHeader(authHeader)
37-
.setResourcePath("/datastreams/" + dataStreamId + "/observations")
67+
.setResourcePath("/datastreams/" + dataStreamId + "/observations" + queryString)
3868
.build()
3969
.execute<DataModels::Observation>();
4070
return response;
4171
}
4272

73+
/// <summary>
74+
/// Get a specific observation by its ID.
75+
/// </summary>
76+
/// <param name="observationId">The ID of the observation to retrieve.</param>
77+
/// <returns>A response object containing the requested observation.</returns>
4378
APIResponse<DataModels::Observation> getObservationById(const std::string& observationId) {
4479
auto response = APIRequest::Builder()
4580
.setApiRoot(apiRoot)
@@ -51,6 +86,12 @@ namespace ConnectedSystemsAPI {
5186
return response;
5287
}
5388

89+
/// <summary>
90+
/// Add a new observation to an existing data stream.
91+
/// </summary>
92+
/// <param name="dataStreamId">The local identifier of the data stream.</param>
93+
/// <param name="observation">The observation to create.</param>
94+
/// <returns>A response object indicating success or failure.</returns>
5495
APIResponse<void> createObservation(const std::string& dataStreamId, const DataModels::Observation& observation) {
5596
nlohmann::ordered_json j;
5697
ConnectedSystemsAPI::DataModels::to_json(j, observation);
@@ -66,6 +107,12 @@ namespace ConnectedSystemsAPI {
66107
return response;
67108
}
68109

110+
/// <summary>
111+
/// Update an existing observation.
112+
/// </summary>
113+
/// <param name="observationId">The ID of the observation to update.</param>
114+
/// <param name="observation">The updated observation.</param>
115+
/// <returns>A response object indicating success or failure.</returns>
69116
APIResponse<void> updateObservation(const std::string& observationId, const DataModels::Observation& observation) {
70117
nlohmann::ordered_json j;
71118
ConnectedSystemsAPI::DataModels::to_json(j, observation);
@@ -81,6 +128,11 @@ namespace ConnectedSystemsAPI {
81128
return response;
82129
}
83130

131+
/// <summary>
132+
/// Delete an observation by its ID.
133+
/// </summary>
134+
/// <param name="observationId">The ID of the observation to delete.</param>
135+
/// <returns>A response object indicating success or failure.</returns>
84136
APIResponse<void> deleteObservation(const std::string& observationId) {
85137
auto response = APIRequest::Builder()
86138
.setApiRoot(apiRoot)
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#pragma once
2+
3+
#include <string>
4+
#include "QueryParameters.h"
5+
#include "..\DataModels\TimeExtent.h"
6+
7+
namespace ConnectedSystemsAPI {
8+
namespace Query {
9+
class ObservationsOfDataStreamQuery : public QueryParameters {
10+
public:
11+
/// <summary>
12+
/// List of resource local IDs or unique IDs (URI).
13+
/// Only resources that have one of the provided identifiers are selected.
14+
/// </summary>
15+
ObservationsOfDataStreamQuery& setId(const std::string& id) {
16+
addParameter("id", id);
17+
return *this;
18+
}
19+
20+
/// <summary>
21+
/// Either a date-time or an interval.
22+
/// Date and time expressions adhere to RFC 3339.
23+
/// Intervals may be bounded or half-bounded (double-dots at start or end).
24+
/// </summary>
25+
ObservationsOfDataStreamQuery& setPhenomenonTime(DataModels::TimeExtent phenomenonTime) {
26+
addParameter("phenomenonTime", phenomenonTime);
27+
return *this;
28+
}
29+
30+
/// <summary>
31+
/// Either a date-time or an interval.
32+
/// Date and time expressions adhere to RFC 3339.
33+
/// Intervals may be bounded or half-bounded (double-dots at start or end).
34+
/// </summary>
35+
ObservationsOfDataStreamQuery& setResultTime(DataModels::TimeExtent resultTime) {
36+
addParameter("resultTime", resultTime);
37+
return *this;
38+
}
39+
40+
/// <summary>
41+
/// List of feature local IDs or unique IDs (URI).
42+
/// Only resources that are associated with a feature of interest that has one of the provided identifiers are selected.
43+
/// </summary>
44+
ObservationsOfDataStreamQuery& setFoi(const std::string& foi) {
45+
addParameter("foi", foi);
46+
return *this;
47+
}
48+
49+
/// <summary>
50+
/// List of property local IDs or unique IDs (URI).
51+
/// Only resources that are associated with an observable property that has one of the provided identifiers are selected.
52+
/// </summary>
53+
ObservationsOfDataStreamQuery& setObservedProperty(const std::string& observedProperty) {
54+
addParameter("observedProperty", observedProperty);
55+
return *this;
56+
}
57+
58+
/// <summary>
59+
/// Limits the number of items that are presented in the response document.
60+
/// Default: 100
61+
/// </summary>
62+
ObservationsOfDataStreamQuery& setLimit(int limit) {
63+
addParameter("limit", limit);
64+
return *this;
65+
}
66+
};
67+
}
68+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#pragma once
2+
3+
#include <string>
4+
#include "QueryParameters.h"
5+
#include "..\DataModels\TimeExtent.h"
6+
7+
namespace ConnectedSystemsAPI {
8+
namespace Query {
9+
class ObservationsQuery : public QueryParameters {
10+
public:
11+
/// <summary>
12+
/// List of resource local IDs or unique IDs (URI).
13+
/// Only resources that have one of the provided identifiers are selected.
14+
/// </summary>
15+
ObservationsQuery& setId(const std::string& id) {
16+
addParameter("id", id);
17+
return *this;
18+
}
19+
20+
/// <summary>
21+
/// Either a date-time or an interval.
22+
/// Date and time expressions adhere to RFC 3339.
23+
/// Intervals may be bounded or half-bounded (double-dots at start or end).
24+
/// </summary>
25+
ObservationsQuery& setPhenomenonTime(DataModels::TimeExtent phenomenonTime) {
26+
addParameter("phenomenonTime", phenomenonTime);
27+
return *this;
28+
}
29+
30+
/// <summary>
31+
/// Either a date-time or an interval.
32+
/// Date and time expressions adhere to RFC 3339.
33+
/// Intervals may be bounded or half-bounded (double-dots at start or end).
34+
/// </summary>
35+
ObservationsQuery& setResultTime(DataModels::TimeExtent resultTime) {
36+
addParameter("resultTime", resultTime);
37+
return *this;
38+
}
39+
40+
/// <summary>
41+
/// List of system local IDs or unique IDs (URI).
42+
/// Only resources that are associated with a data stream that has one of the provided identifiers are selected.
43+
/// </summary>
44+
ObservationsQuery& setDataStream(std::vector<std::string>& dataStream) {
45+
addParameter("dataStream", dataStream);
46+
return *this;
47+
}
48+
49+
/// <summary>
50+
/// List of system local IDs or unique IDs (URI).
51+
/// Only resources that are associated with a System that has one of the provided identifiers are selected.
52+
/// </summary>
53+
ObservationsQuery& setSystem(std::vector<std::string>& system) {
54+
addParameter("system", system);
55+
return *this;
56+
}
57+
58+
/// <summary>
59+
/// List of feature local IDs or unique IDs (URI).
60+
/// Only resources that are associated with a feature of interest that has one of the provided identifiers are selected.
61+
/// </summary>
62+
ObservationsQuery& setFoi(const std::string& foi) {
63+
addParameter("foi", foi);
64+
return *this;
65+
}
66+
67+
/// <summary>
68+
/// List of property local IDs or unique IDs (URI).
69+
/// Only resources that are associated with an observable property that has one of the provided identifiers are selected.
70+
/// </summary>
71+
ObservationsQuery& setObservedProperty(const std::string& observedProperty) {
72+
addParameter("observedProperty", observedProperty);
73+
return *this;
74+
}
75+
76+
/// <summary>
77+
/// Limits the number of items that are presented in the response document.
78+
/// Default: 100
79+
/// </summary>
80+
ObservationsQuery& setLimit(int limit) {
81+
addParameter("limit", limit);
82+
return *this;
83+
}
84+
};
85+
}
86+
}

0 commit comments

Comments
 (0)