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 {
|
2020-04-25 17:30:37 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
}
|