This repository has been archived on 2022-02-10. You can view files and clone it, but cannot push or open issues or pull requests.
titama-backend/lib/server/titamaapi.dart

57 lines
1.2 KiB
Dart
Raw Normal View History

2016-06-13 17:13:02 +02:00
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);
2016-06-14 21:46:42 +02:00
Course course2 = new Course();
course2
..title = "CCC Ulm"
..time = "20:00"
..day = "Monday"
..id = 1
..kind = "Meeting"
..place = "Cafe Einstein"
..prof = ""
..turnin = "";
_courses.add(course2);
2016-06-13 17:13:02 +02:00
}
@ApiMethod(path: 'courses')
List<Course> listCourses() {
if (_courses.isEmpty) {
throw new NotFoundError('Could not find any courses.');
}
2016-06-13 17:13:02 +02:00
return _courses;
}
2016-06-14 21:47:25 +02:00
@ApiMethod(path: 'course/{id}')
Course getCourse(int id) {
for (Course course in _courses) {
if (course.id == id) {
return course;
}
}
throw new NotFoundError('Could not find course \'$id\'.');
}
2016-06-13 17:13:02 +02:00
}