fixing up time types
This commit is contained in:
parent
8e386c3521
commit
4143e02cfd
3 changed files with 11 additions and 23 deletions
16
helpers.go
16
helpers.go
|
@ -1,11 +1,6 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import "fmt"
|
||||||
"fmt"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/lib/pq"
|
|
||||||
)
|
|
||||||
|
|
||||||
// ListOptions specifies general pagination options for fetching a list of results
|
// ListOptions specifies general pagination options for fetching a list of results
|
||||||
type ListOptions struct {
|
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
|
// DefaultPerPage is the default number of items to return in a paginated result set
|
||||||
const DefaultPerPage = 10
|
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 {
|
func valsIn(attribute string, values []int64, vals *[]interface{}, counter *int64) string {
|
||||||
if len(values) == 1 {
|
if len(values) == 1 {
|
||||||
return fmt.Sprintf("%v=%v", attribute, values[0])
|
return fmt.Sprintf("%v=%v", attribute, values[0])
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -28,8 +29,8 @@ type SpeciesBase struct {
|
||||||
SpeciesName string `db:"species_name" json:"speciesName"`
|
SpeciesName string `db:"species_name" json:"speciesName"`
|
||||||
TypeSpecies NullBool `db:"type_species" json:"typeSpecies"`
|
TypeSpecies NullBool `db:"type_species" json:"typeSpecies"`
|
||||||
Etymology NullString `db:"etymology" json:"etymology"`
|
Etymology NullString `db:"etymology" json:"etymology"`
|
||||||
CreatedAt NullTime `db:"created_at" json:"createdAt"`
|
CreatedAt time.Time `db:"created_at" json:"createdAt"`
|
||||||
UpdatedAt NullTime `db:"updated_at" json:"updatedAt"`
|
UpdatedAt time.Time `db:"updated_at" json:"updatedAt"`
|
||||||
DeletedAt NullTime `db:"deleted_at" json:"deletedAt"`
|
DeletedAt NullTime `db:"deleted_at" json:"deletedAt"`
|
||||||
CreatedBy int64 `db:"created_by" json:"createdBy"`
|
CreatedBy int64 `db:"created_by" json:"createdBy"`
|
||||||
UpdatedBy int64 `db:"updated_by" json:"updatedBy"`
|
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 {
|
func (s SpeciesService) update(id int64, e *entity, claims Claims) error {
|
||||||
species := (*e).(*Species)
|
species := (*e).(*Species)
|
||||||
species.UpdatedBy = claims.Sub
|
species.UpdatedBy = claims.Sub
|
||||||
species.UpdatedAt = currentTime()
|
species.UpdatedAt = time.Now()
|
||||||
species.Id = id
|
species.Id = id
|
||||||
|
|
||||||
count, err := DBH.Update(species.SpeciesBase)
|
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 {
|
func (s SpeciesService) create(e *entity, claims Claims) error {
|
||||||
species := (*e).(*Species)
|
species := (*e).(*Species)
|
||||||
ct := currentTime()
|
ct := time.Now()
|
||||||
species.CreatedBy = claims.Sub
|
species.CreatedBy = claims.Sub
|
||||||
species.CreatedAt = ct
|
species.CreatedAt = ct
|
||||||
species.UpdatedBy = claims.Sub
|
species.UpdatedBy = claims.Sub
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -31,8 +32,8 @@ type StrainBase struct {
|
||||||
WholeGenomeSequence NullString `db:"whole_genome_sequence" json:"wholeGenomeSequence"`
|
WholeGenomeSequence NullString `db:"whole_genome_sequence" json:"wholeGenomeSequence"`
|
||||||
IsolatedFrom NullString `db:"isolated_from" json:"isolatedFrom"`
|
IsolatedFrom NullString `db:"isolated_from" json:"isolatedFrom"`
|
||||||
Notes NullString `db:"notes" json:"notes"`
|
Notes NullString `db:"notes" json:"notes"`
|
||||||
CreatedAt NullTime `db:"created_at" json:"createdAt"`
|
CreatedAt time.Time `db:"created_at" json:"createdAt"`
|
||||||
UpdatedAt NullTime `db:"updated_at" json:"updatedAt"`
|
UpdatedAt time.Time `db:"updated_at" json:"updatedAt"`
|
||||||
DeletedAt NullTime `db:"deleted_at" json:"deletedAt"`
|
DeletedAt NullTime `db:"deleted_at" json:"deletedAt"`
|
||||||
CreatedBy int64 `db:"created_by" json:"createdBy"`
|
CreatedBy int64 `db:"created_by" json:"createdBy"`
|
||||||
UpdatedBy int64 `db:"updated_by" json:"updatedBy"`
|
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 {
|
func (s StrainService) update(id int64, e *entity, claims Claims) error {
|
||||||
strain := (*e).(*Strain)
|
strain := (*e).(*Strain)
|
||||||
strain.UpdatedBy = claims.Sub
|
strain.UpdatedBy = claims.Sub
|
||||||
strain.UpdatedAt = currentTime()
|
strain.UpdatedAt = time.Now()
|
||||||
strain.Id = id
|
strain.Id = id
|
||||||
|
|
||||||
count, err := DBH.Update(strain.StrainBase)
|
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 {
|
func (s StrainService) create(e *entity, claims Claims) error {
|
||||||
strain := (*e).(*Strain)
|
strain := (*e).(*Strain)
|
||||||
ct := currentTime()
|
ct := time.Now()
|
||||||
strain.CreatedBy = claims.Sub
|
strain.CreatedBy = claims.Sub
|
||||||
strain.CreatedAt = ct
|
strain.CreatedAt = ct
|
||||||
strain.UpdatedBy = claims.Sub
|
strain.UpdatedBy = claims.Sub
|
||||||
|
|
Reference in a new issue