예제 #1
0
//Fetch a wiki record by its slug
func (wm *WikiManager) ReadBySlug(slug string, wikiRecord *WikiRecord,
	curUser *CurrentUserInfo) (string, error) {
	auth := curUser.Auth
	mainDb := MainDbName()
	cDb := Connection.SelectDB(mainDb, auth)
	response := WikiSlugViewResponse{}
	err := cDb.GetView("wiki_query", "getWikiBySlug", &response, wikit.SetKey(slug))
	if err != nil {
		return "", err
	}
	if len(response.Rows) > 0 {
		*wikiRecord = response.Rows[0].Value.WikiRecord
		wikiRecord.Id = response.Rows[0].Id
		return response.Rows[0].Value.Rev, nil
	} else {
		return "", NotFoundError()
	}
}
예제 #2
0
// Read a page by its slug.
// Assume the wiki Id passed in is a slug also
// Returns the WikiId, the Page Rev, and an error
func (pm *PageManager) ReadBySlug(wikiSlug string, pageSlug string,
	page *wikit.Page, curUser *CurrentUserInfo) (string, string, error) {
	// Need to get the true wiki Id from the slug
	auth := curUser.Auth
	mainDbName := MainDbName()
	mainDb := Connection.SelectDB(mainDbName, auth)
	response := WikiSlugViewResponse{}
	err := mainDb.GetView("wiki_query",
		"getWikiBySlug",
		&response,
		wikit.SetKey(wikiSlug))
	if err != nil {
		return "", "", err
	}
	if len(response.Rows) > 0 {
		wikiId := response.Rows[0].Id
		theWiki := wikit.SelectWiki(Connection, wikiDbString(wikiId), auth)
		pageRev, err := theWiki.ReadPageBySlug(pageSlug, page)
		return wikiId, pageRev, err
	} else {
		return "", "", NotFoundError()
	}
}