@@ -186,22 +186,22 @@ func (p *Documents) LoadByIDs(
|
||||
) error {
|
||||
q := `
|
||||
SELECT
|
||||
id,
|
||||
organization_id,
|
||||
owner_id,
|
||||
title,
|
||||
document_type,
|
||||
classification,
|
||||
current_published_version,
|
||||
trust_center_visibility,
|
||||
created_at,
|
||||
updated_at
|
||||
id,
|
||||
organization_id,
|
||||
owner_id,
|
||||
title,
|
||||
document_type,
|
||||
classification,
|
||||
current_published_version,
|
||||
trust_center_visibility,
|
||||
created_at,
|
||||
updated_at
|
||||
FROM
|
||||
documents
|
||||
documents
|
||||
WHERE
|
||||
%s
|
||||
AND deleted_at IS NULL
|
||||
AND id = ANY(@document_ids)
|
||||
%s
|
||||
AND deleted_at IS NULL
|
||||
AND id = ANY(@document_ids)
|
||||
`
|
||||
|
||||
q = fmt.Sprintf(q, scope.SQLFragment())
|
||||
|
||||
@@ -111,53 +111,6 @@ LIMIT 1;
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f *Files) LoadByIDs(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
scope Scoper,
|
||||
fileIDs []gid.GID,
|
||||
) error {
|
||||
q := `
|
||||
SELECT
|
||||
id,
|
||||
organization_id,
|
||||
bucket_name,
|
||||
mime_type,
|
||||
file_name,
|
||||
file_key,
|
||||
file_size,
|
||||
created_at,
|
||||
updated_at,
|
||||
deleted_at
|
||||
FROM
|
||||
files
|
||||
WHERE
|
||||
%s
|
||||
AND id = ANY(@file_ids)
|
||||
LIMIT 1;
|
||||
`
|
||||
|
||||
q = fmt.Sprintf(q, scope.SQLFragment())
|
||||
|
||||
args := pgx.StrictNamedArgs{"file_ids": fileIDs}
|
||||
maps.Copy(args, scope.SQLArguments())
|
||||
|
||||
rows, err := conn.Query(ctx, q, args)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot query file: %w", err)
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
files, err := pgx.CollectRows(rows, pgx.RowToAddrOfStructByName[File])
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot collect file: %w", err)
|
||||
}
|
||||
|
||||
*f = files
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f File) Insert(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
|
||||
@@ -50,19 +50,19 @@ func (r *Report) LoadByID(
|
||||
) error {
|
||||
q := `
|
||||
SELECT
|
||||
id,
|
||||
organization_id,
|
||||
object_key,
|
||||
mime_type,
|
||||
filename,
|
||||
size,
|
||||
created_at,
|
||||
updated_at
|
||||
id,
|
||||
organization_id,
|
||||
object_key,
|
||||
mime_type,
|
||||
filename,
|
||||
size,
|
||||
created_at,
|
||||
updated_at
|
||||
FROM
|
||||
reports
|
||||
reports
|
||||
WHERE
|
||||
%s
|
||||
AND id = @report_id
|
||||
%s
|
||||
AND id = @report_id
|
||||
LIMIT 1;
|
||||
`
|
||||
|
||||
@@ -98,20 +98,19 @@ func (r *Reports) LoadByIDs(
|
||||
) error {
|
||||
q := `
|
||||
SELECT
|
||||
id,
|
||||
organization_id,
|
||||
object_key,
|
||||
mime_type,
|
||||
filename,
|
||||
size,
|
||||
created_at,
|
||||
updated_at
|
||||
id,
|
||||
organization_id,
|
||||
object_key,
|
||||
mime_type,
|
||||
filename,
|
||||
size,
|
||||
created_at,
|
||||
updated_at
|
||||
FROM
|
||||
reports
|
||||
reports
|
||||
WHERE
|
||||
%s
|
||||
AND id = ANY(@report_ids)
|
||||
LIMIT 1;
|
||||
%s
|
||||
AND id = ANY(@report_ids);
|
||||
`
|
||||
|
||||
q = fmt.Sprintf(q, scope.SQLFragment())
|
||||
@@ -141,25 +140,25 @@ func (r *Report) Insert(
|
||||
) error {
|
||||
q := `
|
||||
INSERT INTO reports (
|
||||
id,
|
||||
tenant_id,
|
||||
organization_id,
|
||||
object_key,
|
||||
mime_type,
|
||||
filename,
|
||||
size,
|
||||
created_at,
|
||||
updated_at
|
||||
id,
|
||||
tenant_id,
|
||||
organization_id,
|
||||
object_key,
|
||||
mime_type,
|
||||
filename,
|
||||
size,
|
||||
created_at,
|
||||
updated_at
|
||||
) VALUES (
|
||||
@id,
|
||||
@tenant_id,
|
||||
@organization_id,
|
||||
@object_key,
|
||||
@mime_type,
|
||||
@filename,
|
||||
@size,
|
||||
@created_at,
|
||||
@updated_at
|
||||
@id,
|
||||
@tenant_id,
|
||||
@organization_id,
|
||||
@object_key,
|
||||
@mime_type,
|
||||
@filename,
|
||||
@size,
|
||||
@created_at,
|
||||
@updated_at
|
||||
)
|
||||
`
|
||||
|
||||
@@ -191,14 +190,14 @@ func (r *Report) Update(
|
||||
q := `
|
||||
UPDATE reports
|
||||
SET
|
||||
object_key = @object_key,
|
||||
mime_type = @mime_type,
|
||||
filename = @filename,
|
||||
size = @size,
|
||||
updated_at = @updated_at
|
||||
object_key = @object_key,
|
||||
mime_type = @mime_type,
|
||||
filename = @filename,
|
||||
size = @size,
|
||||
updated_at = @updated_at
|
||||
WHERE
|
||||
%s
|
||||
AND id = @id
|
||||
%s
|
||||
AND id = @id
|
||||
`
|
||||
|
||||
q = fmt.Sprintf(q, scope.SQLFragment())
|
||||
@@ -229,8 +228,8 @@ func (r *Report) Delete(
|
||||
q := `
|
||||
DELETE FROM reports
|
||||
WHERE
|
||||
%s
|
||||
AND id = @id
|
||||
%s
|
||||
AND id = @id
|
||||
`
|
||||
|
||||
q = fmt.Sprintf(q, scope.SQLFragment())
|
||||
|
||||
@@ -96,6 +96,52 @@ LIMIT 1;
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f *TrustCenterFiles) LoadByIDs(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
scope Scoper,
|
||||
trustCenterFileIDs []gid.GID,
|
||||
) error {
|
||||
q := `
|
||||
SELECT
|
||||
id,
|
||||
organization_id,
|
||||
bucket_name,
|
||||
mime_type,
|
||||
file_name,
|
||||
file_key,
|
||||
file_size,
|
||||
created_at,
|
||||
updated_at,
|
||||
deleted_at
|
||||
FROM
|
||||
files
|
||||
WHERE
|
||||
%s
|
||||
AND id = ANY(@ids);
|
||||
`
|
||||
|
||||
q = fmt.Sprintf(q, scope.SQLFragment())
|
||||
|
||||
args := pgx.StrictNamedArgs{"ids": trustCenterFileIDs}
|
||||
maps.Copy(args, scope.SQLArguments())
|
||||
|
||||
rows, err := conn.Query(ctx, q, args)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot query file: %w", err)
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
files, err := pgx.CollectRows(rows, pgx.RowToAddrOfStructByName[TrustCenterFile])
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot collect file: %w", err)
|
||||
}
|
||||
|
||||
*f = files
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t TrustCenterFile) Insert(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
@@ -322,7 +368,7 @@ FROM
|
||||
trust_center_files
|
||||
WHERE
|
||||
%s
|
||||
%s
|
||||
AND %s
|
||||
AND organization_id = @organization_id
|
||||
ORDER BY
|
||||
created_at DESC
|
||||
|
||||
Reference in New Issue
Block a user