Skip to content

Instantly share code, notes, and snippets.

@Andersmholmgren
Created September 30, 2014 10:37
Show Gist options
  • Save Andersmholmgren/74dc4c66a2e58d7ecae6 to your computer and use it in GitHub Desktop.
Save Andersmholmgren/74dc4c66a2e58d7ecae6 to your computer and use it in GitHub Desktop.
library shelftest.handlers;
import 'database.dart';
import 'user.dart';
import 'package:shelf_exception_response/exception.dart';
import 'package:shelf_bind/shelf_bind.dart';
/**
* Return a [User] as JSON.
*
* Throw [NotFoundException] if the 'userid' GET path parameter doesn't exist.
*/
User getUser(int userid) => db.getUser(userid);
/**
* Set username for the 'userid' GET path parameter [User].
*
* The [request] body is expected to adhere to the following format:
*
* {"name":"Some Name"}
*
* Throw [BadRequestException] if the body is malformed. Throw [NotFoundException]
* if the 'userid' [User] doesn't exist.
*/
User setUserName(int userid, @RequestBody() Map body) {
db.setUserName(userid, body['name']);
return db.getUser(userid);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment