コード例 #1
0
// Delete deletes a single reminder
func (gs *ReminderService) Delete(
	r *http.Request, req *ReminderIdReq, _ *endpoints.VoidMessage) error {

	c := endpoints.NewContext(r)
	key, err := datastore.DecodeKey(req.Id)
	if err != nil {
		return err
	}
	return datastore.Delete(c, key)
}
コード例 #2
0
// List responds with a list of all reminders ordered by Date field.
// Most recent reminders come first.
func (gs *ReminderService) List(
	r *http.Request, req *ReminderUserQuery, resp *RemindersList) error {

	c := endpoints.NewContext(r)

	username := req.UserName

	q := datastore.NewQuery("Reminder").Filter("User =", username)
	reminder := make([]*Reminder, 0, 10)
	keys, err := q.GetAll(c, &reminder)
	if err != nil {
		return err
	}
	for i, k := range keys {
		reminder[i].Id = k.Encode()
	}
	resp.Items = reminder
	return nil
}
コード例 #3
0
// createReminder creates a new Reminder based on provided NewReminder.
// It stores newly created Reminder with Content being that of NewReminder.Reminder.
// User field will have current username
func (gs *ReminderService) CreateReminder(
	r *http.Request, req *NewReminder, reminder *Reminder) error {

	c := endpoints.NewContext(r)

	reminder.Reminder = make([]string, 1)
	reminder.Reminder = append(req.List)
	reminder.Location = make([]float64, 0)
	reminder.Location = append(reminder.Location, req.Lat, req.Lng)
	reminder.Date = time.Now()
	reminder.User = req.UserName
	reminder.Title = req.Title
	reminder.Urgency = req.Urgency

	key, err := datastore.Put(
		c, datastore.NewIncompleteKey(c, "Reminder", nil), reminder)
	if err != nil {
		return err
	}

	reminder.Id = key.Encode()
	return nil
}