Beispiel #1
0
        public void GetEventsFromDate()
        {
            DateTime     now    = DateTime.Now;
            List <Event> events = new List <Event>();
            var          user   = Rand.Next(int.MaxValue);

            for (int i = 0; i < 10; i++)
            {
                events.Add(ProcrastinatorCore.CreateEvent(new Event(user, Guid.NewGuid().ToString(), now)
                {
                    Description = "This is a test",
                    Color       = "#fff"
                }));
            }
            var rEvents = ProcrastinatorCore.GetEventsFromDay(now.Year, now.Month, now.Day, user);

            Debug.Write(events);
            Assert.IsNotNull(rEvents);
            Assert.IsTrue(events.Count == rEvents.Length, "Lengths Mismatch");
            foreach (Event e in events)
            {
                ProcrastinatorCore.RemoveEvent(e.Id);
            }
        }
Beispiel #2
0
        public APIModule() : base("/api")
        {
            StatelessAuthentication.Enable(this, ProcrastinatorCore.StatelessConfig);
            this.RequiresAuthentication();
            //Event
            Get["/event/all"] = _ =>
            {
                return(Response.AsJson(ProcrastinatorCore.GetAllEvents()));
            };

            Get["/event/{year}/{month}"] = date =>
            {
                return(Response.AsJson(ProcrastinatorCore.GetEventsFromMonth((int)date.year, (int)date.month, ((User)Context.CurrentUser).Id)));
            };

            Get["/event/{year}/{month}/{day}"] = date =>
            {
                return(Response.AsJson(ProcrastinatorCore.GetEventsFromDay((int)date.year, (int)date.month, (int)date.day, ((User)Context.CurrentUser).Id)));
            };

            Get["/event/{id}"] = e =>
            {
                return(ProcrastinatorCore.GetEvent((long)e.id));
            };

            Delete["/event/{id}"] = e =>
            {
                ProcrastinatorCore.RemoveEvent((long)e.id);
                return(new Response
                {
                    StatusCode = HttpStatusCode.OK
                });
            };

            Post["/event"] = e =>
            {
                var theEvent = this.Bind <Event>();
                Console.WriteLine(this.Context.Request.Body.AsString());
                theEvent.UserId = ((User)Context.CurrentUser).Id;
                ProcrastinatorCore.CreateEvent(theEvent);
                return(new Response
                {
                    StatusCode = HttpStatusCode.OK
                });
            };

            //Sticker
            Get["/sticker/{id}"] = s =>
            {
                return(Response.AsJson(ProcrastinatorCore.GetSticker((long)s.id)));
            };

            Delete["/sticker/{id}"] = s =>
            {
                ProcrastinatorCore.RemoveSticker((long)s.id);
                return(new Response
                {
                    StatusCode = HttpStatusCode.OK
                });
            };

            //User
            Get["/user/{id}"] = u =>
            {
                return(Response.AsJson(ProcrastinatorCore.GetUser((long)u.id)));
            };

            Delete["/user/{id}"] = u =>
            {
                ProcrastinatorCore.RemoveUser((long)u.id);
                return(new Response
                {
                    StatusCode = HttpStatusCode.OK
                });
            };
        }