getAdminSingleProductById method

Future<PrintifyGetShopSingleProductResponse> getAdminSingleProductById({
  1. required String baseUrl,
  2. required String productId,
})

Gets a specific product by its productId.

Implementation

Future<PrintifyGetShopSingleProductResponse> getAdminSingleProductById({
  required String baseUrl,
  required String productId,
}) async {
  Response? response;

  try {
    final dio = Dio(
      BaseOptions(
        contentType: 'application/json',
        responseType: ResponseType.json,
        baseUrl: 'https://$baseUrl/app',
      ),
    );
    response = await dio.get(
      '/getAdminProductById',
      queryParameters: {
        'productId': productId,
      },
    );

    if (response.statusCode == 200) {
      return PrintifyGetShopSingleProductResponse.fromJson(response.data);
    } else {
      throw Exception(
          'Non 200 return code for getting single product with ID $productId. Response: ${response.statusCode}');
    }
  } catch (e) {
    throw Exception(
        'Exception for getting single admin product with ID $productId. Response: ${response?.statusCode}');
  }
}