public async Task <IActionResult> GetStatements([FromQuery] Queries.PagedStatementsQuery parameters, CancellationToken cancellationToken = default) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } ResultFormat format = parameters.Format ?? ResultFormat.Exact; if (!StringValues.IsNullOrEmpty(Request.Headers[HeaderNames.AcceptLanguage])) { format = ResultFormat.Canonical; } bool attachments = parameters.Attachments.GetValueOrDefault(); if (parameters.StatementId.HasValue || parameters.VoidedStatementId.HasValue) { IRequest <StatementEntity> requestQuery = null; if (parameters.StatementId.HasValue) { Guid statementId = parameters.StatementId.Value; requestQuery = Queries.StatementQuery.Create(statementId, attachments, format); } else if (parameters.VoidedStatementId.HasValue) { Guid voidedStatementId = parameters.VoidedStatementId.Value; requestQuery = Queries.VoidedStatemetQuery.Create(voidedStatementId, attachments, format); } StatementEntity statementEntity = await _mediator.Send(requestQuery, cancellationToken); if (statementEntity == null) { return(NotFound()); } var statement = _mapper.Map <Statement>(statementEntity); return(new StatementActionResult(statement, format)); } PagedStatementsResult pagedResult = await _mediator.Send(parameters, cancellationToken); var mappedStatements = _mapper.Map <IEnumerable <Statement> >(pagedResult.Statements); StatementsResult result = new StatementsResult() { Statements = new StatementCollection(mappedStatements) }; // Generate more url if (!string.IsNullOrEmpty(pagedResult.MoreToken)) { result.More = new Uri($"/xapi/statements?more={pagedResult.MoreToken}", UriKind.Relative); } return(new StatementsActionResult(result, format, attachments)); }
public async Task <IActionResult> GetStatements([FromQuery] Queries.PagedStatementsQuery parameters) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } ResultFormat format = parameters.Format ?? ResultFormat.Exact; if (parameters.StatementId.HasValue || parameters.VoidedStatementId.HasValue) { bool attachments = parameters.Attachments.GetValueOrDefault(); IRequest <Statement> requestQuery = null; if (parameters.StatementId.HasValue) { Guid statementId = parameters.StatementId.Value; requestQuery = Queries.StatementQuery.Create(statementId, attachments, format); } else if (parameters.VoidedStatementId.HasValue) { Guid voidedStatementId = parameters.VoidedStatementId.Value; requestQuery = Queries.VoidedStatemetQuery.Create(voidedStatementId, attachments, format); } Statement statement = await _mediator.Send(requestQuery); if (statement == null) { return(NotFound()); } return(new StatementActionResult(statement, format)); } PagedStatementsResult pagedResult = await _mediator.Send(parameters); StatementsResult result = new StatementsResult { Statements = pagedResult.Statements }; // Generate more url if (!string.IsNullOrEmpty(pagedResult.MoreToken)) { result.More = new Uri($"/xapi/statements?more={pagedResult.MoreToken}", UriKind.Relative); } return(new StatementsActionResult(result, format)); }
/// <inheritdoc/> public async Task <StatementsResult> GetStatementsResult(StatementsQuery parameters, CancellationToken cancellationToken = default) { HttpRequest request = httpContextAccessor.HttpContext.Request; IQueryCollection requestQuery = request.Query; var cmd = new PagedStatementsQuery() { ActivityId = parameters.ActivityId, Agent = parameters.Agent, Ascending = parameters.Ascending, Attachments = parameters.Attachments, Format = parameters.Format, Registration = parameters.Registration, RelatedActivities = parameters.RelatedActivities, RelatedAgents = parameters.RelatedAgents, Limit = parameters.Limit, Since = parameters.Since, Until = parameters.Until, StatementId = parameters.StatementId, VerbId = parameters.VerbId, VoidedStatementId = parameters.VoidedStatementId }; if (requestQuery.TryGetValue("cursor", out StringValues value)) { cmd.Cursor = (string)value; } var pagedResult = await mediator.Send(cmd, cancellationToken); var result = new StatementsResult() { Statements = mapper.Map <StatementCollection>(pagedResult.Statements) }; if (pagedResult.Cursor != null) { string cursor = pagedResult.Cursor; string relativePath = $"{request.Path}?cursor={cursor}"; result.More = new Uri(relativePath, UriKind.Relative); } return(result); }
public StatementsActionResult(StatementsResult result, ResultFormat format, bool attachments) { _result = result; _format = format; _attachments = attachments; }
public StatementsActionResult(StatementsResult result, ResultFormat format) { this.result = result; this.format = format; }