Beispiel #1
0
        /*
         * sr -> sanatise         -> R . W . { vE } + Throwable
         *    -> validate context -> ( C . W )      + { vE } + Throwable
         *    -> apply            -> W . W' . evnt  + { vE } + Throwable
         */


        public static ServiceResponse apply
            (ServiceRequest request)
        {
            var command_result =
                request
                .fmap(sanitise)
                .fmap(transform_validation_result_to_command_context)
                // I. add_shift should be a simple command and I should lift it in the bind function.
                //     - The next step would then be to consider if I should have an equivalent to bind that just lift's the function into  a ->  Result b'
                .bind(add_shift)
            ;



            var ret =
                command_result.match(
                    s => new ServiceResponse(s.world, s.new_world, Enumerable.Empty <DomainEvent>()),
                    f => default(ServiceResponse)
                    );

            return(ret);
        }
Beispiel #2
0
        // Q. Complex data types from the attribute collection e.g. Date is created from three attributes?
        // Q. Lists from the attribute collection e.g. A request with a list of items?
        // Q. How do we deail with validation that is across sanitised fields?
        private static ValidationResult sanitise
            (ServiceRequest request)
        {
            return(new ValidationResult(
                       request.employee_schedules,
                       new Request(

                           title:
                           request
                           .attributes
                           .value_for("title", () => new AttributeCoundNotBeDeterminedInRequest())
                           .bind(val => Result <string> .success(val))
                           //,
                           //duration_in_seconds:
                           //    request
                           //     .attributes
                           //     .value_for("duration_in_seconds", () => new AttributeCoundNotBeDeterminedInRequest())
                           //     // Q. Can I add a convert method that has the same signature as verify?
                           //     .bind(duration => Results.ToInt(duration, () => new AttributeCoundNotBeConvertedToInt()))
                           //.verify(ClockTimes.SecondsAreWithinTwentyfourHourClock, () => new OutsideTwentyFourHourClockRange())

                           //, employee_names:
                           //    request
                           //    .attributes
                           //    .value_of("NewShiftRequest", "employee_names", () => new AttributeCoundNotBeDeterminedInRequest())
                           //    .bind(v => Results.ToStringCollection(v, () => new AttributeCoundNotBeConvertedToStringCollection()))

                           //, date:
                           //    request
                           //    .attributes
                           //    .value_of("NewShiftRequest", "dates", () => new AttributeCoundNotBeDeterminedInRequest())
                           //    .bind(v => Results.ToDate(v, () => new AttributeCoundNotBeConvertedTo<Date>()))


                           ),
                       new ResultError[] { }
                       ));
        }