625 lines
18 KiB
Go
625 lines
18 KiB
Go
|
|
// Code generated by sqlc. DO NOT EDIT.
|
||
|
|
// versions:
|
||
|
|
// sqlc v1.29.0
|
||
|
|
// source: documents.sql
|
||
|
|
|
||
|
|
package db
|
||
|
|
|
||
|
|
import (
|
||
|
|
"context"
|
||
|
|
"database/sql"
|
||
|
|
"time"
|
||
|
|
)
|
||
|
|
|
||
|
|
const archiveDocument = `-- name: ArchiveDocument :exec
|
||
|
|
DELETE FROM documents
|
||
|
|
WHERE id = ?
|
||
|
|
`
|
||
|
|
|
||
|
|
func (q *Queries) ArchiveDocument(ctx context.Context, id int32) error {
|
||
|
|
_, err := q.db.ExecContext(ctx, archiveDocument, id)
|
||
|
|
return err
|
||
|
|
}
|
||
|
|
|
||
|
|
const createDocument = `-- name: CreateDocument :execresult
|
||
|
|
INSERT INTO documents (
|
||
|
|
type,
|
||
|
|
created,
|
||
|
|
user_id,
|
||
|
|
doc_page_count,
|
||
|
|
cmc_reference,
|
||
|
|
pdf_filename,
|
||
|
|
pdf_created_at,
|
||
|
|
pdf_created_by_user_id,
|
||
|
|
shipping_details,
|
||
|
|
revision,
|
||
|
|
bill_to,
|
||
|
|
ship_to,
|
||
|
|
email_sent_at,
|
||
|
|
email_sent_by_user_id
|
||
|
|
) VALUES (
|
||
|
|
?, NOW(), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?
|
||
|
|
)
|
||
|
|
`
|
||
|
|
|
||
|
|
type CreateDocumentParams struct {
|
||
|
|
Type DocumentsType `json:"type"`
|
||
|
|
UserID int32 `json:"user_id"`
|
||
|
|
DocPageCount int32 `json:"doc_page_count"`
|
||
|
|
CmcReference string `json:"cmc_reference"`
|
||
|
|
PdfFilename string `json:"pdf_filename"`
|
||
|
|
PdfCreatedAt time.Time `json:"pdf_created_at"`
|
||
|
|
PdfCreatedByUserID int32 `json:"pdf_created_by_user_id"`
|
||
|
|
ShippingDetails sql.NullString `json:"shipping_details"`
|
||
|
|
Revision int32 `json:"revision"`
|
||
|
|
BillTo sql.NullString `json:"bill_to"`
|
||
|
|
ShipTo sql.NullString `json:"ship_to"`
|
||
|
|
EmailSentAt time.Time `json:"email_sent_at"`
|
||
|
|
EmailSentByUserID int32 `json:"email_sent_by_user_id"`
|
||
|
|
}
|
||
|
|
|
||
|
|
func (q *Queries) CreateDocument(ctx context.Context, arg CreateDocumentParams) (sql.Result, error) {
|
||
|
|
return q.db.ExecContext(ctx, createDocument,
|
||
|
|
arg.Type,
|
||
|
|
arg.UserID,
|
||
|
|
arg.DocPageCount,
|
||
|
|
arg.CmcReference,
|
||
|
|
arg.PdfFilename,
|
||
|
|
arg.PdfCreatedAt,
|
||
|
|
arg.PdfCreatedByUserID,
|
||
|
|
arg.ShippingDetails,
|
||
|
|
arg.Revision,
|
||
|
|
arg.BillTo,
|
||
|
|
arg.ShipTo,
|
||
|
|
arg.EmailSentAt,
|
||
|
|
arg.EmailSentByUserID,
|
||
|
|
)
|
||
|
|
}
|
||
|
|
|
||
|
|
const getDocumentByID = `-- name: GetDocumentByID :one
|
||
|
|
SELECT
|
||
|
|
d.id,
|
||
|
|
d.type,
|
||
|
|
d.created,
|
||
|
|
d.user_id,
|
||
|
|
d.doc_page_count,
|
||
|
|
d.pdf_filename,
|
||
|
|
d.pdf_created_at,
|
||
|
|
d.pdf_created_by_user_id,
|
||
|
|
d.cmc_reference,
|
||
|
|
d.revision,
|
||
|
|
d.shipping_details,
|
||
|
|
d.bill_to,
|
||
|
|
d.ship_to,
|
||
|
|
d.email_sent_at,
|
||
|
|
d.email_sent_by_user_id,
|
||
|
|
u.first_name as user_first_name,
|
||
|
|
u.last_name as user_last_name,
|
||
|
|
u.username as user_username,
|
||
|
|
pdf_creator.first_name as pdf_creator_first_name,
|
||
|
|
pdf_creator.last_name as pdf_creator_last_name,
|
||
|
|
pdf_creator.username as pdf_creator_username,
|
||
|
|
COALESCE(ec.name, ic.name, '') as customer_name,
|
||
|
|
e.title as enquiry_title
|
||
|
|
FROM documents d
|
||
|
|
LEFT JOIN users u ON d.user_id = u.id
|
||
|
|
LEFT JOIN users pdf_creator ON d.pdf_created_by_user_id = pdf_creator.id
|
||
|
|
LEFT JOIN enquiries e ON d.type IN ('quote', 'orderAck') AND d.cmc_reference = e.title
|
||
|
|
LEFT JOIN customers ec ON e.customer_id = ec.id
|
||
|
|
LEFT JOIN invoices i ON d.type = 'invoice' AND d.cmc_reference = i.title
|
||
|
|
LEFT JOIN customers ic ON i.customer_id = ic.id
|
||
|
|
WHERE d.id = ?
|
||
|
|
`
|
||
|
|
|
||
|
|
type GetDocumentByIDRow struct {
|
||
|
|
ID int32 `json:"id"`
|
||
|
|
Type DocumentsType `json:"type"`
|
||
|
|
Created time.Time `json:"created"`
|
||
|
|
UserID int32 `json:"user_id"`
|
||
|
|
DocPageCount int32 `json:"doc_page_count"`
|
||
|
|
PdfFilename string `json:"pdf_filename"`
|
||
|
|
PdfCreatedAt time.Time `json:"pdf_created_at"`
|
||
|
|
PdfCreatedByUserID int32 `json:"pdf_created_by_user_id"`
|
||
|
|
CmcReference string `json:"cmc_reference"`
|
||
|
|
Revision int32 `json:"revision"`
|
||
|
|
ShippingDetails sql.NullString `json:"shipping_details"`
|
||
|
|
BillTo sql.NullString `json:"bill_to"`
|
||
|
|
ShipTo sql.NullString `json:"ship_to"`
|
||
|
|
EmailSentAt time.Time `json:"email_sent_at"`
|
||
|
|
EmailSentByUserID int32 `json:"email_sent_by_user_id"`
|
||
|
|
UserFirstName sql.NullString `json:"user_first_name"`
|
||
|
|
UserLastName sql.NullString `json:"user_last_name"`
|
||
|
|
UserUsername sql.NullString `json:"user_username"`
|
||
|
|
PdfCreatorFirstName sql.NullString `json:"pdf_creator_first_name"`
|
||
|
|
PdfCreatorLastName sql.NullString `json:"pdf_creator_last_name"`
|
||
|
|
PdfCreatorUsername sql.NullString `json:"pdf_creator_username"`
|
||
|
|
CustomerName string `json:"customer_name"`
|
||
|
|
EnquiryTitle sql.NullString `json:"enquiry_title"`
|
||
|
|
}
|
||
|
|
|
||
|
|
func (q *Queries) GetDocumentByID(ctx context.Context, id int32) (GetDocumentByIDRow, error) {
|
||
|
|
row := q.db.QueryRowContext(ctx, getDocumentByID, id)
|
||
|
|
var i GetDocumentByIDRow
|
||
|
|
err := row.Scan(
|
||
|
|
&i.ID,
|
||
|
|
&i.Type,
|
||
|
|
&i.Created,
|
||
|
|
&i.UserID,
|
||
|
|
&i.DocPageCount,
|
||
|
|
&i.PdfFilename,
|
||
|
|
&i.PdfCreatedAt,
|
||
|
|
&i.PdfCreatedByUserID,
|
||
|
|
&i.CmcReference,
|
||
|
|
&i.Revision,
|
||
|
|
&i.ShippingDetails,
|
||
|
|
&i.BillTo,
|
||
|
|
&i.ShipTo,
|
||
|
|
&i.EmailSentAt,
|
||
|
|
&i.EmailSentByUserID,
|
||
|
|
&i.UserFirstName,
|
||
|
|
&i.UserLastName,
|
||
|
|
&i.UserUsername,
|
||
|
|
&i.PdfCreatorFirstName,
|
||
|
|
&i.PdfCreatorLastName,
|
||
|
|
&i.PdfCreatorUsername,
|
||
|
|
&i.CustomerName,
|
||
|
|
&i.EnquiryTitle,
|
||
|
|
)
|
||
|
|
return i, err
|
||
|
|
}
|
||
|
|
|
||
|
|
const getPurchaseOrderByDocumentID = `-- name: GetPurchaseOrderByDocumentID :one
|
||
|
|
SELECT
|
||
|
|
po.id,
|
||
|
|
po.title,
|
||
|
|
po.principle_id,
|
||
|
|
po.principle_reference,
|
||
|
|
po.issue_date,
|
||
|
|
po.ordered_from,
|
||
|
|
po.dispatch_by,
|
||
|
|
po.deliver_to,
|
||
|
|
po.shipping_instructions
|
||
|
|
FROM purchase_orders po
|
||
|
|
JOIN documents d ON d.cmc_reference = po.title
|
||
|
|
WHERE d.id = ? AND d.type = 'purchaseOrder'
|
||
|
|
`
|
||
|
|
|
||
|
|
type GetPurchaseOrderByDocumentIDRow struct {
|
||
|
|
ID int32 `json:"id"`
|
||
|
|
Title string `json:"title"`
|
||
|
|
PrincipleID int32 `json:"principle_id"`
|
||
|
|
PrincipleReference string `json:"principle_reference"`
|
||
|
|
IssueDate time.Time `json:"issue_date"`
|
||
|
|
OrderedFrom string `json:"ordered_from"`
|
||
|
|
DispatchBy string `json:"dispatch_by"`
|
||
|
|
DeliverTo string `json:"deliver_to"`
|
||
|
|
ShippingInstructions string `json:"shipping_instructions"`
|
||
|
|
}
|
||
|
|
|
||
|
|
func (q *Queries) GetPurchaseOrderByDocumentID(ctx context.Context, id int32) (GetPurchaseOrderByDocumentIDRow, error) {
|
||
|
|
row := q.db.QueryRowContext(ctx, getPurchaseOrderByDocumentID, id)
|
||
|
|
var i GetPurchaseOrderByDocumentIDRow
|
||
|
|
err := row.Scan(
|
||
|
|
&i.ID,
|
||
|
|
&i.Title,
|
||
|
|
&i.PrincipleID,
|
||
|
|
&i.PrincipleReference,
|
||
|
|
&i.IssueDate,
|
||
|
|
&i.OrderedFrom,
|
||
|
|
&i.DispatchBy,
|
||
|
|
&i.DeliverTo,
|
||
|
|
&i.ShippingInstructions,
|
||
|
|
)
|
||
|
|
return i, err
|
||
|
|
}
|
||
|
|
|
||
|
|
const listDocuments = `-- name: ListDocuments :many
|
||
|
|
SELECT
|
||
|
|
d.id,
|
||
|
|
d.type,
|
||
|
|
d.created,
|
||
|
|
d.user_id,
|
||
|
|
d.doc_page_count,
|
||
|
|
d.pdf_filename,
|
||
|
|
d.pdf_created_at,
|
||
|
|
d.pdf_created_by_user_id,
|
||
|
|
d.cmc_reference,
|
||
|
|
d.revision,
|
||
|
|
d.email_sent_at,
|
||
|
|
d.email_sent_by_user_id,
|
||
|
|
u.first_name as user_first_name,
|
||
|
|
u.last_name as user_last_name,
|
||
|
|
u.username as user_username,
|
||
|
|
pdf_creator.first_name as pdf_creator_first_name,
|
||
|
|
pdf_creator.last_name as pdf_creator_last_name,
|
||
|
|
pdf_creator.username as pdf_creator_username
|
||
|
|
FROM documents d
|
||
|
|
LEFT JOIN users u ON d.user_id = u.id
|
||
|
|
LEFT JOIN users pdf_creator ON d.pdf_created_by_user_id = pdf_creator.id
|
||
|
|
ORDER BY d.id DESC
|
||
|
|
LIMIT 1000
|
||
|
|
`
|
||
|
|
|
||
|
|
type ListDocumentsRow struct {
|
||
|
|
ID int32 `json:"id"`
|
||
|
|
Type DocumentsType `json:"type"`
|
||
|
|
Created time.Time `json:"created"`
|
||
|
|
UserID int32 `json:"user_id"`
|
||
|
|
DocPageCount int32 `json:"doc_page_count"`
|
||
|
|
PdfFilename string `json:"pdf_filename"`
|
||
|
|
PdfCreatedAt time.Time `json:"pdf_created_at"`
|
||
|
|
PdfCreatedByUserID int32 `json:"pdf_created_by_user_id"`
|
||
|
|
CmcReference string `json:"cmc_reference"`
|
||
|
|
Revision int32 `json:"revision"`
|
||
|
|
EmailSentAt time.Time `json:"email_sent_at"`
|
||
|
|
EmailSentByUserID int32 `json:"email_sent_by_user_id"`
|
||
|
|
UserFirstName sql.NullString `json:"user_first_name"`
|
||
|
|
UserLastName sql.NullString `json:"user_last_name"`
|
||
|
|
UserUsername sql.NullString `json:"user_username"`
|
||
|
|
PdfCreatorFirstName sql.NullString `json:"pdf_creator_first_name"`
|
||
|
|
PdfCreatorLastName sql.NullString `json:"pdf_creator_last_name"`
|
||
|
|
PdfCreatorUsername sql.NullString `json:"pdf_creator_username"`
|
||
|
|
}
|
||
|
|
|
||
|
|
func (q *Queries) ListDocuments(ctx context.Context) ([]ListDocumentsRow, error) {
|
||
|
|
rows, err := q.db.QueryContext(ctx, listDocuments)
|
||
|
|
if err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
defer rows.Close()
|
||
|
|
items := []ListDocumentsRow{}
|
||
|
|
for rows.Next() {
|
||
|
|
var i ListDocumentsRow
|
||
|
|
if err := rows.Scan(
|
||
|
|
&i.ID,
|
||
|
|
&i.Type,
|
||
|
|
&i.Created,
|
||
|
|
&i.UserID,
|
||
|
|
&i.DocPageCount,
|
||
|
|
&i.PdfFilename,
|
||
|
|
&i.PdfCreatedAt,
|
||
|
|
&i.PdfCreatedByUserID,
|
||
|
|
&i.CmcReference,
|
||
|
|
&i.Revision,
|
||
|
|
&i.EmailSentAt,
|
||
|
|
&i.EmailSentByUserID,
|
||
|
|
&i.UserFirstName,
|
||
|
|
&i.UserLastName,
|
||
|
|
&i.UserUsername,
|
||
|
|
&i.PdfCreatorFirstName,
|
||
|
|
&i.PdfCreatorLastName,
|
||
|
|
&i.PdfCreatorUsername,
|
||
|
|
); 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
|
||
|
|
}
|
||
|
|
|
||
|
|
const listDocumentsByType = `-- name: ListDocumentsByType :many
|
||
|
|
SELECT
|
||
|
|
d.id,
|
||
|
|
d.type,
|
||
|
|
d.created,
|
||
|
|
d.user_id,
|
||
|
|
d.doc_page_count,
|
||
|
|
d.pdf_filename,
|
||
|
|
d.pdf_created_at,
|
||
|
|
d.pdf_created_by_user_id,
|
||
|
|
d.cmc_reference,
|
||
|
|
d.revision,
|
||
|
|
d.email_sent_at,
|
||
|
|
d.email_sent_by_user_id,
|
||
|
|
u.first_name as user_first_name,
|
||
|
|
u.last_name as user_last_name,
|
||
|
|
u.username as user_username,
|
||
|
|
pdf_creator.first_name as pdf_creator_first_name,
|
||
|
|
pdf_creator.last_name as pdf_creator_last_name,
|
||
|
|
pdf_creator.username as pdf_creator_username,
|
||
|
|
COALESCE(ec.name, ic.name, '') as customer_name,
|
||
|
|
e.title as enquiry_title
|
||
|
|
FROM documents d
|
||
|
|
LEFT JOIN users u ON d.user_id = u.id
|
||
|
|
LEFT JOIN users pdf_creator ON d.pdf_created_by_user_id = pdf_creator.id
|
||
|
|
LEFT JOIN enquiries e ON d.type IN ('quote', 'orderAck') AND d.cmc_reference = e.title
|
||
|
|
LEFT JOIN customers ec ON e.customer_id = ec.id
|
||
|
|
LEFT JOIN invoices i ON d.type = 'invoice' AND d.cmc_reference = i.title
|
||
|
|
LEFT JOIN customers ic ON i.customer_id = ic.id
|
||
|
|
WHERE d.type = ?
|
||
|
|
ORDER BY d.id DESC
|
||
|
|
LIMIT 1000
|
||
|
|
`
|
||
|
|
|
||
|
|
type ListDocumentsByTypeRow struct {
|
||
|
|
ID int32 `json:"id"`
|
||
|
|
Type DocumentsType `json:"type"`
|
||
|
|
Created time.Time `json:"created"`
|
||
|
|
UserID int32 `json:"user_id"`
|
||
|
|
DocPageCount int32 `json:"doc_page_count"`
|
||
|
|
PdfFilename string `json:"pdf_filename"`
|
||
|
|
PdfCreatedAt time.Time `json:"pdf_created_at"`
|
||
|
|
PdfCreatedByUserID int32 `json:"pdf_created_by_user_id"`
|
||
|
|
CmcReference string `json:"cmc_reference"`
|
||
|
|
Revision int32 `json:"revision"`
|
||
|
|
EmailSentAt time.Time `json:"email_sent_at"`
|
||
|
|
EmailSentByUserID int32 `json:"email_sent_by_user_id"`
|
||
|
|
UserFirstName sql.NullString `json:"user_first_name"`
|
||
|
|
UserLastName sql.NullString `json:"user_last_name"`
|
||
|
|
UserUsername sql.NullString `json:"user_username"`
|
||
|
|
PdfCreatorFirstName sql.NullString `json:"pdf_creator_first_name"`
|
||
|
|
PdfCreatorLastName sql.NullString `json:"pdf_creator_last_name"`
|
||
|
|
PdfCreatorUsername sql.NullString `json:"pdf_creator_username"`
|
||
|
|
CustomerName string `json:"customer_name"`
|
||
|
|
EnquiryTitle sql.NullString `json:"enquiry_title"`
|
||
|
|
}
|
||
|
|
|
||
|
|
func (q *Queries) ListDocumentsByType(ctx context.Context, type_ DocumentsType) ([]ListDocumentsByTypeRow, error) {
|
||
|
|
rows, err := q.db.QueryContext(ctx, listDocumentsByType, type_)
|
||
|
|
if err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
defer rows.Close()
|
||
|
|
items := []ListDocumentsByTypeRow{}
|
||
|
|
for rows.Next() {
|
||
|
|
var i ListDocumentsByTypeRow
|
||
|
|
if err := rows.Scan(
|
||
|
|
&i.ID,
|
||
|
|
&i.Type,
|
||
|
|
&i.Created,
|
||
|
|
&i.UserID,
|
||
|
|
&i.DocPageCount,
|
||
|
|
&i.PdfFilename,
|
||
|
|
&i.PdfCreatedAt,
|
||
|
|
&i.PdfCreatedByUserID,
|
||
|
|
&i.CmcReference,
|
||
|
|
&i.Revision,
|
||
|
|
&i.EmailSentAt,
|
||
|
|
&i.EmailSentByUserID,
|
||
|
|
&i.UserFirstName,
|
||
|
|
&i.UserLastName,
|
||
|
|
&i.UserUsername,
|
||
|
|
&i.PdfCreatorFirstName,
|
||
|
|
&i.PdfCreatorLastName,
|
||
|
|
&i.PdfCreatorUsername,
|
||
|
|
&i.CustomerName,
|
||
|
|
&i.EnquiryTitle,
|
||
|
|
); 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
|
||
|
|
}
|
||
|
|
|
||
|
|
const searchDocuments = `-- name: SearchDocuments :many
|
||
|
|
SELECT
|
||
|
|
d.id,
|
||
|
|
d.type,
|
||
|
|
d.created,
|
||
|
|
d.user_id,
|
||
|
|
d.doc_page_count,
|
||
|
|
d.pdf_filename,
|
||
|
|
d.pdf_created_at,
|
||
|
|
d.pdf_created_by_user_id,
|
||
|
|
d.cmc_reference,
|
||
|
|
d.revision,
|
||
|
|
d.email_sent_at,
|
||
|
|
d.email_sent_by_user_id,
|
||
|
|
u.first_name as user_first_name,
|
||
|
|
u.last_name as user_last_name,
|
||
|
|
u.username as user_username,
|
||
|
|
pdf_creator.first_name as pdf_creator_first_name,
|
||
|
|
pdf_creator.last_name as pdf_creator_last_name,
|
||
|
|
pdf_creator.username as pdf_creator_username,
|
||
|
|
COALESCE(ec.name, ic.name, '') as customer_name,
|
||
|
|
e.title as enquiry_title
|
||
|
|
FROM documents d
|
||
|
|
LEFT JOIN users u ON d.user_id = u.id
|
||
|
|
LEFT JOIN users pdf_creator ON d.pdf_created_by_user_id = pdf_creator.id
|
||
|
|
LEFT JOIN enquiries e ON d.type IN ('quote', 'orderAck') AND d.cmc_reference = e.title
|
||
|
|
LEFT JOIN customers ec ON e.customer_id = ec.id
|
||
|
|
LEFT JOIN invoices i ON d.type = 'invoice' AND d.cmc_reference = i.title
|
||
|
|
LEFT JOIN customers ic ON i.customer_id = ic.id
|
||
|
|
WHERE (
|
||
|
|
d.pdf_filename LIKE ? OR
|
||
|
|
d.cmc_reference LIKE ? OR
|
||
|
|
COALESCE(ec.name, ic.name) LIKE ? OR
|
||
|
|
e.title LIKE ? OR
|
||
|
|
u.username LIKE ?
|
||
|
|
)
|
||
|
|
ORDER BY d.id DESC
|
||
|
|
LIMIT 1000
|
||
|
|
`
|
||
|
|
|
||
|
|
type SearchDocumentsParams struct {
|
||
|
|
PdfFilename string `json:"pdf_filename"`
|
||
|
|
CmcReference string `json:"cmc_reference"`
|
||
|
|
Name string `json:"name"`
|
||
|
|
Title string `json:"title"`
|
||
|
|
Username string `json:"username"`
|
||
|
|
}
|
||
|
|
|
||
|
|
type SearchDocumentsRow struct {
|
||
|
|
ID int32 `json:"id"`
|
||
|
|
Type DocumentsType `json:"type"`
|
||
|
|
Created time.Time `json:"created"`
|
||
|
|
UserID int32 `json:"user_id"`
|
||
|
|
DocPageCount int32 `json:"doc_page_count"`
|
||
|
|
PdfFilename string `json:"pdf_filename"`
|
||
|
|
PdfCreatedAt time.Time `json:"pdf_created_at"`
|
||
|
|
PdfCreatedByUserID int32 `json:"pdf_created_by_user_id"`
|
||
|
|
CmcReference string `json:"cmc_reference"`
|
||
|
|
Revision int32 `json:"revision"`
|
||
|
|
EmailSentAt time.Time `json:"email_sent_at"`
|
||
|
|
EmailSentByUserID int32 `json:"email_sent_by_user_id"`
|
||
|
|
UserFirstName sql.NullString `json:"user_first_name"`
|
||
|
|
UserLastName sql.NullString `json:"user_last_name"`
|
||
|
|
UserUsername sql.NullString `json:"user_username"`
|
||
|
|
PdfCreatorFirstName sql.NullString `json:"pdf_creator_first_name"`
|
||
|
|
PdfCreatorLastName sql.NullString `json:"pdf_creator_last_name"`
|
||
|
|
PdfCreatorUsername sql.NullString `json:"pdf_creator_username"`
|
||
|
|
CustomerName string `json:"customer_name"`
|
||
|
|
EnquiryTitle sql.NullString `json:"enquiry_title"`
|
||
|
|
}
|
||
|
|
|
||
|
|
func (q *Queries) SearchDocuments(ctx context.Context, arg SearchDocumentsParams) ([]SearchDocumentsRow, error) {
|
||
|
|
rows, err := q.db.QueryContext(ctx, searchDocuments,
|
||
|
|
arg.PdfFilename,
|
||
|
|
arg.CmcReference,
|
||
|
|
arg.Name,
|
||
|
|
arg.Title,
|
||
|
|
arg.Username,
|
||
|
|
)
|
||
|
|
if err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
defer rows.Close()
|
||
|
|
items := []SearchDocumentsRow{}
|
||
|
|
for rows.Next() {
|
||
|
|
var i SearchDocumentsRow
|
||
|
|
if err := rows.Scan(
|
||
|
|
&i.ID,
|
||
|
|
&i.Type,
|
||
|
|
&i.Created,
|
||
|
|
&i.UserID,
|
||
|
|
&i.DocPageCount,
|
||
|
|
&i.PdfFilename,
|
||
|
|
&i.PdfCreatedAt,
|
||
|
|
&i.PdfCreatedByUserID,
|
||
|
|
&i.CmcReference,
|
||
|
|
&i.Revision,
|
||
|
|
&i.EmailSentAt,
|
||
|
|
&i.EmailSentByUserID,
|
||
|
|
&i.UserFirstName,
|
||
|
|
&i.UserLastName,
|
||
|
|
&i.UserUsername,
|
||
|
|
&i.PdfCreatorFirstName,
|
||
|
|
&i.PdfCreatorLastName,
|
||
|
|
&i.PdfCreatorUsername,
|
||
|
|
&i.CustomerName,
|
||
|
|
&i.EnquiryTitle,
|
||
|
|
); 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
|
||
|
|
}
|
||
|
|
|
||
|
|
const unarchiveDocument = `-- name: UnarchiveDocument :exec
|
||
|
|
SELECT 1 WHERE ? = ?
|
||
|
|
`
|
||
|
|
|
||
|
|
type UnarchiveDocumentParams struct {
|
||
|
|
Column1 interface{} `json:"column_1"`
|
||
|
|
Column2 interface{} `json:"column_2"`
|
||
|
|
}
|
||
|
|
|
||
|
|
// Note: Unarchiving not supported as documents table doesn't have an archived column
|
||
|
|
// This is a no-op for compatibility
|
||
|
|
func (q *Queries) UnarchiveDocument(ctx context.Context, arg UnarchiveDocumentParams) error {
|
||
|
|
_, err := q.db.ExecContext(ctx, unarchiveDocument, arg.Column1, arg.Column2)
|
||
|
|
return err
|
||
|
|
}
|
||
|
|
|
||
|
|
const updateDocument = `-- name: UpdateDocument :exec
|
||
|
|
UPDATE documents
|
||
|
|
SET
|
||
|
|
type = ?,
|
||
|
|
user_id = ?,
|
||
|
|
doc_page_count = ?,
|
||
|
|
cmc_reference = ?,
|
||
|
|
pdf_filename = ?,
|
||
|
|
pdf_created_at = ?,
|
||
|
|
pdf_created_by_user_id = ?,
|
||
|
|
shipping_details = ?,
|
||
|
|
revision = ?,
|
||
|
|
bill_to = ?,
|
||
|
|
ship_to = ?,
|
||
|
|
email_sent_at = ?,
|
||
|
|
email_sent_by_user_id = ?
|
||
|
|
WHERE id = ?
|
||
|
|
`
|
||
|
|
|
||
|
|
type UpdateDocumentParams struct {
|
||
|
|
Type DocumentsType `json:"type"`
|
||
|
|
UserID int32 `json:"user_id"`
|
||
|
|
DocPageCount int32 `json:"doc_page_count"`
|
||
|
|
CmcReference string `json:"cmc_reference"`
|
||
|
|
PdfFilename string `json:"pdf_filename"`
|
||
|
|
PdfCreatedAt time.Time `json:"pdf_created_at"`
|
||
|
|
PdfCreatedByUserID int32 `json:"pdf_created_by_user_id"`
|
||
|
|
ShippingDetails sql.NullString `json:"shipping_details"`
|
||
|
|
Revision int32 `json:"revision"`
|
||
|
|
BillTo sql.NullString `json:"bill_to"`
|
||
|
|
ShipTo sql.NullString `json:"ship_to"`
|
||
|
|
EmailSentAt time.Time `json:"email_sent_at"`
|
||
|
|
EmailSentByUserID int32 `json:"email_sent_by_user_id"`
|
||
|
|
ID int32 `json:"id"`
|
||
|
|
}
|
||
|
|
|
||
|
|
func (q *Queries) UpdateDocument(ctx context.Context, arg UpdateDocumentParams) error {
|
||
|
|
_, err := q.db.ExecContext(ctx, updateDocument,
|
||
|
|
arg.Type,
|
||
|
|
arg.UserID,
|
||
|
|
arg.DocPageCount,
|
||
|
|
arg.CmcReference,
|
||
|
|
arg.PdfFilename,
|
||
|
|
arg.PdfCreatedAt,
|
||
|
|
arg.PdfCreatedByUserID,
|
||
|
|
arg.ShippingDetails,
|
||
|
|
arg.Revision,
|
||
|
|
arg.BillTo,
|
||
|
|
arg.ShipTo,
|
||
|
|
arg.EmailSentAt,
|
||
|
|
arg.EmailSentByUserID,
|
||
|
|
arg.ID,
|
||
|
|
)
|
||
|
|
return err
|
||
|
|
}
|
||
|
|
|
||
|
|
const updateDocumentPDFInfo = `-- name: UpdateDocumentPDFInfo :exec
|
||
|
|
UPDATE documents
|
||
|
|
SET
|
||
|
|
pdf_filename = ?,
|
||
|
|
pdf_created_at = ?,
|
||
|
|
pdf_created_by_user_id = ?
|
||
|
|
WHERE id = ?
|
||
|
|
`
|
||
|
|
|
||
|
|
type UpdateDocumentPDFInfoParams struct {
|
||
|
|
PdfFilename string `json:"pdf_filename"`
|
||
|
|
PdfCreatedAt time.Time `json:"pdf_created_at"`
|
||
|
|
PdfCreatedByUserID int32 `json:"pdf_created_by_user_id"`
|
||
|
|
ID int32 `json:"id"`
|
||
|
|
}
|
||
|
|
|
||
|
|
func (q *Queries) UpdateDocumentPDFInfo(ctx context.Context, arg UpdateDocumentPDFInfoParams) error {
|
||
|
|
_, err := q.db.ExecContext(ctx, updateDocumentPDFInfo,
|
||
|
|
arg.PdfFilename,
|
||
|
|
arg.PdfCreatedAt,
|
||
|
|
arg.PdfCreatedByUserID,
|
||
|
|
arg.ID,
|
||
|
|
)
|
||
|
|
return err
|
||
|
|
}
|