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