sumitasok
4/28/2016 - 11:07 AM

design-pattern-public-manage.go

  _id, preview_token
  permalink, preview_token

  type publicQueryGen bson.M
  type manageQueryGen bson.M

  func (qG publicQueryGen) Get(config) ([]Events, error) {
    var e []Ebvents
    err := return db(config.DB).C(config.C).Find(qG).All(&e)
    return e, err
  }

  (qG *publicQueryGen)HasID(id string) publicQueryGen {
  // removes multiple implementation
  if !id.IsValidBsonID(){
      return qG
    }

    qG["_id"] = bson.ObjectId(id)
    return qG
  }
  (qG *publicQueryGen) HasPermalink(permalink string) publicQueryGen{
    if permalink.IsBsonID(){
      return qG
    }
    qG["permalink"] = permalink
    return qG
  }

  (qG *manageQueryGen)HasID(id bson.ObjectId) manageQueryGen {
    qG["_id"] = id
    return qG
  }
  (qG *manageQueryGen) HasPermalink(permalink string) manageQueryGen{
    qG["permalink"] = permalink
    return qG
  }

  (qG *manageQueryGen) WithPreviewToken(preview_token string) publicQueryGen{
    qG["preview_token"] = preview_token
    return qG
  }

  //publicQueryGen.HasID(_id).WithPreviewToken(preview_token).Get()
  //publicQueryGen.HasPermalink(permalink).WithPreviewToken(preview_token)


  publicQueryGenEvent := new(publicQueryGen)

  if its ID {
    publicQueryGen.HasID(id)
  }


    publicQueryGenEvent.HasPermalink(permalink)


  if !(previewToken != "") {
    publicQueryGenEvent.HasPreviewToken(preview_token)
  }

  events, err := publicQueryGenEvent.Get(config)
  if err != nil {

  }