This file contains 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 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 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 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 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 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 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 |
This file contains 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
// lib/controller/book_controller.dart | |
import '../fave_reads.dart'; | |
import 'model/book.dart'; | |
List books = [ | |
new Book( | |
title: 'Head First Design Patterns', | |
author: 'Eric Freeman', | |
year: 2004 | |
), |
This file contains 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 ManagedObject<_Book> implements _Book {} | |
class _Book { | |
@managedPrimaryKey | |
int id; | |
String title; | |
String author; |
This file contains 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 FaveReadsSink extends RequestSink { | |
//... | |
//... | |
//... | |
Future createDatabaseSchema(ManagedContext context) async { | |
var builder = new SchemaBuilder.toSchema( | |
context.persistentStore, | |
new Schema.fromDataModel(context.dataModel), | |
isTemporary: false); // Set to false to persist our data |