commit
313d539248
@ -1,8 +1,8 @@
|
|||||||
DROP TABLE IF EXISTS "returnsLog";
|
DROP TABLE IF EXISTS "returnsLog";
|
||||||
DROP TABLE IF EXISTS "returns";
|
DROP TABLE IF EXISTS "returns";
|
||||||
DROP TABLE IF EXISTS "payments";
|
DROP TABLE IF EXISTS "payments";
|
||||||
DROP TABLE IF EXISTS "mails";
|
|
||||||
DROP TABLE IF EXISTS "documents";
|
DROP TABLE IF EXISTS "documents";
|
||||||
|
DROP TABLE IF EXISTS "mails";
|
||||||
DROP TABLE IF EXISTS "persons";
|
DROP TABLE IF EXISTS "persons";
|
||||||
DROP TABLE IF EXISTS "providers";
|
DROP TABLE IF EXISTS "providers";
|
||||||
DROP TABLE IF EXISTS "customers";
|
DROP TABLE IF EXISTS "customers";
|
||||||
|
@ -6,7 +6,11 @@ CREATE TABLE "mails" (
|
|||||||
"timestamp" timestamptz NOT NULL DEFAULT (now()),
|
"timestamp" timestamptz NOT NULL DEFAULT (now()),
|
||||||
"subject" varchar NOT NULL,
|
"subject" varchar NOT NULL,
|
||||||
"body" text NOT NULL,
|
"body" text NOT NULL,
|
||||||
"attachments" bigserial
|
"creator" varchar NOT NULL,
|
||||||
|
"created" timestamptz NOT NULL DEFAULT (now()),
|
||||||
|
"changer" varchar NOT NULL,
|
||||||
|
"changed" timestamptz NOT NULL DEFAULT (now())
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE "customers" (
|
CREATE TABLE "customers" (
|
||||||
@ -35,7 +39,7 @@ CREATE TABLE "customers" (
|
|||||||
|
|
||||||
CREATE TABLE "persons" (
|
CREATE TABLE "persons" (
|
||||||
"ID" bigserial UNIQUE PRIMARY KEY NOT NULL,
|
"ID" bigserial UNIQUE PRIMARY KEY NOT NULL,
|
||||||
"customerID" bigserial NOT NULL,
|
"customerID" bigint NOT NULL,
|
||||||
"firstname" varchar NOT NULL,
|
"firstname" varchar NOT NULL,
|
||||||
"lastname" varchar NOT NULL,
|
"lastname" varchar NOT NULL,
|
||||||
"birthday" timestamptz NOT NULL,
|
"birthday" timestamptz NOT NULL,
|
||||||
@ -51,7 +55,7 @@ CREATE TABLE "persons" (
|
|||||||
|
|
||||||
CREATE TABLE "documents" (
|
CREATE TABLE "documents" (
|
||||||
"ID" bigserial UNIQUE PRIMARY KEY NOT NULL,
|
"ID" bigserial UNIQUE PRIMARY KEY NOT NULL,
|
||||||
"personID" bigserial NOT NULL,
|
"personID" bigint,
|
||||||
"name" varchar NOT NULL,
|
"name" varchar NOT NULL,
|
||||||
"type" varchar NOT NULL,
|
"type" varchar NOT NULL,
|
||||||
"path" varchar NOT NULL,
|
"path" varchar NOT NULL,
|
||||||
@ -59,6 +63,7 @@ CREATE TABLE "documents" (
|
|||||||
"valid" boolean NOT NULL DEFAULT false,
|
"valid" boolean NOT NULL DEFAULT false,
|
||||||
"validDate" timestamptz,
|
"validDate" timestamptz,
|
||||||
"validatedBy" varchar,
|
"validatedBy" varchar,
|
||||||
|
"mailID" bigint,
|
||||||
"creator" varchar NOT NULL,
|
"creator" varchar NOT NULL,
|
||||||
"created" timestamptz NOT NULL DEFAULT (now()),
|
"created" timestamptz NOT NULL DEFAULT (now()),
|
||||||
"changer" varchar NOT NULL,
|
"changer" varchar NOT NULL,
|
||||||
@ -67,7 +72,7 @@ CREATE TABLE "documents" (
|
|||||||
|
|
||||||
CREATE TABLE "payments" (
|
CREATE TABLE "payments" (
|
||||||
"ID" bigserial UNIQUE PRIMARY KEY NOT NULL,
|
"ID" bigserial UNIQUE PRIMARY KEY NOT NULL,
|
||||||
"customerID" bigserial NOT NULL,
|
"customerID" bigint NOT NULL,
|
||||||
"paymentCategory" varchar NOT NULL,
|
"paymentCategory" varchar NOT NULL,
|
||||||
"bankname" varchar,
|
"bankname" varchar,
|
||||||
"IBAN" varchar,
|
"IBAN" varchar,
|
||||||
@ -96,8 +101,8 @@ CREATE TABLE "providers" (
|
|||||||
|
|
||||||
CREATE TABLE "returns" (
|
CREATE TABLE "returns" (
|
||||||
"ID" bigserial UNIQUE PRIMARY KEY NOT NULL,
|
"ID" bigserial UNIQUE PRIMARY KEY NOT NULL,
|
||||||
"personID" bigserial NOT NULL,
|
"personID" bigint NOT NULL,
|
||||||
"providerID" bigserial NOT NULL,
|
"providerID" bigint NOT NULL,
|
||||||
"name" varchar NOT NULL,
|
"name" varchar NOT NULL,
|
||||||
"description" text NOT NULL,
|
"description" text NOT NULL,
|
||||||
"category" varchar NOT NULL,
|
"category" varchar NOT NULL,
|
||||||
@ -111,8 +116,8 @@ CREATE TABLE "returns" (
|
|||||||
|
|
||||||
CREATE TABLE "returnsLog" (
|
CREATE TABLE "returnsLog" (
|
||||||
"ID" bigserial UNIQUE PRIMARY KEY NOT NULL,
|
"ID" bigserial UNIQUE PRIMARY KEY NOT NULL,
|
||||||
"returnsID" bigserial,
|
"returnsID" bigint,
|
||||||
"mailID" bigserial,
|
"mailID" bigint,
|
||||||
"status" varchar,
|
"status" varchar,
|
||||||
"creator" varchar NOT NULL,
|
"creator" varchar NOT NULL,
|
||||||
"created" timestamptz NOT NULL DEFAULT (now()),
|
"created" timestamptz NOT NULL DEFAULT (now()),
|
||||||
@ -120,12 +125,12 @@ CREATE TABLE "returnsLog" (
|
|||||||
"changed" timestamptz NOT NULL DEFAULT (now())
|
"changed" timestamptz NOT NULL DEFAULT (now())
|
||||||
);
|
);
|
||||||
|
|
||||||
ALTER TABLE "mails" ADD FOREIGN KEY ("attachments") REFERENCES "documents" ("ID");
|
|
||||||
|
|
||||||
ALTER TABLE "persons" ADD FOREIGN KEY ("customerID") REFERENCES "customers" ("ID");
|
ALTER TABLE "persons" ADD FOREIGN KEY ("customerID") REFERENCES "customers" ("ID");
|
||||||
|
|
||||||
ALTER TABLE "documents" ADD FOREIGN KEY ("personID") REFERENCES "persons" ("ID");
|
ALTER TABLE "documents" ADD FOREIGN KEY ("personID") REFERENCES "persons" ("ID");
|
||||||
|
|
||||||
|
ALTER TABLE "documents" ADD FOREIGN KEY ("mailID") REFERENCES "mails" ("ID");
|
||||||
|
|
||||||
ALTER TABLE "payments" ADD FOREIGN KEY ("customerID") REFERENCES "customers" ("ID");
|
ALTER TABLE "payments" ADD FOREIGN KEY ("customerID") REFERENCES "customers" ("ID");
|
||||||
|
|
||||||
ALTER TABLE "returns" ADD FOREIGN KEY ("personID") REFERENCES "persons" ("ID");
|
ALTER TABLE "returns" ADD FOREIGN KEY ("personID") REFERENCES "persons" ("ID");
|
||||||
|
@ -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
|
||||||
|
43
db/query/mail.sql
Normal file
43
db/query/mail.sql
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
-- name: GetMail :one
|
||||||
|
SELECT * FROM mails
|
||||||
|
WHERE "ID" = $1 LIMIT 1;
|
||||||
|
|
||||||
|
-- name: CreateMail :one
|
||||||
|
INSERT INTO mails (
|
||||||
|
"from",
|
||||||
|
"to",
|
||||||
|
cc,
|
||||||
|
"subject",
|
||||||
|
body,
|
||||||
|
"timestamp",
|
||||||
|
creator,
|
||||||
|
changer
|
||||||
|
)
|
||||||
|
VALUES (
|
||||||
|
$1, $2, $3, $4, $5, $6, $7, $8
|
||||||
|
)
|
||||||
|
RETURNING *;
|
||||||
|
|
||||||
|
-- name: ListMails :many
|
||||||
|
SELECT * FROM mails
|
||||||
|
ORDER BY "timestamp", "from"
|
||||||
|
LIMIT $1
|
||||||
|
OFFSET $2;
|
||||||
|
|
||||||
|
-- -- name: UpdateMail :one
|
||||||
|
-- UPDATE mails
|
||||||
|
-- SET
|
||||||
|
-- "from" = COALESCE(sqlc.narg(from), "from"),
|
||||||
|
-- "to" = COALESCE(sqlc.narg(to), "to"),
|
||||||
|
-- cc = COALESCE(sqlc.narg(cc), cc),
|
||||||
|
-- "subject" = COALESCE(sqlc.narg(subject), "subject"),
|
||||||
|
-- body = COALESCE(sqlc.narg(body), body),
|
||||||
|
-- "timestamp" = COALESCE(sqlc.narg(timestamp), "timestamp"),
|
||||||
|
-- changer = $2,
|
||||||
|
-- changed = now()
|
||||||
|
-- WHERE "ID" = $1
|
||||||
|
-- RETURNING *;
|
||||||
|
|
||||||
|
-- name: DeleteMail :exec
|
||||||
|
DELETE FROM mails
|
||||||
|
WHERE "ID" = $1;
|
@ -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()
|
||||||
|
|
||||||
|
165
db/sqlc/mail.sql.go
Normal file
165
db/sqlc/mail.sql.go
Normal file
@ -0,0 +1,165 @@
|
|||||||
|
// Code generated by sqlc. DO NOT EDIT.
|
||||||
|
// versions:
|
||||||
|
// sqlc v1.21.0
|
||||||
|
// source: mail.sql
|
||||||
|
|
||||||
|
package db
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"database/sql"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
const createMail = `-- name: CreateMail :one
|
||||||
|
INSERT INTO mails (
|
||||||
|
"from",
|
||||||
|
"to",
|
||||||
|
cc,
|
||||||
|
"subject",
|
||||||
|
body,
|
||||||
|
"timestamp",
|
||||||
|
creator,
|
||||||
|
changer
|
||||||
|
)
|
||||||
|
VALUES (
|
||||||
|
$1, $2, $3, $4, $5, $6, $7, $8
|
||||||
|
)
|
||||||
|
RETURNING "ID", "from", "to", cc, timestamp, subject, body, creator, created, changer, changed
|
||||||
|
`
|
||||||
|
|
||||||
|
type CreateMailParams struct {
|
||||||
|
From string `json:"from"`
|
||||||
|
To string `json:"to"`
|
||||||
|
Cc sql.NullString `json:"cc"`
|
||||||
|
Subject string `json:"subject"`
|
||||||
|
Body string `json:"body"`
|
||||||
|
Timestamp time.Time `json:"timestamp"`
|
||||||
|
Creator string `json:"creator"`
|
||||||
|
Changer string `json:"changer"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *Queries) CreateMail(ctx context.Context, arg CreateMailParams) (Mail, error) {
|
||||||
|
row := q.db.QueryRowContext(ctx, createMail,
|
||||||
|
arg.From,
|
||||||
|
arg.To,
|
||||||
|
arg.Cc,
|
||||||
|
arg.Subject,
|
||||||
|
arg.Body,
|
||||||
|
arg.Timestamp,
|
||||||
|
arg.Creator,
|
||||||
|
arg.Changer,
|
||||||
|
)
|
||||||
|
var i Mail
|
||||||
|
err := row.Scan(
|
||||||
|
&i.ID,
|
||||||
|
&i.From,
|
||||||
|
&i.To,
|
||||||
|
&i.Cc,
|
||||||
|
&i.Timestamp,
|
||||||
|
&i.Subject,
|
||||||
|
&i.Body,
|
||||||
|
&i.Creator,
|
||||||
|
&i.Created,
|
||||||
|
&i.Changer,
|
||||||
|
&i.Changed,
|
||||||
|
)
|
||||||
|
return i, err
|
||||||
|
}
|
||||||
|
|
||||||
|
const deleteMail = `-- name: DeleteMail :exec
|
||||||
|
|
||||||
|
DELETE FROM mails
|
||||||
|
WHERE "ID" = $1
|
||||||
|
`
|
||||||
|
|
||||||
|
// -- name: UpdateMail :one
|
||||||
|
// UPDATE mails
|
||||||
|
// SET
|
||||||
|
//
|
||||||
|
// "from" = COALESCE(sqlc.narg(from), "from"),
|
||||||
|
// "to" = COALESCE(sqlc.narg(to), "to"),
|
||||||
|
// cc = COALESCE(sqlc.narg(cc), cc),
|
||||||
|
// "subject" = COALESCE(sqlc.narg(subject), "subject"),
|
||||||
|
// body = COALESCE(sqlc.narg(body), body),
|
||||||
|
// "timestamp" = COALESCE(sqlc.narg(timestamp), "timestamp"),
|
||||||
|
// changer = $2,
|
||||||
|
// changed = now()
|
||||||
|
//
|
||||||
|
// WHERE "ID" = $1
|
||||||
|
// RETURNING *;
|
||||||
|
func (q *Queries) DeleteMail(ctx context.Context, id int64) error {
|
||||||
|
_, err := q.db.ExecContext(ctx, deleteMail, id)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
const getMail = `-- name: GetMail :one
|
||||||
|
SELECT "ID", "from", "to", cc, timestamp, subject, body, creator, created, changer, changed FROM mails
|
||||||
|
WHERE "ID" = $1 LIMIT 1
|
||||||
|
`
|
||||||
|
|
||||||
|
func (q *Queries) GetMail(ctx context.Context, id int64) (Mail, error) {
|
||||||
|
row := q.db.QueryRowContext(ctx, getMail, id)
|
||||||
|
var i Mail
|
||||||
|
err := row.Scan(
|
||||||
|
&i.ID,
|
||||||
|
&i.From,
|
||||||
|
&i.To,
|
||||||
|
&i.Cc,
|
||||||
|
&i.Timestamp,
|
||||||
|
&i.Subject,
|
||||||
|
&i.Body,
|
||||||
|
&i.Creator,
|
||||||
|
&i.Created,
|
||||||
|
&i.Changer,
|
||||||
|
&i.Changed,
|
||||||
|
)
|
||||||
|
return i, err
|
||||||
|
}
|
||||||
|
|
||||||
|
const listMails = `-- name: ListMails :many
|
||||||
|
SELECT "ID", "from", "to", cc, timestamp, subject, body, creator, created, changer, changed FROM mails
|
||||||
|
ORDER BY "timestamp", "from"
|
||||||
|
LIMIT $1
|
||||||
|
OFFSET $2
|
||||||
|
`
|
||||||
|
|
||||||
|
type ListMailsParams struct {
|
||||||
|
Limit int32 `json:"limit"`
|
||||||
|
Offset int32 `json:"offset"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *Queries) ListMails(ctx context.Context, arg ListMailsParams) ([]Mail, error) {
|
||||||
|
rows, err := q.db.QueryContext(ctx, listMails, arg.Limit, arg.Offset)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
items := []Mail{}
|
||||||
|
for rows.Next() {
|
||||||
|
var i Mail
|
||||||
|
if err := rows.Scan(
|
||||||
|
&i.ID,
|
||||||
|
&i.From,
|
||||||
|
&i.To,
|
||||||
|
&i.Cc,
|
||||||
|
&i.Timestamp,
|
||||||
|
&i.Subject,
|
||||||
|
&i.Body,
|
||||||
|
&i.Creator,
|
||||||
|
&i.Created,
|
||||||
|
&i.Changer,
|
||||||
|
&i.Changed,
|
||||||
|
); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
items = append(items, i)
|
||||||
|
}
|
||||||
|
if err := rows.Close(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if err := rows.Err(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return items, nil
|
||||||
|
}
|
@ -35,7 +35,7 @@ type Customer struct {
|
|||||||
|
|
||||||
type Document struct {
|
type Document struct {
|
||||||
ID int64 `json:"ID"`
|
ID int64 `json:"ID"`
|
||||||
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"`
|
||||||
@ -43,6 +43,7 @@ type Document struct {
|
|||||||
Valid bool `json:"valid"`
|
Valid bool `json:"valid"`
|
||||||
ValidDate sql.NullTime `json:"validDate"`
|
ValidDate sql.NullTime `json:"validDate"`
|
||||||
ValidatedBy sql.NullString `json:"validatedBy"`
|
ValidatedBy sql.NullString `json:"validatedBy"`
|
||||||
|
MailID sql.NullInt64 `json:"mailID"`
|
||||||
Creator string `json:"creator"`
|
Creator string `json:"creator"`
|
||||||
Created time.Time `json:"created"`
|
Created time.Time `json:"created"`
|
||||||
Changer string `json:"changer"`
|
Changer string `json:"changer"`
|
||||||
@ -50,14 +51,17 @@ type Document struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Mail struct {
|
type Mail struct {
|
||||||
ID int64 `json:"ID"`
|
ID int64 `json:"ID"`
|
||||||
From string `json:"from"`
|
From string `json:"from"`
|
||||||
To string `json:"to"`
|
To string `json:"to"`
|
||||||
Cc sql.NullString `json:"cc"`
|
Cc sql.NullString `json:"cc"`
|
||||||
Timestamp time.Time `json:"timestamp"`
|
Timestamp time.Time `json:"timestamp"`
|
||||||
Subject string `json:"subject"`
|
Subject string `json:"subject"`
|
||||||
Body string `json:"body"`
|
Body string `json:"body"`
|
||||||
Attachments sql.NullInt32 `json:"attachments"`
|
Creator string `json:"creator"`
|
||||||
|
Created time.Time `json:"created"`
|
||||||
|
Changer string `json:"changer"`
|
||||||
|
Changed time.Time `json:"changed"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Payment struct {
|
type Payment struct {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user