Skip to content

Commit

Permalink
Add order API endpoint (#413)
Browse files Browse the repository at this point in the history
  • Loading branch information
joeblau authored Jul 14, 2018
1 parent 9a0946d commit 992611f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Sources/App/Controllers/TemplateController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ internal struct TemplateController: ReadOnlyTemplateManagerProtocol {
line.trimmingCharacters(in: .whitespaces).lowercased()
})
.filter({ (line) -> Bool in
!line.hasPrefix("#") || !line.hasPrefix("")
!line.hasPrefix("#") && !line.isEmpty
})
.enumerated()
.reduce([String: Int](), { (orderedDict, line : (offset: Int, text: String)) -> [String: Int] in
Expand Down
12 changes: 11 additions & 1 deletion Sources/App/RouteHandlers/APIRouteHandlers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ internal class APIHandlers {
///
/// - Parameter router: Vapor server side Swift router
internal func createListEndpoint(router: Router) {

router.get("/api/list") { request -> Response in
let response = request.makeResponse()

Expand All @@ -87,6 +86,17 @@ internal class APIHandlers {
}
}

/// Create the API endpoint for showing th eorder of templates
///
/// - Parameter router: Vapor server side Swift router
internal func createOrderEndpoint(router: Router) {
router.get("/api/order") { request -> Response in
let response = request.makeResponse()
try response.content.encode(json: self.order)
return response
}
}

/// Create the API endpoint for help
///
/// - Parameter router: Vapor server side Swift router
Expand Down
1 change: 1 addition & 0 deletions Sources/App/Server.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public class Gitignore {
apiHandlers.createIgnoreEndpoint(router: router)
apiHandlers.createTemplateDownloadEndpoint(router: router)
apiHandlers.createListEndpoint(router: router)
apiHandlers.createOrderEndpoint(router: router)
apiHandlers.createHelp(router: router)
}

Expand Down
11 changes: 10 additions & 1 deletion Tests/AppTests/RouteHandlers/APIHandlersTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class APIHandlersTests: XCTestCase {
("testServer_api_force_sort_sortable", testServer_api_force_sort_sortable),
("testServer_api_no_sort_sortalbe", testServer_api_no_sort_sortalbe),
("testServer_api_no_sort_not_sortable", testServer_api_no_sort_not_sortable),
("testServer_api_order", testServer_api_order),
("testServer_api", testServer_api),
]

Expand Down Expand Up @@ -111,7 +112,7 @@ class APIHandlersTests: XCTestCase {
}
}

func testSErver_api_url_multiple_url_encoded() throws {
func testServer_api_url_multiple_url_encoded() throws {
let body = try responseForRequest("/api/sbt%2Cscala%2Cintellij").http.body
XCTAssertFalse(body.description.contains("!! ERROR:"))
XCTAssertTrue(body.description.contains("### SBT ###"))
Expand All @@ -124,6 +125,14 @@ class APIHandlersTests: XCTestCase {
}
}

func testServer_api_order() throws {
if let byteCount = try responseForRequest("/api/order").http.body.count {
XCTAssertGreaterThan(byteCount, 0)
} else {
XCTFail()
}
}

func testServer_api() throws {
if let byteCount = try responseForRequest("/api/").http.body.count {
XCTAssertGreaterThan(byteCount, 0)
Expand Down

0 comments on commit 992611f

Please sign in to comment.