Reverting back to nulltime
This commit is contained in:
parent
e8c6a92427
commit
e5274e0e9d
7 changed files with 36 additions and 30 deletions
|
@ -8,7 +8,6 @@ import (
|
|||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -26,8 +25,8 @@ type CharacteristicTypeService struct{}
|
|||
type CharacteristicTypeBase struct {
|
||||
Id int64 `json:"id,omitempty"`
|
||||
CharacteristicTypeName string `db:"characteristic_type_name" json:"characteristicTypeName"`
|
||||
CreatedAt time.Time `db:"created_at" json:"createdAt"`
|
||||
UpdatedAt time.Time `db:"updated_at" json:"updatedAt"`
|
||||
CreatedAt NullTime `db:"created_at" json:"createdAt"`
|
||||
UpdatedAt NullTime `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"`
|
||||
|
|
|
@ -8,7 +8,6 @@ import (
|
|||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -28,8 +27,8 @@ type CharacteristicBase struct {
|
|||
CharacteristicName string `db:"characteristic_name" json:"characteristicName"`
|
||||
CharacteristicTypeId int64 `db:"characteristic_type_id" json:"characteristicType"`
|
||||
SortOrder NullInt64 `db:"sort_order" json:"sortOrder"`
|
||||
CreatedAt time.Time `db:"created_at" json:"createdAt"`
|
||||
UpdatedAt time.Time `db:"updated_at" json:"updatedAt"`
|
||||
CreatedAt NullTime `db:"created_at" json:"createdAt"`
|
||||
UpdatedAt NullTime `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"`
|
||||
|
|
12
helpers.go
12
helpers.go
|
@ -4,6 +4,9 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/lib/pq"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -54,3 +57,12 @@ func valsIn(attribute string, values []int64, vals *[]interface{}, counter *int6
|
|||
m = m[:len(m)-1] + ")"
|
||||
return m
|
||||
}
|
||||
|
||||
func currentTime() NullTime {
|
||||
return NullTime{
|
||||
pq.NullTime{
|
||||
Time: time.Now(),
|
||||
Valid: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@ import (
|
|||
"errors"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -35,8 +34,8 @@ type MeasurementBase struct {
|
|||
UnitTypeId NullInt64 `db:"unit_type_id" json:"-"`
|
||||
Notes NullString `db:"notes" json:"notes"`
|
||||
TestMethodId NullInt64 `db:"test_method_id" json:"-"`
|
||||
CreatedAt time.Time `db:"created_at" json:"createdAt"`
|
||||
UpdatedAt time.Time `db:"updated_at" json:"updatedAt"`
|
||||
CreatedAt NullTime `db:"created_at" json:"createdAt"`
|
||||
UpdatedAt NullTime `db:"updated_at" json:"updatedAt"`
|
||||
CreatedBy int64 `db:"created_by" json:"createdBy"`
|
||||
UpdatedBy int64 `db:"updated_by" json:"updatedBy"`
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@ import (
|
|||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -32,8 +31,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 time.Time `db:"created_at" json:"createdAt"`
|
||||
UpdatedAt time.Time `db:"updated_at" json:"updatedAt"`
|
||||
CreatedAt NullTime `db:"created_at" json:"createdAt"`
|
||||
UpdatedAt NullTime `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"`
|
||||
|
@ -134,7 +133,7 @@ func (s SpeciesService) get(id int64, genus string) (entity, *appError) {
|
|||
func (s SpeciesService) update(id int64, e *entity, claims Claims) *appError {
|
||||
species := (*e).(*Species)
|
||||
species.UpdatedBy = claims.Sub
|
||||
species.UpdatedAt = time.Now()
|
||||
species.UpdatedAt = currentTime()
|
||||
species.Id = id
|
||||
|
||||
count, err := DBH.Update(species.SpeciesBase)
|
||||
|
@ -149,7 +148,7 @@ func (s SpeciesService) update(id int64, e *entity, claims Claims) *appError {
|
|||
|
||||
func (s SpeciesService) create(e *entity, claims Claims) *appError {
|
||||
species := (*e).(*Species)
|
||||
ct := time.Now()
|
||||
ct := currentTime()
|
||||
species.CreatedBy = claims.Sub
|
||||
species.CreatedAt = ct
|
||||
species.UpdatedBy = claims.Sub
|
||||
|
|
|
@ -8,7 +8,6 @@ import (
|
|||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -35,8 +34,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 time.Time `db:"created_at" json:"createdAt"`
|
||||
UpdatedAt time.Time `db:"updated_at" json:"updatedAt"`
|
||||
CreatedAt NullTime `db:"created_at" json:"createdAt"`
|
||||
UpdatedAt NullTime `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"`
|
||||
|
@ -137,7 +136,7 @@ func (s StrainService) get(id int64, genus string) (entity, *appError) {
|
|||
func (s StrainService) update(id int64, e *entity, claims Claims) *appError {
|
||||
strain := (*e).(*Strain)
|
||||
strain.UpdatedBy = claims.Sub
|
||||
strain.UpdatedAt = time.Now()
|
||||
strain.UpdatedAt = currentTime()
|
||||
strain.Id = id
|
||||
|
||||
count, err := DBH.Update(strain.StrainBase)
|
||||
|
@ -152,7 +151,7 @@ func (s StrainService) update(id int64, e *entity, claims Claims) *appError {
|
|||
|
||||
func (s StrainService) create(e *entity, claims Claims) *appError {
|
||||
strain := (*e).(*Strain)
|
||||
ct := time.Now()
|
||||
ct := currentTime()
|
||||
strain.CreatedBy = claims.Sub
|
||||
strain.CreatedAt = ct
|
||||
strain.UpdatedBy = claims.Sub
|
||||
|
|
21
users.go
21
users.go
|
@ -6,7 +6,6 @@ import (
|
|||
"errors"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"time"
|
||||
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
)
|
||||
|
@ -26,14 +25,14 @@ func init() {
|
|||
type UserService struct{}
|
||||
|
||||
type User struct {
|
||||
Id int64 `json:"id,omitempty"`
|
||||
Email string `db:"email" json:"email"`
|
||||
Password string `db:"password" json:"-"`
|
||||
Name string `db:"name" json:"name"`
|
||||
Role string `db:"role" json:"role"`
|
||||
CreatedAt time.Time `db:"created_at" json:"createdAt"`
|
||||
UpdatedAt time.Time `db:"updated_at" json:"updatedAt"`
|
||||
DeletedAt NullTime `db:"deleted_at" json:"deletedAt"`
|
||||
Id int64 `json:"id,omitempty"`
|
||||
Email string `db:"email" json:"email"`
|
||||
Password string `db:"password" json:"-"`
|
||||
Name string `db:"name" json:"name"`
|
||||
Role string `db:"role" json:"role"`
|
||||
CreatedAt NullTime `db:"created_at" json:"createdAt"`
|
||||
UpdatedAt NullTime `db:"updated_at" json:"updatedAt"`
|
||||
DeletedAt NullTime `db:"deleted_at" json:"deletedAt"`
|
||||
}
|
||||
|
||||
type UserValidation struct {
|
||||
|
@ -122,7 +121,7 @@ func (u UserService) get(id int64, genus string) (entity, *appError) {
|
|||
|
||||
func (u UserService) update(id int64, e *entity, claims Claims) *appError {
|
||||
user := (*e).(*User)
|
||||
user.UpdatedAt = time.Now()
|
||||
user.UpdatedAt = currentTime()
|
||||
user.Id = id
|
||||
|
||||
count, err := DBH.Update(user)
|
||||
|
@ -140,7 +139,7 @@ func (u UserService) create(e *entity, claims Claims) *appError {
|
|||
if err := user.validate(); err != nil {
|
||||
return err
|
||||
}
|
||||
ct := time.Now()
|
||||
ct := currentTime()
|
||||
user.CreatedAt = ct
|
||||
user.UpdatedAt = ct
|
||||
hash, err := bcrypt.GenerateFromPassword([]byte(user.Password), 10)
|
||||
|
|
Reference in a new issue