Add API to delete a course
This commit is contained in:
parent
b3835b2340
commit
a151081be8
2 changed files with 15 additions and 6 deletions
|
@ -53,6 +53,12 @@ class TitamaApi {
|
||||||
throw new NotFoundError('Could not find course \'$id\'.');
|
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')
|
@ApiMethod(method: 'POST', path: 'course')
|
||||||
Course addCourse (Course newCourse) {
|
Course addCourse (Course newCourse) {
|
||||||
newCourse.id = _courses.length;
|
newCourse.id = _courses.length;
|
||||||
|
|
15
test.sh
15
test.sh
|
@ -4,20 +4,23 @@ 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"}'
|
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"
|
curl "$baseurl/courses"
|
||||||
|
|
||||||
printf "\n\nTesting %s/course/0...\n" "$baseurl"
|
printf "\n\nTesting GET %s/course/0...\n" "$baseurl"
|
||||||
curl "$baseurl/course/0"
|
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"
|
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
|
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"
|
curl "$baseurl/courses"
|
||||||
|
|
||||||
printf "\n\nTesting %s/course/2...\n" "$baseurl"
|
printf "\n\nTesting GET %s/course/2...\n" "$baseurl"
|
||||||
curl "$baseurl/course/2"
|
curl "$baseurl/course/2"
|
||||||
|
|
||||||
|
printf "\n\nTesting DELETE %s/course/2...\n" "$baseurl"
|
||||||
|
curl -X DELETE "$baseurl/course/1"
|
||||||
|
|
Reference in a new issue