mirror of
https://github.com/hay-kot/homebox.git
synced 2025-08-04 08:40:28 +00:00
drop unused time field
This commit is contained in:
parent
98e3b6082e
commit
03c92a3502
7 changed files with 48 additions and 32 deletions
|
@ -1722,9 +1722,6 @@ const docTemplate = `{
|
||||||
"textValue": {
|
"textValue": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
"timeValue": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"type": {
|
"type": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
|
|
|
@ -1714,9 +1714,6 @@
|
||||||
"textValue": {
|
"textValue": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
"timeValue": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"type": {
|
"type": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,8 +93,6 @@ definitions:
|
||||||
type: integer
|
type: integer
|
||||||
textValue:
|
textValue:
|
||||||
type: string
|
type: string
|
||||||
timeValue:
|
|
||||||
type: string
|
|
||||||
type:
|
type:
|
||||||
type: string
|
type: string
|
||||||
type: object
|
type: object
|
||||||
|
|
|
@ -76,11 +76,13 @@ github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27k
|
||||||
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||||
github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng=
|
github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng=
|
||||||
github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||||
|
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
|
||||||
github.com/mattn/go-sqlite3 v1.14.16 h1:yOQRA0RpS5PFz/oikGwBEqvAWhWg5ufRz4ETLjwpU1Y=
|
github.com/mattn/go-sqlite3 v1.14.16 h1:yOQRA0RpS5PFz/oikGwBEqvAWhWg5ufRz4ETLjwpU1Y=
|
||||||
github.com/mattn/go-sqlite3 v1.14.16/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
|
github.com/mattn/go-sqlite3 v1.14.16/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
|
||||||
github.com/mitchellh/go-wordwrap v1.0.1 h1:TLuKupo69TCn6TQSyGxwI1EblZZEsQ0vMlAFQflz0v0=
|
github.com/mitchellh/go-wordwrap v1.0.1 h1:TLuKupo69TCn6TQSyGxwI1EblZZEsQ0vMlAFQflz0v0=
|
||||||
github.com/mitchellh/go-wordwrap v1.0.1/go.mod h1:R62XHJLzvMFRBbcrT7m7WgmE1eOyTSsCt+hzestvNj0=
|
github.com/mitchellh/go-wordwrap v1.0.1/go.mod h1:R62XHJLzvMFRBbcrT7m7WgmE1eOyTSsCt+hzestvNj0=
|
||||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
|
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
|
||||||
|
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
|
||||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
|
@ -90,6 +92,8 @@ github.com/rs/xid v1.4.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
|
||||||
github.com/rs/zerolog v1.29.0 h1:Zes4hju04hjbvkVkOhdl2HpZa+0PmVwigmo8XoORE5w=
|
github.com/rs/zerolog v1.29.0 h1:Zes4hju04hjbvkVkOhdl2HpZa+0PmVwigmo8XoORE5w=
|
||||||
github.com/rs/zerolog v1.29.0/go.mod h1:NILgTygv/Uej1ra5XxGf82ZFSLk58MFGAUS2o6usyD0=
|
github.com/rs/zerolog v1.29.0/go.mod h1:NILgTygv/Uej1ra5XxGf82ZFSLk58MFGAUS2o6usyD0=
|
||||||
github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ=
|
github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ=
|
||||||
|
github.com/spf13/cobra v1.6.1 h1:o94oiPyS4KD1mPy2fmcYYHHfCxLqYjJOhGsCHFZtEzA=
|
||||||
|
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||||
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
||||||
|
|
|
@ -45,7 +45,7 @@ type (
|
||||||
TextValue string `json:"textValue"`
|
TextValue string `json:"textValue"`
|
||||||
NumberValue int `json:"numberValue"`
|
NumberValue int `json:"numberValue"`
|
||||||
BooleanValue bool `json:"booleanValue"`
|
BooleanValue bool `json:"booleanValue"`
|
||||||
TimeValue time.Time `json:"timeValue,omitempty"`
|
// TimeValue time.Time `json:"timeValue,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemCreate struct {
|
ItemCreate struct {
|
||||||
|
@ -198,7 +198,7 @@ func mapFields(fields []*ent.ItemField) []ItemField {
|
||||||
TextValue: f.TextValue,
|
TextValue: f.TextValue,
|
||||||
NumberValue: f.NumberValue,
|
NumberValue: f.NumberValue,
|
||||||
BooleanValue: f.BooleanValue,
|
BooleanValue: f.BooleanValue,
|
||||||
TimeValue: f.TimeValue,
|
// TimeValue: f.TimeValue,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
|
@ -585,7 +585,7 @@ func (e *ItemsRepository) UpdateByGroup(ctx context.Context, GID uuid.UUID, data
|
||||||
SetTextValue(f.TextValue).
|
SetTextValue(f.TextValue).
|
||||||
SetNumberValue(f.NumberValue).
|
SetNumberValue(f.NumberValue).
|
||||||
SetBooleanValue(f.BooleanValue).
|
SetBooleanValue(f.BooleanValue).
|
||||||
SetTimeValue(f.TimeValue).
|
// SetTimeValue(f.TimeValue).
|
||||||
Save(ctx)
|
Save(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ItemOut{}, err
|
return ItemOut{}, err
|
||||||
|
@ -601,8 +601,8 @@ func (e *ItemsRepository) UpdateByGroup(ctx context.Context, GID uuid.UUID, data
|
||||||
SetName(f.Name).
|
SetName(f.Name).
|
||||||
SetTextValue(f.TextValue).
|
SetTextValue(f.TextValue).
|
||||||
SetNumberValue(f.NumberValue).
|
SetNumberValue(f.NumberValue).
|
||||||
SetBooleanValue(f.BooleanValue).
|
SetBooleanValue(f.BooleanValue)
|
||||||
SetTimeValue(f.TimeValue)
|
// SetTimeValue(f.TimeValue)
|
||||||
|
|
||||||
_, err = opt.Save(ctx)
|
_, err = opt.Save(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -1,6 +1,11 @@
|
||||||
package types
|
package types
|
||||||
|
|
||||||
import "time"
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
// Date is a custom type that implements the MarshalJSON interface
|
// Date is a custom type that implements the MarshalJSON interface
|
||||||
// that applies date only formatting to the time.Time fields in order
|
// that applies date only formatting to the time.Time fields in order
|
||||||
|
@ -34,17 +39,20 @@ func DateFromString(s string) Date {
|
||||||
return Date{}
|
return Date{}
|
||||||
}
|
}
|
||||||
|
|
||||||
t, err := time.Parse("2006-01-02", s)
|
try := [...]string{
|
||||||
if err != nil {
|
"2006-01-02",
|
||||||
// TODO: Remove - used by legacy importer
|
"01/02/2006",
|
||||||
t, err = time.Parse("01/02/2006", s)
|
time.RFC3339,
|
||||||
|
}
|
||||||
|
|
||||||
if err != nil {
|
for _, format := range try {
|
||||||
return Date{}
|
t, err := time.Parse(format, s)
|
||||||
|
if err == nil {
|
||||||
|
return DateFromTime(t)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return DateFromTime(t)
|
return Date{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d Date) String() string {
|
func (d Date) String() string {
|
||||||
|
@ -63,24 +71,37 @@ func (d Date) MarshalJSON() ([]byte, error) {
|
||||||
return []byte(`"` + d.String() + `"`), nil
|
return []byte(`"` + d.String() + `"`), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Date) UnmarshalJSON(data []byte) error {
|
func (d *Date) UnmarshalJSON(data []byte) (err error) {
|
||||||
str := string(data)
|
// unescape the string if necessary `\"` -> `"`
|
||||||
if str == `""` {
|
str := strings.Trim(string(data), "\"")
|
||||||
|
fmt.Printf("str: %q\n", str)
|
||||||
|
if str == "" || str == "null" || str == `""` {
|
||||||
|
println("empty date")
|
||||||
*d = Date{}
|
*d = Date{}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try YYYY-MM-DD format
|
try := [...]string{
|
||||||
|
"2006-01-02",
|
||||||
|
"01/02/2006",
|
||||||
|
time.RFC3339,
|
||||||
|
}
|
||||||
|
|
||||||
|
set := false
|
||||||
var t time.Time
|
var t time.Time
|
||||||
t, err := time.Parse("2006-01-02", str)
|
|
||||||
if err != nil {
|
for _, format := range try {
|
||||||
// Try default interface
|
t, err = time.Parse(format, str)
|
||||||
err = t.UnmarshalJSON(data)
|
if err == nil {
|
||||||
if err != nil {
|
set = true
|
||||||
return err
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !set {
|
||||||
|
return errors.New("invalid date format")
|
||||||
|
}
|
||||||
|
|
||||||
// strip the time and timezone information
|
// strip the time and timezone information
|
||||||
*d = DateFromTime(t)
|
*d = DateFromTime(t)
|
||||||
|
|
||||||
|
|
|
@ -66,7 +66,6 @@ export interface ItemField {
|
||||||
name: string;
|
name: string;
|
||||||
numberValue: number;
|
numberValue: number;
|
||||||
textValue: string;
|
textValue: string;
|
||||||
timeValue: string;
|
|
||||||
type: string;
|
type: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue