(u *User)
| 2161 | } |
| 2162 | |
| 2163 | func (db *datastore) GetUserPosts(u *User) (*[]PublicPost, error) { |
| 2164 | rows, err := db.Query("SELECT p.id, p.slug, p.view_count, p.title, p.created, p.updated, p.content, p.text_appearance, p.language, p.rtl, c.alias, c.title, c.description, c.view_count FROM posts p LEFT JOIN collections c ON collection_id = c.id WHERE p.owner_id = ? ORDER BY created ASC", u.ID) |
| 2165 | if err != nil { |
| 2166 | log.Error("Failed selecting from posts: %v", err) |
| 2167 | return nil, impart.HTTPError{http.StatusInternalServerError, "Couldn't retrieve user posts."} |
| 2168 | } |
| 2169 | defer rows.Close() |
| 2170 | |
| 2171 | posts := []PublicPost{} |
| 2172 | var gotErr bool |
| 2173 | for rows.Next() { |
| 2174 | p := Post{} |
| 2175 | c := Collection{} |
| 2176 | var alias, title, description sql.NullString |
| 2177 | var views sql.NullInt64 |
| 2178 | err = rows.Scan(&p.ID, &p.Slug, &p.ViewCount, &p.Title, &p.Created, &p.Updated, &p.Content, &p.Font, &p.Language, &p.RTL, &alias, &title, &description, &views) |
| 2179 | if err != nil { |
| 2180 | log.Error("Failed scanning User.getPosts() row: %v", err) |
| 2181 | gotErr = true |
| 2182 | break |
| 2183 | } |
| 2184 | p.extractData() |
| 2185 | pubPost := p.processPost() |
| 2186 | |
| 2187 | if alias.Valid && alias.String != "" { |
| 2188 | c.Alias = alias.String |
| 2189 | c.Title = title.String |
| 2190 | c.Description = description.String |
| 2191 | c.Views = views.Int64 |
| 2192 | pubPost.Collection = &CollectionObj{Collection: c} |
| 2193 | } |
| 2194 | |
| 2195 | posts = append(posts, pubPost) |
| 2196 | } |
| 2197 | err = rows.Err() |
| 2198 | if err != nil { |
| 2199 | log.Error("Error after Next() on rows: %v", err) |
| 2200 | } |
| 2201 | |
| 2202 | if gotErr && len(posts) == 0 { |
| 2203 | // There were a lot of errors |
| 2204 | return nil, impart.HTTPError{http.StatusInternalServerError, "Unable to get data."} |
| 2205 | } |
| 2206 | |
| 2207 | return &posts, nil |
| 2208 | } |
| 2209 | |
| 2210 | func (db *datastore) GetUserPostsCount(userID int64) int64 { |
| 2211 | var count int64 |
nothing calls this directly
no test coverage detected