├── .gitignore ├── .idea ├── .name ├── compiler.xml ├── copyright │ ├── Apache_Software_License__Version_2_0.xml │ └── profiles_settings.xml ├── dictionaries │ └── bhale.xml ├── encodings.xml ├── misc.xml ├── modules.xml ├── runConfigurations │ └── Application.xml ├── scopes │ └── scope_settings.xml └── vcs.xml ├── Gemfile ├── Gemfile.lock ├── Paw.paw ├── creating-restful-hypermedia-based-micro-services-with-spring-boot.key ├── Data │ ├── 230ss__235ssB-863.jpg │ ├── 230ss__235ssB-small-864.jpg │ ├── C60_RACING_THBI-882.jpg │ ├── C60_RACING_THBI-small-883.jpg │ ├── Photo 20-07-2010 16 28 10-858.jpg │ ├── Photo 20-07-2010 16 28 10-small-859.jpg │ ├── PresetImageFill0-1.jpg │ ├── PresetImageFill1-2.jpg │ ├── PresetImageFill2-3.jpg │ ├── PresetImageFill3-4.jpg │ ├── PresetImageFill4-5.jpg │ ├── PresetImageFill5-6.jpg │ ├── image1-8.png │ ├── image1-small-9.png │ ├── image2-11.png │ ├── image3-12.png │ ├── image3-small-13.png │ ├── image4-14.png │ ├── mt0@2x-410.jpg │ ├── mt10@2x-429.jpg │ ├── mt1@2x-412.jpg │ ├── mt2@2x-438.jpg │ ├── mt3@2x-444.jpg │ ├── mt4@2x-445.jpg │ ├── mt5@2x-446.jpg │ ├── mt6@2x-425.jpg │ ├── mt7@2x-426.jpg │ ├── mt8@2x-427.jpg │ ├── mt9@2x-428.jpg │ ├── st0-411.jpg │ ├── st1-721.jpg │ ├── st11-1137.jpg │ ├── st12-1246.jpg │ ├── st13-1251.jpg │ ├── st14-1274.jpg │ ├── st15-1287.jpg │ ├── st16-1294.jpg │ ├── st17-1490.jpg │ ├── st18-1346.jpg │ ├── st19-1396.jpg │ ├── st2-755.jpg │ ├── st20-1442.jpg │ ├── st21-1485.jpg │ ├── st22-1488.jpg │ ├── st23-1525.jpg │ ├── st24-1565.jpg │ ├── st25-1663.jpg │ ├── st26-1665.jpg │ ├── st27-1698.jpg │ ├── st28-1701.jpg │ ├── st29-1727.jpg │ ├── st3-645.jpg │ ├── st3-788.jpg │ ├── st4-853.jpg │ ├── st5-1079.jpg │ ├── st5-905.jpg │ ├── st6-1100.jpg │ ├── st6-999.jpg │ ├── st7-1093.jpg │ └── st8-1116.jpg ├── Index.zip ├── Metadata │ ├── BuildVersionHistory.plist │ ├── DocumentIdentifier │ └── Properties.plist ├── preview-micro.jpg ├── preview-web.jpg └── preview.jpg ├── creating-restful-hypermedia-based-micro-services-with-spring-boot.pdf ├── lets-make-a-deal.rb ├── manifest.yml ├── micro-service.iml ├── pom.xml └── src └── main ├── java └── com │ └── nebhale │ └── springone2014 │ ├── Application.java │ ├── model │ ├── Door.java │ ├── DoorContent.java │ ├── DoorDoesNotExistException.java │ ├── DoorStatus.java │ ├── Game.java │ ├── GameStatus.java │ └── IllegalTransitionException.java │ ├── repository │ ├── GameDoesNotExistException.java │ ├── GameRepository.java │ └── InMemoryGameRepository.java │ └── web │ ├── DoorsResourceAssembler.java │ ├── GameResourceAssembler.java │ └── GamesController.java └── resources └── logback.xml /.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | .idea/libraries 3 | .idea/tasks.xml 4 | .idea/workspace.xml 5 | -------------------------------------------------------------------------------- /.idea/.name: -------------------------------------------------------------------------------- 1 | micro-service -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /.idea/copyright/Apache_Software_License__Version_2_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 9 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/dictionaries/bhale.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | hateoas 5 | springone 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 38 | 39 | 40 | 51 | 52 | 53 | 66 | 67 | 68 | 69 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 94 | 95 | 97 | 98 | localhost 99 | 5050 100 | 101 | 102 | 103 | 104 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/runConfigurations/Application.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 8 | 9 | 24 | -------------------------------------------------------------------------------- /.idea/scopes/scope_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | # Cloud Foundry Java Buildpack 2 | # Copyright (c) 2013 the original author or authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | source 'https://rubygems.org' 17 | 18 | gem 'highline' 19 | gem 'json' 20 | gem 'rest-client' 21 | -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | GEM 2 | remote: https://rubygems.org/ 3 | specs: 4 | highline (1.6.21) 5 | json (1.8.1) 6 | mime-types (1.25.1) 7 | rdoc (4.1.0) 8 | rest-client (1.6.8.rc1) 9 | mime-types (~> 1.16) 10 | rdoc (>= 2.4.2) 11 | 12 | PLATFORMS 13 | ruby 14 | 15 | DEPENDENCIES 16 | highline 17 | json 18 | rest-client 19 | -------------------------------------------------------------------------------- /Paw.paw: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 134481920 7 | 14C41AB4-612B-4E14-9E61-237FB6C9D655 8 | 147 9 | 10 | 11 | 12 | NSPersistenceFrameworkVersion 13 | 481 14 | NSStoreModelVersionHashes 15 | 16 | LMEnvironment 17 | 18 | wh7gaVcwAwVVkE9Tw+70wsMIMdQ+Jo4SBtig40m91Yw= 19 | 20 | LMEnvironmentVariable 21 | 22 | hHCdQevDLYfrdM0/QNEGiWSHhmNvoh+4vxxg/A3QXMw= 23 | 24 | LMEnvironmentVariableValue 25 | 26 | my5hNPJ51oDCSa8EgdNxWAnRcDLcERUGjtuXnzhSxQ0= 27 | 28 | LMKeyValue 29 | 30 | bIXXbyYF2xAv2MXg8JTVFsslmMKuvsfnR86QdUcFkdM= 31 | 32 | LMRequest 33 | 34 | N69H9XINxPl0wW8fuBadsvokjnyj4GqLD2bPiCXvgM8= 35 | 36 | LMRequestGroup 37 | 38 | ptyuN+dtvB4llhGC64PJYI5PwHlE6qpl6SwAWX91nCk= 39 | 40 | LMRequestTreeItem 41 | 42 | ak+hYb/lDeG55U0kgGvU5ej7HUltUj0RTrX5z/izNrs= 43 | 44 | 45 | NSStoreModelVersionHashesVersion 46 | 3 47 | NSStoreModelVersionIdentifiers 48 | 49 | LMDocumentVersion2 50 | 51 | 52 | 53 | 54 | 55 | 56 | 60CFF76A-6002-4F4A-A732-5EE51FF77B27 57 | http://localhost:8080/games/0/doors 58 | 30 59 | 0 60 | 0 61 | GET 62 | 0 63 | 3 64 | Display Doors 65 | 66 | 67 | 68 | 69 | 70 | Local 71 | 72 | 73 | 74 | 75 | 1 76 | 77 | 1 78 | 79 | 80 | 81 | 82 | 83 | 84 | application/json 85 | 0 86 | Content-Type 87 | 1 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 0 96 | 97 | 1 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 0 106 | 107 | 1 108 | 109 | 110 | 111 | 112 | 113 | 114 | ["{\\n \\"status\\": \\"selected\\"\\n}"] 115 | 184C6840-ED51-4404-87A4-6ACE5CC4F7CF 116 | http://localhost:8080/games/0/doors/1 117 | 30 118 | 0 119 | 0 120 | PUT 121 | 0 122 | 0 123 | Select Door 1 124 | 125 | 126 | 127 | 128 | 129 | D3BB92F8-A2A4-4D19-99E8-7AB6804503AB 130 | http://localhost:8080/games/0 131 | 30 132 | 0 133 | 0 134 | GET 135 | 0 136 | 2 137 | Display Game 138 | 139 | 140 | 141 | 142 | 143 | 6ED1A329-EB00-4006-B3D0-7B6C4AA1E000 144 | http://localhost:8080/games 145 | 30 146 | 0 147 | 0 148 | POST 149 | 0 150 | 1 151 | Create Game 152 | 153 | 154 | 155 | 156 | 157 | 158 | 1 159 | 160 | 1 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 1 169 | 170 | 1 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 1 179 | 180 | 1 181 | 182 | 183 | 184 | 185 | 186 | 187 | application/json 188 | 0 189 | Content-Type 190 | 1 191 | 192 | 193 | 194 | 195 | 196 | 197 | 378211D5-A395-45BA-B47B-27DAB1127836 198 | http://localhost:8080/games/0/doors/2 199 | 30 200 | 0 201 | 0 202 | PUT 203 | 0 204 | ["{\\n \\"status\\": \\"selected\\"\\n}"] 205 | 1 206 | Select Door 2 207 | 208 | 209 | 210 | 211 | 212 | application/json 213 | 0 214 | Content-Type 215 | 1 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 1 224 | 225 | 1 226 | 227 | 228 | 229 | 230 | 231 | 232 | 8E0F320C-6B2B-408D-8D32-AFD0BA3B83A0 233 | http://localhost:8080/games/0/doors/2 234 | 30 235 | 0 236 | 0 237 | PUT 238 | 0 239 | ["{\\n \\"status\\": \\"opened\\"\\n}"] 240 | 1 241 | Open Door 2 242 | 243 | 244 | 245 | 246 | 247 | 248 | 1 249 | 250 | 1 251 | 252 | 253 | 254 | 255 | 256 | 257 | application/json 258 | 0 259 | Content-Type 260 | 1 261 | 262 | 263 | 264 | 265 | 266 | 267 | application/json 268 | 0 269 | Content-Type 270 | 1 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 1 279 | 280 | 1 281 | 282 | 283 | 284 | 285 | 286 | 287 | 2704B944-08EF-49C9-B634-7381EE91B002 288 | http://localhost:8080/games/0/doors/1 289 | 30 290 | 0 291 | 0 292 | PUT 293 | 0 294 | ["{\\n \\"status\\": \\"opened\\"\\n}"] 295 | 0 296 | Open Door 1 297 | 298 | 299 | 300 | 301 | 302 | 1C72BA12-0D0A-4E76-8FE8-413A8971B3B9 303 | http://localhost:8080/games/0/doors/3 304 | 30 305 | 0 306 | 0 307 | PUT 308 | 0 309 | ["{\\n \\"status\\": \\"selected\\"\\n}"] 310 | 2 311 | Select Door 3 312 | 313 | 314 | 315 | 316 | 317 | 6CC6E623-D62A-4561-98D4-C177246FC41B 318 | http://localhost:8080/games/0/doors/3 319 | 30 320 | 0 321 | 0 322 | PUT 323 | 0 324 | ["{\\n \\"status\\": \\"opened\\"\\n}"] 325 | 2 326 | Open Door 3 327 | 328 | 329 | 330 | 331 | 332 | application/json 333 | 0 334 | Content-Type 335 | 1 336 | 337 | 338 | 339 | 340 | 341 | 342 | 4 343 | Select Door 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 0 353 | 354 | 1 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 1 363 | 364 | 1 365 | 366 | 367 | 368 | 369 | 370 | 371 | 6 372 | Open Door 373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | CEC45D6E-31C9-481D-B6B4-5D9FEA82BAF7 381 | http://localhost:8080/games/0/doors 382 | 30 383 | 0 384 | 0 385 | GET 386 | 0 387 | 5 388 | Display Doors 389 | 390 | 391 | 392 | 393 | 394 | 395 | 0 396 | 397 | 1 398 | 399 | 400 | 401 | 402 | 403 | 404 | D379C6D6-21FF-42D6-ACB2-60319E070F8D 405 | http://localhost:8080/games/0 406 | 30 407 | 0 408 | 0 409 | GET 410 | 0 411 | 8 412 | Display Game 413 | 414 | 415 | 416 | 417 | 418 | BE50DCE8-6627-4291-82A0-B37FBCF0BCE0 419 | http://localhost:8080/games/0 420 | 30 421 | 0 422 | 0 423 | DELETE 424 | 0 425 | 9 426 | Cleanup Game 427 | 428 | 429 | 430 | 431 | 432 | 433 | 1 434 | 435 | 1 436 | 437 | 438 | 439 | 440 | 441 | 442 | 938903B7-2FB4-4F7D-A040-C310C02B31B0 443 | http://localhost:8080/games/0/doors 444 | 30 445 | 0 446 | 0 447 | GET 448 | 0 449 | 7 450 | Display Doors 451 | 452 | 453 | 454 | 455 | -------------------------------------------------------------------------------- /creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/230ss__235ssB-863.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebhale/spring-one-2014/d5f500805f0d554fc0dbd3e6c8f24ddd726ef24d/creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/230ss__235ssB-863.jpg -------------------------------------------------------------------------------- /creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/230ss__235ssB-small-864.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebhale/spring-one-2014/d5f500805f0d554fc0dbd3e6c8f24ddd726ef24d/creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/230ss__235ssB-small-864.jpg -------------------------------------------------------------------------------- /creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/C60_RACING_THBI-882.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebhale/spring-one-2014/d5f500805f0d554fc0dbd3e6c8f24ddd726ef24d/creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/C60_RACING_THBI-882.jpg -------------------------------------------------------------------------------- /creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/C60_RACING_THBI-small-883.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebhale/spring-one-2014/d5f500805f0d554fc0dbd3e6c8f24ddd726ef24d/creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/C60_RACING_THBI-small-883.jpg -------------------------------------------------------------------------------- /creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/Photo 20-07-2010 16 28 10-858.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebhale/spring-one-2014/d5f500805f0d554fc0dbd3e6c8f24ddd726ef24d/creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/Photo 20-07-2010 16 28 10-858.jpg -------------------------------------------------------------------------------- /creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/Photo 20-07-2010 16 28 10-small-859.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebhale/spring-one-2014/d5f500805f0d554fc0dbd3e6c8f24ddd726ef24d/creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/Photo 20-07-2010 16 28 10-small-859.jpg -------------------------------------------------------------------------------- /creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/PresetImageFill0-1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebhale/spring-one-2014/d5f500805f0d554fc0dbd3e6c8f24ddd726ef24d/creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/PresetImageFill0-1.jpg -------------------------------------------------------------------------------- /creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/PresetImageFill1-2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebhale/spring-one-2014/d5f500805f0d554fc0dbd3e6c8f24ddd726ef24d/creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/PresetImageFill1-2.jpg -------------------------------------------------------------------------------- /creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/PresetImageFill2-3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebhale/spring-one-2014/d5f500805f0d554fc0dbd3e6c8f24ddd726ef24d/creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/PresetImageFill2-3.jpg -------------------------------------------------------------------------------- /creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/PresetImageFill3-4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebhale/spring-one-2014/d5f500805f0d554fc0dbd3e6c8f24ddd726ef24d/creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/PresetImageFill3-4.jpg -------------------------------------------------------------------------------- /creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/PresetImageFill4-5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebhale/spring-one-2014/d5f500805f0d554fc0dbd3e6c8f24ddd726ef24d/creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/PresetImageFill4-5.jpg -------------------------------------------------------------------------------- /creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/PresetImageFill5-6.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebhale/spring-one-2014/d5f500805f0d554fc0dbd3e6c8f24ddd726ef24d/creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/PresetImageFill5-6.jpg -------------------------------------------------------------------------------- /creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/image1-8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebhale/spring-one-2014/d5f500805f0d554fc0dbd3e6c8f24ddd726ef24d/creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/image1-8.png -------------------------------------------------------------------------------- /creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/image1-small-9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebhale/spring-one-2014/d5f500805f0d554fc0dbd3e6c8f24ddd726ef24d/creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/image1-small-9.png -------------------------------------------------------------------------------- /creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/image2-11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebhale/spring-one-2014/d5f500805f0d554fc0dbd3e6c8f24ddd726ef24d/creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/image2-11.png -------------------------------------------------------------------------------- /creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/image3-12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebhale/spring-one-2014/d5f500805f0d554fc0dbd3e6c8f24ddd726ef24d/creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/image3-12.png -------------------------------------------------------------------------------- /creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/image3-small-13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebhale/spring-one-2014/d5f500805f0d554fc0dbd3e6c8f24ddd726ef24d/creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/image3-small-13.png -------------------------------------------------------------------------------- /creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/image4-14.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebhale/spring-one-2014/d5f500805f0d554fc0dbd3e6c8f24ddd726ef24d/creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/image4-14.png -------------------------------------------------------------------------------- /creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/mt0@2x-410.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebhale/spring-one-2014/d5f500805f0d554fc0dbd3e6c8f24ddd726ef24d/creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/mt0@2x-410.jpg -------------------------------------------------------------------------------- /creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/mt10@2x-429.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebhale/spring-one-2014/d5f500805f0d554fc0dbd3e6c8f24ddd726ef24d/creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/mt10@2x-429.jpg -------------------------------------------------------------------------------- /creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/mt1@2x-412.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebhale/spring-one-2014/d5f500805f0d554fc0dbd3e6c8f24ddd726ef24d/creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/mt1@2x-412.jpg -------------------------------------------------------------------------------- /creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/mt2@2x-438.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebhale/spring-one-2014/d5f500805f0d554fc0dbd3e6c8f24ddd726ef24d/creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/mt2@2x-438.jpg -------------------------------------------------------------------------------- /creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/mt3@2x-444.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebhale/spring-one-2014/d5f500805f0d554fc0dbd3e6c8f24ddd726ef24d/creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/mt3@2x-444.jpg -------------------------------------------------------------------------------- /creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/mt4@2x-445.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebhale/spring-one-2014/d5f500805f0d554fc0dbd3e6c8f24ddd726ef24d/creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/mt4@2x-445.jpg -------------------------------------------------------------------------------- /creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/mt5@2x-446.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebhale/spring-one-2014/d5f500805f0d554fc0dbd3e6c8f24ddd726ef24d/creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/mt5@2x-446.jpg -------------------------------------------------------------------------------- /creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/mt6@2x-425.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebhale/spring-one-2014/d5f500805f0d554fc0dbd3e6c8f24ddd726ef24d/creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/mt6@2x-425.jpg -------------------------------------------------------------------------------- /creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/mt7@2x-426.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebhale/spring-one-2014/d5f500805f0d554fc0dbd3e6c8f24ddd726ef24d/creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/mt7@2x-426.jpg -------------------------------------------------------------------------------- /creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/mt8@2x-427.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebhale/spring-one-2014/d5f500805f0d554fc0dbd3e6c8f24ddd726ef24d/creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/mt8@2x-427.jpg -------------------------------------------------------------------------------- /creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/mt9@2x-428.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebhale/spring-one-2014/d5f500805f0d554fc0dbd3e6c8f24ddd726ef24d/creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/mt9@2x-428.jpg -------------------------------------------------------------------------------- /creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/st0-411.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebhale/spring-one-2014/d5f500805f0d554fc0dbd3e6c8f24ddd726ef24d/creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/st0-411.jpg -------------------------------------------------------------------------------- /creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/st1-721.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebhale/spring-one-2014/d5f500805f0d554fc0dbd3e6c8f24ddd726ef24d/creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/st1-721.jpg -------------------------------------------------------------------------------- /creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/st11-1137.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebhale/spring-one-2014/d5f500805f0d554fc0dbd3e6c8f24ddd726ef24d/creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/st11-1137.jpg -------------------------------------------------------------------------------- /creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/st12-1246.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebhale/spring-one-2014/d5f500805f0d554fc0dbd3e6c8f24ddd726ef24d/creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/st12-1246.jpg -------------------------------------------------------------------------------- /creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/st13-1251.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebhale/spring-one-2014/d5f500805f0d554fc0dbd3e6c8f24ddd726ef24d/creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/st13-1251.jpg -------------------------------------------------------------------------------- /creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/st14-1274.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebhale/spring-one-2014/d5f500805f0d554fc0dbd3e6c8f24ddd726ef24d/creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/st14-1274.jpg -------------------------------------------------------------------------------- /creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/st15-1287.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebhale/spring-one-2014/d5f500805f0d554fc0dbd3e6c8f24ddd726ef24d/creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/st15-1287.jpg -------------------------------------------------------------------------------- /creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/st16-1294.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebhale/spring-one-2014/d5f500805f0d554fc0dbd3e6c8f24ddd726ef24d/creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/st16-1294.jpg -------------------------------------------------------------------------------- /creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/st17-1490.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebhale/spring-one-2014/d5f500805f0d554fc0dbd3e6c8f24ddd726ef24d/creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/st17-1490.jpg -------------------------------------------------------------------------------- /creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/st18-1346.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebhale/spring-one-2014/d5f500805f0d554fc0dbd3e6c8f24ddd726ef24d/creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/st18-1346.jpg -------------------------------------------------------------------------------- /creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/st19-1396.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebhale/spring-one-2014/d5f500805f0d554fc0dbd3e6c8f24ddd726ef24d/creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/st19-1396.jpg -------------------------------------------------------------------------------- /creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/st2-755.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebhale/spring-one-2014/d5f500805f0d554fc0dbd3e6c8f24ddd726ef24d/creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/st2-755.jpg -------------------------------------------------------------------------------- /creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/st20-1442.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebhale/spring-one-2014/d5f500805f0d554fc0dbd3e6c8f24ddd726ef24d/creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/st20-1442.jpg -------------------------------------------------------------------------------- /creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/st21-1485.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebhale/spring-one-2014/d5f500805f0d554fc0dbd3e6c8f24ddd726ef24d/creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/st21-1485.jpg -------------------------------------------------------------------------------- /creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/st22-1488.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebhale/spring-one-2014/d5f500805f0d554fc0dbd3e6c8f24ddd726ef24d/creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/st22-1488.jpg -------------------------------------------------------------------------------- /creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/st23-1525.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebhale/spring-one-2014/d5f500805f0d554fc0dbd3e6c8f24ddd726ef24d/creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/st23-1525.jpg -------------------------------------------------------------------------------- /creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/st24-1565.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebhale/spring-one-2014/d5f500805f0d554fc0dbd3e6c8f24ddd726ef24d/creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/st24-1565.jpg -------------------------------------------------------------------------------- /creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/st25-1663.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebhale/spring-one-2014/d5f500805f0d554fc0dbd3e6c8f24ddd726ef24d/creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/st25-1663.jpg -------------------------------------------------------------------------------- /creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/st26-1665.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebhale/spring-one-2014/d5f500805f0d554fc0dbd3e6c8f24ddd726ef24d/creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/st26-1665.jpg -------------------------------------------------------------------------------- /creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/st27-1698.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebhale/spring-one-2014/d5f500805f0d554fc0dbd3e6c8f24ddd726ef24d/creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/st27-1698.jpg -------------------------------------------------------------------------------- /creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/st28-1701.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebhale/spring-one-2014/d5f500805f0d554fc0dbd3e6c8f24ddd726ef24d/creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/st28-1701.jpg -------------------------------------------------------------------------------- /creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/st29-1727.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebhale/spring-one-2014/d5f500805f0d554fc0dbd3e6c8f24ddd726ef24d/creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/st29-1727.jpg -------------------------------------------------------------------------------- /creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/st3-645.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebhale/spring-one-2014/d5f500805f0d554fc0dbd3e6c8f24ddd726ef24d/creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/st3-645.jpg -------------------------------------------------------------------------------- /creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/st3-788.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebhale/spring-one-2014/d5f500805f0d554fc0dbd3e6c8f24ddd726ef24d/creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/st3-788.jpg -------------------------------------------------------------------------------- /creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/st4-853.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebhale/spring-one-2014/d5f500805f0d554fc0dbd3e6c8f24ddd726ef24d/creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/st4-853.jpg -------------------------------------------------------------------------------- /creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/st5-1079.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebhale/spring-one-2014/d5f500805f0d554fc0dbd3e6c8f24ddd726ef24d/creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/st5-1079.jpg -------------------------------------------------------------------------------- /creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/st5-905.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebhale/spring-one-2014/d5f500805f0d554fc0dbd3e6c8f24ddd726ef24d/creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/st5-905.jpg -------------------------------------------------------------------------------- /creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/st6-1100.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebhale/spring-one-2014/d5f500805f0d554fc0dbd3e6c8f24ddd726ef24d/creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/st6-1100.jpg -------------------------------------------------------------------------------- /creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/st6-999.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebhale/spring-one-2014/d5f500805f0d554fc0dbd3e6c8f24ddd726ef24d/creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/st6-999.jpg -------------------------------------------------------------------------------- /creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/st7-1093.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebhale/spring-one-2014/d5f500805f0d554fc0dbd3e6c8f24ddd726ef24d/creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/st7-1093.jpg -------------------------------------------------------------------------------- /creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/st8-1116.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebhale/spring-one-2014/d5f500805f0d554fc0dbd3e6c8f24ddd726ef24d/creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Data/st8-1116.jpg -------------------------------------------------------------------------------- /creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Index.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebhale/spring-one-2014/d5f500805f0d554fc0dbd3e6c8f24ddd726ef24d/creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Index.zip -------------------------------------------------------------------------------- /creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Metadata/BuildVersionHistory.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | pptx 6 | M6.2-1861-1 7 | M6.2.2-1878-1 8 | 9 | 10 | -------------------------------------------------------------------------------- /creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Metadata/DocumentIdentifier: -------------------------------------------------------------------------------- 1 | 147A23B9-8F05-4452-BF8D-80969AF36F0E -------------------------------------------------------------------------------- /creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Metadata/Properties.plist: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebhale/spring-one-2014/d5f500805f0d554fc0dbd3e6c8f24ddd726ef24d/creating-restful-hypermedia-based-micro-services-with-spring-boot.key/Metadata/Properties.plist -------------------------------------------------------------------------------- /creating-restful-hypermedia-based-micro-services-with-spring-boot.key/preview-micro.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebhale/spring-one-2014/d5f500805f0d554fc0dbd3e6c8f24ddd726ef24d/creating-restful-hypermedia-based-micro-services-with-spring-boot.key/preview-micro.jpg -------------------------------------------------------------------------------- /creating-restful-hypermedia-based-micro-services-with-spring-boot.key/preview-web.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebhale/spring-one-2014/d5f500805f0d554fc0dbd3e6c8f24ddd726ef24d/creating-restful-hypermedia-based-micro-services-with-spring-boot.key/preview-web.jpg -------------------------------------------------------------------------------- /creating-restful-hypermedia-based-micro-services-with-spring-boot.key/preview.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebhale/spring-one-2014/d5f500805f0d554fc0dbd3e6c8f24ddd726ef24d/creating-restful-hypermedia-based-micro-services-with-spring-boot.key/preview.jpg -------------------------------------------------------------------------------- /creating-restful-hypermedia-based-micro-services-with-spring-boot.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebhale/spring-one-2014/d5f500805f0d554fc0dbd3e6c8f24ddd726ef24d/creating-restful-hypermedia-based-micro-services-with-spring-boot.pdf -------------------------------------------------------------------------------- /lets-make-a-deal.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # Encoding: utf-8 3 | # Cloud Foundry Java Buildpack 4 | # Copyright (c) 2013 the original author or authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | 18 | require 'highline/import' 19 | require 'json' 20 | require 'rest_client' 21 | 22 | GAME_ROOT = 'http://localhost:8080/games' 23 | # GAME_ROOT = 'http://micro-service.cfapps.io/games' 24 | 25 | def get_link_location(source, rel) 26 | payload = (source.is_a? String) ? JSON.parse(RestClient.get(source)) : source 27 | 28 | location = nil 29 | payload['links'].each do |link| 30 | location = link['href'] if link['rel'] == rel 31 | next if location.nil? 32 | end 33 | 34 | location 35 | end 36 | 37 | def get_doors(location) 38 | doors = {} 39 | 40 | JSON.parse(RestClient.get(location))['content'].each do |door| 41 | doors[get_link_location(door, 'self')] = {'status' => door['status'], 'content' => door['content']} 42 | end 43 | 44 | doors 45 | end 46 | 47 | def print_current_state(game_location, doors) 48 | puts 49 | puts "Game Status: #{JSON.parse(RestClient.get(game_location))['status']}" 50 | 51 | index = -1 52 | doors.each_value { |door| puts "Door #{index += 1} Status: #{door['status']}/#{door['content']}" } 53 | end 54 | 55 | ######################################################################################################################## 56 | 57 | game_location = RestClient.post(GAME_ROOT, nil).headers[:location] 58 | doors_location = get_link_location game_location, 'doors' 59 | 60 | puts "Let's Make A Deal!" 61 | 62 | doors = get_doors doors_location 63 | print_current_state game_location, doors 64 | selection = ask('Select a door: ', Integer) { |q| q.in = 0..2 } 65 | RestClient.put doors.keys[selection], {'status' => 'SELECTED'}.to_json, {:content_type => 'application/json'} 66 | 67 | doors = get_doors doors_location 68 | print_current_state game_location, doors 69 | selection = ask('Open a door: ', Integer) { |q| q.in = 0..2 } 70 | RestClient.put doors.keys[selection], {'status' => 'OPENED'}.to_json, {:content_type => 'application/json'} 71 | 72 | doors = get_doors doors_location 73 | print_current_state game_location, doors 74 | 75 | RestClient.delete game_location 76 | -------------------------------------------------------------------------------- /manifest.yml: -------------------------------------------------------------------------------- 1 | --- 2 | applications: 3 | - name: micro-service 4 | memory: 512M 5 | instances: 1 6 | path: target/large-application-1-SNAPSHOT.jar 7 | buildpack: https://github.com/cloudfoundry/java-buildpack.git 8 | -------------------------------------------------------------------------------- /micro-service.iml: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 23 | 24 | 4.0.0 25 | 26 | 27 | org.springframework.boot 28 | spring-boot-starter-parent 29 | 1.1.6.RELEASE 30 | 31 | 32 | com.nebhale.springone2014 33 | micro-service 34 | 1-SNAPSHOT 35 | jar 36 | 37 | 38 | 1.8 39 | 40 | 41 | 42 | 43 | 44 | org.springframework.hateoas 45 | spring-hateoas 46 | 47 | 48 | org.springframework.boot 49 | spring-boot-starter-web 50 | 51 | 52 | 53 | 54 | 55 | 56 | org.springframework.boot 57 | spring-boot-maven-plugin 58 | 59 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /src/main/java/com/nebhale/springone2014/Application.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.nebhale.springone2014; 18 | 19 | import org.springframework.boot.SpringApplication; 20 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 21 | import org.springframework.context.annotation.ComponentScan; 22 | 23 | // TODO 1: Component scan, auto-configuration 24 | @ComponentScan 25 | @EnableAutoConfiguration 26 | public final class Application { 27 | 28 | // TODO 1: main() method 29 | public static void main(String[] args) { 30 | SpringApplication.run(Application.class, args); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/nebhale/springone2014/model/Door.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.nebhale.springone2014.model; 18 | 19 | import com.fasterxml.jackson.annotation.JsonIgnore; 20 | 21 | public final class Door { 22 | 23 | private final DoorContent content; 24 | 25 | private final Long id; 26 | 27 | private final Object monitor = new Object(); 28 | 29 | private volatile DoorStatus status = DoorStatus.CLOSED; 30 | 31 | public Door(Long id, DoorContent content) { 32 | this.id = id; 33 | this.content = content; 34 | } 35 | 36 | @JsonIgnore 37 | public Long getId() { 38 | return this.id; 39 | } 40 | 41 | public DoorContent getContent() { 42 | synchronized (this.monitor) { 43 | if (this.status == DoorStatus.OPENED) { 44 | return this.content; 45 | } 46 | return DoorContent.UNKNOWN; 47 | } 48 | } 49 | 50 | public DoorStatus getStatus() { 51 | synchronized (this.monitor) { 52 | return this.status; 53 | } 54 | } 55 | 56 | DoorContent peekContent() { 57 | return this.content; 58 | } 59 | 60 | void setStatus(DoorStatus status) { 61 | synchronized (this.monitor) { 62 | this.status = status; 63 | } 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/com/nebhale/springone2014/model/DoorContent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.nebhale.springone2014.model; 18 | 19 | public enum DoorContent { 20 | 21 | BICYCLE, 22 | SMALL_FURRY_ANIMAL, 23 | UNKNOWN 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/nebhale/springone2014/model/DoorDoesNotExistException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.nebhale.springone2014.model; 18 | 19 | import org.springframework.http.HttpStatus; 20 | import org.springframework.web.bind.annotation.ResponseStatus; 21 | 22 | @ResponseStatus(HttpStatus.NOT_FOUND) 23 | public final class DoorDoesNotExistException extends Exception { 24 | 25 | DoorDoesNotExistException(Long gameId, Long doorId) { 26 | super(String.format("Door '%d' in game '%d' does not exist", doorId, gameId)); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/nebhale/springone2014/model/DoorStatus.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.nebhale.springone2014.model; 18 | 19 | import java.util.Map; 20 | 21 | public enum DoorStatus { 22 | 23 | CLOSED, 24 | OPENED, 25 | SELECTED; 26 | 27 | private static final String STATUS_KEY = "status"; 28 | 29 | public static DoorStatus parse(Map payload) { 30 | String value = payload.get(STATUS_KEY); 31 | 32 | if (value == null) { 33 | throw new IllegalArgumentException("Payload is missing key status'"); 34 | } 35 | 36 | try { 37 | return DoorStatus.valueOf(value.toUpperCase()); 38 | } catch (IllegalArgumentException e) { 39 | throw new IllegalArgumentException( 40 | String.format("'%s' is an illegal value for key '%s'", value, STATUS_KEY), e); 41 | } 42 | 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/nebhale/springone2014/model/Game.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.nebhale.springone2014.model; 18 | 19 | import com.fasterxml.jackson.annotation.JsonIgnore; 20 | 21 | import java.util.Collection; 22 | import java.util.HashMap; 23 | import java.util.Map; 24 | 25 | public final class Game { 26 | 27 | private final Map doors; 28 | 29 | private final Long id; 30 | 31 | private final Object monitor = new Object(); 32 | 33 | private volatile GameStatus status; 34 | 35 | public Game(Long id, Collection doors) { 36 | this.id = id; 37 | 38 | this.doors = new HashMap<>(); 39 | for (Door door : doors) { 40 | this.doors.put(door.getId(), door); 41 | } 42 | 43 | this.status = GameStatus.AWAITING_INITIAL_SELECTION; 44 | } 45 | 46 | public void transition(Long doorId, DoorStatus status) throws DoorDoesNotExistException, 47 | IllegalTransitionException { 48 | 49 | synchronized (this.monitor) { 50 | if (DoorStatus.SELECTED == status) { 51 | select(doorId); 52 | } else if (DoorStatus.OPENED == status) { 53 | open(doorId); 54 | } else { 55 | throw new IllegalTransitionException(this.id, doorId, status); 56 | } 57 | } 58 | } 59 | 60 | @JsonIgnore 61 | public Long getId() { 62 | synchronized (this.monitor) { 63 | return this.id; 64 | } 65 | } 66 | 67 | @JsonIgnore 68 | public Collection getDoors() { 69 | return this.doors.values(); 70 | } 71 | 72 | public GameStatus getStatus() { 73 | synchronized (this.monitor) { 74 | return this.status; 75 | } 76 | } 77 | 78 | private Door getDoor(Long doorId) throws DoorDoesNotExistException { 79 | if (this.doors.containsKey(doorId)) { 80 | return this.doors.get(doorId); 81 | } 82 | 83 | throw new DoorDoesNotExistException(this.id, doorId); 84 | } 85 | 86 | private void open(Long doorId) throws IllegalTransitionException, DoorDoesNotExistException { 87 | if (this.status != GameStatus.AWAITING_FINAL_SELECTION) { 88 | throw new IllegalTransitionException(this.id, this.status, GameStatus.WON); 89 | } 90 | 91 | Door door = getDoor(doorId); 92 | if (DoorStatus.OPENED == door.getStatus()) { 93 | throw new IllegalTransitionException(this.id, doorId, door.getStatus(), DoorStatus.OPENED); 94 | } 95 | 96 | door.setStatus(DoorStatus.OPENED); 97 | 98 | if (DoorContent.BICYCLE == door.getContent()) { 99 | this.status = GameStatus.WON; 100 | } else { 101 | this.status = GameStatus.LOST; 102 | } 103 | } 104 | 105 | private void openHintDoor() { 106 | for (Door door : getDoors()) { 107 | if ((DoorStatus.CLOSED == door.getStatus()) && (DoorContent.SMALL_FURRY_ANIMAL == door.peekContent())) { 108 | door.setStatus(DoorStatus.OPENED); 109 | break; 110 | } 111 | } 112 | } 113 | 114 | private void select(Long doorId) throws IllegalTransitionException, DoorDoesNotExistException { 115 | if (this.status != GameStatus.AWAITING_INITIAL_SELECTION) { 116 | throw new IllegalTransitionException(this.id, this.status, GameStatus.AWAITING_FINAL_SELECTION); 117 | } 118 | 119 | Door door = getDoor(doorId); 120 | door.setStatus(DoorStatus.SELECTED); 121 | 122 | openHintDoor(); 123 | 124 | this.status = GameStatus.AWAITING_FINAL_SELECTION; 125 | } 126 | 127 | } 128 | -------------------------------------------------------------------------------- /src/main/java/com/nebhale/springone2014/model/GameStatus.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.nebhale.springone2014.model; 18 | 19 | public enum GameStatus { 20 | 21 | AWAITING_INITIAL_SELECTION, 22 | AWAITING_FINAL_SELECTION, 23 | LOST, 24 | WON 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/nebhale/springone2014/model/IllegalTransitionException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.nebhale.springone2014.model; 18 | 19 | import org.springframework.http.HttpStatus; 20 | import org.springframework.web.bind.annotation.ResponseStatus; 21 | 22 | // TODO 2: CONFLICT status code 23 | @ResponseStatus(HttpStatus.CONFLICT) 24 | public final class IllegalTransitionException extends Exception { 25 | 26 | IllegalTransitionException(Long gameId, Long doorId, DoorStatus from, DoorStatus to) { 27 | super(String.format("It is illegal to transition door '%d' in game '%d' from '%s' to '%s'", 28 | doorId, gameId, from, to)); 29 | } 30 | 31 | IllegalTransitionException(Long gameId, Long doorId, DoorStatus to) { 32 | super(String.format("It is illegal to transition door '%d' in game '%d' to '%s'", doorId, gameId, to)); 33 | } 34 | 35 | IllegalTransitionException(Long gameId, GameStatus from, GameStatus to) { 36 | super(String.format("It is illegal to transition game '%d' from '%s' to '%s'", gameId, from, to)); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/nebhale/springone2014/repository/GameDoesNotExistException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.nebhale.springone2014.repository; 18 | 19 | import org.springframework.http.HttpStatus; 20 | import org.springframework.web.bind.annotation.ResponseStatus; 21 | 22 | // TODO 2: NOT_FOUND Status Code 23 | @ResponseStatus(HttpStatus.NOT_FOUND) 24 | public final class GameDoesNotExistException extends Exception { 25 | 26 | public GameDoesNotExistException(Long id) { 27 | super(String.format("Game '%d' does not exist", id)); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/nebhale/springone2014/repository/GameRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.nebhale.springone2014.repository; 18 | 19 | import com.nebhale.springone2014.model.Game; 20 | 21 | public interface GameRepository { 22 | 23 | Game create(); 24 | 25 | Game retrieve(Long id) throws GameDoesNotExistException; 26 | 27 | void remove(Long id) throws GameDoesNotExistException; 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/nebhale/springone2014/repository/InMemoryGameRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.nebhale.springone2014.repository; 18 | 19 | import com.nebhale.springone2014.model.Door; 20 | import com.nebhale.springone2014.model.DoorContent; 21 | import com.nebhale.springone2014.model.Game; 22 | import org.springframework.stereotype.Component; 23 | 24 | import java.security.SecureRandom; 25 | import java.util.Collection; 26 | import java.util.HashMap; 27 | import java.util.Map; 28 | import java.util.concurrent.atomic.AtomicLong; 29 | import java.util.stream.Collectors; 30 | import java.util.stream.IntStream; 31 | 32 | @Component 33 | final class InMemoryGameRepository implements GameRepository { 34 | 35 | private final Map games = new HashMap<>(); 36 | 37 | private final AtomicLong idGenerator = new AtomicLong(); 38 | 39 | private final Object monitor = new Object(); 40 | 41 | private final SecureRandom random = new SecureRandom(); 42 | 43 | @Override 44 | public Game create() { 45 | synchronized (this.monitor) { 46 | Long id = this.idGenerator.getAndIncrement(); 47 | Game game = new Game(id, createDoors()); 48 | 49 | this.games.put(id, game); 50 | 51 | return game; 52 | } 53 | } 54 | 55 | @Override 56 | public Game retrieve(Long id) throws GameDoesNotExistException { 57 | synchronized (this.monitor) { 58 | if (!this.games.containsKey(id)) { 59 | throw new GameDoesNotExistException(id); 60 | } 61 | 62 | return this.games.get(id); 63 | } 64 | } 65 | 66 | @Override 67 | public void remove(Long id) throws GameDoesNotExistException { 68 | synchronized (this.monitor) { 69 | if (!this.games.containsKey(id)) { 70 | throw new GameDoesNotExistException(id); 71 | } 72 | 73 | this.games.remove(id); 74 | } 75 | } 76 | 77 | private Collection createDoors() { 78 | int winner = this.random.nextInt(3); 79 | 80 | return IntStream.range(0, 3).mapToObj(index -> { 81 | Long id = this.idGenerator.getAndIncrement(); 82 | DoorContent content = (index == winner) ? DoorContent.BICYCLE : DoorContent.SMALL_FURRY_ANIMAL; 83 | return new Door(id, content); 84 | }).collect(Collectors.toList()); 85 | } 86 | 87 | } 88 | -------------------------------------------------------------------------------- /src/main/java/com/nebhale/springone2014/web/DoorsResourceAssembler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.nebhale.springone2014.web; 18 | 19 | import com.nebhale.springone2014.model.Door; 20 | import com.nebhale.springone2014.model.Game; 21 | import org.springframework.hateoas.Resource; 22 | import org.springframework.hateoas.ResourceAssembler; 23 | import org.springframework.hateoas.Resources; 24 | import org.springframework.stereotype.Component; 25 | 26 | import java.util.List; 27 | import java.util.stream.Collectors; 28 | 29 | import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo; 30 | 31 | @Component 32 | final class DoorsResourceAssembler implements ResourceAssembler>> { 33 | 34 | @Override 35 | public Resources> toResource(Game game) { 36 | List> doors = game.getDoors().stream() 37 | .map(door -> toResource(game, door)).collect(Collectors.toList()); 38 | 39 | Resources> resource = new Resources>(doors); 40 | resource.add(linkTo(GamesController.class).slash(game.getId()).slash("doors").withSelfRel()); 41 | 42 | return resource; 43 | } 44 | 45 | private Resource toResource(Game game, Door door) { 46 | Resource resource = new Resource(door); 47 | resource.add(linkTo(GamesController.class).slash(game.getId()).slash("doors") 48 | .slash(door.getId()).withSelfRel()); 49 | 50 | return resource; 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/com/nebhale/springone2014/web/GameResourceAssembler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.nebhale.springone2014.web; 18 | 19 | import com.nebhale.springone2014.model.Game; 20 | import org.springframework.hateoas.Resource; 21 | import org.springframework.hateoas.ResourceAssembler; 22 | import org.springframework.stereotype.Component; 23 | 24 | import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo; 25 | 26 | @Component 27 | final class GameResourceAssembler implements ResourceAssembler> { 28 | 29 | @Override 30 | public Resource toResource(Game game) { 31 | Resource resource = new Resource(game); 32 | // TODO 3: link to /games/{gameId}/doors, rel: doors 33 | // TODO 3: link to /games/{gameId}, rel: self 34 | resource.add(linkTo(GamesController.class).slash(game.getId()).slash("doors").withRel("doors")); 35 | resource.add(linkTo(GamesController.class).slash(game.getId()).withSelfRel()); 36 | return resource; 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/nebhale/springone2014/web/GamesController.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.nebhale.springone2014.web; 18 | 19 | import com.nebhale.springone2014.model.*; 20 | import com.nebhale.springone2014.repository.GameDoesNotExistException; 21 | import com.nebhale.springone2014.repository.GameRepository; 22 | import org.springframework.beans.factory.annotation.Autowired; 23 | import org.springframework.hateoas.Resource; 24 | import org.springframework.hateoas.Resources; 25 | import org.springframework.http.HttpHeaders; 26 | import org.springframework.http.HttpStatus; 27 | import org.springframework.http.MediaType; 28 | import org.springframework.web.bind.annotation.*; 29 | 30 | import java.util.Map; 31 | 32 | import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo; 33 | 34 | // TODO 1: REST Controller for /games 35 | @RestController 36 | @RequestMapping(value = "/games") 37 | final class GamesController { 38 | 39 | private final DoorsResourceAssembler doorsResourceAssembler; 40 | 41 | private final GameRepository gameRepository; 42 | 43 | private final GameResourceAssembler gameResourceAssembler; 44 | 45 | @Autowired 46 | GamesController(DoorsResourceAssembler doorsResourceAssembler, GameRepository gameRepository, 47 | GameResourceAssembler gameResourceAssembler) { 48 | this.doorsResourceAssembler = doorsResourceAssembler; 49 | this.gameRepository = gameRepository; 50 | this.gameResourceAssembler = gameResourceAssembler; 51 | } 52 | 53 | // TODO 1: POST / 54 | @RequestMapping(method = RequestMethod.POST, value = "") 55 | // TODO 2: CREATED Status Code 56 | @ResponseStatus(HttpStatus.CREATED) 57 | HttpHeaders createGame() { 58 | Game game = this.gameRepository.create(); 59 | 60 | HttpHeaders headers = new HttpHeaders(); 61 | // TODO 1: Location: /games/{gameId} 62 | headers.setLocation(linkTo(GamesController.class).slash(game.getId()).toUri()); 63 | 64 | return headers; 65 | } 66 | 67 | // TODO 1: GET /{gameId}, Content-Type: application/json 68 | @RequestMapping(method = RequestMethod.GET, value = "/{gameId}", produces = MediaType.APPLICATION_JSON_VALUE) 69 | @ResponseStatus(HttpStatus.OK) 70 | Resource showGame(@PathVariable Long gameId) throws GameDoesNotExistException { 71 | Game game = this.gameRepository.retrieve(gameId); 72 | // TODO 3: return assembled Game Resource 73 | return this.gameResourceAssembler.toResource(game); 74 | } 75 | 76 | // TODO 1: DELETE /{gameId} 77 | @RequestMapping(method = RequestMethod.DELETE, value = "/{gameId}") 78 | @ResponseStatus(HttpStatus.OK) 79 | void destroyGame(@PathVariable Long gameId) throws GameDoesNotExistException { 80 | this.gameRepository.remove(gameId); 81 | } 82 | 83 | @RequestMapping(method = RequestMethod.GET, value = "/{gameId}/doors", produces = MediaType.APPLICATION_JSON_VALUE) 84 | @ResponseStatus(HttpStatus.OK) 85 | Resources> showDoors(@PathVariable Long gameId) throws GameDoesNotExistException { 86 | Game game = this.gameRepository.retrieve(gameId); 87 | // TODO 3: return assembled Resources Door Resource 88 | return this.doorsResourceAssembler.toResource(game); 89 | } 90 | 91 | // TODO 1: PUT /{gameId}/doors/{doorId}, Accepts: application/json, Content-Type: application/json 92 | @RequestMapping(method = RequestMethod.PUT, value = "/{gameId}/doors/{doorId}", 93 | consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) 94 | @ResponseStatus(HttpStatus.OK) 95 | void transitionDoor(@PathVariable Long gameId, @PathVariable Long doorId, 96 | @RequestBody Map payload) 97 | throws GameDoesNotExistException, IllegalTransitionException, DoorDoesNotExistException { 98 | 99 | DoorStatus status = DoorStatus.parse(payload); 100 | this.gameRepository.retrieve(gameId).transition(doorId, status); 101 | } 102 | 103 | // TODO 2: Handle IllegalArgumentException, BAD_REQUEST Status Code 104 | @ExceptionHandler(IllegalArgumentException.class) 105 | @ResponseStatus(HttpStatus.BAD_REQUEST) 106 | String handleBadRequests(Exception e) { 107 | return e.getMessage(); 108 | } 109 | 110 | } 111 | -------------------------------------------------------------------------------- /src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | 21 | 22 | %-5level %msg%n 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | --------------------------------------------------------------------------------