Add API to delete a course

This commit is contained in:
Marcel Kapfer (mmk2410) 2016-06-19 12:40:21 +02:00
parent b3835b2340
commit a151081be8
2 changed files with 15 additions and 6 deletions

View file

@ -53,6 +53,12 @@ class TitamaApi {
throw new NotFoundError('Could not find course \'$id\'.');
}
@ApiMethod(method: 'DELETE', path: 'course/{id}')
List<Course> deleteCourse(int id) {
_courses.removeWhere((course) => course.id == id);
return _courses;
}
@ApiMethod(method: 'POST', path: 'course')
Course addCourse (Course newCourse) {
newCourse.id = _courses.length;

15
test.sh
View file

@ -4,20 +4,23 @@ baseurl="http://localhost:8080/titamaApi/v1"
header="Content-Type: application/json"
new_course_data='{"title": "FIN Sitzung", "day": "Wed", "time": "18:00"}'
printf "Testing %s/courses...\n" "$baseurl"
printf "Testing GET %s/courses...\n" "$baseurl"
curl "$baseurl/courses"
printf "\n\nTesting %s/course/0...\n" "$baseurl"
printf "\n\nTesting GET %s/course/0...\n" "$baseurl"
curl "$baseurl/course/0"
printf "\n\nTesting %s/course/1...\n" "$baseurl"
printf "\n\nTesting GET %s/course/1...\n" "$baseurl"
curl "$baseurl/course/1"
printf "\n\nTesting %s/course...\n" "$baseurl"
printf "\n\nTesting POST %s/course...\n" "$baseurl"
curl -d "$new_course_data" -H "$header" $baseurl/course
printf "\n\nTesting %s/courses...\n" "$baseurl"
printf "\n\nTesting GET %s/courses...\n" "$baseurl"
curl "$baseurl/courses"
printf "\n\nTesting %s/course/2...\n" "$baseurl"
printf "\n\nTesting GET %s/course/2...\n" "$baseurl"
curl "$baseurl/course/2"
printf "\n\nTesting DELETE %s/course/2...\n" "$baseurl"
curl -X DELETE "$baseurl/course/1"