Skip to content

Commit bcb4d4f

Browse files
taeyzzzThanetpon Kultontikorn
andauthored
add json type mapping (#25)
* add json type mapping * update package --------- Co-authored-by: Thanetpon Kultontikorn <[email protected]>
1 parent 11ee31f commit bcb4d4f

12 files changed

+297
-2
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using Newtonsoft.Json;
4+
using Newtonsoft.Json.Converters;
5+
using Newtonsoft.Json.Linq;
6+
using Agoda.Graphql;
7+
8+
namespace Agoda.Graphql.EngageConnect.Queries.AttributionEnum
9+
{
10+
public class Query : QueryBase<Data>
11+
{
12+
private const string _query = @"query ChannelRecommendationAttributionsEnum($propertyId: Int!, $whiteLabelId: Int!, $includeInactive: Boolean!, $recommendationChannel: RecommendationChannel!, $productCategoryNames: [String!]) {
13+
findProductRecommendations(
14+
hotelId: $propertyId
15+
whiteLabelId: $whiteLabelId
16+
includeInactive: $includeInactive
17+
recommendationChannel: $recommendationChannel
18+
productCategoryNames: $productCategoryNames
19+
) {
20+
recommendationId
21+
channelRecommendationAttributions {
22+
recommendationChannel
23+
}
24+
}
25+
}";
26+
27+
public int PropertyId { get; }
28+
public int WhiteLabelId { get; }
29+
public bool IncludeInactive { get; }
30+
public RecommendationChannel RecommendationChannel { get; }
31+
public List<string>? ProductCategoryNames { get; }
32+
33+
public Query(int propertyId, int whiteLabelId, bool includeInactive, RecommendationChannel recommendationChannel, List<string>? productCategoryNames, IResultProcessor<Data> resultProcessor = null) : base(resultProcessor)
34+
{
35+
PropertyId = propertyId;
36+
WhiteLabelId = whiteLabelId;
37+
IncludeInactive = includeInactive;
38+
RecommendationChannel = recommendationChannel;
39+
ProductCategoryNames = productCategoryNames;
40+
}
41+
42+
protected override string QueryText => _query;
43+
44+
protected override Dictionary<string, object> Variables => new Dictionary<string, object>
45+
{
46+
{ "propertyId", PropertyId },
47+
{ "whiteLabelId", WhiteLabelId },
48+
{ "includeInactive", IncludeInactive },
49+
{ "recommendationChannel", RecommendationChannel },
50+
{ "productCategoryNames", ProductCategoryNames }
51+
};
52+
}
53+
54+
public sealed class Data
55+
{
56+
[JsonProperty("findProductRecommendations")]
57+
public List<FindProductRecommendations> FindProductRecommendations { get; set; }
58+
}
59+
60+
public sealed class ChannelRecommendationAttributions
61+
{
62+
[JsonProperty("recommendationChannel")]
63+
public RecommendationChannel RecommendationChannel { get; set; }
64+
}
65+
66+
public sealed class FindProductRecommendations
67+
{
68+
[JsonProperty("recommendationId")]
69+
public long? RecommendationId { get; set; }
70+
[JsonProperty("channelRecommendationAttributions")]
71+
public List<ChannelRecommendationAttributions> ChannelRecommendationAttributions { get; set; }
72+
}
73+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
query ChannelRecommendationAttributionsEnum($propertyId: Int!, $whiteLabelId: Int!, $includeInactive: Boolean!, $recommendationChannel: RecommendationChannel!, $productCategoryNames: [String!]) {
2+
findProductRecommendations(hotelId: $propertyId, whiteLabelId: $whiteLabelId, includeInactive: $includeInactive, recommendationChannel: $recommendationChannel, productCategoryNames: $productCategoryNames) {
3+
recommendationId
4+
channelRecommendationAttributions{
5+
recommendationChannel
6+
}
7+
}
8+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using Newtonsoft.Json;
4+
using Newtonsoft.Json.Converters;
5+
using Newtonsoft.Json.Linq;
6+
using Agoda.Graphql;
7+
8+
namespace Agoda.Graphql.EngageConnect.Queries.GetProductRecommendations
9+
{
10+
public class Query : QueryBase<Data>
11+
{
12+
private const string _query = @"query GetProductRecommendations($propertyId: Int!, $whiteLabelId: Int!, $includeInactive: Boolean!, $recommendationChannel: RecommendationChannel!, $productNames: [String!], $pagination: PaginationInput!) {
13+
findProductRecommendations(
14+
hotelId: $propertyId
15+
whiteLabelId: $whiteLabelId
16+
includeInactive: $includeInactive
17+
recommendationChannel: $recommendationChannel
18+
productNames: $productNames
19+
pagination: $pagination
20+
) {
21+
recommendationId
22+
productName
23+
productCategoryName
24+
recommendationScore
25+
recommendationTraceId
26+
activationParameters
27+
}
28+
}";
29+
30+
public int PropertyId { get; }
31+
public int WhiteLabelId { get; }
32+
public bool IncludeInactive { get; }
33+
public RecommendationChannel RecommendationChannel { get; }
34+
public List<string>? ProductNames { get; }
35+
public PaginationInput Pagination { get; }
36+
37+
public Query(int propertyId, int whiteLabelId, bool includeInactive, RecommendationChannel recommendationChannel, List<string>? productNames, PaginationInput pagination, IResultProcessor<Data> resultProcessor = null) : base(resultProcessor)
38+
{
39+
PropertyId = propertyId;
40+
WhiteLabelId = whiteLabelId;
41+
IncludeInactive = includeInactive;
42+
RecommendationChannel = recommendationChannel;
43+
ProductNames = productNames;
44+
Pagination = pagination;
45+
}
46+
47+
protected override string QueryText => _query;
48+
49+
protected override Dictionary<string, object> Variables => new Dictionary<string, object>
50+
{
51+
{ "propertyId", PropertyId },
52+
{ "whiteLabelId", WhiteLabelId },
53+
{ "includeInactive", IncludeInactive },
54+
{ "recommendationChannel", RecommendationChannel },
55+
{ "productNames", ProductNames },
56+
{ "pagination", Pagination }
57+
};
58+
}
59+
60+
public sealed class Data
61+
{
62+
[JsonProperty("findProductRecommendations")]
63+
public List<FindProductRecommendations> FindProductRecommendations { get; set; }
64+
}
65+
66+
public sealed class FindProductRecommendations
67+
{
68+
[JsonProperty("recommendationId")]
69+
public long? RecommendationId { get; set; }
70+
[JsonProperty("productName")]
71+
public string ProductName { get; set; }
72+
[JsonProperty("productCategoryName")]
73+
public string ProductCategoryName { get; set; }
74+
[JsonProperty("recommendationScore")]
75+
public decimal RecommendationScore { get; set; }
76+
[JsonProperty("recommendationTraceId")]
77+
public string RecommendationTraceId { get; set; }
78+
[JsonProperty("activationParameters")]
79+
public JToken? ActivationParameters { get; set; }
80+
}
81+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
query GetProductRecommendations($propertyId: Int!, $whiteLabelId: Int!, $includeInactive: Boolean!, $recommendationChannel: RecommendationChannel!, $productNames: [String!], $pagination: PaginationInput!) {
2+
findProductRecommendations(hotelId: $propertyId, whiteLabelId: $whiteLabelId, includeInactive: $includeInactive, recommendationChannel: $recommendationChannel, productNames: $productNames, pagination: $pagination) {
3+
recommendationId
4+
productName
5+
productCategoryName
6+
recommendationScore
7+
recommendationTraceId
8+
activationParameters
9+
}
10+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using Newtonsoft.Json;
4+
using Newtonsoft.Json.Converters;
5+
using Agoda.Graphql;
6+
7+
namespace Agoda.Graphql.EngageConnect.Queries
8+
{
9+
public enum RecommendationChannel
10+
{
11+
DEFAULT,
12+
PCOMM,
13+
SDM_EMAIL,
14+
SDM_POPUP,
15+
YCS,
16+
YCS_PROMO_PAGE_2
17+
}
18+
19+
public sealed class PaginationInput
20+
{
21+
[JsonProperty("limit")]
22+
public int Limit { get; set; }
23+
[JsonProperty("offset")]
24+
public int Offset { get; set; }
25+
}
26+
27+
public sealed class RecommendationTraceInput
28+
{
29+
[JsonProperty("recommendationId")]
30+
public long? RecommendationId { get; set; }
31+
[JsonProperty("recommendationRank")]
32+
public int? RecommendationRank { get; set; }
33+
[JsonProperty("recommendationTraceId")]
34+
public string RecommendationTraceId { get; set; }
35+
[JsonProperty("ticketId")]
36+
public long? TicketId { get; set; }
37+
}
38+
39+
public enum ChannelStatus
40+
{
41+
ACTIVATED,
42+
DISPATCHED,
43+
READ,
44+
RECOMMENDED,
45+
TOUCHED
46+
}
47+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using Newtonsoft.Json;
4+
using Newtonsoft.Json.Converters;
5+
using Newtonsoft.Json.Linq;
6+
using Agoda.Graphql;
7+
8+
namespace Agoda.Graphql.EngageConnect.Queries.UpsertChannelRecommendationAttribution
9+
{
10+
public class Mutation : QueryBase<Data>
11+
{
12+
private const string _query = @"mutation UpsertChannelRecommendationAttribution($recommendationTraceInput: [RecommendationTraceInput!]!, $channelStatus: ChannelStatus!, $recommendationChannel: RecommendationChannel!) {
13+
upsertChannelRecommendationAttributions(
14+
recommendationChannel: $recommendationChannel
15+
channelStatus: $channelStatus
16+
recommendationTraces: $recommendationTraceInput
17+
) {
18+
recommendationId
19+
channelStatus
20+
recommendationTraceId
21+
}
22+
}";
23+
24+
public List<RecommendationTraceInput> RecommendationTraceInput { get; }
25+
public ChannelStatus ChannelStatus { get; }
26+
public RecommendationChannel RecommendationChannel { get; }
27+
28+
public Mutation(List<RecommendationTraceInput> recommendationTraceInput, ChannelStatus channelStatus, RecommendationChannel recommendationChannel, IResultProcessor<Data> resultProcessor = null) : base(resultProcessor)
29+
{
30+
RecommendationTraceInput = recommendationTraceInput;
31+
ChannelStatus = channelStatus;
32+
RecommendationChannel = recommendationChannel;
33+
}
34+
35+
protected override string QueryText => _query;
36+
37+
protected override Dictionary<string, object> Variables => new Dictionary<string, object>
38+
{
39+
{ "recommendationTraceInput", RecommendationTraceInput },
40+
{ "channelStatus", ChannelStatus },
41+
{ "recommendationChannel", RecommendationChannel }
42+
};
43+
}
44+
45+
public sealed class Data
46+
{
47+
[JsonProperty("upsertChannelRecommendationAttributions")]
48+
public List<UpsertChannelRecommendationAttributions> UpsertChannelRecommendationAttributions { get; set; }
49+
}
50+
51+
public sealed class UpsertChannelRecommendationAttributions
52+
{
53+
[JsonProperty("recommendationId")]
54+
public long? RecommendationId { get; set; }
55+
[JsonProperty("channelStatus")]
56+
public ChannelStatus ChannelStatus { get; set; }
57+
[JsonProperty("recommendationTraceId")]
58+
public string RecommendationTraceId { get; set; }
59+
}
60+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
mutation UpsertChannelRecommendationAttribution(
2+
$recommendationTraceInput: [RecommendationTraceInput!]!
3+
$channelStatus: ChannelStatus!
4+
$recommendationChannel: RecommendationChannel!) {
5+
upsertChannelRecommendationAttributions (recommendationChannel: $recommendationChannel, channelStatus: $channelStatus, recommendationTraces: $recommendationTraceInput)
6+
{
7+
recommendationId
8+
channelStatus
9+
recommendationTraceId
10+
}
11+
}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "agoda-graphql-csharp-generator",
3-
"version": "2.1.6",
3+
"version": "2.1.7",
44
"main": "dist/agoda-csharp-operation.js",
55
"exports": {
66
"./shared-types": "./dist/agoda-csharp-shared-types.js",
@@ -11,6 +11,7 @@
1111
],
1212
"scripts": {
1313
"generate-codegen-config": "ts-node ./src/generate.ts --schema-url 'https://smapi-qa-http.privatecloud.qa.agoda.is/v2/graphql' --graphql-dir './Agoda.Graphql/SupplyApi/Queries' --graphql-project 'Agoda.Graphql' --yml-out './codegen.yml'",
14+
"generate-codegen-config-engage": "ts-node ./src/generate.ts --schema-url 'https://engagev4-server-qa.privatecloud.qa.agoda.is/graphql' --graphql-dir './Agoda.Graphql/EngageConnect/Queries' --graphql-project 'Agoda.Graphql' --yml-out './codegen.yml'",
1415
"generate-codegen-config-with-headers": "ts-node ./src/generate.ts --schema-url 'http://booking-query-high-qa.privatecloud.qa.agoda.is' --graphql-dir './Agoda.Graphql/BookingQueries' --graphql-project 'Agoda.Graphql.BookingQueries' --yml-out './codegen.yml' --header 'API-Key: xxx' --header 'Client-ID: xxx'",
1516
"generate-graphql-csharp": "gql-gen --config codegen.yml",
1617
"build": "tsc"

src/agoda-csharp-operation.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,7 @@ export const plugin: PluginFunction<AgodaCSharpCodegenConfig> = (
468468
using System.Collections.Generic;
469469
using Newtonsoft.Json;
470470
using Newtonsoft.Json.Converters;
471+
using Newtonsoft.Json.Linq;
471472
using Agoda.Graphql;
472473
473474
namespace ${namespace}

src/agoda-csharp-shared-types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ export const plugin: PluginFunction<AgodaCSharpSharedConfig> = (
272272
using System.Collections.Generic;
273273
using Newtonsoft.Json;
274274
using Newtonsoft.Json.Converters;
275+
using Newtonsoft.Json.Linq;
275276
using Agoda.Graphql;
276277
277278
namespace ${config.namespace}

0 commit comments

Comments
 (0)