Basic structure and courses api

This commit is contained in:
Marcel Kapfer (mmk2410) 2016-06-13 17:13:02 +02:00
parent 1c60f68c62
commit 9f4eb7f79a
5 changed files with 71 additions and 0 deletions

1
bin/packages Symbolic link
View File

@ -0,0 +1 @@
../packages

22
bin/titama.dart Normal file
View File

@ -0,0 +1,22 @@
library titama;
import 'dart:io';
import 'package:logging/logging.dart';
import 'package:rpc/rpc.dart';
import '../lib/server/titamaapi.dart';
final ApiServer _apiServer = new ApiServer(prettyPrint: true);
main() async {
Logger.root
..level = Level.INFO
..onRecord.listen(print);
_apiServer.addApi(new TitamaApi());
HttpServer server = await HttpServer.bind(InternetAddress.ANY_IP_V4, 8080);
server.listen(_apiServer.httpRequestHandler);
print('Server listening on http://${server.address.host}:${server.port}');
}

14
lib/common/messages.dart Normal file
View File

@ -0,0 +1,14 @@
library titama.messages;
class Course {
String title;
String time;
String day;
String kind;
String place;
String prof;
String turnin;
int id;
Course();
}

0
lib/common/utils.dart Normal file
View File

34
lib/server/titamaapi.dart Normal file
View File

@ -0,0 +1,34 @@
library titama.server;
import 'package:rpc/rpc.dart';
import '../common/messages.dart';
@ApiClass(version: 'v1')
class TitamaApi {
final List<Course> _courses = new List<Course>();
TitamaApi() {
// example course, to remove once the database connection is implemented
Course course = new Course();
course
..title = "UlmAPI"
..time = "18:00"
..day = "Monday"
..id = 0
..kind = "Lab"
..place = "O27/343"
..prof = ""
..turnin = "";
_courses.add(course);
}
@ApiMethod(path: 'courses')
List<Course> listCourses() {
return _courses;
}
}