getAuctions method

Future<ApiResponse<List<Auction>>> getAuctions(
  1. AuctionType auctionType,
  2. int page,
  3. int perPage
)

Implementation

Future<ApiResponse<List<Auction>>> getAuctions(
    AuctionType auctionType,
    int page,
    int perPage,
    ) async {
  try {
    final Map<String, dynamic> queryParams = {
      "expand": "order,order.vehicle,order.featuredImage",
      'page': page,
      'per_page': perPage,
      'auction_type': auctionType.toApiString,
    };

    final response = await call(endpoint: 'auctions', method: Method.GET, body: queryParams);
    final bodyJson = jsonDecode(response.body);

    if (response.statusCode == 200) {
      return ApiResponse.fromJson(
        bodyJson,
            (data) => (data as List).map<Auction>((json) => Auction.fromJson(json)).toList(),
      );
    } else {
      return ApiResponse(
        success: false,
        data: null,
        message: bodyJson['message'] ?? 'Failed to fetch auctions',
      );
    }
  } catch (e) {
    return ApiResponse(
      success: false,
      data: null,
      message: 'Error fetching auctions: $e',
    );
  }
}