snapshot of https://github.com/cortezaproject/corteza.git (2024.9.x, 2026-09-18; blobs > 131072B omitted)
Some checks failed
SonarQube / SonarQube (push) Failing after 5m28s
E2e test on main branch push / server and client test (map[name:admin port:8080]) (push) Failing after 3m33s
Server and lib tests / Library test (js) (push) Failing after 1m36s
Server and lib tests / Library test (vue) (push) Successful in 2m24s
Server and lib tests / Web client test (admin) (push) Successful in 2m52s
Server and lib tests / Web client test (compose) (push) Successful in 3m23s
Server and lib tests / Web client test (discovery) (push) Successful in 2m49s
Server and lib tests / Web client test (one) (push) Successful in 2m52s
Server and lib tests / Web client test (privacy) (push) Successful in 2m44s
Server and lib tests / Web client test (reporter) (push) Successful in 2m56s
Server and lib tests / Web client test (workflow) (push) Successful in 3m0s
Server and lib tests / Server tests (push) Failing after 4m55s
E2e test on main branch push / notify-failure (push) Failing after 9s
Server and lib tests / Send matrix testing notification (push) Successful in 2s
Mark stale issues and pull requests / stale (push) Successful in 40s
Some checks failed
SonarQube / SonarQube (push) Failing after 5m28s
E2e test on main branch push / server and client test (map[name:admin port:8080]) (push) Failing after 3m33s
Server and lib tests / Library test (js) (push) Failing after 1m36s
Server and lib tests / Library test (vue) (push) Successful in 2m24s
Server and lib tests / Web client test (admin) (push) Successful in 2m52s
Server and lib tests / Web client test (compose) (push) Successful in 3m23s
Server and lib tests / Web client test (discovery) (push) Successful in 2m49s
Server and lib tests / Web client test (one) (push) Successful in 2m52s
Server and lib tests / Web client test (privacy) (push) Successful in 2m44s
Server and lib tests / Web client test (reporter) (push) Successful in 2m56s
Server and lib tests / Web client test (workflow) (push) Successful in 3m0s
Server and lib tests / Server tests (push) Failing after 4m55s
E2e test on main branch push / notify-failure (push) Failing after 9s
Server and lib tests / Send matrix testing notification (push) Successful in 2s
Mark stale issues and pull requests / stale (push) Successful in 40s
This commit is contained in:
154
server/system/rest/queues.go
Normal file
154
server/system/rest/queues.go
Normal file
@@ -0,0 +1,154 @@
|
||||
package rest
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/cortezaproject/corteza/server/pkg/api"
|
||||
"github.com/cortezaproject/corteza/server/pkg/filter"
|
||||
"github.com/cortezaproject/corteza/server/system/rest/request"
|
||||
"github.com/cortezaproject/corteza/server/system/service"
|
||||
"github.com/cortezaproject/corteza/server/system/types"
|
||||
)
|
||||
|
||||
type (
|
||||
Queue struct {
|
||||
svc queueService
|
||||
ac queueAccessController
|
||||
}
|
||||
|
||||
queuePayload struct {
|
||||
*types.Queue
|
||||
|
||||
CanGrant bool `json:"canGrant"`
|
||||
CanUpdateQueue bool `json:"canUpdateQueue"`
|
||||
CanDeleteQueue bool `json:"canDeleteQueue"`
|
||||
}
|
||||
|
||||
queueSetPayload struct {
|
||||
Filter types.QueueFilter `json:"filter"`
|
||||
Set []*queuePayload `json:"set"`
|
||||
}
|
||||
|
||||
queueService interface {
|
||||
FindByID(ctx context.Context, ID uint64) (q *types.Queue, err error)
|
||||
Create(ctx context.Context, new *types.Queue) (q *types.Queue, err error)
|
||||
Update(ctx context.Context, upd *types.Queue) (q *types.Queue, err error)
|
||||
DeleteByID(ctx context.Context, ID uint64) (err error)
|
||||
UndeleteByID(ctx context.Context, ID uint64) (err error)
|
||||
Search(ctx context.Context, filter types.QueueFilter) (q types.QueueSet, f types.QueueFilter, err error)
|
||||
}
|
||||
|
||||
queueAccessController interface {
|
||||
CanGrant(context.Context) bool
|
||||
|
||||
CanCreateQueue(context.Context) bool
|
||||
CanUpdateQueue(context.Context, *types.Queue) bool
|
||||
CanDeleteQueue(context.Context, *types.Queue) bool
|
||||
}
|
||||
)
|
||||
|
||||
func (Queue) New() *Queue {
|
||||
return &Queue{
|
||||
svc: service.DefaultQueue,
|
||||
ac: service.DefaultAccessControl,
|
||||
}
|
||||
}
|
||||
|
||||
func (ctrl *Queue) List(ctx context.Context, r *request.QueuesList) (interface{}, error) {
|
||||
var (
|
||||
err error
|
||||
f = types.QueueFilter{
|
||||
Query: r.Query,
|
||||
Deleted: filter.State(r.Deleted),
|
||||
}
|
||||
)
|
||||
|
||||
if f.Paging, err = filter.NewPaging(r.Limit, r.PageCursor); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
f.IncTotal = r.IncTotal
|
||||
|
||||
if f.Sorting, err = filter.NewSorting(r.Sort); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
set, filter, err := ctrl.svc.Search(ctx, f)
|
||||
return ctrl.makeFilterPayload(ctx, set, filter, err)
|
||||
}
|
||||
|
||||
func (ctrl *Queue) Create(ctx context.Context, r *request.QueuesCreate) (interface{}, error) {
|
||||
var (
|
||||
err error
|
||||
q = &types.Queue{
|
||||
Consumer: r.Consumer,
|
||||
Queue: r.Queue,
|
||||
Meta: r.Meta,
|
||||
}
|
||||
)
|
||||
|
||||
q, err = ctrl.svc.Create(ctx, q)
|
||||
|
||||
return ctrl.makePayload(ctx, q, err)
|
||||
}
|
||||
|
||||
func (ctrl *Queue) Read(ctx context.Context, r *request.QueuesRead) (interface{}, error) {
|
||||
res, err := ctrl.svc.FindByID(ctx, r.QueueID)
|
||||
return ctrl.makePayload(ctx, res, err)
|
||||
}
|
||||
|
||||
func (ctrl *Queue) Update(ctx context.Context, r *request.QueuesUpdate) (interface{}, error) {
|
||||
var (
|
||||
err error
|
||||
q = &types.Queue{
|
||||
ID: r.QueueID,
|
||||
Consumer: r.Consumer,
|
||||
Queue: r.Queue,
|
||||
Meta: r.Meta,
|
||||
UpdatedAt: r.UpdatedAt,
|
||||
}
|
||||
)
|
||||
|
||||
q, err = ctrl.svc.Update(ctx, q)
|
||||
|
||||
return ctrl.makePayload(ctx, q, err)
|
||||
}
|
||||
|
||||
func (ctrl *Queue) Delete(ctx context.Context, r *request.QueuesDelete) (interface{}, error) {
|
||||
return api.OK(), ctrl.svc.DeleteByID(ctx, r.QueueID)
|
||||
}
|
||||
|
||||
func (ctrl *Queue) Undelete(ctx context.Context, r *request.QueuesUndelete) (interface{}, error) {
|
||||
return api.OK(), ctrl.svc.UndeleteByID(ctx, r.QueueID)
|
||||
}
|
||||
|
||||
func (ctrl *Queue) makePayload(ctx context.Context, q *types.Queue, err error) (*queuePayload, error) {
|
||||
if err != nil || q == nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
qq := &queuePayload{
|
||||
Queue: q,
|
||||
|
||||
CanGrant: ctrl.ac.CanGrant(ctx),
|
||||
|
||||
CanUpdateQueue: ctrl.ac.CanUpdateQueue(ctx, q),
|
||||
CanDeleteQueue: ctrl.ac.CanDeleteQueue(ctx, q),
|
||||
}
|
||||
|
||||
return qq, nil
|
||||
}
|
||||
|
||||
func (ctrl *Queue) makeFilterPayload(ctx context.Context, nn types.QueueSet, f types.QueueFilter, err error) (*queueSetPayload, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
msp := &queueSetPayload{Filter: f, Set: make([]*queuePayload, len(nn))}
|
||||
|
||||
for i := range nn {
|
||||
msp.Set[i], _ = ctrl.makePayload(ctx, nn[i], nil)
|
||||
}
|
||||
|
||||
return msp, nil
|
||||
}
|
||||
Reference in New Issue
Block a user