Created
September 30, 2014 10:37
-
-
Save Andersmholmgren/74dc4c66a2e58d7ecae6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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