parent
ae17363f8b
commit
2894efaf46
9 changed files with 9 additions and 34 deletions
|
@ -16,7 +16,6 @@ CREATE TABLE users (
|
|||
|
||||
created_at TIMESTAMP WITH TIME ZONE NOT NULL,
|
||||
updated_at TIMESTAMP WITH TIME ZONE NOT NULL,
|
||||
deleted_at TIMESTAMP WITH TIME ZONE NULL,
|
||||
|
||||
CONSTRAINT users_pkey PRIMARY KEY (id)
|
||||
);
|
||||
|
|
|
@ -11,18 +11,15 @@ CREATE TABLE species (
|
|||
|
||||
created_at TIMESTAMP WITH TIME ZONE NOT NULL,
|
||||
updated_at TIMESTAMP WITH TIME ZONE NOT NULL,
|
||||
deleted_at TIMESTAMP WITH TIME ZONE NULL,
|
||||
|
||||
created_by BIGINT NOT NULL,
|
||||
updated_by BIGINT NOT NULL,
|
||||
deleted_by BIGINT NULL,
|
||||
|
||||
CONSTRAINT species_pkey PRIMARY KEY (id),
|
||||
FOREIGN KEY (genus_id) REFERENCES genera(id),
|
||||
FOREIGN KEY (subspecies_species_id) REFERENCES species(id),
|
||||
FOREIGN KEY (created_by) REFERENCES users(id),
|
||||
FOREIGN KEY (updated_by) REFERENCES users(id),
|
||||
FOREIGN KEY (deleted_by) REFERENCES users(id)
|
||||
FOREIGN KEY (updated_by) REFERENCES users(id)
|
||||
);
|
||||
|
||||
CREATE INDEX genus_id_idx ON species (genus_id);
|
||||
|
|
|
@ -14,17 +14,14 @@ CREATE TABLE strains (
|
|||
|
||||
created_at TIMESTAMP WITH TIME ZONE NOT NULL,
|
||||
updated_at TIMESTAMP WITH TIME ZONE NOT NULL,
|
||||
deleted_at TIMESTAMP WITH TIME ZONE NULL,
|
||||
|
||||
created_by BIGINT NOT NULL,
|
||||
updated_by BIGINT NOT NULL,
|
||||
deleted_by BIGINT NULL,
|
||||
|
||||
CONSTRAINT strain_pkey PRIMARY KEY (id),
|
||||
FOREIGN KEY (species_id) REFERENCES species(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (created_by) REFERENCES users(id),
|
||||
FOREIGN KEY (updated_by) REFERENCES users(id),
|
||||
FOREIGN KEY (deleted_by) REFERENCES users(id)
|
||||
FOREIGN KEY (updated_by) REFERENCES users(id)
|
||||
);
|
||||
|
||||
CREATE INDEX species_id_idx ON strains (species_id);
|
||||
|
|
|
@ -7,15 +7,12 @@ CREATE TABLE characteristic_types (
|
|||
|
||||
created_at TIMESTAMP WITH TIME ZONE NOT NULL,
|
||||
updated_at TIMESTAMP WITH TIME ZONE NOT NULL,
|
||||
deleted_at TIMESTAMP WITH TIME ZONE NULL,
|
||||
|
||||
created_by BIGINT NOT NULL,
|
||||
updated_by BIGINT NOT NULL,
|
||||
deleted_by BIGINT NULL,
|
||||
|
||||
CONSTRAINT characteristic_types_pkey PRIMARY KEY (id),
|
||||
FOREIGN KEY (created_by) REFERENCES users(id),
|
||||
FOREIGN KEY (updated_by) REFERENCES users(id),
|
||||
FOREIGN KEY (deleted_by) REFERENCES users(id)
|
||||
FOREIGN KEY (updated_by) REFERENCES users(id)
|
||||
);
|
||||
|
||||
|
|
|
@ -9,17 +9,14 @@ CREATE TABLE characteristics (
|
|||
|
||||
created_at TIMESTAMP WITH TIME ZONE NOT NULL,
|
||||
updated_at TIMESTAMP WITH TIME ZONE NOT NULL,
|
||||
deleted_at TIMESTAMP WITH TIME ZONE NULL,
|
||||
|
||||
created_by BIGINT NOT NULL,
|
||||
updated_by BIGINT NOT NULL,
|
||||
deleted_by BIGINT NULL,
|
||||
|
||||
CONSTRAINT characteristics_pkey PRIMARY KEY (id),
|
||||
FOREIGN KEY (characteristic_type_id) REFERENCES characteristic_types(id),
|
||||
FOREIGN KEY (created_by) REFERENCES users(id),
|
||||
FOREIGN KEY (updated_by) REFERENCES users(id),
|
||||
FOREIGN KEY (deleted_by) REFERENCES users(id)
|
||||
FOREIGN KEY (updated_by) REFERENCES users(id)
|
||||
);
|
||||
|
||||
CREATE INDEX characteristic_type_id_idx ON characteristics (characteristic_type_id);
|
||||
|
|
|
@ -64,10 +64,8 @@ type CharacteristicBase struct {
|
|||
SortOrder types.NullInt64 `db:"sort_order" json:"sortOrder"`
|
||||
CreatedAt types.NullTime `db:"created_at" json:"createdAt"`
|
||||
UpdatedAt types.NullTime `db:"updated_at" json:"updatedAt"`
|
||||
DeletedAt types.NullTime `db:"deleted_at" json:"deletedAt"`
|
||||
CreatedBy int64 `db:"created_by" json:"createdBy"`
|
||||
UpdatedBy int64 `db:"updated_by" json:"updatedBy"`
|
||||
DeletedBy types.NullInt64 `db:"deleted_by" json:"deletedBy"`
|
||||
}
|
||||
|
||||
// Characteristic is what the DB expects for read operations, and is what the API
|
||||
|
|
|
@ -67,10 +67,8 @@ type SpeciesBase struct {
|
|||
Etymology types.NullString `db:"etymology" json:"etymology"`
|
||||
CreatedAt types.NullTime `db:"created_at" json:"createdAt"`
|
||||
UpdatedAt types.NullTime `db:"updated_at" json:"updatedAt"`
|
||||
DeletedAt types.NullTime `db:"deleted_at" json:"deletedAt"`
|
||||
CreatedBy int64 `db:"created_by" json:"createdBy"`
|
||||
UpdatedBy int64 `db:"updated_by" json:"updatedBy"`
|
||||
DeletedBy types.NullInt64 `db:"deleted_by" json:"deletedBy"`
|
||||
}
|
||||
|
||||
// Species is what the DB expects for read operations, and is what the API expects
|
||||
|
|
|
@ -70,10 +70,8 @@ type StrainBase struct {
|
|||
Notes types.NullString `db:"notes" json:"notes"`
|
||||
CreatedAt types.NullTime `db:"created_at" json:"createdAt"`
|
||||
UpdatedAt types.NullTime `db:"updated_at" json:"updatedAt"`
|
||||
DeletedAt types.NullTime `db:"deleted_at" json:"deletedAt"`
|
||||
CreatedBy int64 `db:"created_by" json:"createdBy"`
|
||||
UpdatedBy int64 `db:"updated_by" json:"updatedBy"`
|
||||
DeletedBy types.NullInt64 `db:"deleted_by" json:"deletedBy"`
|
||||
}
|
||||
|
||||
// Strain is what the DB expects for read operations, and is what the API expects
|
||||
|
|
|
@ -76,7 +76,6 @@ type UserBase struct {
|
|||
Verified bool `db:"verified" json:"-"`
|
||||
CreatedAt types.NullTime `db:"created_at" json:"createdAt"`
|
||||
UpdatedAt types.NullTime `db:"updated_at" json:"updatedAt"`
|
||||
DeletedAt types.NullTime `db:"deleted_at" json:"deletedAt"`
|
||||
}
|
||||
|
||||
// User is what the DB expects to see for read operations, and is what the API
|
||||
|
@ -109,8 +108,7 @@ func DbAuthenticate(email string, password string) error {
|
|||
q := `SELECT *
|
||||
FROM users
|
||||
WHERE lower(email)=lower($1)
|
||||
AND verified IS TRUE
|
||||
AND deleted_at IS NULL;`
|
||||
AND verified IS TRUE;`
|
||||
if err := DBH.SelectOne(&user, q, email); err != nil {
|
||||
return errors.ErrInvalidEmailOrPassword
|
||||
}
|
||||
|
@ -126,8 +124,7 @@ func GetUser(id int64, dummy string, claims *types.Claims) (*User, error) {
|
|||
q := `SELECT *
|
||||
FROM users
|
||||
WHERE id=$1
|
||||
AND verified IS TRUE
|
||||
AND deleted_at IS NULL;`
|
||||
AND verified IS TRUE;`
|
||||
if err := DBH.SelectOne(&user, q, id); err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, errors.ErrUserNotFound
|
||||
|
@ -147,8 +144,7 @@ func DbGetUserByEmail(email string) (*User, error) {
|
|||
q := `SELECT *
|
||||
FROM users
|
||||
WHERE lower(email)=lower($1)
|
||||
AND verified IS TRUE
|
||||
AND deleted_at IS NULL;`
|
||||
AND verified IS TRUE;`
|
||||
if err := DBH.SelectOne(&user, q, email); err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, errors.ErrUserNotFound
|
||||
|
@ -160,11 +156,9 @@ func DbGetUserByEmail(email string) (*User, error) {
|
|||
|
||||
// ListUsers returns all users.
|
||||
func ListUsers(opt helpers.ListOptions, claims *types.Claims) (*Users, error) {
|
||||
q := `SELECT id, email, 'password' AS password, name, role, created_at,
|
||||
updated_at, deleted_at
|
||||
q := `SELECT id, email, 'password' AS password, name, role, created_at, updated_at
|
||||
FROM users
|
||||
WHERE verified IS TRUE
|
||||
AND deleted_at IS NULL;`
|
||||
WHERE verified IS TRUE;`
|
||||
|
||||
users := make(Users, 0)
|
||||
if err := DBH.Select(&users, q); err != nil {
|
||||
|
|
Reference in a new issue