feat(note/repo): added getall func
This commit is contained in:
parent
ba94ac781b
commit
4e921a8b0d
1 changed files with 24 additions and 0 deletions
|
|
@ -16,6 +16,7 @@ type INoteRepository interface {
|
|||
GetBySlug(ctx context.Context, slug string) (*models.Note, error)
|
||||
GetByPath(ctx context.Context, path string) (*models.Note, error)
|
||||
GetByTag(ctx context.Context, tag string) ([]*models.Note, error)
|
||||
GetAll(ctx context.Context, skip, top int) ([]*models.Note, error)
|
||||
GetNoteCount(ctx context.Context) (int, error)
|
||||
}
|
||||
|
||||
|
|
@ -138,3 +139,26 @@ func (r *noteRepository) GetByTag(ctx context.Context, tag string) ([]*models.No
|
|||
|
||||
return notes, nil
|
||||
}
|
||||
|
||||
func (r *noteRepository) GetAll(ctx context.Context, skip, top int) ([]*models.Note, error) {
|
||||
rows, err := r.readDBContext.QueryContext(ctx, `
|
||||
SELECT id, title, path, slug, created_at, updated_at
|
||||
FROM note
|
||||
ORDER BY created_at DESC
|
||||
LIMIT ? OFFSET ?`, top, skip)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
notes := make([]*models.Note, 0)
|
||||
for rows.Next() {
|
||||
var id, title, path, slug, createdAt, updatedAt string
|
||||
if err := rows.Scan(&id, &title, &path, &slug, &createdAt, &updatedAt); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
notes = append(notes, models.NewNote(id, path, title, slug, createdAt, updatedAt))
|
||||
}
|
||||
|
||||
return notes, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue