Rewrite identity and access management
Signed-off-by: Bryan Frimin <bryan@getprobo.com>
This commit is contained in:
@@ -46,24 +46,8 @@ type (
|
||||
}
|
||||
|
||||
Tasks []*Task
|
||||
|
||||
ErrTaskNotFound struct {
|
||||
Identifier string
|
||||
}
|
||||
|
||||
ErrTaskAlreadyExists struct {
|
||||
message string
|
||||
}
|
||||
)
|
||||
|
||||
func (e ErrTaskNotFound) Error() string {
|
||||
return fmt.Sprintf("task not found: %q", e.Identifier)
|
||||
}
|
||||
|
||||
func (e ErrTaskAlreadyExists) Error() string {
|
||||
return e.message
|
||||
}
|
||||
|
||||
func (c Task) CursorKey(orderBy TaskOrderField) page.CursorKey {
|
||||
switch orderBy {
|
||||
case TaskOrderFieldCreatedAt:
|
||||
@@ -114,7 +98,7 @@ LIMIT 1;
|
||||
task, err := pgx.CollectExactlyOneRow(rows, pgx.RowToStructByName[Task])
|
||||
if err != nil {
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return &ErrTaskNotFound{Identifier: taskID.String()}
|
||||
return ErrResourceNotFound
|
||||
}
|
||||
|
||||
return fmt.Errorf("cannot collect tasks: %w", err)
|
||||
@@ -185,9 +169,7 @@ VALUES (
|
||||
var pgErr *pgconn.PgError
|
||||
if errors.As(err, &pgErr) {
|
||||
if pgErr.Code == "23505" && pgErr.ConstraintName == "tasks_reference_id_unique" {
|
||||
return &ErrTaskAlreadyExists{
|
||||
message: fmt.Sprintf("task with measure_id %s and reference_id %q already exists", c.MeasureID, c.ReferenceID),
|
||||
}
|
||||
return ErrResourceAlreadyExists
|
||||
}
|
||||
}
|
||||
return fmt.Errorf("cannot insert task: %w", err)
|
||||
|
||||
Reference in New Issue
Block a user