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

Unified Diff: 2-4-extended/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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « 2-4-extended/lib/server/piratenames.json ('k') | 2-5-generated/lib/client/piratesapi.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: 2-4-extended/lib/server/piratesapi.dart
diff --git a/2-4-extended/lib/server/piratesapi.dart b/2-4-extended/lib/server/piratesapi.dart
index c26c266b715ec8379d9e325baee7eae47e73e1bd..7ec7708eb36e1c3c864fb7a80b0b8909848e480f 100644
--- a/2-4-extended/lib/server/piratesapi.dart
+++ b/2-4-extended/lib/server/piratesapi.dart
@@ -4,8 +4,6 @@
library pirate.server;
-import 'dart:convert' show JSON;
-import 'dart:io';
import 'package:rpc/rpc.dart';
import '../common/messages.dart';
@@ -13,50 +11,42 @@ import '../common/utils.dart';
@ApiClass(version: 'v1')
class PiratesApi {
- final Map<int, Pirate> _alivePirates = {};
- PirateShanghaier _shanghaier;
- Map<String, List<String>> _properPirates;
-
- PiratesApi() {
- var namesFile = new File(
- Platform.script.resolve('../lib/server/piratenames.json').toFilePath());
- _properPirates = JSON.decode(namesFile.readAsStringSync());
- _shanghaier = new PirateShanghaier(_properPirates);
- }
+ final Map<int, Pirate> _pirateCrew = {};
+ final PirateShanghaier _shanghaier = new PirateShanghaier(properPirateNames);
@ApiMethod(method: 'POST', path: 'pirate')
- Pirate addPirate(Pirate newPirate) {
+ Pirate hirePirate(Pirate newPirate) {
// Make sure this is a real pirate...
if (!truePirate(newPirate)) {
throw new BadRequestError(
'$newPirate cannot be a pirate. \'Tis not a pirate name!');
}
- if (_alivePirates.containsKey(newPirate.toString().hashCode)) {
+ if (_pirateCrew.containsKey(newPirate.toString().hashCode)) {
throw new BadRequestError(
'$newPirate is already part of your crew!');
}
// Add pirate to store.
- _alivePirates[newPirate.toString().hashCode] = newPirate;
+ _pirateCrew[newPirate.toString().hashCode] = newPirate;
return newPirate;
}
@ApiMethod(
method: 'DELETE', path: 'pirate/{name}/the/{appellation}')
- Pirate killPirate(String name, String appellation) {
+ Pirate firePirate(String name, String appellation) {
var pirate = new Pirate()
..name = Uri.decodeComponent(name)
..appellation = Uri.decodeComponent(appellation);
- if (!_alivePirates.containsKey(pirate.toString().hashCode)) {
+ if (!_pirateCrew.containsKey(pirate.toString().hashCode)) {
throw new NotFoundError(
'Could not find pirate \'$pirate\'! Maybe they\'ve abandoned ship!');
}
- return _alivePirates.remove(pirate.toString().hashCode);
+ return _pirateCrew.remove(pirate.toString().hashCode);
}
@ApiMethod(method: 'GET', path: 'pirates')
List<Pirate> listPirates() {
- return _alivePirates.values.toList();
+ return _pirateCrew.values.toList();
}
@ApiMethod(path: 'shanghai') // Default HTTP method is GET.
@@ -65,12 +55,12 @@ class PiratesApi {
if (pirate == null) {
throw new InternalServerError('Ran out of pirates!');
}
- _alivePirates[pirate.toString().hashCode] = pirate;
+ _pirateCrew[pirate.toString().hashCode] = pirate;
return pirate;
}
@ApiMethod(path: 'proper/pirates')
Map<String, List<String>> properPirates() {
- return _properPirates;
+ return properPirateNames;
}
}
« no previous file with comments | « 2-4-extended/lib/server/piratenames.json ('k') | 2-5-generated/lib/client/piratesapi.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698