ft/differs between person and mail in documents
This commit is contained in:
parent
45bb0dc5e8
commit
01f98eea1e
@ -2,7 +2,7 @@
|
|||||||
SELECT * FROM documents
|
SELECT * FROM documents
|
||||||
WHERE "ID" = $1 LIMIT 1;
|
WHERE "ID" = $1 LIMIT 1;
|
||||||
|
|
||||||
-- name: CreateDocument :one
|
-- name: CreateDocumentUpload :one
|
||||||
INSERT INTO documents (
|
INSERT INTO documents (
|
||||||
"personID",
|
"personID",
|
||||||
name,
|
name,
|
||||||
@ -15,6 +15,19 @@ INSERT INTO documents (
|
|||||||
$1, $2, $3, $4, $5, $6, $7
|
$1, $2, $3, $4, $5, $6, $7
|
||||||
) RETURNING *;
|
) RETURNING *;
|
||||||
|
|
||||||
|
-- name: CreateDocumentMail :one
|
||||||
|
INSERT INTO documents (
|
||||||
|
"mailID",
|
||||||
|
name,
|
||||||
|
type,
|
||||||
|
path,
|
||||||
|
url,
|
||||||
|
creator,
|
||||||
|
changer
|
||||||
|
) VALUES (
|
||||||
|
$1, $2, $3, $4, $5, $6, $7
|
||||||
|
) RETURNING *;
|
||||||
|
|
||||||
-- name: ListDocuments :many
|
-- name: ListDocuments :many
|
||||||
SELECT * FROM documents
|
SELECT * FROM documents
|
||||||
ORDER BY valid, type, name
|
ORDER BY valid, type, name
|
||||||
|
@ -10,7 +10,61 @@ import (
|
|||||||
"database/sql"
|
"database/sql"
|
||||||
)
|
)
|
||||||
|
|
||||||
const createDocument = `-- name: CreateDocument :one
|
const createDocumentMail = `-- name: CreateDocumentMail :one
|
||||||
|
INSERT INTO documents (
|
||||||
|
"mailID",
|
||||||
|
name,
|
||||||
|
type,
|
||||||
|
path,
|
||||||
|
url,
|
||||||
|
creator,
|
||||||
|
changer
|
||||||
|
) VALUES (
|
||||||
|
$1, $2, $3, $4, $5, $6, $7
|
||||||
|
) RETURNING "ID", "personID", name, type, path, url, valid, "validDate", "validatedBy", "mailID", creator, created, changer, changed
|
||||||
|
`
|
||||||
|
|
||||||
|
type CreateDocumentMailParams struct {
|
||||||
|
MailID sql.NullInt64 `json:"mailID"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
Path string `json:"path"`
|
||||||
|
Url string `json:"url"`
|
||||||
|
Creator string `json:"creator"`
|
||||||
|
Changer string `json:"changer"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *Queries) CreateDocumentMail(ctx context.Context, arg CreateDocumentMailParams) (Document, error) {
|
||||||
|
row := q.db.QueryRowContext(ctx, createDocumentMail,
|
||||||
|
arg.MailID,
|
||||||
|
arg.Name,
|
||||||
|
arg.Type,
|
||||||
|
arg.Path,
|
||||||
|
arg.Url,
|
||||||
|
arg.Creator,
|
||||||
|
arg.Changer,
|
||||||
|
)
|
||||||
|
var i Document
|
||||||
|
err := row.Scan(
|
||||||
|
&i.ID,
|
||||||
|
&i.PersonID,
|
||||||
|
&i.Name,
|
||||||
|
&i.Type,
|
||||||
|
&i.Path,
|
||||||
|
&i.Url,
|
||||||
|
&i.Valid,
|
||||||
|
&i.ValidDate,
|
||||||
|
&i.ValidatedBy,
|
||||||
|
&i.MailID,
|
||||||
|
&i.Creator,
|
||||||
|
&i.Created,
|
||||||
|
&i.Changer,
|
||||||
|
&i.Changed,
|
||||||
|
)
|
||||||
|
return i, err
|
||||||
|
}
|
||||||
|
|
||||||
|
const createDocumentUpload = `-- name: CreateDocumentUpload :one
|
||||||
INSERT INTO documents (
|
INSERT INTO documents (
|
||||||
"personID",
|
"personID",
|
||||||
name,
|
name,
|
||||||
@ -21,21 +75,21 @@ INSERT INTO documents (
|
|||||||
changer
|
changer
|
||||||
) VALUES (
|
) VALUES (
|
||||||
$1, $2, $3, $4, $5, $6, $7
|
$1, $2, $3, $4, $5, $6, $7
|
||||||
) RETURNING "ID", "personID", name, type, path, url, valid, "validDate", "validatedBy", creator, created, changer, changed
|
) RETURNING "ID", "personID", name, type, path, url, valid, "validDate", "validatedBy", "mailID", creator, created, changer, changed
|
||||||
`
|
`
|
||||||
|
|
||||||
type CreateDocumentParams struct {
|
type CreateDocumentUploadParams struct {
|
||||||
PersonID int64 `json:"personID"`
|
PersonID sql.NullInt64 `json:"personID"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
Path string `json:"path"`
|
Path string `json:"path"`
|
||||||
Url string `json:"url"`
|
Url string `json:"url"`
|
||||||
Creator string `json:"creator"`
|
Creator string `json:"creator"`
|
||||||
Changer string `json:"changer"`
|
Changer string `json:"changer"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *Queries) CreateDocument(ctx context.Context, arg CreateDocumentParams) (Document, error) {
|
func (q *Queries) CreateDocumentUpload(ctx context.Context, arg CreateDocumentUploadParams) (Document, error) {
|
||||||
row := q.db.QueryRowContext(ctx, createDocument,
|
row := q.db.QueryRowContext(ctx, createDocumentUpload,
|
||||||
arg.PersonID,
|
arg.PersonID,
|
||||||
arg.Name,
|
arg.Name,
|
||||||
arg.Type,
|
arg.Type,
|
||||||
@ -55,6 +109,7 @@ func (q *Queries) CreateDocument(ctx context.Context, arg CreateDocumentParams)
|
|||||||
&i.Valid,
|
&i.Valid,
|
||||||
&i.ValidDate,
|
&i.ValidDate,
|
||||||
&i.ValidatedBy,
|
&i.ValidatedBy,
|
||||||
|
&i.MailID,
|
||||||
&i.Creator,
|
&i.Creator,
|
||||||
&i.Created,
|
&i.Created,
|
||||||
&i.Changer,
|
&i.Changer,
|
||||||
@ -74,7 +129,7 @@ func (q *Queries) DeleteDocument(ctx context.Context, id int64) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const getDocument = `-- name: GetDocument :one
|
const getDocument = `-- name: GetDocument :one
|
||||||
SELECT "ID", "personID", name, type, path, url, valid, "validDate", "validatedBy", creator, created, changer, changed FROM documents
|
SELECT "ID", "personID", name, type, path, url, valid, "validDate", "validatedBy", "mailID", creator, created, changer, changed FROM documents
|
||||||
WHERE "ID" = $1 LIMIT 1
|
WHERE "ID" = $1 LIMIT 1
|
||||||
`
|
`
|
||||||
|
|
||||||
@ -91,6 +146,7 @@ func (q *Queries) GetDocument(ctx context.Context, id int64) (Document, error) {
|
|||||||
&i.Valid,
|
&i.Valid,
|
||||||
&i.ValidDate,
|
&i.ValidDate,
|
||||||
&i.ValidatedBy,
|
&i.ValidatedBy,
|
||||||
|
&i.MailID,
|
||||||
&i.Creator,
|
&i.Creator,
|
||||||
&i.Created,
|
&i.Created,
|
||||||
&i.Changer,
|
&i.Changer,
|
||||||
@ -108,7 +164,7 @@ SET
|
|||||||
changer = $2,
|
changer = $2,
|
||||||
changed = now()
|
changed = now()
|
||||||
WHERE "ID" = $1
|
WHERE "ID" = $1
|
||||||
RETURNING "ID", "personID", name, type, path, url, valid, "validDate", "validatedBy", creator, created, changer, changed
|
RETURNING "ID", "personID", name, type, path, url, valid, "validDate", "validatedBy", "mailID", creator, created, changer, changed
|
||||||
`
|
`
|
||||||
|
|
||||||
type InvalidateDocumentParams struct {
|
type InvalidateDocumentParams struct {
|
||||||
@ -129,6 +185,7 @@ func (q *Queries) InvalidateDocument(ctx context.Context, arg InvalidateDocument
|
|||||||
&i.Valid,
|
&i.Valid,
|
||||||
&i.ValidDate,
|
&i.ValidDate,
|
||||||
&i.ValidatedBy,
|
&i.ValidatedBy,
|
||||||
|
&i.MailID,
|
||||||
&i.Creator,
|
&i.Creator,
|
||||||
&i.Created,
|
&i.Created,
|
||||||
&i.Changer,
|
&i.Changer,
|
||||||
@ -138,7 +195,7 @@ func (q *Queries) InvalidateDocument(ctx context.Context, arg InvalidateDocument
|
|||||||
}
|
}
|
||||||
|
|
||||||
const listDocuments = `-- name: ListDocuments :many
|
const listDocuments = `-- name: ListDocuments :many
|
||||||
SELECT "ID", "personID", name, type, path, url, valid, "validDate", "validatedBy", creator, created, changer, changed FROM documents
|
SELECT "ID", "personID", name, type, path, url, valid, "validDate", "validatedBy", "mailID", creator, created, changer, changed FROM documents
|
||||||
ORDER BY valid, type, name
|
ORDER BY valid, type, name
|
||||||
LIMIT $1
|
LIMIT $1
|
||||||
OFFSET $2
|
OFFSET $2
|
||||||
@ -168,6 +225,7 @@ func (q *Queries) ListDocuments(ctx context.Context, arg ListDocumentsParams) ([
|
|||||||
&i.Valid,
|
&i.Valid,
|
||||||
&i.ValidDate,
|
&i.ValidDate,
|
||||||
&i.ValidatedBy,
|
&i.ValidatedBy,
|
||||||
|
&i.MailID,
|
||||||
&i.Creator,
|
&i.Creator,
|
||||||
&i.Created,
|
&i.Created,
|
||||||
&i.Changer,
|
&i.Changer,
|
||||||
@ -197,7 +255,7 @@ SET
|
|||||||
changer = $2,
|
changer = $2,
|
||||||
changed = now()
|
changed = now()
|
||||||
WHERE "ID" = $1
|
WHERE "ID" = $1
|
||||||
RETURNING "ID", "personID", name, type, path, url, valid, "validDate", "validatedBy", creator, created, changer, changed
|
RETURNING "ID", "personID", name, type, path, url, valid, "validDate", "validatedBy", "mailID", creator, created, changer, changed
|
||||||
`
|
`
|
||||||
|
|
||||||
type UpdateDocumentParams struct {
|
type UpdateDocumentParams struct {
|
||||||
@ -231,6 +289,7 @@ func (q *Queries) UpdateDocument(ctx context.Context, arg UpdateDocumentParams)
|
|||||||
&i.Valid,
|
&i.Valid,
|
||||||
&i.ValidDate,
|
&i.ValidDate,
|
||||||
&i.ValidatedBy,
|
&i.ValidatedBy,
|
||||||
|
&i.MailID,
|
||||||
&i.Creator,
|
&i.Creator,
|
||||||
&i.Created,
|
&i.Created,
|
||||||
&i.Changer,
|
&i.Changer,
|
||||||
@ -248,7 +307,7 @@ SET
|
|||||||
changer = $2,
|
changer = $2,
|
||||||
changed = now()
|
changed = now()
|
||||||
WHERE "ID" = $1
|
WHERE "ID" = $1
|
||||||
RETURNING "ID", "personID", name, type, path, url, valid, "validDate", "validatedBy", creator, created, changer, changed
|
RETURNING "ID", "personID", name, type, path, url, valid, "validDate", "validatedBy", "mailID", creator, created, changer, changed
|
||||||
`
|
`
|
||||||
|
|
||||||
type ValidateDocumentParams struct {
|
type ValidateDocumentParams struct {
|
||||||
@ -269,6 +328,7 @@ func (q *Queries) ValidateDocument(ctx context.Context, arg ValidateDocumentPara
|
|||||||
&i.Valid,
|
&i.Valid,
|
||||||
&i.ValidDate,
|
&i.ValidDate,
|
||||||
&i.ValidatedBy,
|
&i.ValidatedBy,
|
||||||
|
&i.MailID,
|
||||||
&i.Creator,
|
&i.Creator,
|
||||||
&i.Created,
|
&i.Created,
|
||||||
&i.Changer,
|
&i.Changer,
|
||||||
|
@ -10,21 +10,24 @@ import (
|
|||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func createRandomDocument(t *testing.T) Document {
|
func createRandomDocumentUpload(t *testing.T) Document {
|
||||||
person := createRandomPerson(t)
|
person := createRandomPerson(t)
|
||||||
require.NotEmpty(t, person)
|
require.NotEmpty(t, person)
|
||||||
|
|
||||||
arg := CreateDocumentParams{
|
arg := CreateDocumentUploadParams{
|
||||||
PersonID: person.ID,
|
PersonID: sql.NullInt64{
|
||||||
Name: util.RandomUser(),
|
Valid: true,
|
||||||
Type: util.RandomUser(),
|
Int64: person.ID,
|
||||||
Path: util.RandomString(50),
|
},
|
||||||
Url: util.RandomString(60),
|
Name: util.RandomUser(),
|
||||||
Creator: util.RandomUser(),
|
Type: util.RandomUser(),
|
||||||
Changer: util.RandomUser(),
|
Path: util.RandomString(50),
|
||||||
|
Url: util.RandomString(60),
|
||||||
|
Creator: util.RandomUser(),
|
||||||
|
Changer: util.RandomUser(),
|
||||||
}
|
}
|
||||||
|
|
||||||
document, err := testQueries.CreateDocument(context.Background(), arg)
|
document, err := testQueries.CreateDocumentUpload(context.Background(), arg)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NotEmpty(t, document)
|
require.NotEmpty(t, document)
|
||||||
|
|
||||||
@ -45,12 +48,12 @@ func createRandomDocument(t *testing.T) Document {
|
|||||||
return document
|
return document
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCreateDocument(t *testing.T) {
|
func TestCreateDocumentUpload(t *testing.T) {
|
||||||
createRandomDocument(t)
|
createRandomDocumentUpload(t)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetDocument(t *testing.T) {
|
func TestGetDocument(t *testing.T) {
|
||||||
newdocument := createRandomDocument(t)
|
newdocument := createRandomDocumentUpload(t)
|
||||||
require.NotEmpty(t, newdocument)
|
require.NotEmpty(t, newdocument)
|
||||||
|
|
||||||
document, err := testQueries.GetDocument(context.Background(), newdocument.ID)
|
document, err := testQueries.GetDocument(context.Background(), newdocument.ID)
|
||||||
@ -72,7 +75,7 @@ func TestGetDocument(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestDeleteDocument(t *testing.T) {
|
func TestDeleteDocument(t *testing.T) {
|
||||||
document1 := createRandomDocument(t)
|
document1 := createRandomDocumentUpload(t)
|
||||||
err := testQueries.DeleteDocument(context.Background(), document1.ID)
|
err := testQueries.DeleteDocument(context.Background(), document1.ID)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
@ -83,7 +86,7 @@ func TestDeleteDocument(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestUpdateDocument(t *testing.T) {
|
func TestUpdateDocument(t *testing.T) {
|
||||||
document1 := createRandomDocument(t)
|
document1 := createRandomDocumentUpload(t)
|
||||||
require.NotEmpty(t, document1)
|
require.NotEmpty(t, document1)
|
||||||
|
|
||||||
arg := UpdateDocumentParams{
|
arg := UpdateDocumentParams{
|
||||||
@ -105,7 +108,7 @@ func TestUpdateDocument(t *testing.T) {
|
|||||||
|
|
||||||
func TestListDocuments(t *testing.T) {
|
func TestListDocuments(t *testing.T) {
|
||||||
for i := 0; i < 10; i++ {
|
for i := 0; i < 10; i++ {
|
||||||
createRandomDocument(t)
|
createRandomDocumentUpload(t)
|
||||||
}
|
}
|
||||||
|
|
||||||
arg := ListDocumentsParams{
|
arg := ListDocumentsParams{
|
||||||
@ -123,7 +126,7 @@ func TestListDocuments(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestValidateDocument(t *testing.T) {
|
func TestValidateDocument(t *testing.T) {
|
||||||
document1 := createRandomDocument(t)
|
document1 := createRandomDocumentUpload(t)
|
||||||
|
|
||||||
validator := util.RandomUser()
|
validator := util.RandomUser()
|
||||||
|
|
||||||
@ -148,7 +151,7 @@ func TestValidateDocument(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestInvalidateDocument(t *testing.T) {
|
func TestInvalidateDocument(t *testing.T) {
|
||||||
document1 := createRandomDocument(t)
|
document1 := createRandomDocumentUpload(t)
|
||||||
|
|
||||||
validator := util.RandomUser()
|
validator := util.RandomUser()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user