musicus_mobile/server/lib/src/works.dart

34 lines
838 B
Dart
Raw Normal View History

2020-04-25 13:21:38 +02:00
import 'package:aqueduct/aqueduct.dart';
import 'package:musicus_database/musicus_database.dart';
class WorksController extends ResourceController {
final Database db;
WorksController(this.db);
@Operation.get('id')
Future<Response> getWork(@Bind.path('id') int id) async {
final work = await db.getWork(id);
2020-04-25 13:21:38 +02:00
if (work != null) {
return Response.ok(work);
} else {
return Response.notFound();
}
}
@Operation.put('id')
Future<Response> putWork(
@Bind.path('id') int id, @Bind.body() Map<String, dynamic> json) async {
2020-04-26 16:48:05 +02:00
final workInfo = WorkInfo.fromJson(json);
await db.updateWork(workInfo);
return Response.ok(null);
2020-04-25 13:21:38 +02:00
}
2020-05-01 14:46:36 +02:00
@Operation.delete('id')
Future<Response> deleteWork(@Bind.path('id') int id) async {
await db.deleteWork(id);
return Response.ok(null);
}
2020-04-25 13:21:38 +02:00
}