Skip to content

Commit

Permalink
Merge branch 'feature-DATAAPI-31_ability-to-have-deleted-record-detai…
Browse files Browse the repository at this point in the history
…l-in-queue-data' into release-3.6.0
  • Loading branch information
pixl8-brayden committed Sep 5, 2024
2 parents 5942a57 + e031e00 commit 8454f0f
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 16 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## v3.5.11

* [#83](https://github.com/pixl8/preside-ext-data-api/issues/83) Fix sort order in docs
* [#84](https://github.com/pixl8/preside-ext-data-api/issues/84) Minimize database table generation based on feature flags

## v3.5.10

* Add flag option to allow renderers to process empty values (fix for certain implementations with changes made in 3.5.5)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Additional _optional_ annotation options at the _object_ level are:
* `dataApiCategory`: For the HTML documentation. Allows sub-groups of entities. Especially useful for large APIs.
* `dataApiQueueEnabled`: Whether or not the change queue is enabled for this object
* `dataApiQueue`: Specific queue name for this object
* `dataApiQueueDeleteDetail`: Whether or not the deleted record detail is available in the change queue data for this object
* `dataApiSortOrder`: Sort order for paginated results. Default is date last modified ascending.
* `dataApiSavedFilters`: Comma-separated list of saved filters to apply to all requests to this object (e.g. only return active records)
* `dataApiIgnoreDefaultFilters`: Comma-separated list of ignore default filters to apply to all requests to this object
Expand Down
2 changes: 1 addition & 1 deletion config/Config.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ component {
settings.features.apiManager.enabled = true;
settings.features.restTokenAuth.enabled = true;

settings.features.dataApiQueue = settings.features.dataApiQueue ?: { enabled=true };
settings.features.dataApiQueue = settings.features.dataApiQueue ?: { enabled=true, dependsOn=[ "restTokenAuth" ] };
settings.features.dataApiUseNullForNumerics = settings.features.dataApiUseNullForNumerics ?: { enabled=true };
settings.features.dataApiUseNullForStrings = settings.features.dataApiUseNullForStrings ?: { enabled=true };
settings.features.dataApiFormulaFieldsForAtomic = settings.features.dataApiFormulaFieldsForAtomic ?: { enabled=true };
Expand Down
5 changes: 0 additions & 5 deletions handlers/rest-apis/data/v1/docs/Html.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,7 @@ component {

args.spec = variables[ "_spec#api#" ];

try {

restResponse.setData( Trim( renderView( view="/dataApiHtmlDocs/index", args=args ) ) );
} catch( any e ) {
WriteDump( e ); abort;
}
restResponse.setMimeType( "text/html" );
restResponse.setRenderer( "html" );
}
Expand Down
17 changes: 17 additions & 0 deletions interceptors/DataApiInterceptors.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ component extends="coldbox.system.Interceptor" {
property name="dataApiService" inject="delayedInjector:dataApiService";
property name="dataApiQueueService" inject="delayedInjector:dataApiQueueService";
property name="dataApiConfigurationService" inject="delayedInjector:dataApiConfigurationService";
property name="presideObjectService" inject="delayedInjector:presideObjectService";
property name="interceptorService" inject="coldbox:InterceptorService";

variables._applicationLoaded = false;
Expand Down Expand Up @@ -116,6 +117,22 @@ component extends="coldbox.system.Interceptor" {

if( isEmptyString( interceptData.id ?: "" ) ){
interceptData.deletedIds = dataApiQueueService.getDeletedRecordIds( argumentCollection = interceptData );

if ( ArrayLen( interceptData.deletedIds ) && dataApiConfigurationService.isObjectQueueDeleteDetailEnabled( objectName=interceptData.objectName ) ) {
var deletedQuery = presideObjectService.selectData(
objectName = interceptData.objectName
, filter = { id=interceptData.deletedIds }
, selectFields = dataApiConfigurationService.getSelectFields( entity=dataApiConfigurationService.getObjectEntity( objectName=interceptData.objectName ) )
);

if ( deletedQuery.recordcount ) {
interceptData.deletedRecords = {};

for ( var row in deletedQuery ) {
interceptData.deletedRecords[ row.id ] = row;
}
}
}
}
}

Expand Down
1 change: 1 addition & 0 deletions preside-objects/data_api_queue.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* @versioned false
* @nolabel true
* @noDateModified true
* @feature dataApiQueue
*/
component {
property name="object_name" type="string" dbtype="varchar" maxlength=100 required=true indexes="object_name";
Expand Down
1 change: 1 addition & 0 deletions preside-objects/data_api_user_settings.cfc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* @versioned false
* @nolabel true
* @feature restTokenAuth
*/
component {
property name="user" relatedto="rest_user" relationship="many-to-one" required=true uniqueindexes="userobject|1";
Expand Down
15 changes: 15 additions & 0 deletions services/DataApiConfigurationService.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,21 @@ component {
} );
}

public boolean function isObjectQueueDeleteDetailEnabled( required string objectName, string namespace=_getDataApiNamespace() ) {
var args = arguments;
var cacheKey = "isObjectQueueDeleteDetailEnabled-#arguments.objectName#-#arguments.namespace#";

return _simpleLocalCache( cacheKey, function(){
if ( !isObjectQueueEnabled( args.objectName, args.namespace ) ) {
return false;
}

var queueDeleteDetailEnabled = $getPresideObjectService().getObjectAttribute( args.objectName, "dataApiQueueDeleteDetail#_getNamespaceWithSeparator( args.namespace )#" );

return _isTrue( queueDeleteDetailEnabled );
} );
}

public struct function getDefaultQueueConfig() {
return {
name = ""
Expand Down
17 changes: 12 additions & 5 deletions services/DataApiQueueService.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ component {
, recordId = record.record_id
, queueId = record.id
, timestamp = _unixTimestamp( record.dateCreated )
, record = IsJson( record.data ) ? DeserializeJson( record.data ) : {}
} );
break;
case "update":
Expand Down Expand Up @@ -243,10 +244,11 @@ component {
}

public void function queueDelete(
string objectName = ""
, string id = ""
, any filter = {}
, array deletedIds = []
string objectName = ""
, string id = ""
, any filter = {}
, array deletedIds = []
, struct deletedRecords = {}
) {
if( !Len( filter.id ?: "" ) && !Len( filter[ "#objectName#.id" ] ?: "" ) && arrayLen( deletedIds ) ) {
filter = { id = deletedIds };
Expand All @@ -257,7 +259,11 @@ component {
value = ListToArray( value );
}
for( var id in value ) {
queueDelete( arguments.objectName, id );
queueDelete(
objectName = arguments.objectName
, id = id
, deletedRecords = arguments.deletedRecords
);
}
return;
}
Expand All @@ -283,6 +289,7 @@ component {
, namespace = namespace
, queue_name = queueSettings.name
, operation = "delete"
, data = StructKeyExists( arguments.deletedRecords, arguments.id ) ? SerializeJSON( arguments.deletedRecords[ arguments.id ] ) : ""
} );
}

Expand Down
14 changes: 9 additions & 5 deletions services/DataApiSpecService.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,7 @@ component {
parameters = [{name="queueId", in="path", required=true, description=_i18nNamespaced( "dataapi:operation.queue.delete.params.queueId" ), schema={ type="string" } } ]
};
}

}


}

private void function _addEntitySpecs( required struct spec ) {
Expand Down Expand Up @@ -453,9 +450,16 @@ component {
};
}
}

tags.sort( function( a, b ){
return a.name > b.name ? 1 : -1;
if ( StructKeyExists( a, "x-sort-order" ) ) {
if ( !StructKeyExists( b, "x-sort-order" ) ) {
return 1;
} else if ( a[ "x-sort-order" ] != b[ "x-sort-order" ] ) {
return a[ "x-sort-order" ] > b[ "x-sort-order" ] ? 1 : -1;
}
}

return a.name > b.name ? 1 : ( a.name < b.name ? -1 : 0 );
} );

spec.tags.append( tags, true );
Expand Down

0 comments on commit 8454f0f

Please sign in to comment.