Permalink
Browse files

Add the repos search

  • Loading branch information...
Dinduks committed Sep 11, 2012
1 parent 4cd9e30 commit 826cae664cf40677138e481a3042c4bf7a7fb800
@@ -2,11 +2,24 @@ package controllers
import play.api._
import play.api.mvc._
+import play.api.libs.ws._
+import play.api.libs.json._
object Application extends Controller {
-
def index = Action {
Ok(views.html.index())
}
+ def search(keyword: String) = Action {
+ val githubApiUrl = Play.current.configuration.getString("github.apiUrl").get
+ val githubSearchReposPath = Play.current.configuration.getString("github.searchReposPath").get
+
+ Async {
+ WS.url(githubApiUrl + githubSearchReposPath + keyword).get().map { response =>
+ val repos = (response.json \ "repositories")
+ Ok(views.html.searchResults(repos.as[List[JsValue]], keyword))
+ }
+ }
+ }
}
+
@@ -0,0 +1,8 @@
+@(username: play.api.libs.json.JsValue, repositoryName: play.api.libs.json.JsValue)
+
+@defining(username.toString.replaceAll("\"", "") + "/" + repositoryName.toString.replaceAll("\"", "")) { repositoryFullName =>
+ <a href="/@repositoryFullName">
+ @repositoryFullName
+ </a>
+}
+
@@ -0,0 +1,14 @@
+@(repos: List[play.api.libs.json.JsValue], keyword: String)
+
+@import views.html.helper._
+
+@main("Search results for " + keyword) {
+<ul>
+ @for(repo <- repos) {
+ <li>
+ @repositoryLink(repo \ "owner", repo \ "name")
+ </li>
+ }
+</ul>
+}
+
View
@@ -45,3 +45,5 @@ logger.play=INFO
# Logger provided to your application:
logger.application=DEBUG
+github.apiUrl = "https://api.github.com"
+github.searchReposPath = "/legacy/repos/search/"
View
@@ -1,3 +1,3 @@
GET / controllers.Application.index
-GET /search/:repo controllers.Application.search(repo: Long)
+GET /search/:keyword controllers.Application.search(keyword: String)
GET /assets/*file controllers.Assets.at(path="/public", file)

0 comments on commit 826cae6

Please sign in to comment.