item repository and api progress.

This commit is contained in:
2022-04-19 00:57:40 +02:00
parent 5ec3d938ab
commit b2624dc4ab
23 changed files with 1830 additions and 347 deletions
+46
View File
@@ -0,0 +1,46 @@
package sqltypes
import (
"database/sql/driver"
"errors"
"git.aiterp.net/stufflog3/stufflog3-api/internal/models"
"time"
)
type NullDate struct {
Date models.Date
Valid bool
}
func (n *NullDate) Scan(value interface{}) error {
if value == nil {
n.Valid = false
return nil
}
switch value := value.(type) {
case string:
date, err := models.ParseDate(value)
if err != nil {
return err
}
n.Date = date
n.Valid = true
case time.Time:
n.Date = models.Date{value.Year(), int(value.Month()), value.Day()}
n.Valid = true
default:
return errors.New("invalid type")
}
return nil
}
func (n NullDate) Value() (driver.Value, error) {
if !n.Valid {
return nil, nil
}
return n.Date.String(), nil
}