LCOV - code coverage report
Current view: top level - lib/src - entry_queryable.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 51 53 96.2 %
Date: 2021-05-07 19:45:01 Functions: 0 0 -

          Line data    Source code
       1             : import 'package:contentstack/src/enums/include.dart';
       2             : 
       3             : /// Applies Queries on [Entry](https://www.contentstack.com/docs/developers/apis/content-delivery-api/#entries)
       4             : class EntryQueryable {
       5             :   final Map<String, String> parameter = <String, String>{};
       6             : 
       7             :   ///
       8             :   /// This method adds key and value to an Entry.
       9             :   /// [key] The key as string which needs to be added to an Entry
      10             :   /// [value] The value as string which needs to be added to an Entry
      11             :   /// [EntryQueryable] object, so you can chain this call.
      12             :   ///
      13             :   /// Example:
      14             :   ///
      15             :   /// ```dart
      16             :   /// final stack = contentstack.Stack('apiKey','deliveryToken','environment');
      17             :   /// final entry  = stack.contentType("contentTypeUid").entry("entryUid");
      18             :   /// entry.addParam(key, value);
      19             :   /// ```
      20           1 :   void addParam(String key, String value) {
      21           2 :     if (key != null && value != null && key.isNotEmpty && value.isNotEmpty) {
      22             :       parameter[key] = value.toString();
      23             :     }
      24             :   }
      25             : 
      26             :   ///
      27             :   /// Specifies list of field uids that would be excluded from the response.
      28             :   /// [fieldUid] field uid  which get excluded from the response.
      29             :   /// [EntryQueryable] object, so you can chain this call.
      30             :   ///
      31             :   /// Example:
      32             :   ///
      33             :   /// ```dart
      34             :   /// final stack = contentstack.Stack('apiKey','deliveryToken','environment');
      35             :   /// final entry = stack.contentType("contentTypeUid").entry("entryUid");
      36             :   /// fieldUid is String type of List
      37             :   /// entry.except(fieldUid);
      38           1 :   /// ```
      39           1 :   ///
      40           1 :   void except(List<String> fieldUid) {
      41           2 :     if (fieldUid != null && fieldUid.isNotEmpty) {
      42           1 :       final List referenceArray = [];
      43             :       for (final item in fieldUid) {
      44           3 :         referenceArray.add(item);
      45             :       }
      46             :       parameter['except[BASE][]'] = referenceArray.toString();
      47             :     }
      48             :   }
      49             : 
      50             :   ///
      51             :   /// Include Content Type of all
      52             :   /// returned objects along with objects themselves.
      53             :   /// return, [EntryQueryable] so you can chain this call.
      54             :   ///
      55             :   /// Example:
      56             :   /// ```dart
      57             :   /// final stack = contentstack.Stack('apiKey','deliveryToken','environment');
      58             :   /// final entry  = stack.contentType("contentTypeUid").entry("entryUid");
      59             :   /// entry.includeContentType();
      60             :   /// ```
      61             :   ///
      62           1 :   void includeContentType() {
      63           1 :     parameter['include_content_type'] = 'true';
      64           1 :     parameter['include_global_field_schema'] = 'true';
      65           2 :   }
      66           1 : 
      67             :   ///
      68           3 :   /// Retrieve the published content of the fallback locale if an entry is not
      69             :   /// localized in specified locale.
      70             :   /// ```dart
      71             :   /// final stack = contentstack.Stack('apiKey, 'deliveryKey', 'environment);
      72             :   /// final entry = stack.contentType('contentType').entry()..includeFallback();
      73             :   /// ```
      74             :   ///
      75             :   void includeFallback() {
      76             :     parameter['include_fallback'] = 'true';
      77             :   }
      78             : 
      79             :   ///
      80             :   /// includeEmbeddedItems instance of Entry
      81             :   /// Include Embedded Objects (Entries and Assets) along with entry/entries details
      82             :   ///
      83             :   /// [Example for Entry class]
      84             :   /// ```
      85             :   /// final stack = contentstack.Stack('apiKey','deliveryToken','environment');
      86             :   /// final entry = stack.contentType("contentTypeUid").entry("entryUid");
      87             :   /// entry = entry.includeEmbeddedItems()
      88             :   /// ```
      89             :   ///
      90             :   void includeEmbeddedItems() {
      91             :     parameter['include_embedded_items[]'] = 'BASE';
      92             :   }
      93             : 
      94             :   ///
      95             :   /// Include Reference:
      96             :   /// When you fetch an entry of a content type that has a reference field,
      97             :   /// by default, the content of the referred entry is not fetched.
      98             :   /// It only fetches the UID of the referred entry, along with the content of
      99             :   /// the specified entry.
     100             :   ///
     101             :   /// If you wish to fetch the content of the entry that is included in
     102             :   /// the reference field, you need to use the include[] parameter,
     103             :   ///  and specify the UID of the reference field as value.
     104             :   /// This informs Contentstack that the request also includes
     105             :   /// fetching the entry used in the specified reference field.
     106             :   /// Add a constraint that requires a particular reference key details.
     107             :   /// includeReference provides three options, none, only and except
     108             :   /// i.e accepts list of fieldUid
     109             :   /// referenceFieldUid Key who has reference to some other class object.
     110             :   /// Array of the only reference keys to be included in response.
     111             :   ///
     112             :   /// Example 1: Reference type None
     113             :   ///
     114             :   /// ```dart
     115             :   /// final stack = contentstack.Stack("apiKey", "deliveryKey", "environment");
     116             :   /// final entry = stack.contentType("contentTypeUid").entry("entryUid");
     117             :   /// entry.includeReference("referenceFieldUid",
     118             :   ///       IncludeReference.none(fieldUidList: null));
     119             :   /// response = await entry.fetch();
     120             :   /// prints(response)
     121             :   /// ```
     122             :   ///
     123           1 :   /// Example 2: Reference type only
     124             :   ///
     125           1 :   /// ```dart
     126           1 :   /// final stack = contentstack.Stack("apiKey", "deliveryKey", "environment");
     127             :   /// final entry = stack.contentType("contentTypeUid").entry("entryUid");
     128           2 :   /// final fieldUid = list of string type;
     129           1 :   /// entry.includeReference("referenceFieldUid",
     130           1 :   ///       IncludeReference.only(fieldUidList: fieldUid));
     131           2 :   /// response = await entry.fetch();
     132           2 :   /// prints(response)
     133           1 :   /// ```
     134             :   ///
     135             :   /// Example 3: Reference type except
     136           3 :   /// ```dart
     137           1 :   /// final stack = contentstack.Stack("apiKey", "deliveryKey", "environment");
     138           1 :   /// final entry = stack.contentType("contentTypeUid").entry("entryUid");
     139           1 :   /// entry.includeReference("referenceFieldUid",
     140           2 :   ///       IncludeReference.except(fieldUidList: fieldUid));
     141           2 :   /// response = await entry.fetch();
     142           1 :   /// prints(response)
     143             :   /// ```
     144             :   ///
     145           1 :   void includeReference(String referenceFieldUid,
     146             :       {Include includeReferenceField}) {
     147           1 :     if (referenceFieldUid != null && referenceFieldUid.isNotEmpty) {
     148           3 :       final List referenceArray = [];
     149           1 :       if (includeReferenceField != null) {
     150           1 :         includeReferenceField.when(none: (fieldUid) {
     151           1 :           referenceArray.add(referenceFieldUid);
     152           2 :           if (fieldUid.fieldUidList != null &&
     153           2 :               fieldUid.fieldUidList.isNotEmpty) {
     154           1 :             for (final item in fieldUid.fieldUidList) {
     155             :               referenceArray.add(item);
     156             :             }
     157           1 :           }
     158             :           parameter['include[]'] = referenceArray.toString();
     159           1 :         }, only: (fieldUid) {
     160           3 :           final Map<String, dynamic> referenceOnlyParam = <String, dynamic>{};
     161             :           if (fieldUid.fieldUidList != null &&
     162             :               fieldUid.fieldUidList.isNotEmpty) {
     163             :             for (final item in fieldUid.fieldUidList) {
     164           2 :               referenceArray.add(item);
     165             :             }
     166             :           }
     167             :           referenceOnlyParam[referenceFieldUid] = referenceArray;
     168             :           //_include(referenceFieldUid);
     169             :           includeReference(referenceFieldUid);
     170             :           parameter['only'] = referenceOnlyParam.toString();
     171             :         }, except: (fieldUid) {
     172             :           final Map<String, dynamic> referenceOnlyParam = <String, dynamic>{};
     173             :           if (fieldUid.fieldUidList != null &&
     174             :               fieldUid.fieldUidList.isNotEmpty) {
     175             :             for (final item in fieldUid.fieldUidList) {
     176             :               referenceArray.add(item);
     177             :             }
     178             :           }
     179             :           referenceOnlyParam[referenceFieldUid] = referenceArray;
     180             :           //_include(referenceFieldUid);
     181           1 :           includeReference(referenceFieldUid);
     182           2 :           parameter['except'] = referenceOnlyParam.toString();
     183           2 :         });
     184             :       } else {
     185             :         //referenceArray.add(referenceFieldUid);
     186             :         parameter['include[]'] = referenceFieldUid;
     187             :       }
     188             :     }
     189             :   }
     190             : 
     191             :   /// This method also includes the content type
     192             :   /// UIDs of the referenced entries returned in the response
     193             :   /// return [EntryQueryable] so you can chain this call
     194             :   ///
     195             :   /// Example:
     196             :   ///
     197             :   /// ```dart
     198           1 :   /// final stack = contentstack.Stack('apiKey','deliveryToken','environment');
     199           2 :   /// final entry  = stack.contentType("contentTypeUid").entry("entryUid");
     200             :   /// entry.includeReferenceContentTypeUID();
     201             :   /// ```
     202             :   ///
     203             :   void includeReferenceContentTypeUID() {
     204             :     parameter['include_reference_content_type_uid'] = 'true';
     205             :   }
     206             : 
     207             :   ///
     208             :   /// [locale] is code of the `language` of which the
     209             :   /// entries needs to be included.
     210             :   /// Only the entries published in this locale will be fetched.
     211             :   ///
     212             :   /// Example:
     213             :   ///
     214             :   /// ```dart
     215             :   /// final stack = contentstack.Stack('apiKey','deliveryToken','environment');
     216           1 :   /// final entry = stack.contentType("contentTypeUid").entry("entryUid");
     217           2 :   /// entry.locale('en-eu');
     218           3 :   /// ```
     219             :   ///
     220             :   void locale(String locale) {
     221             :     parameter['locale'] = locale;
     222             :   }
     223             : 
     224             :   /// Specifies an array of only keys in BASE object that
     225             :   /// would be included in the response.
     226             :   /// [fieldUid] Array of the only reference keys to be included in response.
     227             :   /// [EntryQueryable] object, so you can chain this call.
     228             :   ///
     229             :   /// Example:
     230           0 :   ///
     231           0 :   /// ```dart
     232             :   /// final stack = contentstack.Stack('apiKey','deliveryToken','environment');
     233             :   /// final entry = stack.contentType("contentTypeUid").entry("entryUid");
     234             :   /// fieldUid is String type of List
     235             :   /// entry.only(fieldUid);
     236             :   /// ```
     237             :   ///
     238             :   void only(List<String> fieldUid) {
     239             :     if (fieldUid != null && fieldUid.isNotEmpty) {
     240             :       final List referenceArray = [];
     241             :       for (final item in fieldUid) {
     242             :         referenceArray.add(item);
     243             :       }
     244             :       parameter['only[BASE][]'] = referenceArray.toString();
     245             :     }
     246             :   }
     247             : }

Generated by: LCOV version 1.15