refactor: Unmarshal recurrer JSON in Updated and RecursBefore methods
This commit is contained in:
parent
f4ca723102
commit
7e094d04cc
|
@ -111,9 +111,17 @@ func (p *Postgres) Updated(ks []item.Kind, t time.Time) ([]item.Item, error) {
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var item item.Item
|
var item item.Item
|
||||||
var recurNext sql.NullTime
|
var recurNext sql.NullTime
|
||||||
if err := rows.Scan(&item.ID, &item.Kind, &item.Updated, &item.Deleted, &item.Body, &item.Recurrer, &recurNext); err != nil {
|
var recurrerJSON []byte
|
||||||
|
if err := rows.Scan(&item.ID, &item.Kind, &item.Updated, &item.Deleted, &item.Body, &recurrerJSON, &recurNext); err != nil {
|
||||||
return nil, fmt.Errorf("%w: %v", ErrPostgresFailure, err)
|
return nil, fmt.Errorf("%w: %v", ErrPostgresFailure, err)
|
||||||
}
|
}
|
||||||
|
if len(recurrerJSON) > 0 {
|
||||||
|
var recurrer item.Recur
|
||||||
|
if err := json.Unmarshal(recurrerJSON, &recurrer); err != nil {
|
||||||
|
return nil, fmt.Errorf("%w: %v", ErrPostgresFailure, err)
|
||||||
|
}
|
||||||
|
item.Recurrer = &recurrer
|
||||||
|
}
|
||||||
if recurNext.Valid {
|
if recurNext.Valid {
|
||||||
item.RecurNext = recurNext.Time
|
item.RecurNext = recurNext.Time
|
||||||
}
|
}
|
||||||
|
@ -139,9 +147,17 @@ func (p *Postgres) RecursBefore(date time.Time) ([]item.Item, error) {
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var item item.Item
|
var item item.Item
|
||||||
var recurNext sql.NullTime
|
var recurNext sql.NullTime
|
||||||
if err := rows.Scan(&item.ID, &item.Kind, &item.Updated, &item.Deleted, &item.Body, &item.Recurrer, &recurNext); err != nil {
|
var recurrerJSON []byte
|
||||||
|
if err := rows.Scan(&item.ID, &item.Kind, &item.Updated, &item.Deleted, &item.Body, &recurrerJSON, &recurNext); err != nil {
|
||||||
return nil, fmt.Errorf("%w: %v", ErrPostgresFailure, err)
|
return nil, fmt.Errorf("%w: %v", ErrPostgresFailure, err)
|
||||||
}
|
}
|
||||||
|
if len(recurrerJSON) > 0 {
|
||||||
|
var recurrer item.Recur
|
||||||
|
if err := json.Unmarshal(recurrerJSON, &recurrer); err != nil {
|
||||||
|
return nil, fmt.Errorf("%w: %v", ErrPostgresFailure, err)
|
||||||
|
}
|
||||||
|
item.Recurrer = &recurrer
|
||||||
|
}
|
||||||
if recurNext.Valid {
|
if recurNext.Valid {
|
||||||
item.RecurNext = recurNext.Time
|
item.RecurNext = recurNext.Time
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue