Exemple #1
0
// Delete removes a group from database
func Delete(c *echo.Context) (int, interface{}) {
	digitsID, ok := c.Get("digitsID").(int64)
	if !ok {
		return msg.Forbidden("session required")
	}

	// Get group id and convert from string to objectId
	rawGID := c.Param("gid")
	if !bson.IsObjectIdHex(rawGID) {
		return msg.BadRequest("bad id: not a ObjectId")
	}

	// find the group
	groupID := bson.ObjectIdHex(rawGID)
	err := mangos.Delete(constants.CGroups, bson.M{
		"$and": []bson.M{
			bson.M{"_id": groupID},
			bson.M{"admins": digitsID},
		},
	})
	if err != nil {
		return msg.InternalError(err)
	}

	return msg.Ok("deleted")
}
Exemple #2
0
// Delete inserts a new friendship in database
func Delete(c *echo.Context) (int, interface{}) {
	digitsID, ok := c.Get("digitsID").(int64)
	if !ok {
		return msg.Forbidden("session required")
	}

	friendID, err := strconv.Atoi(c.Param("id"))
	if err != nil {
		return msg.BadRequest(err)
	}

	err = mangos.Delete(constants.CFriends, bson.M{"friend_id": int64(friendID), "digits_id": digitsID})
	if err != nil {
		return msg.InternalError(err)
	}

	return msg.Ok("deleted")
}