OSDN Git Service

endpointを文字列のまま扱わないようにした
[kcd/KCD.git] / KCD / SetActionCommand.swift
1 //
2 //  SetActionCommand.swift
3 //  KCD
4 //
5 //  Created by Hori,Masaki on 2017/01/14.
6 //  Copyright © 2017年 Hori,Masaki. All rights reserved.
7 //
8
9 import Cocoa
10
11 final class SetActionCommand: JSONCommand {
12     
13     override class func canExecuteAPI(_ api: API) -> Bool {
14         
15         return api.endpoint == .setAction
16     }
17     
18     override func execute() {
19         
20         guard let areaId = parameter["api_area_id"].int else {
21             
22             return Logger.shared.log("api_area_id is wrong.")
23         }
24         guard let rIds = parameter["api_base_id"]
25             .string?
26             .components(separatedBy: ",")
27             .map({ Int($0) ?? -1 }) else {
28                 
29                 return Logger.shared.log("api_base_id is wrong.")
30         }
31         guard let actions = parameter["api_action_kind"]
32             .string?
33             .components(separatedBy: ",")
34             .map({ Int($0) ?? -1 }) else {
35                 
36                 return Logger.shared.log("api_action_kind is rwong")
37         }
38         
39         if rIds.count != actions.count { print("missmatch count") }
40         
41         let store = ServerDataStore.oneTimeEditor()
42         
43         zip(rIds, actions).forEach { (rId, action) in
44             
45             store.airBase(area: areaId, base: rId)?.action_kind = action
46         }
47     }
48 }