Skip to content

Instantly share code, notes, and snippets.

View graphicbeacon's full-sized avatar
🏠
Working from home

Jermaine Oppong graphicbeacon

🏠
Working from home
View GitHub Profile
@graphicbeacon
graphicbeacon / main_order1.dart
Last active April 21, 2018 18:40
Sample code for 'Learn Dart Before You Flutter' blog post on Medium (1)
class Order {
var _id;
var _reference;
var _date;
Order(id, reference, date) {
this._id = id;
this._reference = reference;
this._date = date;
}
@graphicbeacon
graphicbeacon / main.dart
Created April 21, 2018 18:41
Sample code for 'Learn Dart Before You Flutter' blog post on Medium (2)
class Order {
var _id;
var _reference;
var _date;
Order(this._id, this._reference, this._date);
getInfo() {
return 'Your order information:'
'\n-------------------------------'
@graphicbeacon
graphicbeacon / main.dart
Last active April 21, 2018 20:01
Sample code for 'Learn Dart Before You Flutter' blog post on Medium (3)
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();
}
@graphicbeacon
graphicbeacon / main.dart
Created April 21, 2018 20:10
Sample code for 'Learn Dart Before You Flutter' blog post on Medium (Complete)
class Order {
// private properties
int _id;
String _reference;
DateTime _date;
// public properties
String code;
String from;
List<String> bookings;
@graphicbeacon
graphicbeacon / fave_reads_sink.dart
Last active May 16, 2018 21:32
Sample code for "Building RESTful Web APIs with Dart, Aqueduct and PostgreSQL (Part 2)" post on Medium
@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;
});
});
@graphicbeacon
graphicbeacon / fave_reads_sink.dart
Created May 16, 2018 21:39
Sample code for "Building RESTful Web APIs with Dart, Aqueduct and PostgreSQL (Part 2)" post on Medium (2)
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') {
@graphicbeacon
graphicbeacon / books_controller.dart
Last active May 16, 2018 21:58
Sample code for "Building RESTful Web APIs with Dart, Aqueduct and PostgreSQL (Part 2)" post on Medium (3)
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');
@graphicbeacon
graphicbeacon / books_controller.dart
Last active May 16, 2018 22:10
Sample code for "Building RESTful Web APIs with Dart, Aqueduct and PostgreSQL (Part 2)" post on Medium (4)
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',
@graphicbeacon
graphicbeacon / books_controller.dart
Created May 16, 2018 22:13
Sample code for "Building RESTful Web APIs with Dart, Aqueduct and PostgreSQL (Part 2)" post on Medium (5)
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]);
@graphicbeacon
graphicbeacon / book.dart
Created May 16, 2018 22:29
Sample code for "Building RESTful Web APIs with Dart, Aqueduct and PostgreSQL (Part 2)" post on Medium (6)
import '../fave_reads.dart';
class Book extends HTTPSerializable {
String title;
String author;
int year;
Book({this.title, this.author, this.year});
@override