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 : /// Include Reference: 81 : /// When you fetch an entry of a content type that has a reference field, 82 : /// by default, the content of the referred entry is not fetched. 83 : /// It only fetches the UID of the referred entry, along with the content of 84 : /// the specified entry. 85 : /// 86 : /// If you wish to fetch the content of the entry that is included in 87 : /// the reference field, you need to use the include[] parameter, 88 : /// and specify the UID of the reference field as value. 89 : /// This informs Contentstack that the request also includes 90 : /// fetching the entry used in the specified reference field. 91 : /// Add a constraint that requires a particular reference key details. 92 : /// includeReference provides three options, none, only and except 93 : /// i.e accepts list of fieldUid 94 : /// referenceFieldUid Key who has reference to some other class object. 95 : /// Array of the only reference keys to be included in response. 96 : /// 97 : /// Example 1: Reference type None 98 : /// 99 : /// ```dart 100 : /// final stack = contentstack.Stack("apiKey", "deliveryKey", "environment"); 101 : /// final entry = stack.contentType("contentTypeUid").entry("entryUid"); 102 : /// entry.includeReference("referenceFieldUid", 103 : /// IncludeReference.none(fieldUidList: null)); 104 : /// response = await entry.fetch(); 105 : /// prints(response) 106 : /// ``` 107 : /// 108 : /// Example 2: Reference type only 109 : /// 110 : /// ```dart 111 : /// final stack = contentstack.Stack("apiKey", "deliveryKey", "environment"); 112 : /// final entry = stack.contentType("contentTypeUid").entry("entryUid"); 113 : /// final fieldUid = list of string type; 114 : /// entry.includeReference("referenceFieldUid", 115 : /// IncludeReference.only(fieldUidList: fieldUid)); 116 : /// response = await entry.fetch(); 117 : /// prints(response) 118 : /// ``` 119 : /// 120 : /// Example 3: Reference type except 121 : /// ```dart 122 : /// final stack = contentstack.Stack("apiKey", "deliveryKey", "environment"); 123 1 : /// final entry = stack.contentType("contentTypeUid").entry("entryUid"); 124 : /// entry.includeReference("referenceFieldUid", 125 1 : /// IncludeReference.except(fieldUidList: fieldUid)); 126 1 : /// response = await entry.fetch(); 127 : /// prints(response) 128 2 : /// ``` 129 1 : /// 130 1 : void includeReference(String referenceFieldUid, 131 2 : {Include includeReferenceField}) { 132 2 : if (referenceFieldUid != null && referenceFieldUid.isNotEmpty) { 133 1 : final List referenceArray = []; 134 : if (includeReferenceField != null) { 135 : includeReferenceField.when(none: (fieldUid) { 136 3 : referenceArray.add(referenceFieldUid); 137 1 : if (fieldUid.fieldUidList != null && 138 1 : fieldUid.fieldUidList.isNotEmpty) { 139 1 : for (final item in fieldUid.fieldUidList) { 140 2 : referenceArray.add(item); 141 2 : } 142 1 : } 143 : parameter['include[]'] = referenceArray.toString(); 144 : }, only: (fieldUid) { 145 1 : final Map<String, dynamic> referenceOnlyParam = <String, dynamic>{}; 146 : if (fieldUid.fieldUidList != null && 147 1 : fieldUid.fieldUidList.isNotEmpty) { 148 3 : for (final item in fieldUid.fieldUidList) { 149 1 : referenceArray.add(item); 150 1 : } 151 1 : } 152 2 : referenceOnlyParam[referenceFieldUid] = referenceArray; 153 2 : //_include(referenceFieldUid); 154 1 : includeReference(referenceFieldUid); 155 : parameter['only'] = referenceOnlyParam.toString(); 156 : }, except: (fieldUid) { 157 1 : final Map<String, dynamic> referenceOnlyParam = <String, dynamic>{}; 158 : if (fieldUid.fieldUidList != null && 159 1 : fieldUid.fieldUidList.isNotEmpty) { 160 3 : for (final item in fieldUid.fieldUidList) { 161 : referenceArray.add(item); 162 : } 163 : } 164 2 : referenceOnlyParam[referenceFieldUid] = referenceArray; 165 : //_include(referenceFieldUid); 166 : includeReference(referenceFieldUid); 167 : parameter['except'] = referenceOnlyParam.toString(); 168 : }); 169 : } else { 170 : //referenceArray.add(referenceFieldUid); 171 : parameter['include[]'] = referenceFieldUid; 172 : } 173 : } 174 : } 175 : 176 : /// This method also includes the content type 177 : /// UIDs of the referenced entries returned in the response 178 : /// return [EntryQueryable] so you can chain this call 179 : /// 180 : /// Example: 181 1 : /// 182 2 : /// ```dart 183 2 : /// final stack = contentstack.Stack('apiKey','deliveryToken','environment'); 184 : /// final entry = stack.contentType("contentTypeUid").entry("entryUid"); 185 : /// entry.includeReferenceContentTypeUID(); 186 : /// ``` 187 : /// 188 : void includeReferenceContentTypeUID() { 189 : parameter['include_reference_content_type_uid'] = 'true'; 190 : } 191 : 192 : /// 193 : /// [locale] is code of the `language` of which the 194 : /// entries needs to be included. 195 : /// Only the entries published in this locale will be fetched. 196 : /// 197 : /// Example: 198 1 : /// 199 2 : /// ```dart 200 : /// final stack = contentstack.Stack('apiKey','deliveryToken','environment'); 201 : /// final entry = stack.contentType("contentTypeUid").entry("entryUid"); 202 : /// entry.locale('en-eu'); 203 : /// ``` 204 : /// 205 : void locale(String locale) { 206 : parameter['locale'] = locale; 207 : } 208 : 209 : /// Specifies an array of only keys in BASE object that 210 : /// would be included in the response. 211 : /// [fieldUid] Array of the only reference keys to be included in response. 212 : /// [EntryQueryable] object, so you can chain this call. 213 : /// 214 : /// Example: 215 : /// 216 1 : /// ```dart 217 2 : /// final stack = contentstack.Stack('apiKey','deliveryToken','environment'); 218 3 : /// final entry = stack.contentType("contentTypeUid").entry("entryUid"); 219 : /// fieldUid is String type of List 220 : /// entry.only(fieldUid); 221 : /// ``` 222 : /// 223 : void only(List<String> fieldUid) { 224 : if (fieldUid != null && fieldUid.isNotEmpty) { 225 : final List referenceArray = []; 226 : for (final item in fieldUid) { 227 : referenceArray.add(item); 228 : } 229 : parameter['only[BASE][]'] = referenceArray.toString(); 230 0 : } 231 0 : } 232 : }