Beispiel #1
0
// Remove Class from User Class List
func (c App) ClassRemove(dept string, num int) revel.Result {
	user, ok := c.Session["user"]
	if !ok {
		c.Response.Status = 403
		return c.Render()
	}

	var u models.User
	err := users.Find(map[string]string{"email": user}).One(&u)
	if err != nil {
		panic(err)
	}

	newBucket := make([]string, len(u.ClassBucket)-1)
	found := false
	i := 0
	for _, v := range u.ClassBucket {
		if v == fmt.Sprintf("%v %v", dept, num) && !found {
			found = true
			continue
		}
		newBucket[i] = v
		i++
	}
	u.ClassBucket = newBucket

	err = users.Update(map[string]string{"email": user}, u)
	if err != nil {
		panic(err)
	}

	return c.Redirect(routes.App.Index())
}
Beispiel #2
0
// Add Class to User Class List
func (c App) ClassAdd(dept string, num int) revel.Result {
	user, ok := c.Session["user"]
	if !ok {
		c.Response.Status = 403
		return c.Render()
	}

	var u models.User
	err := users.Find(map[string]string{"email": user}).One(&u)
	if err != nil {
		panic(err)
	}

	u.ClassBucket = append(u.ClassBucket, fmt.Sprintf("%v %v", dept, num))

	err = users.Update(map[string]string{"email": user}, u)
	if err != nil {
		panic(err)
	}

	return c.Redirect(routes.App.Index())
}