mirror of
https://github.com/johrpan/musicus_mobile.git
synced 2025-10-27 11:17:25 +01:00
Add basic http server
This commit is contained in:
parent
a43bd91922
commit
d77f49a21b
17 changed files with 340 additions and 0 deletions
36
server/lib/src/instruments.dart
Normal file
36
server/lib/src/instruments.dart
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
import 'package:aqueduct/aqueduct.dart';
|
||||
import 'package:musicus_database/musicus_database.dart';
|
||||
|
||||
class InstrumentsController extends ResourceController {
|
||||
final Database db;
|
||||
|
||||
InstrumentsController(this.db);
|
||||
|
||||
@Operation.get()
|
||||
Future<Response> getInstruments() async {
|
||||
final instruments = await db.allInstruments().get();
|
||||
return Response.ok(instruments);
|
||||
}
|
||||
|
||||
@Operation.get('id')
|
||||
Future<Response> getInstrument(@Bind.path('id') int id) async {
|
||||
final instrument = await db.instrumentById(id).getSingle();
|
||||
if (instrument != null) {
|
||||
return Response.ok(instrument);
|
||||
} else {
|
||||
return Response.notFound();
|
||||
}
|
||||
}
|
||||
|
||||
@Operation.put('id')
|
||||
Future<Response> putInstrument(
|
||||
@Bind.path('id') int id, @Bind.body() Map<String, dynamic> json) async {
|
||||
final instrument = Instrument.fromJson(json).copyWith(
|
||||
id: id,
|
||||
);
|
||||
|
||||
await db.updateInstrument(instrument);
|
||||
|
||||
return Response.ok(null);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue