Skip to content

Commit 5d207ff

Browse files
committed
moved boardgames routes into dedicated file
1 parent 0f5c0e6 commit 5d207ff

File tree

3 files changed

+37
-32
lines changed

3 files changed

+37
-32
lines changed

microservices-swift/Sources/Application/Application.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public class App {
2121
func postInit() throws {
2222
// Endpoints
2323
initializeHealthRoutes(app: self)
24+
initializeBoardgamesRoutes(app: self)
2425
}
2526

2627
public func run() throws {
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import LoggerAPI
2+
import Health
3+
import KituraContracts
4+
5+
func initializeBoardgamesRoutes(app: App) {
6+
var boardgames: [Boardgame] = [Boardgame(id: 1, name: "Risk", emoji: "💣"), Boardgame(id: 2, name: "Uno", emoji: "1️⃣")]
7+
8+
app.router.get("/boardgames") { (respondWith: ([Boardgame]?, RequestError?) -> Void) -> Void in
9+
respondWith(boardgames, nil)
10+
}
11+
12+
app.router.post("/boardgames") { (boardgame: Boardgame, respondWith: (Boardgame?, RequestError?) -> Void) -> Void in
13+
boardgames.append(boardgame)
14+
15+
respondWith(boardgame, nil)
16+
}
17+
18+
app.router.delete("/boardgames") { (boardgameId: Int, respondWith: (RequestError?) -> Void) -> Void in
19+
guard let index = boardgames.firstIndex(where: { $0.id == boardgameId }) else {
20+
respondWith(RequestError.notFound)
21+
return
22+
}
23+
boardgames.remove(at: index)
24+
respondWith(nil)
25+
}
26+
27+
// PUT?
28+
// UPDATE?
29+
// error for inserting boardgame with existing id
30+
// update swagger
31+
32+
// Next Up!
33+
// database?
34+
// deploy?
35+
36+
}

microservices-swift/Sources/Application/Routes/HealthRoutes.swift

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,43 +3,11 @@ import Health
33
import KituraContracts
44

55
func initializeHealthRoutes(app: App) {
6-
7-
var boardgames: [Boardgame] = [Boardgame(id: 1, name: "Risk", emoji: "💣"), Boardgame(id: 2, name: "Uno", emoji: "1️⃣")]
8-
96
app.router.get("/health") { (respondWith: (Status?, RequestError?) -> Void) -> Void in
107
if health.status.state == .UP {
118
respondWith(health.status, nil)
129
} else {
1310
respondWith(nil, RequestError(.serviceUnavailable, body: health.status))
1411
}
1512
}
16-
17-
app.router.get("/boardgames") { (respondWith: ([Boardgame]?, RequestError?) -> Void) -> Void in
18-
respondWith(boardgames, nil)
19-
}
20-
21-
app.router.post("/boardgames") { (boardgame: Boardgame, respondWith: (Boardgame?, RequestError?) -> Void) -> Void in
22-
boardgames.append(boardgame)
23-
24-
respondWith(boardgame, nil)
25-
}
26-
27-
app.router.delete("/boardgames") { (boardgameId: Int, respondWith: (RequestError?) -> Void) -> Void in
28-
guard let index = boardgames.firstIndex(where: { $0.id == boardgameId }) else {
29-
respondWith(RequestError.notFound)
30-
return
31-
}
32-
boardgames.remove(at: index)
33-
respondWith(nil)
34-
}
35-
36-
// PUT?
37-
// UPDATE?
38-
// error for inserting boardgame with existing id
39-
// update swagger
40-
41-
// Next Up!
42-
// database?
43-
// deploy?
44-
4513
}

0 commit comments

Comments
 (0)