diff --git a/helpers.go b/helpers.go index c96f8e8..b7c7795 100644 --- a/helpers.go +++ b/helpers.go @@ -1,11 +1,6 @@ package main -import ( - "fmt" - "time" - - "github.com/lib/pq" -) +import "fmt" // ListOptions specifies general pagination options for fetching a list of results type ListOptions struct { @@ -36,15 +31,6 @@ func (o ListOptions) PerPageOrDefault() int64 { // DefaultPerPage is the default number of items to return in a paginated result set const DefaultPerPage = 10 -func currentTime() NullTime { - return NullTime{ - pq.NullTime{ - Time: time.Now(), - Valid: true, - }, - } -} - func valsIn(attribute string, values []int64, vals *[]interface{}, counter *int64) string { if len(values) == 1 { return fmt.Sprintf("%v=%v", attribute, values[0]) diff --git a/species.go b/species.go index fed8894..b5dca92 100644 --- a/species.go +++ b/species.go @@ -7,6 +7,7 @@ import ( "fmt" "net/url" "strings" + "time" ) var ( @@ -28,8 +29,8 @@ type SpeciesBase struct { SpeciesName string `db:"species_name" json:"speciesName"` TypeSpecies NullBool `db:"type_species" json:"typeSpecies"` Etymology NullString `db:"etymology" json:"etymology"` - CreatedAt NullTime `db:"created_at" json:"createdAt"` - UpdatedAt NullTime `db:"updated_at" json:"updatedAt"` + CreatedAt time.Time `db:"created_at" json:"createdAt"` + UpdatedAt time.Time `db:"updated_at" json:"updatedAt"` DeletedAt NullTime `db:"deleted_at" json:"deletedAt"` CreatedBy int64 `db:"created_by" json:"createdBy"` UpdatedBy int64 `db:"updated_by" json:"updatedBy"` @@ -130,7 +131,7 @@ func (s SpeciesService) get(id int64, genus string) (entity, error) { func (s SpeciesService) update(id int64, e *entity, claims Claims) error { species := (*e).(*Species) species.UpdatedBy = claims.Sub - species.UpdatedAt = currentTime() + species.UpdatedAt = time.Now() species.Id = id count, err := DBH.Update(species.SpeciesBase) @@ -145,7 +146,7 @@ func (s SpeciesService) update(id int64, e *entity, claims Claims) error { func (s SpeciesService) create(e *entity, claims Claims) error { species := (*e).(*Species) - ct := currentTime() + ct := time.Now() species.CreatedBy = claims.Sub species.CreatedAt = ct species.UpdatedBy = claims.Sub diff --git a/strains.go b/strains.go index ea9e2c1..d25e9dc 100644 --- a/strains.go +++ b/strains.go @@ -7,6 +7,7 @@ import ( "fmt" "net/url" "strings" + "time" ) var ( @@ -31,8 +32,8 @@ type StrainBase struct { WholeGenomeSequence NullString `db:"whole_genome_sequence" json:"wholeGenomeSequence"` IsolatedFrom NullString `db:"isolated_from" json:"isolatedFrom"` Notes NullString `db:"notes" json:"notes"` - CreatedAt NullTime `db:"created_at" json:"createdAt"` - UpdatedAt NullTime `db:"updated_at" json:"updatedAt"` + CreatedAt time.Time `db:"created_at" json:"createdAt"` + UpdatedAt time.Time `db:"updated_at" json:"updatedAt"` DeletedAt NullTime `db:"deleted_at" json:"deletedAt"` CreatedBy int64 `db:"created_by" json:"createdBy"` UpdatedBy int64 `db:"updated_by" json:"updatedBy"` @@ -133,7 +134,7 @@ func (s StrainService) get(id int64, genus string) (entity, error) { func (s StrainService) update(id int64, e *entity, claims Claims) error { strain := (*e).(*Strain) strain.UpdatedBy = claims.Sub - strain.UpdatedAt = currentTime() + strain.UpdatedAt = time.Now() strain.Id = id count, err := DBH.Update(strain.StrainBase) @@ -148,7 +149,7 @@ func (s StrainService) update(id int64, e *entity, claims Claims) error { func (s StrainService) create(e *entity, claims Claims) error { strain := (*e).(*Strain) - ct := currentTime() + ct := time.Now() strain.CreatedBy = claims.Sub strain.CreatedAt = ct strain.UpdatedBy = claims.Sub