func DeleteComment(rdb *Store, profile *pb.Profile, entry *pb.Entry, commentId string) (*pb.Entry, error) { var err error index := -1 for i, cmt := range entry.Comments { if commentId == cmt.Id { index = i break } } if index >= 0 { entry.Comments = append(entry.Comments[:index], entry.Comments[index+1:]...) _, err = PutEntry(rdb, entry, true) } return entry, err }
func Comment(rdb *Store, profile *pb.Profile, entry *pb.Entry, comment *pb.Comment) (*UUIDKey, *pb.Entry, error) { var err error // is update? idx := -1 for i, cmt := range entry.Comments { if cmt.Id == comment.Id { // recheck perm if cmt.From.Id != comment.From.Id { return nil, nil, fmt.Errorf("403: perm error") } idx = i break } } if idx >= 0 { entry.Comments[idx] = comment } else { entry.Comments = append(entry.Comments, comment) } key, err := PutEntry(rdb, entry, true) return key, entry, err }