Esempio n. 1
0
        public async Task <IActionResult> GetLifeCyclePhase(
            [FromServices] BackofficeContext context,
            [FromRoute] string id,
            [FromRoute] int faseId,
            CancellationToken cancellationToken = default)
        {
            var projectionPosition = await context.GetProjectionPositionAsync(typeof(PublicServiceLifeCycleListProjections), cancellationToken);

            Response.Headers.Add(PublicServiceHeaderNames.LastObservedPosition, projectionPosition.ToString());

            await context.CheckPublicServiceAsync(id, cancellationToken);

            var publicServiceLifeCycleItem =
                await context
                .PublicServiceLifeCycleList
                .AsNoTracking()
                .SingleOrDefaultAsync(item => item.PublicServiceId == id && item.LifeCycleStageId == faseId, cancellationToken);

            if (publicServiceLifeCycleItem == null)
            {
                throw new ApiException("Onbestaande levensloopfase.", StatusCodes.Status404NotFound);
            }

            // TODO: Introduce soft delete for lifecycle
            //if (publicServiceLifeCycleItem.Removed)
            //    throw new ApiException("Levensloopfase werd verwijderd.", StatusCodes.Status410Gone);

            return(Ok(
                       new LifeCycleStageResponse(
                           publicServiceLifeCycleItem.LifeCycleStageType,
                           PublicServiceRegistry.LifeCycleStageType.Parse(publicServiceLifeCycleItem.LifeCycleStageType).Translation.Name,
                           publicServiceLifeCycleItem.From,
                           publicServiceLifeCycleItem.To)));
        }
Esempio n. 2
0
        public async Task <IActionResult> List(
            [FromServices] BackofficeContext context,
            [FromRoute] string id,
            CancellationToken cancellationToken = default)
        {
            await context.CheckPublicServiceAsync(id, cancellationToken);

            return(Ok(
                       await context
                       .PublicServiceLabelList
                       .AsNoTracking()
                       .Where(item => item.PublicServiceId == id)
                       .ToListAsync(cancellationToken)));
        }
Esempio n. 3
0
        public async Task <IActionResult> RemoveStageFromLifeCycle(
            [FromServices] BackofficeContext context,
            [FromCommandId] Guid commandId,
            [FromRoute] string id,
            [FromRoute] int faseId,
            CancellationToken cancellationToken = default)
        {
            await context.CheckPublicServiceAsync(id, cancellationToken);

            return(Accepted(
                       await Bus.Dispatch(
                           commandId,
                           new RemoveStageFromLifeCycle(new PublicServiceId(id), LifeCycleStageId.FromNumber(faseId)),
                           GetMetadata(),
                           cancellationToken)));
        }
Esempio n. 4
0
        public async Task <IActionResult> Put(
            [FromServices] BackofficeContext context,
            [FromCommandId] Guid commandId,
            [FromRoute] string id,
            [FromBody] UpdateLabelsRequest updateLabelsRequest,
            CancellationToken cancellationToken = default)
        {
            if (!TryValidateModel(updateLabelsRequest))
            {
                return(BadRequest(ModelState));
            }

            await context.CheckPublicServiceAsync(id, cancellationToken);

            return(Accepted(
                       await Bus.Dispatch(
                           commandId,
                           UpdateLabelsRequestMapping.Map(id, updateLabelsRequest),
                           GetMetadata(),
                           cancellationToken)));
        }
Esempio n. 5
0
        public async Task <IActionResult> ChangePeriodOfLifeCycleStage(
            [FromServices] BackofficeContext context,
            [FromCommandId] Guid commandId,
            [FromRoute] string id,
            [FromRoute] int faseId,
            [FromBody] ChangePeriodOfLifeCycleStageRequest request,
            CancellationToken cancellationToken = default)
        {
            if (!TryValidateModel(request))
            {
                return(BadRequest(ModelState));
            }

            await context.CheckPublicServiceAsync(id, cancellationToken);

            return(Accepted(
                       await Bus.Dispatch(
                           commandId,
                           ChangePeriodOfLifeCycleStageRequestMapping.Map(id, faseId, request),
                           GetMetadata(),
                           cancellationToken)));
        }
Esempio n. 6
0
        public async Task <IActionResult> ListLifeCycleStages(
            [FromServices] BackofficeContext context,
            [FromRoute] string id,
            CancellationToken cancellationToken = default)
        {
            var projectionPosition = await context.GetProjectionPositionAsync(typeof(PublicServiceLifeCycleListProjections), cancellationToken);

            Response.Headers.Add(PublicServiceHeaderNames.LastObservedPosition, projectionPosition.ToString());

            await context.CheckPublicServiceAsync(id, cancellationToken);

            var filter     = Request.ExtractFilteringRequest <LifeCycleFilter>();
            var sorting    = Request.ExtractSortingRequest();
            var pagination = Request.ExtractPaginationRequest();

            var pagedLifeCycle =
                new LifeCycleQuery(context, id)
                .Fetch(filter, sorting, pagination);

            Response.AddPagedQueryResultHeaders(pagedLifeCycle);

            return(Ok(await pagedLifeCycle.Items.ToListAsync(cancellationToken)));
        }