import Cocoa
-fileprivate enum BasicAPI: String {
- case getMemberBasic = "/kcsapi/api_get_member/basic"
- case port = "/kcsapi/api_port/port"
-}
-
-fileprivate func dataKey(_ apiResponse: APIResponse) -> String {
- guard let basicApi = BasicAPI(rawValue: apiResponse.api)
- else { return "api_data" }
- switch basicApi {
- case .port: return "api_data.api_basic"
- default: return "api_data"
- }
-}
-
-class BasicMapper: JSONMapper {
- typealias ObjectType = Basic
-
+final class BasicMapper: JSONMapper {
+
let apiResponse: APIResponse
let configuration: MappingConfiguration<Basic>
required init(_ apiResponse: APIResponse) {
+
self.apiResponse = apiResponse
self.configuration = MappingConfiguration(entity: Basic.entity,
- dataKey: dataKey(apiResponse),
+ dataKeys: BasicMapper.dataKeys(apiResponse),
editorStore: ServerDataStore.oneTimeEditor())
}
+ private class func dataKeys(_ apiResponse: APIResponse) -> [String] {
+
+ switch apiResponse.api.endpoint {
+
+ case .port: return ["api_data", "api_basic"]
+
+ case .basic: return ["api_data"]
+
+ default: return Logger.shared.log("Missing API: \(apiResponse.api)", value: ["api_data"])
+ }
+ }
+
func commit() {
+
let store = ServerDataStore.oneTimeEditor()
- guard let basic = store.basic() ?? store.createBasic()
- else { return print("Can not Get Basic") }
+
+ guard let basic = store.basic() ?? store.createBasic() else {
+
+ return Logger.shared.log("Can not Get Basic")
+ }
+
registerElement(data, to: basic)
}
}