Skip to content

Commit 641bf15

Browse files
committed
added Subitems.CreateMultiple, improved response handling for queries with multiple aliased mutation commands
1 parent 5784ef6 commit 641bf15

File tree

4 files changed

+35
-7
lines changed

4 files changed

+35
-7
lines changed

MondayApi/Columns/ColumnActions.cs

+2-3
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,8 @@ public async Task<IEnumerable<Item>> ChangeMultipleItems(IEnumerable<ColumnMulti
130130
);
131131
createIndex++;
132132
}
133-
134-
var response = await client.Run<Newtonsoft.Json.Linq.JObject>(mutation);
135-
return response.AsEnumerable<KeyValuePair<string, Newtonsoft.Json.Linq.JToken>>().Select(i => i.Value.ToObject<Item>());
133+
var response = await client.Run<Dictionary<string, Item>>(mutation);
134+
return response.Select(kv => kv.Value);
136135
}
137136

138137

MondayApi/Items/ItemActions.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ public async Task<IEnumerable<Item>> CreateMultiple(IEnumerable<Item> items, boo
141141
createIndex++;
142142
}
143143

144-
var response = await client.Run<Newtonsoft.Json.Linq.JObject>(mutation);
145-
return response.AsEnumerable<KeyValuePair<string, Newtonsoft.Json.Linq.JToken>>().Select(i => i.Value.ToObject<Item>());
144+
var response = await client.Run<Dictionary<string, Item>>(mutation);
145+
return response.Select(kv => kv.Value);
146146
}
147147

148148
public async Task<Item> MoveToGroup(string itemID, string groupID) {
@@ -214,8 +214,8 @@ public async Task<IEnumerable<Item>> DeleteMultiple(IEnumerable<string> ids) {
214214
deleteIndex++;
215215
}
216216

217-
var response = await client.Run<Newtonsoft.Json.Linq.JObject>(mutation);
218-
return response.AsEnumerable<KeyValuePair<string, Newtonsoft.Json.Linq.JToken>>().Select(i => i.Value.ToObject<Item>());
217+
var response = await client.Run<Dictionary<string, Item>>(mutation);
218+
return response.Select(kv => kv.Value);
219219
}
220220
}
221221
}

MondayApi/Subitems/ISubitemActions.cs

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ namespace MondayApi.Subitems {
66
public interface ISubitemActions {
77
Task<IEnumerable<Item>> Get(string parentItemID, bool withColumnValues = false, IEnumerable<string> columnIDs = null);
88
Task<Item> GetParentItem(string subitemID, bool withColumnValues = false, IEnumerable<string> columnIDs = null);
9+
910
Task<Item> CreateSubitem(string itemName, string parentItemID, IEnumerable<IColumnValue> columnValues = null, bool? createLabelsIfMissing = null);
11+
/// <summary>Allows creating multiple subitems with one request</summary>
12+
/// <param name="items">Subitems to be created. Properties used are <see cref="Item.Name"/> and <see cref="Item.ColumnValues"/></param>
13+
Task<IEnumerable<Item>> CreateMultiple(string parentItemID, IEnumerable<Item> items, bool? createLabelsIfMissing = null);
1014
}
1115
}

MondayApi/Subitems/SubitemActions.cs

+25
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,30 @@ public async Task<Item> CreateSubitem(string itemName, string parentItemID, IEnu
6262
var response = await client.RunMutation(mutation);
6363
return response.CreateSubitem;
6464
}
65+
66+
/// <inheritdoc />
67+
public async Task<IEnumerable<Item>> CreateMultiple(string parentItemID, IEnumerable<Item> items, bool? createLabelsIfMissing = null) {
68+
Utils.Utils.RequireArgument(nameof(items), items);
69+
var mutation = new MutationQueryBuilder();
70+
71+
int createIndex = 0;
72+
foreach (var item in items) {
73+
Utils.Utils.RequireArgument($"{nameof(items)}.{nameof(item.Name)}", item.Name);
74+
75+
mutation = mutation.WithCreateSubitem(
76+
getSubitemQueryBuilder(true, null),
77+
itemName: item.Name,
78+
parentItemID: parentItemID,
79+
columnValues: Utils.Utils.SerializeColumnValues(item.ColumnValues),
80+
createLabelsIfMissing: createLabelsIfMissing,
81+
82+
alias: $"createItem{createIndex}"
83+
);
84+
createIndex++;
85+
}
86+
87+
var response = await client.Run<Dictionary<string, Item>>(mutation);
88+
return response.Select(kv => kv.Value);
89+
}
6590
}
6691
}

0 commit comments

Comments
 (0)