@@ -448,4 +448,150 @@ public async Task<IActionResult> DeleteEdge(string graphId, string edgeId)
448448 new { message = "An error occurred while deleting the edge." , error = ex . Message } ) ;
449449 }
450450 }
451+
452+ /// <summary>
453+ /// Simulate a PGT definition
454+ /// </summary>
455+ /// <param name="graphId">The graph identifier</param>
456+ /// <param name="definitionId">The PGT definition identifier</param>
457+ /// <param name="request">The simulation request containing start node and options</param>
458+ /// <returns>Simulation result with trace log and visited nodes</returns>
459+ #if DEBUG
460+ [ AllowAnonymous ]
461+ #endif
462+ [ HttpPost ( "/membase/{graphId}/pgt-definitions/{definitionId}/simulate" ) ]
463+ [ ProducesResponseType ( StatusCodes . Status200OK ) ]
464+ [ ProducesResponseType ( StatusCodes . Status400BadRequest ) ]
465+ [ ProducesResponseType ( StatusCodes . Status500InternalServerError ) ]
466+ public async Task < IActionResult > SimulatePgtDefinition ( string graphId , string definitionId , [ FromBody ] PgtSimulationRequest request )
467+ {
468+ if ( string . IsNullOrWhiteSpace ( graphId ) )
469+ {
470+ return BadRequest ( "Graph ID cannot be empty." ) ;
471+ }
472+
473+ if ( string . IsNullOrWhiteSpace ( definitionId ) )
474+ {
475+ return BadRequest ( "Definition ID cannot be empty." ) ;
476+ }
477+
478+ if ( string . IsNullOrWhiteSpace ( request ? . StartId ) )
479+ {
480+ return BadRequest ( "Start ID cannot be empty." ) ;
481+ }
482+
483+ try
484+ {
485+ request . Options ??= new ( ) ;
486+ if ( string . IsNullOrEmpty ( request . Options . RunId ) )
487+ {
488+ request . Options . RunId = $ "sim-{ Guid . NewGuid ( ) } ";
489+ }
490+
491+ var result = await _membaseApi . SimulatePgtDefinitionAsync ( graphId , definitionId , request ) ;
492+ result . RunId = request . Options . RunId ;
493+ return Ok ( result ) ;
494+ }
495+ catch ( Exception ex )
496+ {
497+ return StatusCode (
498+ StatusCodes . Status500InternalServerError ,
499+ new { message = "An error occurred while simulating the PGT definition." , error = ex . Message } ) ;
500+ }
501+ }
502+
503+ /// <summary>
504+ /// Traverse a PGT definition
505+ /// </summary>
506+ /// <param name="graphId">The graph identifier</param>
507+ /// <param name="definitionId">The PGT definition identifier</param>
508+ /// <param name="request">The traversal request containing start node and options</param>
509+ /// <returns>Traversal result with context, visited nodes, and trace log</returns>
510+ #if DEBUG
511+ [ AllowAnonymous ]
512+ #endif
513+ [ HttpPost ( "/membase/{graphId}/pgt-definitions/{definitionId}/traverse" ) ]
514+ [ ProducesResponseType ( StatusCodes . Status200OK ) ]
515+ [ ProducesResponseType ( StatusCodes . Status400BadRequest ) ]
516+ [ ProducesResponseType ( StatusCodes . Status500InternalServerError ) ]
517+ public async Task < IActionResult > TraversePgtDefinition ( string graphId , string definitionId , [ FromBody ] PgtTraversalRequest request )
518+ {
519+ if ( string . IsNullOrWhiteSpace ( graphId ) )
520+ {
521+ return BadRequest ( "Graph ID cannot be empty." ) ;
522+ }
523+
524+ if ( string . IsNullOrWhiteSpace ( definitionId ) )
525+ {
526+ return BadRequest ( "Definition ID cannot be empty." ) ;
527+ }
528+
529+ if ( string . IsNullOrWhiteSpace ( request ? . StartId ) )
530+ {
531+ return BadRequest ( "Start ID cannot be empty." ) ;
532+ }
533+
534+ try
535+ {
536+ request . Options ??= new ( ) ;
537+ if ( string . IsNullOrEmpty ( request . Options . RunId ) )
538+ {
539+ request . Options . RunId = $ "trv-{ Guid . NewGuid ( ) } ";
540+ }
541+
542+ var result = await _membaseApi . TraversePgtDefinitionAsync ( graphId , definitionId , request ) ;
543+ result . RunId = request . Options . RunId ;
544+ return Ok ( result ) ;
545+ }
546+ catch ( Exception ex )
547+ {
548+ return StatusCode (
549+ StatusCodes . Status500InternalServerError ,
550+ new { message = "An error occurred while traversing the PGT definition." , error = ex . Message } ) ;
551+ }
552+ }
553+
554+ /// <summary>
555+ /// Validate a PGT definition
556+ /// </summary>
557+ /// <param name="graphId">The graph identifier</param>
558+ /// <param name="definitionId">The PGT definition identifier</param>
559+ /// <param name="request">The validation request containing start node and options</param>
560+ /// <returns>Validation result with valid flag, errors, warnings, and stats</returns>
561+ #if DEBUG
562+ [ AllowAnonymous ]
563+ #endif
564+ [ HttpPost ( "/membase/{graphId}/pgt-definitions/{definitionId}/validate" ) ]
565+ [ ProducesResponseType ( StatusCodes . Status200OK ) ]
566+ [ ProducesResponseType ( StatusCodes . Status400BadRequest ) ]
567+ [ ProducesResponseType ( StatusCodes . Status500InternalServerError ) ]
568+ public async Task < IActionResult > ValidatePgtDefinition ( string graphId , string definitionId , [ FromBody ] PgtValidationRequest request )
569+ {
570+ if ( string . IsNullOrWhiteSpace ( graphId ) )
571+ {
572+ return BadRequest ( "Graph ID cannot be empty." ) ;
573+ }
574+
575+ if ( string . IsNullOrWhiteSpace ( definitionId ) )
576+ {
577+ return BadRequest ( "Definition ID cannot be empty." ) ;
578+ }
579+
580+ if ( string . IsNullOrWhiteSpace ( request ? . StartId ) )
581+ {
582+ return BadRequest ( "Start ID cannot be empty." ) ;
583+ }
584+
585+ try
586+ {
587+ var result = await _membaseApi . ValidatePgtDefinitionAsync ( graphId , definitionId , request ) ;
588+ return Ok ( result ) ;
589+ }
590+ catch ( Exception ex )
591+ {
592+ return StatusCode (
593+ StatusCodes . Status500InternalServerError ,
594+ new { message = "An error occurred while validating the PGT definition." , error = ex . Message } ) ;
595+ }
596+ }
451597}
0 commit comments