OSDN Git Service

UAをVersion/10.0.3 Safari/602.4.8に変更
[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 class SetActionCommand: JSONCommand {
12     override class func canExecuteAPI(_ api: String) -> Bool {
13         if api == "/kcsapi/api_req_air_corps/set_action" { return true }
14         return false
15     }
16     
17     override func execute() {
18         guard let areaId = parameter["api_area_id"].int,
19             let rIds = parameter["api_base_id"]
20                 .string?
21                 .components(separatedBy: ",")
22                 .map({ Int($0) ?? -1 }),
23             let actions = parameter["api_action_kind"]
24                 .string?
25                 .components(separatedBy: ",")
26                 .map({ Int($0) ?? -1 })
27             else { return print("Argument is rwong") }
28         if rIds.count != actions.count { print("missmatch count") }
29         
30         let store = ServerDataStore.oneTimeEditor()
31         zip(rIds, actions).forEach { (rId, action) in
32             store.airBase(area: areaId, base: rId)?.action_kind = action
33         }
34     }
35 }