GetNotes returns a list of matching notes
(userID int, params GetNotesParams)
| 264 | |
| 265 | // GetNotes returns a list of matching notes |
| 266 | func (a *App) GetNotes(userID int, params GetNotesParams) (GetNotesResult, error) { |
| 267 | conn := getNotesBaseQuery(a.DB, userID, params) |
| 268 | |
| 269 | var total int64 |
| 270 | if err := conn.Model(database.Note{}).Count(&total).Error; err != nil { |
| 271 | return GetNotesResult{}, pkgErrors.Wrap(err, "counting total") |
| 272 | } |
| 273 | |
| 274 | notes := []database.Note{} |
| 275 | if total != 0 { |
| 276 | conn = orderGetNotes(conn) |
| 277 | conn = database.PreloadNote(conn) |
| 278 | conn = paginate(conn, params.Page, params.PerPage) |
| 279 | |
| 280 | if err := conn.Find(¬es).Error; err != nil { |
| 281 | return GetNotesResult{}, pkgErrors.Wrap(err, "finding notes") |
| 282 | } |
| 283 | } |
| 284 | |
| 285 | res := GetNotesResult{ |
| 286 | Notes: notes, |
| 287 | Total: total, |
| 288 | } |
| 289 | |
| 290 | return res, nil |
| 291 | } |