OSDN Git Service

NSArrayに対してジェネリクスを使用するようにした
[kcd/KCD.git] / KCD / HMAirCorpsChangeNameCommand.m
1 //
2 //  HMAirCorpsChangeNameCommand.m
3 //  KCD
4 //
5 //  Created by Hori,Masaki on 2016/12/04.
6 //  Copyright © 2016年 Hori,Masaki. All rights reserved.
7 //
8
9 #import "HMAirCorpsChangeNameCommand.h"
10
11 #import "HMKCAirBase.h"
12 #import "HMKCAirBasePlaneInfo.h"
13 #import "HMKCMaterial.h"
14
15 #import "HMServerDataStore.h"
16
17 @implementation HMAirCorpsChangeNameCommand
18 + (void)load
19 {
20     static dispatch_once_t onceToken;
21     dispatch_once(&onceToken, ^{
22         [HMJSONCommand registerClass:self];
23     });
24 }
25
26 + (BOOL)canExcuteAPI:(NSString *)api
27 {
28     if([api isEqualToString:@"/kcsapi/api_req_air_corps/change_name"]) return YES;
29     return NO;
30 }
31
32 - (void)execute
33 {
34     HMServerDataStore *store = [HMServerDataStore oneTimeEditor];
35     NSError *error = nil;
36     
37     NSString *areaId = self.arguments[@"api_area_id"];
38     NSString *rId = self.arguments[@"api_base_id"];
39     NSArray<HMKCAirBase *> *airBases = [store objectsWithEntityName:@"AirBase"
40                                                     sortDescriptors:nil
41                                                               error:&error
42                                                     predicateFormat:@"area_id == %@ AND rid == %@", @(areaId.integerValue), @(rId.integerValue)];
43     if(airBases.count == 0) { return; }
44     
45     airBases[0].name = self.arguments[@"api_name"];
46 }
47 @end