MCPcopy Index your code
hub / github.com/writefreely/writefreely / GetPinnedPosts

Method GetPinnedPosts

database.go:1899–1928  ·  view source on GitHub ↗
(coll *CollectionObj, includeFuture bool)

Source from the content-addressed store, hash-verified

1897}
1898
1899func (db *datastore) GetPinnedPosts(coll *CollectionObj, includeFuture bool) (*[]PublicPost, error) {
1900 // FIXME: sqlite-backed instances don't include ellipsis on truncated titles
1901 timeCondition := ""
1902 if !includeFuture {
1903 timeCondition = "AND created <= " + db.now()
1904 }
1905 rows, err := db.Query("SELECT id, slug, title, "+db.clip("content", 80)+", pinned_position FROM posts WHERE collection_id = ? AND pinned_position IS NOT NULL "+timeCondition+" ORDER BY pinned_position ASC", coll.ID)
1906 if err != nil {
1907 log.Error("Failed selecting pinned posts: %v", err)
1908 return nil, impart.HTTPError{http.StatusInternalServerError, "Couldn't retrieve pinned posts."}
1909 }
1910 defer rows.Close()
1911
1912 posts := []PublicPost{}
1913 for rows.Next() {
1914 p := &Post{}
1915 err = rows.Scan(&p.ID, &p.Slug, &p.Title, &p.Content, &p.PinnedPosition)
1916 if err != nil {
1917 log.Error("Failed scanning row: %v", err)
1918 break
1919 }
1920 p.extractData()
1921 p.augmentContent(&coll.Collection)
1922
1923 pp := p.processPost()
1924 pp.Collection = coll
1925 posts = append(posts, pp)
1926 }
1927 return &posts, nil
1928}
1929
1930func (db *datastore) GetCollections(u *User, hostName string) (*[]Collection, error) {
1931 rows, err := db.Query("SELECT id, alias, title, description, privacy, view_count FROM collections WHERE owner_id = ? ORDER BY id ASC", u.ID)

Callers

nothing calls this directly

Calls 6

nowMethod · 0.95
clipMethod · 0.95
extractDataMethod · 0.95
augmentContentMethod · 0.95
processPostMethod · 0.95
CloseMethod · 0.80

Tested by

no test coverage detected