Rewrite identity and access management
Signed-off-by: Bryan Frimin <bryan@getprobo.com>
This commit is contained in:
@@ -46,32 +46,8 @@ type (
|
||||
}
|
||||
|
||||
DocumentVersions []*DocumentVersion
|
||||
|
||||
ErrDocumentVersionNotFound struct {
|
||||
Identifier string
|
||||
}
|
||||
|
||||
ErrDocumentVersionAlreadyExists struct {
|
||||
message string
|
||||
}
|
||||
|
||||
ErrDocumentVersionNoChanges struct {
|
||||
Message string
|
||||
}
|
||||
)
|
||||
|
||||
func (e ErrDocumentVersionNotFound) Error() string {
|
||||
return fmt.Sprintf("document version not found: %q", e.Identifier)
|
||||
}
|
||||
|
||||
func (e ErrDocumentVersionAlreadyExists) Error() string {
|
||||
return e.message
|
||||
}
|
||||
|
||||
func (e ErrDocumentVersionNoChanges) Error() string {
|
||||
return e.Message
|
||||
}
|
||||
|
||||
func (p *DocumentVersions) LoadByDocumentID(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
@@ -245,15 +221,8 @@ VALUES (
|
||||
var pgErr *pgconn.PgError
|
||||
if errors.As(err, &pgErr) {
|
||||
if pgErr.Code == "23505" {
|
||||
if pgErr.ConstraintName == "document_versions_document_id_version_number_key" {
|
||||
return &ErrDocumentVersionAlreadyExists{
|
||||
message: fmt.Sprintf("document version with document_id %s and version_number %d already exists", p.DocumentID, p.VersionNumber),
|
||||
}
|
||||
}
|
||||
if pgErr.ConstraintName == "document_one_draft_version_idx" {
|
||||
return &ErrDocumentVersionAlreadyExists{
|
||||
message: fmt.Sprintf("document %s already has a draft version", p.DocumentID),
|
||||
}
|
||||
if pgErr.ConstraintName == "document_versions_document_id_version_number_key" || pgErr.ConstraintName == "document_one_draft_version_idx" {
|
||||
return ErrResourceAlreadyExists
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user