Skip to content

Commit f2c8326

Browse files
author
Michael Wunderlich
committed
Angular frontend
1 parent 428cccf commit f2c8326

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+853
-62
lines changed

.ebextensions/dynamodb-tables.config

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ Resources:
55
TableName: scorekeep-user
66
KeySchema:
77
HashKeyElement: {AttributeName: id, AttributeType: S}
8-
ProvisionedThroughput: {ReadCapacityUnits: 5, WriteCapacityUnits: 5}
8+
ProvisionedThroughput: {ReadCapacityUnits: 2, WriteCapacityUnits: 2}
99
SessionTable:
1010
Type: AWS::DynamoDB::Table
1111
Properties:
1212
TableName: scorekeep-session
1313
KeySchema:
1414
HashKeyElement: {AttributeName: id, AttributeType: S}
15-
ProvisionedThroughput: {ReadCapacityUnits: 5, WriteCapacityUnits: 5}
15+
ProvisionedThroughput: {ReadCapacityUnits: 2, WriteCapacityUnits: 2}
1616
GameTable:
1717
Type: AWS::DynamoDB::Table
1818
Properties:
@@ -30,9 +30,9 @@ Resources:
3030
KeySchema:
3131
- AttributeName: "session"
3232
KeyType: "HASH"
33-
ProvisionedThroughput: {ReadCapacityUnits: 5, WriteCapacityUnits: 5}
33+
ProvisionedThroughput: {ReadCapacityUnits: 2, WriteCapacityUnits: 2}
3434
Projection: { ProjectionType: ALL }
35-
ProvisionedThroughput: {ReadCapacityUnits: 5, WriteCapacityUnits: 5}
35+
ProvisionedThroughput: {ReadCapacityUnits: 2, WriteCapacityUnits: 2}
3636
MoveTable:
3737
Type: AWS::DynamoDB::Table
3838
Properties:
@@ -50,9 +50,9 @@ Resources:
5050
KeySchema:
5151
- AttributeName: "game"
5252
KeyType: "HASH"
53-
ProvisionedThroughput: {ReadCapacityUnits: 5, WriteCapacityUnits: 5}
53+
ProvisionedThroughput: {ReadCapacityUnits: 2, WriteCapacityUnits: 2}
5454
Projection: { ProjectionType: ALL }
55-
ProvisionedThroughput: {ReadCapacityUnits: 5, WriteCapacityUnits: 5}
55+
ProvisionedThroughput: {ReadCapacityUnits: 2, WriteCapacityUnits: 2}
5656
StateTable:
5757
Type: AWS::DynamoDB::Table
5858
Properties:
@@ -70,7 +70,6 @@ Resources:
7070
KeySchema:
7171
- AttributeName: "game"
7272
KeyType: "HASH"
73-
ProvisionedThroughput: {ReadCapacityUnits: 5, WriteCapacityUnits: 5}
73+
ProvisionedThroughput: {ReadCapacityUnits: 2, WriteCapacityUnits: 2}
7474
Projection: { ProjectionType: ALL }
75-
ProvisionedThroughput: {ReadCapacityUnits: 5, WriteCapacityUnits: 5}
76-
75+
ProvisionedThroughput: {ReadCapacityUnits: 2, WriteCapacityUnits: 2}

