Ejemplo n.º 1
0
        public DeleteToDoEndPoint(string modulePath, [NotNull] ToDoDataStore dataStore)
            : base(modulePath)
        {
            if (dataStore == null)
            {
                throw new ArgumentNullException(nameof(dataStore));
            }

            _dataStore = dataStore;

            Delete["{id}"] = _ => Handle(this.Bind <DeleteToDoRequest>());
        }
Ejemplo n.º 2
0
        private static void CreateRandomToDos(ToDoDataStore dataStore)
        {
            foreach (var thingToDo in GetRandomThingsToDo())
            {
                var toDo = dataStore.Create(thingToDo);

                if (_rnd.NextDouble() < 0.5)
                {
                    dataStore.Complete(toDo.Id);
                }
            }
        }
Ejemplo n.º 3
0
        public void Initialize(IRegistry registry)
        {
            var modulePath = "/api/todos/";
            var dataStore  = new ToDoDataStore();

            CreateRandomToDos(dataStore);

            registry.RegisterNancyEndPoint(() => new CreateToDoEndPoint(modulePath, dataStore));
            registry.RegisterNancyEndPoint(() => new CompleteToDoEndPoint(modulePath, dataStore));
            registry.RegisterNancyEndPoint(() => new UpdateToDoEndPoint(modulePath, dataStore));
            registry.RegisterNancyEndPoint(() => new DeleteToDoEndPoint(modulePath, dataStore));
            registry.RegisterNancyEndPoint(() => new GetToDoesEndPoint(modulePath, dataStore));
        }
Ejemplo n.º 4
0
        public GetToDoesEndPoint(string modulePath, [NotNull] ToDoDataStore dataStore)
            : base(modulePath)
        {
            if (dataStore == null)
            {
                throw new ArgumentNullException(nameof(dataStore));
            }

            _dataStore = dataStore;

            Get["{id}"]         = _ => GetById(this.Bind <GetByIdRequest>());
            Get["/uncompleted"] = _ => GetAllUncompleted();
            Get["/completed"]   = _ => GetAllCompleted();
        }