Update link repository use Links type

This commit is contained in:
Andrey Chervyakov 2021-03-15 01:23:50 +06:00
parent 4c78b655ce
commit 221eb3f346

View file

@ -13,7 +13,7 @@ import (
type Repository interface {
Save(link *Link) error
FindById(id string) (*Link, error)
FindAll(limit int, offset int) ([]Link, error)
FindAll(limit int, offset int) (Links, error)
DeleteById(id string) error
}
@ -80,7 +80,7 @@ func (r *PgRepository) FindById(id string) (*Link, error) {
return entity, nil
}
func (r *PgRepository) FindAll(limit int, offset int) ([]Link, error) {
func (r *PgRepository) FindAll(limit int, offset int) (Links, error) {
if limit < 0 {
return nil, errors.New("limit can't be negative")
}
@ -110,7 +110,7 @@ func (r *PgRepository) FindAll(limit int, offset int) ([]Link, error) {
}
defer rows.Close()
links := make([]Link, 0)
links := make(Links, 0)
for rows.Next() {
link, err := mapRowToEntity(rows)
if err != nil {
@ -118,7 +118,7 @@ func (r *PgRepository) FindAll(limit int, offset int) ([]Link, error) {
return nil, err
}
links = append(links, *link)
links = append(links, link)
}
if err = rows.Err(); err != nil {