This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import PerfectHTTP | |
extension Routes { | |
func configure(basedOnControllers controllers: [Controller]) { | |
for controller in controllers { | |
routes.add(controller.routes) | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import PerfectHTTP | |
import PerfectHTTPServer | |
import PerfectLib | |
import Dip | |
// Configure dependency injection. | |
let container = DependencyContainer() | |
container.configure() | |
// Initialize all controllers. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import Dip | |
extension DependencyContainer { | |
func configure() { | |
self.registerRepositories(container: self) | |
self.registerControllers(container: self) | |
} | |
func resolveAllControllers() -> [Controller] { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
class User : Codable { | |
var id: Int | |
var name: String | |
var email: String | |
var isLocked: Bool | |
init(id: Int, name: String, email: String, isLocked: Bool) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
class Task : Codable { | |
var id: Int | |
var name: String | |
var isFinished: Bool | |
init(id: Int, name: String, isFinished: Bool) { | |
self.id = id |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TasksRepository : TasksRepositoryProtocol { | |
var tasks = [ | |
1: Task(id: 1, name: "Create new Perfect server", isFinished: false), | |
2: Task(id: 2, name: "Improve MVC pattern on server side", isFinished: false), | |
3: Task(id: 3, name: "Finish code refactoring", isFinished: false), | |
4: Task(id: 4, name: "Move to newest fremeworks", isFinished: false) | |
] | |
func getTasks() -> [Task] { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol TasksRepositoryProtocol { | |
func getTasks() -> [Task] | |
func getTask(id: Int) -> Task? | |
func addTask(task: Task) | |
func updateTask(task: Task) | |
func deleteTask(id: Int) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import PerfectHTTP | |
class TasksController : Controller { | |
private let tasksRepository: TasksRepositoryProtocol! | |
init(tasksRepository: TasksRepositoryProtocol) { | |
self.tasksRepository = tasksRepository | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import PerfectHTTP | |
class Controller { | |
var routes = Routes() | |
init() { | |
initRoutes() | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, | |
shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool { | |
return true | |
} |