Commit 196c642d by Brent Gulanowski

Use the "upsert" interface to avoid creating duplicate model objects.

parent e5d24a48
...@@ -64,7 +64,7 @@ ...@@ -64,7 +64,7 @@
return [self getRequestForURL:components.URL completionHandler:^(NSDictionary *json, NSURLResponse *response, NSError *error) { return [self getRequestForURL:components.URL completionHandler:^(NSDictionary *json, NSURLResponse *response, NSError *error) {
BUYCustomer *customer = nil; BUYCustomer *customer = nil;
if (json && !error) { if (json && !error) {
customer = [self.modelManager insertCustomerWithJSONDictionary:json[@"customer"]]; customer = [self.modelManager customerWithJSONDictionary:json[@"customer"]];
} }
block(customer, error); block(customer, error);
}]; }];
...@@ -97,7 +97,7 @@ ...@@ -97,7 +97,7 @@
}]; }];
} }
else { else {
BUYCustomer *customer = [self.modelManager insertCustomerWithJSONDictionary:json[@"customer"]]; BUYCustomer *customer = [self.modelManager customerWithJSONDictionary:json[@"customer"]];
block(customer, self.customerToken, error); block(customer, self.customerToken, error);
} }
} }
...@@ -191,9 +191,8 @@ ...@@ -191,9 +191,8 @@
{ {
NSURLComponents *components = [self URLComponentsForCustomerOrders]; NSURLComponents *components = [self URLComponentsForCustomerOrders];
return [self getRequestForURL:components.URL completionHandler:^(NSDictionary *json, NSURLResponse *response, NSError *error) { return [self getRequestForURL:components.URL completionHandler:^(NSDictionary *json, NSURLResponse *response, NSError *error) {
NSArray *ordersJSON = json[@"orders"]; if (json && !error) {
if (ordersJSON && !error) { NSArray *orders = [self.modelManager ordersWithJSONDictionary:json];
NSArray *orders = [self.modelManager insertOrdersWithJSONArray:ordersJSON];
block(orders, error); block(orders, error);
} else { } else {
block(nil, error); block(nil, error);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment