Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(288)

Side by Side Diff: 2-2-simple/lib/server/piratesapi.dart

Issue 1056193003: Rename methods to better match new terminology and get rid of json data file. (Closed) Base URL: https://github.com/dart-lang/one-hour-codelab.git@server2
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « 2-2-simple/lib/server/piratenames.json ('k') | 2-4-extended/lib/common/messages.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library pirate.server; 5 library pirate.server;
6 6
7 import 'dart:convert' show JSON;
8 import 'dart:io';
9 import 'package:rpc/rpc.dart'; 7 import 'package:rpc/rpc.dart';
10 8
11 import '../common/messages.dart'; 9 import '../common/messages.dart';
12 import '../common/utils.dart'; 10 import '../common/utils.dart';
13 11
14 @ApiClass(version: 'v1') 12 @ApiClass(version: 'v1')
15 class PiratesApi { 13 class PiratesApi {
16 final Map<int, Pirate> _alivePirates = {}; 14 final Map<int, Pirate> _pirateCrew = {};
17 PirateShanghaier _shanghaier; 15 final PirateShanghaier _shanghaier = new PirateShanghaier(properPirateNames);
18 Map<String, List<String>> _properPirates;
19
20 PiratesApi() {
21 var namesFile = new File(
22 Platform.script.resolve('../lib/server/piratenames.json').toFilePath());
23 _properPirates = JSON.decode(namesFile.readAsStringSync());
24 _shanghaier = new PirateShanghaier(_properPirates);
25 }
26 16
27 @ApiMethod(path: 'pirates') 17 @ApiMethod(path: 'pirates')
28 List<Pirate> listPirates() { 18 List<Pirate> listPirates() {
29 return _alivePirates.values.toList(); 19 return _pirateCrew.values.toList();
30 } 20 }
31 21
32 @ApiMethod(path: 'shanghai') 22 @ApiMethod(path: 'shanghai')
33 Pirate shanghaiAPirate() { 23 Pirate shanghaiAPirate() {
34 var pirate = _shanghaier.shanghaiAPirate(); 24 var pirate = _shanghaier.shanghaiAPirate();
35 if (pirate == null) { 25 if (pirate == null) {
36 throw new InternalServerError('Ran out of pirates!'); 26 throw new InternalServerError('Ran out of pirates!');
37 } 27 }
38 _alivePirates[pirate.toString().hashCode] = pirate; 28 _pirateCrew[pirate.toString().hashCode] = pirate;
39 return pirate; 29 return pirate;
40 } 30 }
41 } 31 }
OLDNEW
« no previous file with comments | « 2-2-simple/lib/server/piratenames.json ('k') | 2-4-extended/lib/common/messages.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698