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
| class Order { | |
| var _id; | |
| var _reference; | |
| var _date; | |
| Order(id, reference, date) { | |
| this._id = id; | |
| this._reference = reference; | |
| this._date = date; | |
| } |
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
| class Order { | |
| var _id; | |
| var _reference; | |
| var _date; | |
| Order(this._id, this._reference, this._date); | |
| getInfo() { | |
| return 'Your order information:' | |
| '\n-------------------------------' |
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
| class Order { | |
| int _id; | |
| String _reference; | |
| DateTime _date; | |
| String code; // public property | |
| Order(this._id, this._reference, this._date); | |
| Order.withDiscount(this._id, this._reference, {this.code}) { | |
| _date = new DateTime.now(); | |
| } |
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
| class Order { | |
| // private properties | |
| int _id; | |
| String _reference; | |
| DateTime _date; | |
| // public properties | |
| String code; | |
| String from; | |
| List<String> bookings; |
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
| @override | |
| void setupRouter((Router router) async { | |
| router.route('/books[/:index]').listen((Request incomingRequest) async { | |
| return new Response.ok('Showing all books.'); | |
| }); | |
| router.route('/').listen((Request incomingRequest) async { | |
| return new Response.ok('<h1>Welcome to FaveReads</h1>') | |
| ..contentType = ContentType.HTML; | |
| }); | |
| }); |
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
| router.route('/books[/:index]').listen((Request incomingRequest) async { | |
| String reqMethod = incomingRequest.innerRequest.method; | |
| String index = incomingRequest.path.variables["index"]; | |
| if (reqMethod == 'GET') { | |
| if(index != null) { | |
| return new Response.ok('Showing book by index: $index'); | |
| } | |
| return new Response.ok('Showing all books.'); | |
| } else if (reqMethod == 'POST') { |
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
| import '../fave_reads.dart'; | |
| class BooksController extends HTTPController { | |
| // invoked for GET /books | |
| @httpGet // HTTPMethod meta data | |
| Future<Response> getAllBooks() async => new Response.ok('Showing all books'); | |
| // invoked for GET /books/:index | |
| @httpGet // HTTPMethod meta data | |
| Future<Response> getBook(@HTTPPath("index") int idx) async => new Response.ok('Showing single book'); |
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
| import '../fave_reads.dart'; | |
| List books = [ | |
| { | |
| 'title': 'Head First Design Patterns', | |
| 'author': 'Eric Freeman', | |
| 'year': 2004 | |
| }, | |
| { | |
| 'title': 'Clean Code: A handbook of Agile Software Craftsmanship', |
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
| class BooksController extends HTTPController { | |
| @httpGet | |
| Future<Response> getAll() async => new Response.ok(books); | |
| @httpGet | |
| Future<Response> getSingle(@HTTPPath("index") int idx) async { | |
| if (idx < 0 || idx > books.length - 1) { // index out of range | |
| return new Response.notFound(body: 'Book does not exist'); | |
| } | |
| return new Response.ok(books[idx]); |
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
| import '../fave_reads.dart'; | |
| class Book extends HTTPSerializable { | |
| String title; | |
| String author; | |
| int year; | |
| Book({this.title, this.author, this.year}); | |
| @override |