mirror of
https://github.com/flutter/samples.git
synced 2025-11-10 23:08:59 +00:00
Compass app (#2446)
This commit is contained in:
35
compass_app/server/lib/routes/destination.dart
Normal file
35
compass_app/server/lib/routes/destination.dart
Normal file
@@ -0,0 +1,35 @@
|
||||
// Copyright 2024 The Flutter team. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:shelf/shelf.dart';
|
||||
import 'package:shelf_router/shelf_router.dart';
|
||||
|
||||
import '../config/assets.dart';
|
||||
|
||||
class DestinationApi {
|
||||
Router get router {
|
||||
final router = Router();
|
||||
|
||||
router.get('/', (Request request) {
|
||||
return Response.ok(
|
||||
json.encode(Assets.destinations),
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
);
|
||||
});
|
||||
|
||||
router.get('/<id>/activity', (Request request, String id) {
|
||||
final list = Assets.activities
|
||||
.where((activity) => activity.destinationRef == id)
|
||||
.toList();
|
||||
return Response.ok(
|
||||
json.encode(list),
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
);
|
||||
});
|
||||
|
||||
return router;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user