Exemplo n.º 1
0
        public ValidationResult Validate(SightingRequest request)
        {
            ValidationResult MissingFieldResult(string field)
            {
                return(new ValidationResult($"A sighting {field} must be specified."));
            }

            if (request == null)
            {
                return(new ValidationResult("No request found."));
            }

            if (string.IsNullOrWhiteSpace(request.Summary))
            {
                return(MissingFieldResult("summary"));
            }

            if (string.IsNullOrWhiteSpace(request.Origin))
            {
                return(MissingFieldResult("origin"));
            }

            if (string.IsNullOrWhiteSpace(request.CorellationId))
            {
                return(MissingFieldResult("correlationId"));
            }

            return(ValidationResult.Success);
        }
Exemplo n.º 2
0
        public async Task ReportSighting(SightingRequest validatedRequest, CancellationToken cancellationToken)
        {
            var correlationId = Guid.NewGuid();

            await _gateway.Publish(
                _translator.TranslateToNewSightingEvent(validatedRequest, correlationId),
                cancellationToken);
        }
Exemplo n.º 3
0
 public NewSightingReported TranslateToNewSightingEvent(SightingRequest request, Guid correlationId)
 {
     return(new NewSightingReported
     {
         Summary = request.Summary,
         Origin = request.Origin,
         ReportedCause = request.ReportedCause,
         CorrelationId = correlationId,
         SupplementalData = request.SupplementalData,
         ReportedCorrelationId = request.CorellationId,
         Timestamp = DateTime.UtcNow,
         IncludedTrace = request.IncludedTrace
     });
 }
Exemplo n.º 4
0
        public async Task <IActionResult> Report([FromBody] SightingRequest request,
                                                 CancellationToken cancellationToken)
        {
            try
            {
                var validate = _requestValidator.Validate(request);
                if (validate.Succeeded)
                {
                    await _service.ReportSighting(request, cancellationToken);

                    return(Ok());
                }

                return(BadRequest(new { rejectionReason = validate.Reason }));
            }
            catch (Exception ex)
            {
                _logger.Error($"Error occured while reporting a sighting. ${ex.Message}", ex);
                throw;
            }
        }