diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..f3c36ff --- /dev/null +++ b/LICENSE @@ -0,0 +1,13 @@ +Copyright (C) 2014 david@gageot.net + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License diff --git a/app/_includes/jumbotron.html b/app/_includes/jumbotron.html new file mode 100644 index 0000000..e2f2437 --- /dev/null +++ b/app/_includes/jumbotron.html @@ -0,0 +1,13 @@ +
+
+

Managed VMs Sample Project

+ +

Powered by Fluent-http.

+ +

+ + Learn more + +

+
+
diff --git a/app/_includes/navbar.html b/app/_includes/navbar.html new file mode 100644 index 0000000..e8b4a33 --- /dev/null +++ b/app/_includes/navbar.html @@ -0,0 +1,11 @@ + \ No newline at end of file diff --git a/app/_layouts/main.html b/app/_layouts/main.html index 581ae74..4d9337c 100644 --- a/app/_layouts/main.html +++ b/app/_layouts/main.html @@ -3,12 +3,5 @@ styles: ['/webjars/bootstrap/3.3.1/css/bootstrap.min.css', '/style.css'] --- -
-
-
-

[[title]]

- - [[body]] -
-
-
+[[>navbar]] +[[body]] diff --git a/app/add.html b/app/add.html deleted file mode 100644 index 314039a..0000000 --- a/app/add.html +++ /dev/null @@ -1,7 +0,0 @@ ---- -layout: main -title: Cloud Storage ---- - -[[entry.key]] -[[entry.content]] diff --git a/app/demo.coffee b/app/demo.coffee index bc663c1..4c39daa 100644 --- a/app/demo.coffee +++ b/app/demo.coffee @@ -1,6 +1,19 @@ angular.module 'demo', [] +.service 'Messages', ($http) -> + list: -> + $http.get '/message/list', {cached: false} + create: (message) -> + $http.post '/message', message + .controller 'IndexController', class - constructor: ($http) -> - $http.get('/greeting').success (data) => - @greeting = data \ No newline at end of file + constructor: (@Messages) -> + @refresh() + + refresh: -> + @Messages.list().success (data) => + @messages = data + + create: (message) -> + @Messages.create(message).success => + @refresh() diff --git a/app/env.html b/app/env.html deleted file mode 100644 index 0c8652d..0000000 --- a/app/env.html +++ /dev/null @@ -1,11 +0,0 @@ ---- -layout: main -title: Environment Variables ---- - -
- [[#each variables]] -
[[@key]]
-
[[.]]
- [[/each]] -
\ No newline at end of file diff --git a/app/index.html b/app/index.html index dda01c4..11dd87e 100644 --- a/app/index.html +++ b/app/index.html @@ -4,19 +4,24 @@ ng-app: demo --- -
-

{{index.greeting}}

+[[>jumbotron]] - +
+

Messages stored on Google Data Store:

-

Brought to you by Google App Engine.

- -
+ +
+
+ +
+ +
+ \ No newline at end of file diff --git a/app/request.html b/app/request.html deleted file mode 100644 index 3f5645e..0000000 --- a/app/request.html +++ /dev/null @@ -1,11 +0,0 @@ ---- -layout: main -title: Request ---- - -
- [[#each headers]] -
[[@key]]
-
[[.]]
- [[/each]] -
diff --git a/app/style.less b/app/style.less index e1f8ebf..c2a9b04 100644 --- a/app/style.less +++ b/app/style.less @@ -2,8 +2,15 @@ display: none !important; } -.container { - h1 { - margin-top: 50px; +.navbar { + margin-bottom: 0; + + .navbar-brand { + padding-top: 5px; + + img { + width: 40px; + height: 40px; + } } -} \ No newline at end of file +} diff --git a/index.yaml b/index.yaml new file mode 100644 index 0000000..0cdde05 --- /dev/null +++ b/index.yaml @@ -0,0 +1,17 @@ +indexes: + +# AUTOGENERATED + +# This index.yaml is automatically updated whenever the dev_appserver +# detects that a new type of query is run. If you want to manage the +# index.yaml file manually, remove the above marker line (the line +# saying "# AUTOGENERATED"). If you want to manage some indexes +# manually, move them above the marker line. The index.yaml file is +# automatically uploaded to the admin console when you next deploy +# your application using appcfg.py. + +- kind: Message + ancestor: yes + properties: + - name: date + direction: desc diff --git a/pom.xml b/pom.xml index 6c34bd2..40a3511 100644 --- a/pom.xml +++ b/pom.xml @@ -45,7 +45,7 @@ true dependency - MainWeb + gageot.net.MainWeb @@ -59,6 +59,11 @@ fluent-http-appengine-adapter 2.31 + + net.code-story + fluent + 1.1 + diff --git a/src/main/java/MainWeb.java b/src/main/java/MainWeb.java deleted file mode 100644 index 48fc68a..0000000 --- a/src/main/java/MainWeb.java +++ /dev/null @@ -1,42 +0,0 @@ -import com.google.appengine.api.datastore.*; -import net.codestory.http.Configuration; -import net.codestory.http.WebServer; -import net.codestory.http.annotations.Get; -import net.codestory.http.appengine.AppEngineFilter; -import net.codestory.http.routes.Routes; -import net.codestory.http.templating.Model; -import net.codestory.http.templating.ModelAndView; - -import static com.google.appengine.api.datastore.KeyFactory.createKey; - -public class MainWeb { - public static void main(String[] args) { - new WebServer().configure(WebConfiguration.class).start(); - } - - public static class WebConfiguration implements Configuration { - @Override - public void configure(Routes routes) { - routes - .filter(AppEngineFilter.class) - .get("/greeting", "Welcome to fluent-http") - .add("/api", CloudStorageTestResource.class) - .get("/env", Model.of("variables", System.getenv())) - .get("/request", context -> Model.of("headers", context.request().headers())); - } - } - - public static class CloudStorageTestResource { - @Get("/add/:name") - public ModelAndView add(String name) throws EntityNotFoundException { - DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(); - - Key key = createKey("Entries", name); - Entity entity = new Entity("Test", key); - entity.setProperty("content", "Hello World"); - datastore.put(entity); - - return ModelAndView.of("add", "entry", entity); - } - } -} diff --git a/src/main/java/gageot/net/MainWeb.java b/src/main/java/gageot/net/MainWeb.java new file mode 100644 index 0000000..cf36b0d --- /dev/null +++ b/src/main/java/gageot/net/MainWeb.java @@ -0,0 +1,36 @@ +/** + * Copyright (C) 2014 david@gageot.net + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ +package gageot.net; + +import net.codestory.http.Configuration; +import net.codestory.http.WebServer; +import net.codestory.http.appengine.AppEngineFilter; +import net.codestory.http.routes.Routes; + +public class MainWeb { + public static void main(String[] args) { + new WebServer().configure(WebConfiguration.class).start(); + } + + public static class WebConfiguration implements Configuration { + @Override + public void configure(Routes routes) { + routes + .filter(AppEngineFilter.class) + .add(MessagesResource.class); + } + } +} diff --git a/src/main/java/gageot/net/MessagesResource.java b/src/main/java/gageot/net/MessagesResource.java new file mode 100644 index 0000000..8f7ecfb --- /dev/null +++ b/src/main/java/gageot/net/MessagesResource.java @@ -0,0 +1,50 @@ +/** + * Copyright (C) 2014 david@gageot.net + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ +package gageot.net; + +import com.google.appengine.api.datastore.Entity; +import com.google.appengine.api.datastore.Query; +import net.codestory.http.annotations.Get; +import net.codestory.http.annotations.Post; + +import java.util.Date; +import java.util.List; + +import static com.google.appengine.api.datastore.DatastoreServiceFactory.getDatastoreService; +import static com.google.appengine.api.datastore.FetchOptions.Builder.withLimit; +import static com.google.appengine.api.datastore.KeyFactory.createKey; +import static com.google.appengine.api.datastore.Query.SortDirection.DESCENDING; +import static net.codestory.Fluent.of; + +public class MessagesResource { + @Get("/message/list") + public List list() { + Query query = new Query("Message", createKey("Messages", "list")).addSort("date", DESCENDING); + + List messages = getDatastoreService().prepare(query).asList(withLimit(100)); + + return of(messages).map(message -> (String) message.getProperty("message")).toList(); + } + + @Post("/message") + public void create(String message) { + Entity entity = new Entity("Message", createKey("Messages", "list")); + entity.setProperty("message", message); + entity.setProperty("date", new Date()); + + getDatastoreService().put(entity); + } +} diff --git a/src/test/java/MainWebTest.java b/src/test/java/MainWebTest.java deleted file mode 100644 index 6ae96ce..0000000 --- a/src/test/java/MainWebTest.java +++ /dev/null @@ -1,21 +0,0 @@ -import net.codestory.http.WebServer; -import net.codestory.simplelenium.SeleniumTest; -import org.junit.Test; - -public class MainWebTest extends SeleniumTest { - WebServer webServer = new WebServer().configure(MainWeb.WebConfiguration.class).startOnRandomPort(); - - @Override - protected String getDefaultBaseUrl() { - return "http://localhost:" + webServer.port(); - } - - @Test - public void index() { - goTo("/"); - - find("h1").should().contain("Hello World!"); - find("h3").should().contain("Welcome to fluent-http"); - find("p").should().contain("Brought to you by Google App Engine."); - } -} \ No newline at end of file diff --git a/src/test/java/gageot/net/MainWebTest.java b/src/test/java/gageot/net/MainWebTest.java new file mode 100644 index 0000000..1a29a83 --- /dev/null +++ b/src/test/java/gageot/net/MainWebTest.java @@ -0,0 +1,36 @@ +/** + * Copyright (C) 2014 david@gageot.net + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ +package gageot.net; + +import net.codestory.http.WebServer; +import net.codestory.simplelenium.SeleniumTest; +import org.junit.Test; + +public class MainWebTest extends SeleniumTest { + WebServer webServer = new WebServer().configure(MainWeb.WebConfiguration.class).startOnRandomPort(); + + @Override + protected String getDefaultBaseUrl() { + return "http://localhost:" + webServer.port(); + } + + @Test + public void index() { + goTo("/"); + + find("h2").should().contain("Managed VMs Sample Project"); + } +} \ No newline at end of file