requestTowing method

Future<ApiResponse<Towing>> requestTowing(
  1. TowingParam param
)

Implementation

Future<ApiResponse<Towing>> requestTowing(TowingParam param) async {
  try {
    final response = await call(endpoint: 'towing-request', method: Method.POST, body: param.toJson());
    final bodyJson = jsonDecode(response.body);

    if (response.statusCode == 201) {
      return ApiResponse.fromJson(
        bodyJson,
            (data) => Towing.fromJson(data),
      );
    } else {
      return ApiResponse(
        success: false,
        data: null,
        message: bodyJson['message'] ?? "Failed to request towing",
      );
    }
  } catch (e) {
    return ApiResponse(
      success: false,
      data: null,
      message: "Error requesting towing: $e",
    );
  }
}