.ebextensions/nginx/nginx.conf

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
user nginx;
2+
error_log /var/log/nginx/error.log warn;
3+
pid /var/run/nginx.pid;
4+
worker_processes auto;
5+
worker_rlimit_nofile 33282;
6+
7+
events {
8+
worker_connections 1024;
9+
}
10+
11+
http {
12+
include /etc/nginx/mime.types;
13+
default_type application/octet-stream;
14+
15+
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
16+
'$status $body_bytes_sent "$http_referer" '
17+
'"$http_user_agent" "$http_x_forwarded_for"';
18+
19+
include conf.d/*.conf;
20+
21+
map $http_upgrade $connection_upgrade {
22+
default "upgrade";
23+
}
24+
25+
server {
26+
listen 80 default_server;
27+
root /var/app/current/public;
28+
29+
location / {
30+
}
31+
32+
location /api {
33+
proxy_pass http://127.0.0.1:5000;
34+
proxy_http_version 1.1;
35+
36+
proxy_set_header Connection $connection_upgrade;
37+
proxy_set_header Upgrade $http_upgrade;
38+
proxy_set_header Host $host;
39+
proxy_set_header X-Real-IP $remote_addr;
40+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
41+
}
42+
43+
access_log /var/log/nginx/access.log main;
44+
45+
client_header_timeout 60;
46+
client_body_timeout 60;
47+
keepalive_timeout 60;
48+
gzip off;
49+
gzip_comp_level 4;
50+
51+
# Include the Elastic Beanstalk generated locations
52+
include conf.d/elasticbeanstalk/01_static.conf;
53+
include conf.d/elasticbeanstalk/healthd.conf;
54+
}
55+
}

Procfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
web: java -Dserver.port=5000 -jar build/libs/scorekeep-api-0.1.0.jar
1+
web: java -Dserver.port=5000 -jar build/libs/scorekeep-api-1.0.0.jar

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1+
Scorekeep is a RESTFul web API in Java that uses Spring that provides an HTTP interface for create and managing game sessions and users.
12

23
# Running the application on Elastic Beanstalk
34

45
## Create environment
56
Create a Java 8 SE environment in Elastic Beanstalk
7+
68
## Permissions
79
Add DynamoDB permissions to your instance profile (aws-elasticbeanstalk-ec2-role): [IAM console](https://console.aws.amazon.com/iam/home#roles)
10+
811
## Configure
9-
Set API endpoint in public/app/scorekeep.js
12+
Set API endpoint in public/app/scorekeep.js and bin/test-api.sh.
13+
1014
## Deploy
1115
Deploy the application to your environment.
1216

@@ -16,4 +20,4 @@ Deploy the application to your environment.
1620
## Spring CLI
1721
## CORS
1822

19-
# Running on separate servers
23+
# Running on separate servers

app.groovy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@Controller class JsApp { }

bin/test-api.sh

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
API=.us-east-1.elasticbeanstalk.com
2+
API=XXXXX.elasticbeanstalk.com/api
33

44
# for (( c=1; c<=5; c++ ))
55
for (( ; ; ))

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ apply plugin: 'io.spring.dependency-management'
1616

1717
jar {
1818
baseName = 'scorekeep-api'
19-
version = '0.1.0'
19+
version = '1.0.0'
2020
}
2121

2222
repositories {

public/app/gameCollection.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
var module = angular.module('scorekeep');
2+
module.service('GameCollection', function($http, GameService, api) {
3+
var collection = {};
4+
5+
collection.createGame = function(sessionid, gamename, gamerules) {
6+
var game = new GameService();
7+
return game.$save( { sessionid: sessionid })
8+
.then( function() {
9+
game.session = sessionid;
10+
game.name = gamename;
11+
game.rules = gamerules;
12+
return game.$update({ sessionid: sessionid, id: game.id }, function() {
13+
return angular.copy(game);
14+
})
15+
})
16+
}
17+
18+
collection.setField = function(sessionid, gameid, fieldname, value) {
19+
return $http.put( api + 'game/' + sessionid + '/' + gameid + '/' + fieldname + '/' + value);
20+
}
21+
22+
collection.setUsers = function(sessionid, gameid, users){
23+
return $http.post( api + 'game/' + sessionid + '/' + gameid + '/users', users)
24+
}
25+
26+
collection.deleteGame = function(sessionid, gameid) {
27+
return $http.delete( api + 'game/' + sessionid + '/' + gameid);
28+
}
29+
30+
collection.move = function(sessionid, gameid, userid, move) {
31+
return $http.post( api + 'move/' + sessionid + '/' + gameid + '/' + userid, move)
32+
}
33+
return collection;
34+
})

public/app/gameController.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
var module = angular.module('scorekeep');
2+
module.controller('GameController', Game);
3+
function Game($scope, $http, $routeParams, SessionService, UserService, GameService, GameCollection, RulesService, StateService, api) {
4+
$scope.game = new GameService;
5+
$scope.state = new StateService; // game state object
6+
$scope.gamestate = []; // game state as Array
7+
8+
$scope.playgame = function(){
9+
GetGame = $scope.game.$get({ sessionid: $routeParams.sessionid, id: $routeParams.gameid });
10+
GetState = GetGame.then(function(){
11+
currentstate = $scope.game.states[$scope.game.states.length-1];
12+
return $scope.state.$get({ sessionid: $routeParams.sessionid, gameid: $routeParams.gameid, id: currentstate});
13+
})
14+
GetState.then(function(result){
15+
console.log(result);
16+
$scope.gamestate = $scope.state.state.split('');
17+
console.log("state string: '" + $scope.state.state + "'");
18+
console.log("state array: " + $scope.gamestate);
19+
});
20+
}
21+
$scope.playgame();
22+
23+
$scope.move = function(cellid){
24+
console.log("MOVE on cell " + cellid);
25+
$scope.gamestate = $scope.state.state.split('');
26+
console.log("state id: " + $scope.state.id);
27+
console.log("state string: '" + $scope.state.state + "'");
28+
move = ""
29+
if ( $scope.gamestate[cellid] != " " ) {
30+
return;
31+
}
32+
if ($scope.gamestate[0] == "X") {
33+
$scope.gamestate[cellid] = "X";
34+
$scope.gamestate[0] = "O";
35+
move = "X" + cellid;
36+
console.log(move);
37+
} else {
38+
$scope.gamestate[cellid] = "O";
39+
$scope.gamestate[0] = "X";
40+
move = "O" + cellid;
41+
console.log(move);
42+
}
43+
console.log("new state string: '" + $scope.gamestate.join('') + "'");
44+
PostMove = $http.post(api + 'move/' + $routeParams.sessionid + "/" + $routeParams.gameid + "/" + $routeParams.userid, move);
45+
GetGame = PostMove.then(function(){
46+
return $scope.game.$get({ sessionid: $routeParams.sessionid, id: $routeParams.gameid });
47+
})
48+
GetState = GetGame.then(function(GetGameResult){
49+
stateid = $scope.game.states[$scope.game.states.length-1];
50+
return $scope.state.$get({ sessionid: $routeParams.sessionid, gameid: $routeParams.gameid, id: stateid});
51+
});
52+
GetState.then(function(){
53+
$scope.gamestate = $scope.state.state.split('');
54+
});
55+
}
56+
}

public/app/gamesController.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
var module = angular.module('scorekeep');
2+
module.controller('GamesController', Games);
3+
function Games($scope, $http, $routeParams, SessionService, UserService, GameService, api) {
4+
$scope.games = GameService.query({ sessionid: $routeParams.sessionid });
5+
$scope.session = SessionService.get({ id: $routeParams.sessionid });
6+
$scope.gamename = "my game";
7+
8+
$scope.createGame = function () {
9+
var game = new GameService();
10+
game.$save( { sessionid: $routeParams.sessionid }, function() {
11+
game.session = $routeParams.sessionid;
12+
game.name = $scope.gamename;
13+
game.$update({ sessionid: $routeParams.sessionid, id: game.id }, function() {
14+
$scope.games.push(angular.copy(game));
15+
})
16+
}
17+
)};
18+
$scope.deleteGame = function (index) {
19+
var gameId = $scope.games[index].id;
20+
$http.delete( api + 'game/' + $routeParams.sessionid + "/" + gameId);
21+
$scope.games.splice(index, 1);
22+
};
23+
}

0 commit comments

Comments
 (0)