Add people signature filtering
Signed-off-by: Bryan Frimin <bryan@getprobo.com>
This commit is contained in:
@@ -203,6 +203,7 @@ func (pvss *DocumentVersionSignatures) LoadByDocumentVersionID(
|
||||
scope Scoper,
|
||||
documentVersionID gid.GID,
|
||||
cursor *page.Cursor[DocumentVersionSignatureOrderField],
|
||||
filter *DocumentVersionSignatureFilter,
|
||||
) error {
|
||||
q := `
|
||||
SELECT
|
||||
@@ -220,13 +221,15 @@ WHERE
|
||||
%s
|
||||
AND document_version_id = @document_version_id
|
||||
AND %s
|
||||
AND %s
|
||||
`
|
||||
|
||||
q = fmt.Sprintf(q, scope.SQLFragment(), cursor.SQLFragment())
|
||||
q = fmt.Sprintf(q, scope.SQLFragment(), filter.SQLFragment(), cursor.SQLFragment())
|
||||
|
||||
args := pgx.StrictNamedArgs{"document_version_id": documentVersionID}
|
||||
maps.Copy(args, scope.SQLArguments())
|
||||
maps.Copy(args, cursor.SQLArguments())
|
||||
maps.Copy(args, filter.SQLArguments())
|
||||
|
||||
rows, err := conn.Query(ctx, q, args)
|
||||
if err != nil {
|
||||
|
||||
48
pkg/coredata/document_version_signature_filter.go
Normal file
48
pkg/coredata/document_version_signature_filter.go
Normal file
@@ -0,0 +1,48 @@
|
||||
// Copyright (c) 2025 Probo Inc <hello@getprobo.com>.
|
||||
//
|
||||
// Permission to use, copy, modify, and/or distribute this software for any
|
||||
// purpose with or without fee is hereby granted, provided that the above
|
||||
// copyright notice and this permission notice appear in all copies.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
||||
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
// PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
package coredata
|
||||
|
||||
import (
|
||||
"github.com/jackc/pgx/v5"
|
||||
)
|
||||
|
||||
type (
|
||||
DocumentVersionSignatureFilter struct {
|
||||
states DocumentVersionSignatureStates
|
||||
}
|
||||
)
|
||||
|
||||
func NewDocumentVersionSignatureFilter(states []DocumentVersionSignatureState) *DocumentVersionSignatureFilter {
|
||||
return &DocumentVersionSignatureFilter{
|
||||
states: DocumentVersionSignatureStates(states),
|
||||
}
|
||||
}
|
||||
|
||||
func (f *DocumentVersionSignatureFilter) SQLArguments() pgx.StrictNamedArgs {
|
||||
return pgx.StrictNamedArgs{
|
||||
"states": f.states,
|
||||
}
|
||||
}
|
||||
|
||||
func (f *DocumentVersionSignatureFilter) SQLFragment() string {
|
||||
return `
|
||||
(
|
||||
CASE
|
||||
WHEN @states::policy_version_signature_state[] IS NOT NULL THEN
|
||||
state = ANY(@states::policy_version_signature_state[])
|
||||
ELSE TRUE
|
||||
END
|
||||
)`
|
||||
}
|
||||
@@ -17,10 +17,12 @@ package coredata
|
||||
import (
|
||||
"database/sql/driver"
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type (
|
||||
DocumentVersionSignatureState string
|
||||
DocumentVersionSignatureState string
|
||||
DocumentVersionSignatureStates []DocumentVersionSignatureState
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -74,3 +76,16 @@ func (pvs *DocumentVersionSignatureState) Scan(value any) error {
|
||||
func (pvs DocumentVersionSignatureState) Value() (driver.Value, error) {
|
||||
return pvs.String(), nil
|
||||
}
|
||||
|
||||
func (states DocumentVersionSignatureStates) Value() (driver.Value, error) {
|
||||
var result strings.Builder
|
||||
result.WriteString("{")
|
||||
for i, state := range states {
|
||||
if i > 0 {
|
||||
result.WriteString(",")
|
||||
}
|
||||
result.WriteString(fmt.Sprintf("%q", state.String()))
|
||||
}
|
||||
result.WriteString("}")
|
||||
return result.String(), nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user