import 'dart:convert';
import 'package:shelf/shelf.dart';
import 'package:shelf_router/shelf_router.dart';
import 'OrderDatabase.dart';

class OrderApi {
  final Router _router = Router();
  late OrderDatabase _orderDatabase;

  OrderApi() {
    _orderDatabase = OrderDatabase.instance;
    _router.get('/orders', _getAllOrders);
    // Ajoutez d'autres routes nécessaires
  }

  Router get router => _router;

  Future<Response> _getAllOrders(Request request) async {
    await _orderDatabase.initDatabase();
    final orders = await _orderDatabase.getAllOrders();

    final ordersJson = jsonEncode(orders);

    return Response.ok(ordersJson,
        headers: {'content-type': 'application/json'});
  }
}
