Skip to content

Commit

Permalink
Better demonstration of DataStore
Browse files Browse the repository at this point in the history
  • Loading branch information
dgageot committed Nov 28, 2014
1 parent 45ae281 commit 68784b5
Show file tree
Hide file tree
Showing 17 changed files with 226 additions and 119 deletions.
13 changes: 13 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Copyright (C) 2014 [email protected]

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
13 changes: 13 additions & 0 deletions app/_includes/jumbotron.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<div class="jumbotron">
<div class="container">
<h2>Managed VMs Sample Project</h2>

<p>Powered by Fluent-http.</p>

<p>
<a class="btn btn-primary btn-lg" href="https://github.com/CodeStory/fluent-http" role="button">
Learn more
</a>
</p>
</div>
</div>
11 changes: 11 additions & 0 deletions app/_includes/navbar.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<nav class="navbar navbar-default" role="navigation">
<div class="container-fluid">
<div class="navbar-header">

<a class="navbar-brand" href="#">
<img alt="Brand" src="/assets/appengine.png">
</a>
<p class="navbar-text">App Engine</p>
</div>
</div>
</nav>
11 changes: 2 additions & 9 deletions app/_layouts/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,5 @@
styles: ['/webjars/bootstrap/3.3.1/css/bootstrap.min.css', '/style.css']
---

<div class="container">
<div class="row">
<div class="col-md12">
<h1>[[title]]</h1>

[[body]]
</div>
</div>
</div>
[[>navbar]]
[[body]]
7 changes: 0 additions & 7 deletions app/add.html

This file was deleted.

19 changes: 16 additions & 3 deletions app/demo.coffee
Original file line number Diff line number Diff line change
@@ -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
constructor: (@Messages) ->
@refresh()

refresh: ->
@Messages.list().success (data) =>
@messages = data

create: (message) ->
@Messages.create(message).success =>
@refresh()
11 changes: 0 additions & 11 deletions app/env.html

This file was deleted.

25 changes: 15 additions & 10 deletions app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,24 @@
ng-app: demo
---

<section ng-controller="IndexController as index">
<h3 ng-cloak>{{index.greeting}}</h3>
[[>jumbotron]]

<img src="/assets/appengine.png"/>
<div class="container-fluid" ng-controller="IndexController as index">
<h3>Messages stored on Google Data Store:</h3>

<p>Brought to you by Google App Engine.</p>

<ul>
<li><a href="/env">Show environment variables</a></li>
<li><a href="/request">Show request parameters</a></li>
<li><a href="/api/add/test">Insert entity in cloud storage</a></li>
<ul ng-cloak>
<li ng-repeat="message in index.messages track by $index">
<a href="/api/add/test">{{message}}</a>
</li>
</ul>
</section>

<form class="form-inline" role="form">
<div class="form-group">
<input type="text" ng-model="message" class="form-control" id="message" placeholder="Enter a new message">
</div>
<button type="submit" class="btn btn-default" ng-click="index.create(message)">Add</button>
</form>
</div>

<script src="/webjars/angularjs/1.3.3/angular.min.js"></script>
<script src="/demo.js"></script>
11 changes: 0 additions & 11 deletions app/request.html

This file was deleted.

15 changes: 11 additions & 4 deletions app/style.less
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
}
17 changes: 17 additions & 0 deletions index.yaml
Original file line number Diff line number Diff line change
@@ -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
7 changes: 6 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>dependency</classpathPrefix>
<mainClass>MainWeb</mainClass>
<mainClass>gageot.net.MainWeb</mainClass>
</manifest>
</archive>
</configuration>
Expand All @@ -59,6 +59,11 @@
<artifactId>fluent-http-appengine-adapter</artifactId>
<version>2.31</version>
</dependency>
<dependency>
<groupId>net.code-story</groupId>
<artifactId>fluent</artifactId>
<version>1.1</version>
</dependency>

<!-- WebJars -->
<dependency>
Expand Down
42 changes: 0 additions & 42 deletions src/main/java/MainWeb.java

This file was deleted.

36 changes: 36 additions & 0 deletions src/main/java/gageot/net/MainWeb.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* Copyright (C) 2014 [email protected]
*
* 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);
}
}
}
50 changes: 50 additions & 0 deletions src/main/java/gageot/net/MessagesResource.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* Copyright (C) 2014 [email protected]
*
* 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<String> list() {
Query query = new Query("Message", createKey("Messages", "list")).addSort("date", DESCENDING);

List<Entity> 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);
}
}
21 changes: 0 additions & 21 deletions src/test/java/MainWebTest.java

This file was deleted.

Loading

0 comments on commit 68784b5

Please sign in to comment.