Add API to update a course

This commit is contained in:
Marcel Kapfer (mmk2410) 2016-06-19 13:19:22 +02:00
parent a151081be8
commit e1c2eedadb
2 changed files with 20 additions and 2 deletions

View file

@ -66,5 +66,13 @@ class TitamaApi {
return newCourse; return newCourse;
} }
@ApiMethod(method: 'PUT', path: 'course/{id}')
Course updateCourse(int id, Course course) {
course.id = id;
int index = _courses.indexOf(_courses.singleWhere((crs) => crs.id == id));
_courses.replaceRange(index, index + 1, [course]);
return course;
}
} }

14
test.sh
View file

@ -2,7 +2,8 @@
baseurl="http://localhost:8080/titamaApi/v1" baseurl="http://localhost:8080/titamaApi/v1"
header="Content-Type: application/json" header="Content-Type: application/json"
new_course_data='{"title": "FIN Sitzung", "day": "Wed", "time": "18:00"}' post_course_data='{"title": "FIN Sitzung", "day": "Wed", "time": "18:00"}'
put_course_data='{"title": "FIN Sitzung", "day": "Wed", "time": "18:00", "kind": "meeting"}'
printf "Testing GET %s/courses...\n" "$baseurl" printf "Testing GET %s/courses...\n" "$baseurl"
curl "$baseurl/courses" curl "$baseurl/courses"
@ -14,7 +15,7 @@ printf "\n\nTesting GET %s/course/1...\n" "$baseurl"
curl "$baseurl/course/1" curl "$baseurl/course/1"
printf "\n\nTesting POST %s/course...\n" "$baseurl" printf "\n\nTesting POST %s/course...\n" "$baseurl"
curl -d "$new_course_data" -H "$header" $baseurl/course curl -d "$post_course_data" -H "$header" $baseurl/course
printf "\n\nTesting GET %s/courses...\n" "$baseurl" printf "\n\nTesting GET %s/courses...\n" "$baseurl"
curl "$baseurl/courses" curl "$baseurl/courses"
@ -24,3 +25,12 @@ curl "$baseurl/course/2"
printf "\n\nTesting DELETE %s/course/2...\n" "$baseurl" printf "\n\nTesting DELETE %s/course/2...\n" "$baseurl"
curl -X DELETE "$baseurl/course/1" curl -X DELETE "$baseurl/course/1"
printf "\n\nTesting GET %s/courses...\n" "$baseurl"
curl "$baseurl/courses"
printf "\n\nTesting PUT %s/course/2...\n" "$baseurl"
curl -d "$put_course_data" -H "$header" -X PUT $baseurl/course/2
printf "\n\nTesting GET %s/courses...\n" "$baseurl"
curl "$baseurl/courses"