November 2018
Intermediate to advanced
404 pages
10h 16m
English
Now, you can proceed to implement route handlers that work with the controller's CRUD operations. Create another new directory, /Sources/Application/Routes, and add the following JournalRoute.swift file to it:
import Foundationimport Kiturastruct JournalRoutes { let journal = JournalController() func newEntry(entry: Entry, completion: (Entry?, RequestError?) -> Void ) { let newID = UUID().uuidString if let result = journal.create(Entry(id: newID, title: entry.title, content: entry.content)) { print("Created: \(result)") completion(result, nil) } else { completion(Entry(id: "-1"), nil) } } func editEntry(id: Int, new: Entry, completion: (Entry?, RequestError?) -> Void ) -> Void { let newID = UUID().uuidString ...Read now
Unlock full access