Skip to content

Instantly share code, notes, and snippets.

Jermaine Oppong graphicbeacon

Block or report user

Report or block graphicbeacon

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@graphicbeacon
graphicbeacon / main.dart
Created Apr 21, 2018
Sample code for 'Learn Dart Before You Flutter' blog post on Medium (Complete)
View main.dart
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
Sample code for "Building RESTful Web APIs with Dart, Aqueduct and PostgreSQL (Part 2)" post on Medium
View fave_reads_sink.dart
@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
Sample code for "Building RESTful Web APIs with Dart, Aqueduct and PostgreSQL (Part 2)" post on Medium (2)
View fave_reads_sink.dart
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
Sample code for "Building RESTful Web APIs with Dart, Aqueduct and PostgreSQL (Part 2)" post on Medium (3)
View books_controller.dart
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
Sample code for "Building RESTful Web APIs with Dart, Aqueduct and PostgreSQL (Part 2)" post on Medium (4)
View books_controller.dart
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
Sample code for "Building RESTful Web APIs with Dart, Aqueduct and PostgreSQL (Part 2)" post on Medium (5)
View books_controller.dart
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
Sample code for "Building RESTful Web APIs with Dart, Aqueduct and PostgreSQL (Part 2)" post on Medium (6)
View book.dart
import '../fave_reads.dart';
class Book extends HTTPSerializable {
String title;
String author;
int year;
Book({this.title, this.author, this.year});
@override
@graphicbeacon
graphicbeacon / books_controller.dart
Created May 16, 2018
Sample code for "Building RESTful Web APIs with Dart, Aqueduct and PostgreSQL (Part 2)" post on Medium (7)
View books_controller.dart
// 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
),
@graphicbeacon
graphicbeacon / book.dart
Created May 21, 2018
Sample code for "Building RESTful Web APIs with Dart, Aqueduct and PostgreSQL (Part 3)" post on Medium
View book.dart
import '../fave_reads.dart';
class Book extends ManagedObject<_Book> implements _Book {}
class _Book {
@managedPrimaryKey
int id;
String title;
String author;
@graphicbeacon
graphicbeacon / fave_reads_sink.dart
Last active May 22, 2018
Sample code for "Building RESTful Web APIs with Dart, Aqueduct and PostgreSQL (Part 3)" post on Medium (3)
View fave_reads_sink.dart
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
You can’t perform that action at this time.