getGroupSettings method

Future<List<Setting>> getGroupSettings({
  1. required String group,
  2. bool? useFaker,
})

Get settings for a specific group

Implementation

Future<List<Setting>> getGroupSettings({
  required String group,
  bool? useFaker,
}) async {
  final isUsingFaker = useFaker ?? this.useFaker;

  if (isUsingFaker) {
    return [
      Setting(
        id: '${group}_setting_1',
        label: 'Test Setting 1',
        description: 'Test setting description',
        parentId: group,
        subGroups: [],
        links: SettingLinks(
          options: [
            SettingLink(
              href:
                  'https://example.com/wp-json/wc/v3/settings/$group/setting_1',
            ),
          ],
        ),
      ),
    ];
  }

  try {
    final response = await dio.get(_SettingsEndpoints.groupSettings(group));
    if (response.statusCode != null &&
        response.statusCode! >= 200 &&
        response.statusCode! < 300) {
      return response.data.map((json) => Setting.fromJson(json)).toList();
    } else {
      throw Exception(
        "API call failed with status code: ${response.statusCode}",
      );
    }
  } on DioException catch (e) {
    final errorMsg = e.response?.data["message"] ?? e.message;
    throw Exception("API call failed: $errorMsg");
  } catch (e) {
    throw Exception("Unexpected error in API call: $e");
  }
}