(db *gorm.DB, userID int, q GetNotesParams)
| 199 | } |
| 200 | |
| 201 | func getNotesBaseQuery(db *gorm.DB, userID int, q GetNotesParams) *gorm.DB { |
| 202 | conn := db.Where( |
| 203 | "notes.user_id = ? AND notes.deleted = ?", |
| 204 | userID, false, |
| 205 | ) |
| 206 | |
| 207 | if q.Search != "" { |
| 208 | conn = selectFTSFields(conn, nil) |
| 209 | conn = conn.Joins("INNER JOIN notes_fts ON notes_fts.rowid = notes.id") |
| 210 | conn = conn.Where("notes_fts MATCH ?", q.Search) |
| 211 | } |
| 212 | |
| 213 | if len(q.Books) > 0 { |
| 214 | conn = conn.Joins("INNER JOIN books ON books.uuid = notes.book_uuid"). |
| 215 | Where("books.label in (?)", q.Books) |
| 216 | } |
| 217 | |
| 218 | if q.Year != 0 || q.Month != 0 { |
| 219 | dateLowerbound, dateUpperbound := getDateBounds(q.Year, q.Month) |
| 220 | conn = conn.Where("notes.added_on >= ? AND notes.added_on < ?", dateLowerbound, dateUpperbound) |
| 221 | } |
| 222 | |
| 223 | return conn |
| 224 | } |
| 225 | |
| 226 | func getDateBounds(year, month int) (int64, int64) { |
| 227 | var yearUpperbound, monthUpperbound int |
no test coverage detected