// Insert insert new group func Insert(group *tat.Group) error { cache.CleanAllGroups() group.ID = bson.NewObjectId().Hex() group.DateCreation = time.Now().Unix() err := store.Tat().CGroups.Insert(group) if err != nil { log.Errorf("Error while inserting new group %s", err) } return err }
// Create creates a new group func (*GroupsController) Create(ctx *gin.Context) { var groupBind tat.GroupJSON ctx.Bind(&groupBind) var groupIn tat.Group groupIn.Name = groupBind.Name groupIn.Description = groupBind.Description err := groupDB.Insert(&groupIn) if err != nil { log.Errorf("Error while InsertGroup %s", err) ctx.AbortWithError(http.StatusInternalServerError, err) return } ctx.JSON(http.StatusCreated, groupIn) }
// Update updates a group : name and description func Update(group *tat.Group, newGroupname, description string, user *tat.User) error { cache.CleanAllGroups() // Check if name already exists -> checked in controller err := store.Tat().CGroups.Update( bson.M{"_id": group.ID}, bson.M{"$set": bson.M{"name": newGroupname, "description": description}}) if err != nil { log.Errorf("Error while update group %s to %s:%s", group.Name, newGroupname, err.Error()) return fmt.Errorf("Error while update group") } group.Name = newGroupname group.Description = description return err }