-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.tt
56 lines (44 loc) · 1.55 KB
/
server.tt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
use 'module:undertow/http' with
'java:io.undertow' stand-alone
'java:io.undertow.server' stand-alone
'java:io.undertow.util' stand-alone
provided
//include 'rps'
include 'rpsts'
include 'json'
data value <>
def rpsService: $GameService;
templates convertRpsResult
when <´´ =''> do {statusCode: 404} !
when <´´ '.*'> do {statusCode: 400, body: $} !
otherwise
{body: $ -> serialize,
headers:[{header:'Content-Type', value:'application/json'}]} !
end convertRpsResult
composer toInt
<INT>
end toInt
processor CreateGameHandler
templates handleRequest
$.body -> parse -> rpsService::createGame -> convertRpsResult !
end handleRequest
end CreateGameHandler
processor GetGameStatusHandler
templates handleRequest
def id: $.parameters... -> \(<{key: <='id'>}> $.value(1) !\) -> toInt;
$rpsService::getStatus&{id: $id} -> convertRpsResult !
end handleRequest
end GetGameStatusHandler
processor UpdateGameHandler
templates handleRequest
def id: $.parameters... -> \(<{key: <='id'>}> $.value(1) !\) -> toInt;
$.body -> parse -> rpsService::updateGame&{id: $id} -> convertRpsResult !
end handleRequest
end UpdateGameHandler
data uri-pattern <'(\/(\w+|\{\w+\}))+'>,
routing <{post: <uri-pattern>, handler: <>}|{get: <uri-pattern>, handler: <handler>}>
def config: [{post: uri-pattern´'/games', handler: $CreateGameHandler},
{get: uri-pattern´'/games/{id}', handler: $GetGameStatusHandler},
{post: uri-pattern´'/games/{id}', handler: $UpdateGameHandler}
];
$config -> !http/startServer&{port: 8080, name: 'localhost'}