Skip to content

Commit

Permalink
chore: LCQuery#Get(string objectId)
Browse files Browse the repository at this point in the history
  • Loading branch information
onerain88 committed Jan 7, 2021
1 parent 58245c1 commit 346dcb3
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions Storage/Storage/LCQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -346,12 +346,13 @@ public async Task<int> Count() {
return (int)ret["count"];
}

public Task<T> Get(string objectId) {
public async Task<T> Get(string objectId) {
if (string.IsNullOrEmpty(objectId)) {
throw new ArgumentNullException(nameof(objectId));
}
WhereEqualTo("objectId", objectId);
return First();
string path = $"classes/{ClassName}/{objectId}";
Dictionary<string, object> response = await LCApplication.HttpClient.Get<Dictionary<string, object>>(path);
return DecodeLCObject(response);
}

public async Task<ReadOnlyCollection<T>> Find() {
Expand All @@ -361,9 +362,7 @@ public async Task<ReadOnlyCollection<T>> Find() {
List<object> results = response["results"] as List<object>;
List<T> list = new List<T>();
foreach (object item in results) {
LCObjectData objectData = LCObjectData.Decode(item as Dictionary<string, object>);
T obj = LCObject.Create(ClassName) as T;
obj.Merge(objectData);
T obj = DecodeLCObject(item as Dictionary<string, object>);
list.Add(obj);
}
return list.AsReadOnly();
Expand Down Expand Up @@ -412,5 +411,12 @@ public static LCQuery<T> Or(IEnumerable<LCQuery<T>> queries) {
compositionQuery.ClassName = className;
return compositionQuery;
}

private T DecodeLCObject(Dictionary<string, object> data) {
LCObjectData objectData = LCObjectData.Decode(data);
T obj = LCObject.Create(ClassName) as T;
obj.Merge(objectData);
return obj;
}
}
}

0 comments on commit 346dcb3

Please sign in to comment.