diff --git a/bin/packages b/bin/packages new file mode 120000 index 0000000..a16c405 --- /dev/null +++ b/bin/packages @@ -0,0 +1 @@ +../packages \ No newline at end of file diff --git a/bin/titama.dart b/bin/titama.dart new file mode 100644 index 0000000..3785ded --- /dev/null +++ b/bin/titama.dart @@ -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}'); +} diff --git a/lib/common/messages.dart b/lib/common/messages.dart new file mode 100644 index 0000000..878dbcd --- /dev/null +++ b/lib/common/messages.dart @@ -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(); +} diff --git a/lib/common/utils.dart b/lib/common/utils.dart new file mode 100644 index 0000000..e69de29 diff --git a/lib/server/titamaapi.dart b/lib/server/titamaapi.dart new file mode 100644 index 0000000..4ab8560 --- /dev/null +++ b/lib/server/titamaapi.dart @@ -0,0 +1,34 @@ +library titama.server; + +import 'package:rpc/rpc.dart'; + +import '../common/messages.dart'; + +@ApiClass(version: 'v1') +class TitamaApi { + + final List _courses = new List(); + + 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 listCourses() { + return _courses; + } + + + +}