MSP-634 add func get_access_list_by_app_id to access_list repository
This commit is contained in:
1 parent
ab89a27053
commit
bb0d2b460a
1 file changed
+20
@@ -2,11 +2,13 @@ package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
|
||||
"github.com/Masterminds/squirrel"
|
||||
"github.com/integration-system/isp-kit/db"
|
||||
"github.com/integration-system/isp-kit/db/query"
|
||||
"github.com/pkg/errors"
|
||||
"isp-system-service/domain"
|
||||
"isp-system-service/entity"
|
||||
)
|
||||
|
||||
@@ -20,6 +22,24 @@ func NewAccessList(db db.DB) AccessList {
|
||||
}
|
||||
}
|
||||
|
||||
func (r AccessList) GetAccessListByAppIdAndMethod(ctx context.Context, appId int, method string) (*entity.AccessList, error) {
|
||||
q := `
|
||||
SELECT app_id, method, value
|
||||
FROM access_list
|
||||
WHERE app_id = $1 AND method = $2
|
||||
`
|
||||
result := entity.AccessList{}
|
||||
err := r.db.SelectRow(ctx, &result, q, appId, method)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, domain.ErrAccessListNotFound
|
||||
}
|
||||
return nil, errors.WithMessagef(err, "select db")
|
||||
}
|
||||
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
func (r AccessList) GetAccessListByAppId(ctx context.Context, appId int) ([]entity.AccessList, error) {
|
||||
q := `
|
||||
SELECT app_id, method, value
|
||||
|
||||
Reference in new issue
Block a user