diff --git a/api/ws/handlers/detector-config.go b/api/ws/handlers/detector-config.go index 370fad30..e71c7cae 100644 --- a/api/ws/handlers/detector-config.go +++ b/api/ws/handlers/detector-config.go @@ -11,7 +11,7 @@ import ( "go.mongodb.org/mongo-driver/mongo/options" ) -func HandleDetectorConfigReq(req *protos.DetectorConfigReq, hctx wsHelpers.HandlerContext) (*protos.DetectorConfigResp, error) { +func HandleDetectorConfigReq(req *protos.DetectorConfigReq, hctx wsHelpers.HandlerContext) ([]*protos.DetectorConfigResp, error) { if err := wsHelpers.CheckStringField(&req.Id, "Id", 1, 255); err != nil { return nil, err } @@ -21,13 +21,13 @@ func HandleDetectorConfigReq(req *protos.DetectorConfigReq, hctx wsHelpers.Handl return nil, err } - return &protos.DetectorConfigResp{ + return []*protos.DetectorConfigResp{&protos.DetectorConfigResp{ Config: cfg, PiquantConfigVersions: piquant.GetPiquantConfigVersions(hctx.Svcs, req.Id), - }, nil + }}, nil } -func HandleDetectorConfigListReq(req *protos.DetectorConfigListReq, hctx wsHelpers.HandlerContext) (*protos.DetectorConfigListResp, error) { +func HandleDetectorConfigListReq(req *protos.DetectorConfigListReq, hctx wsHelpers.HandlerContext) ([]*protos.DetectorConfigListResp, error) { coll := hctx.Svcs.MongoDB.Collection(dbCollections.DetectorConfigsName) filter := bson.D{} @@ -51,7 +51,7 @@ func HandleDetectorConfigListReq(req *protos.DetectorConfigListReq, hctx wsHelpe configList = append(configList, cfg.Id) } - return &protos.DetectorConfigListResp{ + return []*protos.DetectorConfigListResp{&protos.DetectorConfigListResp{ Configs: configList, - }, nil + }}, nil } diff --git a/api/ws/handlers/diffraction-detected-peak.go b/api/ws/handlers/diffraction-detected-peak.go index 545549e5..3e10b12c 100644 --- a/api/ws/handlers/diffraction-detected-peak.go +++ b/api/ws/handlers/diffraction-detected-peak.go @@ -8,7 +8,7 @@ import ( protos "github.com/pixlise/core/v4/generated-protos" ) -func HandleDetectedDiffractionPeaksReq(req *protos.DetectedDiffractionPeaksReq, hctx wsHelpers.HandlerContext) (*protos.DetectedDiffractionPeaksResp, error) { +func HandleDetectedDiffractionPeaksReq(req *protos.DetectedDiffractionPeaksReq, hctx wsHelpers.HandlerContext) ([]*protos.DetectedDiffractionPeaksResp, error) { // Because we're dealing in entry indexes (relative to the scan), we download the dataset.bin file here too // to get the totals, and to look up PMCs from diffraction DB exprPB, err := beginDatasetFileReq(req.ScanId, hctx) @@ -64,7 +64,7 @@ func HandleDetectedDiffractionPeaksReq(req *protos.DetectedDiffractionPeaksReq, } } - return &protos.DetectedDiffractionPeaksResp{ + return []*protos.DetectedDiffractionPeaksResp{&protos.DetectedDiffractionPeaksResp{ PeaksPerLocation: diffPerLoc, - }, nil + }}, nil } diff --git a/api/ws/handlers/diffraction-manual.go b/api/ws/handlers/diffraction-manual.go index 7a480438..cc485ef5 100644 --- a/api/ws/handlers/diffraction-manual.go +++ b/api/ws/handlers/diffraction-manual.go @@ -14,7 +14,7 @@ import ( "go.mongodb.org/mongo-driver/mongo/options" ) -func HandleDiffractionPeakManualListReq(req *protos.DiffractionPeakManualListReq, hctx wsHelpers.HandlerContext) (*protos.DiffractionPeakManualListResp, error) { +func HandleDiffractionPeakManualListReq(req *protos.DiffractionPeakManualListReq, hctx wsHelpers.HandlerContext) ([]*protos.DiffractionPeakManualListResp, error) { if err := wsHelpers.CheckStringField(&req.ScanId, "ScanId", 1, wsHelpers.IdFieldMaxLength); err != nil { return nil, err } @@ -30,9 +30,9 @@ func HandleDiffractionPeakManualListReq(req *protos.DiffractionPeakManualListReq if err != nil { if err == mongo.ErrNoDocuments { // Silent error, just return empty - return &protos.DiffractionPeakManualListResp{ + return []*protos.DiffractionPeakManualListResp{&protos.DiffractionPeakManualListResp{ Peaks: map[string]*protos.ManualDiffractionPeak{}, - }, nil + }}, nil } return nil, err @@ -51,15 +51,15 @@ func HandleDiffractionPeakManualListReq(req *protos.DiffractionPeakManualListReq item.ScanId = "" // Also no point keeping this around, it was part of the request params } - return &protos.DiffractionPeakManualListResp{ + return []*protos.DiffractionPeakManualListResp{&protos.DiffractionPeakManualListResp{ Peaks: resultMap, - }, nil + }}, nil } // NOTE: ScanId isn't checked to see if it's a real scan upon insertion! // NOTE2: Insert ONLY! We generate an ID and insert into DB -func HandleDiffractionPeakManualInsertReq(req *protos.DiffractionPeakManualInsertReq, hctx wsHelpers.HandlerContext) (*protos.DiffractionPeakManualInsertResp, error) { +func HandleDiffractionPeakManualInsertReq(req *protos.DiffractionPeakManualInsertReq, hctx wsHelpers.HandlerContext) ([]*protos.DiffractionPeakManualInsertResp, error) { if err := wsHelpers.CheckStringField(&req.ScanId, "ScanId", 1, wsHelpers.IdFieldMaxLength); err != nil { return nil, err } @@ -91,10 +91,10 @@ func HandleDiffractionPeakManualInsertReq(req *protos.DiffractionPeakManualInser hctx.Svcs.Log.Errorf("Manual diffraction insertion expected InsertedID of %v, got %v", id, result.InsertedID) } - return &protos.DiffractionPeakManualInsertResp{CreatedId: id}, nil + return []*protos.DiffractionPeakManualInsertResp{&protos.DiffractionPeakManualInsertResp{CreatedId: id}}, nil } -func HandleDiffractionPeakManualDeleteReq(req *protos.DiffractionPeakManualDeleteReq, hctx wsHelpers.HandlerContext) (*protos.DiffractionPeakManualDeleteResp, error) { +func HandleDiffractionPeakManualDeleteReq(req *protos.DiffractionPeakManualDeleteReq, hctx wsHelpers.HandlerContext) ([]*protos.DiffractionPeakManualDeleteResp, error) { if err := wsHelpers.CheckStringField(&req.Id, "Id", 1, wsHelpers.IdFieldMaxLength*2+1); err != nil { return nil, err } @@ -114,5 +114,5 @@ func HandleDiffractionPeakManualDeleteReq(req *protos.DiffractionPeakManualDelet return nil, errorwithstatus.MakeNotFoundError(req.Id) } - return &protos.DiffractionPeakManualDeleteResp{}, nil + return []*protos.DiffractionPeakManualDeleteResp{&protos.DiffractionPeakManualDeleteResp{}}, nil } diff --git a/api/ws/handlers/diffraction-status.go b/api/ws/handlers/diffraction-status.go index 87f46b4a..d86d9efa 100644 --- a/api/ws/handlers/diffraction-status.go +++ b/api/ws/handlers/diffraction-status.go @@ -12,7 +12,7 @@ import ( "go.mongodb.org/mongo-driver/mongo/options" ) -func HandleDiffractionPeakStatusListReq(req *protos.DiffractionPeakStatusListReq, hctx wsHelpers.HandlerContext) (*protos.DiffractionPeakStatusListResp, error) { +func HandleDiffractionPeakStatusListReq(req *protos.DiffractionPeakStatusListReq, hctx wsHelpers.HandlerContext) ([]*protos.DiffractionPeakStatusListResp, error) { if err := wsHelpers.CheckStringField(&req.ScanId, "ScanId", 1, wsHelpers.IdFieldMaxLength); err != nil { return nil, err } @@ -27,13 +27,13 @@ func HandleDiffractionPeakStatusListReq(req *protos.DiffractionPeakStatusListReq if dbResult.Err() != nil { if dbResult.Err() == mongo.ErrNoDocuments { // Silent error, just return empty - return &protos.DiffractionPeakStatusListResp{ + return []*protos.DiffractionPeakStatusListResp{&protos.DiffractionPeakStatusListResp{ PeakStatuses: &protos.DetectedDiffractionPeakStatuses{ Id: req.ScanId, ScanId: req.ScanId, Statuses: map[string]*protos.DetectedDiffractionPeakStatuses_PeakStatus{}, }, - }, nil + }}, nil } return nil, dbResult.Err() } @@ -44,14 +44,14 @@ func HandleDiffractionPeakStatusListReq(req *protos.DiffractionPeakStatusListReq return nil, err } - return &protos.DiffractionPeakStatusListResp{ + return []*protos.DiffractionPeakStatusListResp{&protos.DiffractionPeakStatusListResp{ PeakStatuses: &result, - }, nil + }}, nil } // NOTE: ScanId isn't checked to see if it's a real scan upon insertion! -func HandleDiffractionPeakStatusWriteReq(req *protos.DiffractionPeakStatusWriteReq, hctx wsHelpers.HandlerContext) (*protos.DiffractionPeakStatusWriteResp, error) { +func HandleDiffractionPeakStatusWriteReq(req *protos.DiffractionPeakStatusWriteReq, hctx wsHelpers.HandlerContext) ([]*protos.DiffractionPeakStatusWriteResp, error) { if err := wsHelpers.CheckStringField(&req.ScanId, "ScanId", 1, wsHelpers.IdFieldMaxLength); err != nil { return nil, err } @@ -83,10 +83,10 @@ func HandleDiffractionPeakStatusWriteReq(req *protos.DiffractionPeakStatusWriteR hctx.Svcs.Log.Errorf("DiffractionPeakStatusWriteReq UpdateByID result had unexpected counts %+v", dbResult) } - return &protos.DiffractionPeakStatusWriteResp{}, nil + return []*protos.DiffractionPeakStatusWriteResp{&protos.DiffractionPeakStatusWriteResp{}}, nil } -func HandleDiffractionPeakStatusDeleteReq(req *protos.DiffractionPeakStatusDeleteReq, hctx wsHelpers.HandlerContext) (*protos.DiffractionPeakStatusDeleteResp, error) { +func HandleDiffractionPeakStatusDeleteReq(req *protos.DiffractionPeakStatusDeleteReq, hctx wsHelpers.HandlerContext) ([]*protos.DiffractionPeakStatusDeleteResp, error) { if err := wsHelpers.CheckStringField(&req.ScanId, "ScanId", 1, wsHelpers.IdFieldMaxLength); err != nil { return nil, err } @@ -110,5 +110,5 @@ func HandleDiffractionPeakStatusDeleteReq(req *protos.DiffractionPeakStatusDelet //hctx.Svcs.Log.Errorf("DiffractionPeakStatusDeleteReq UpdateByID result had unexpected counts %+v", dbResult) } - return &protos.DiffractionPeakStatusDeleteResp{}, nil + return []*protos.DiffractionPeakStatusDeleteResp{&protos.DiffractionPeakStatusDeleteResp{}}, nil } diff --git a/api/ws/handlers/doi.go b/api/ws/handlers/doi.go index d4fbaa13..e6ee2034 100644 --- a/api/ws/handlers/doi.go +++ b/api/ws/handlers/doi.go @@ -317,7 +317,7 @@ func PublishExpressionToZenodo(id string, output string, metadata *protos.DOIMet return publishResponse, nil } -func HandlePublishExpressionToZenodoReq(req *protos.PublishExpressionToZenodoReq, hctx wsHelpers.HandlerContext) (*protos.PublishExpressionToZenodoResp, error) { +func HandlePublishExpressionToZenodoReq(req *protos.PublishExpressionToZenodoReq, hctx wsHelpers.HandlerContext) ([]*protos.PublishExpressionToZenodoResp, error) { if hctx.Svcs.Config.EnvironmentName == "unittest" || hctx.Svcs.Config.EnvironmentName == "local" { http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true} } @@ -360,19 +360,19 @@ func HandlePublishExpressionToZenodoReq(req *protos.PublishExpressionToZenodoReq return nil, err } - return &protos.PublishExpressionToZenodoResp{ + return []*protos.PublishExpressionToZenodoResp{&protos.PublishExpressionToZenodoResp{ Doi: &metadata, - }, nil + }}, nil } -func HandleZenodoDOIGetReq(req *protos.ZenodoDOIGetReq, hctx wsHelpers.HandlerContext) (*protos.ZenodoDOIGetResp, error) { +func HandleZenodoDOIGetReq(req *protos.ZenodoDOIGetReq, hctx wsHelpers.HandlerContext) ([]*protos.ZenodoDOIGetResp, error) { metadata := &protos.DOIMetadata{} err := hctx.Svcs.MongoDB.Collection(dbCollections.DOIName).FindOne(context.TODO(), bson.D{{Key: "_id", Value: req.Id}}).Decode(&metadata) if err != nil { return nil, err } - return &protos.ZenodoDOIGetResp{ + return []*protos.ZenodoDOIGetResp{&protos.ZenodoDOIGetResp{ Doi: metadata, - }, nil + }}, nil } diff --git a/api/ws/handlers/element-set.go b/api/ws/handlers/element-set.go index b8aa244d..a7dde07f 100644 --- a/api/ws/handlers/element-set.go +++ b/api/ws/handlers/element-set.go @@ -16,23 +16,23 @@ import ( "go.mongodb.org/mongo-driver/mongo/writeconcern" ) -func HandleElementSetDeleteReq(req *protos.ElementSetDeleteReq, hctx wsHelpers.HandlerContext) (*protos.ElementSetDeleteResp, error) { +func HandleElementSetDeleteReq(req *protos.ElementSetDeleteReq, hctx wsHelpers.HandlerContext) ([]*protos.ElementSetDeleteResp, error) { return wsHelpers.DeleteUserObject[protos.ElementSetDeleteResp](req.Id, protos.ObjectType_OT_ELEMENT_SET, dbCollections.ElementSetsName, hctx) } -func HandleElementSetGetReq(req *protos.ElementSetGetReq, hctx wsHelpers.HandlerContext) (*protos.ElementSetGetResp, error) { +func HandleElementSetGetReq(req *protos.ElementSetGetReq, hctx wsHelpers.HandlerContext) ([]*protos.ElementSetGetResp, error) { dbItem, owner, err := wsHelpers.GetUserObjectById[protos.ElementSet](false, req.Id, protos.ObjectType_OT_ELEMENT_SET, dbCollections.ElementSetsName, hctx) if err != nil { return nil, err } dbItem.Owner = wsHelpers.MakeOwnerSummary(owner, hctx.SessUser, hctx.Svcs.MongoDB, hctx.Svcs.TimeStamper) - return &protos.ElementSetGetResp{ + return []*protos.ElementSetGetResp{&protos.ElementSetGetResp{ ElementSet: dbItem, - }, nil + }}, nil } -func HandleElementSetListReq(req *protos.ElementSetListReq, hctx wsHelpers.HandlerContext) (*protos.ElementSetListResp, error) { +func HandleElementSetListReq(req *protos.ElementSetListReq, hctx wsHelpers.HandlerContext) ([]*protos.ElementSetListResp, error) { idToOwner, err := wsHelpers.ListAccessibleIDs(false, protos.ObjectType_OT_ELEMENT_SET, hctx.Svcs, hctx.SessUser) if err != nil { return nil, err @@ -75,9 +75,9 @@ func HandleElementSetListReq(req *protos.ElementSetListReq, hctx wsHelpers.Handl itemMap[item.Id] = summary } - return &protos.ElementSetListResp{ + return []*protos.ElementSetListResp{&protos.ElementSetListResp{ ElementSets: itemMap, - }, nil + }}, nil } func validateElementSet(elementSet *protos.ElementSet) error { @@ -183,7 +183,7 @@ func updateElementSet(elementSet *protos.ElementSet, hctx wsHelpers.HandlerConte return dbItem, nil } -func HandleElementSetWriteReq(req *protos.ElementSetWriteReq, hctx wsHelpers.HandlerContext) (*protos.ElementSetWriteResp, error) { +func HandleElementSetWriteReq(req *protos.ElementSetWriteReq, hctx wsHelpers.HandlerContext) ([]*protos.ElementSetWriteResp, error) { // Owner should never be accepted from API if req.ElementSet.Owner != nil { return nil, errorwithstatus.MakeBadRequestError(errors.New("Owner must be empty for write messages")) @@ -201,7 +201,7 @@ func HandleElementSetWriteReq(req *protos.ElementSetWriteReq, hctx wsHelpers.Han return nil, err } - return &protos.ElementSetWriteResp{ + return []*protos.ElementSetWriteResp{&protos.ElementSetWriteResp{ ElementSet: item, - }, nil + }}, nil } diff --git a/api/ws/handlers/export.go b/api/ws/handlers/export.go index 4c336496..d342c374 100644 --- a/api/ws/handlers/export.go +++ b/api/ws/handlers/export.go @@ -12,7 +12,7 @@ import ( protos "github.com/pixlise/core/v4/generated-protos" ) -func HandleExportFilesReq(req *protos.ExportFilesReq, hctx wsHelpers.HandlerContext) (*protos.ExportFilesResp, error) { +func HandleExportFilesReq(req *protos.ExportFilesReq, hctx wsHelpers.HandlerContext) ([]*protos.ExportFilesResp, error) { if len(req.ExportTypes) <= 0 { return nil, errors.New("no export types specified") } @@ -62,5 +62,5 @@ func HandleExportFilesReq(req *protos.ExportFilesReq, hctx wsHelpers.HandlerCont } } - return &protos.ExportFilesResp{Files: files}, nil + return []*protos.ExportFilesResp{&protos.ExportFilesResp{Files: files}}, nil } diff --git a/api/ws/handlers/expression-group.go b/api/ws/handlers/expression-group.go index 69fec35d..c89faa98 100644 --- a/api/ws/handlers/expression-group.go +++ b/api/ws/handlers/expression-group.go @@ -16,11 +16,11 @@ import ( "go.mongodb.org/mongo-driver/mongo/writeconcern" ) -func HandleExpressionGroupDeleteReq(req *protos.ExpressionGroupDeleteReq, hctx wsHelpers.HandlerContext) (*protos.ExpressionGroupDeleteResp, error) { +func HandleExpressionGroupDeleteReq(req *protos.ExpressionGroupDeleteReq, hctx wsHelpers.HandlerContext) ([]*protos.ExpressionGroupDeleteResp, error) { return wsHelpers.DeleteUserObject[protos.ExpressionGroupDeleteResp](req.Id, protos.ObjectType_OT_EXPRESSION_GROUP, dbCollections.ExpressionGroupsName, hctx) } -func HandleExpressionGroupListReq(req *protos.ExpressionGroupListReq, hctx wsHelpers.HandlerContext) (*protos.ExpressionGroupListResp, error) { +func HandleExpressionGroupListReq(req *protos.ExpressionGroupListReq, hctx wsHelpers.HandlerContext) ([]*protos.ExpressionGroupListResp, error) { filter, idToOwner, err := wsHelpers.MakeFilter(req.SearchParams, false, protos.ObjectType_OT_EXPRESSION_GROUP, hctx) if err != nil { return nil, err @@ -47,21 +47,21 @@ func HandleExpressionGroupListReq(req *protos.ExpressionGroupListReq, hctx wsHel itemMap[item.Id] = item } - return &protos.ExpressionGroupListResp{ + return []*protos.ExpressionGroupListResp{&protos.ExpressionGroupListResp{ Groups: itemMap, - }, nil + }}, nil } -func HandleExpressionGroupGetReq(req *protos.ExpressionGroupGetReq, hctx wsHelpers.HandlerContext) (*protos.ExpressionGroupGetResp, error) { +func HandleExpressionGroupGetReq(req *protos.ExpressionGroupGetReq, hctx wsHelpers.HandlerContext) ([]*protos.ExpressionGroupGetResp, error) { dbItem, owner, err := wsHelpers.GetUserObjectById[protos.ExpressionGroup](false, req.Id, protos.ObjectType_OT_EXPRESSION_GROUP, dbCollections.ExpressionGroupsName, hctx) if err != nil { return nil, err } dbItem.Owner = wsHelpers.MakeOwnerSummary(owner, hctx.SessUser, hctx.Svcs.MongoDB, hctx.Svcs.TimeStamper) - return &protos.ExpressionGroupGetResp{ + return []*protos.ExpressionGroupGetResp{&protos.ExpressionGroupGetResp{ Group: dbItem, - }, nil + }}, nil } func validateExpressionGroup(egroup *protos.ExpressionGroup) error { @@ -198,7 +198,7 @@ func updateExpressionGroup(egroup *protos.ExpressionGroup, hctx wsHelpers.Handle return dbItem, nil } -func HandleExpressionGroupWriteReq(req *protos.ExpressionGroupWriteReq, hctx wsHelpers.HandlerContext) (*protos.ExpressionGroupWriteResp, error) { +func HandleExpressionGroupWriteReq(req *protos.ExpressionGroupWriteReq, hctx wsHelpers.HandlerContext) ([]*protos.ExpressionGroupWriteResp, error) { // Owner should never be accepted from API if req.Group.Owner != nil { return nil, errorwithstatus.MakeBadRequestError(errors.New("Owner must be empty for write messages")) @@ -216,7 +216,7 @@ func HandleExpressionGroupWriteReq(req *protos.ExpressionGroupWriteReq, hctx wsH return nil, err } - return &protos.ExpressionGroupWriteResp{ + return []*protos.ExpressionGroupWriteResp{&protos.ExpressionGroupWriteResp{ Group: item, - }, nil + }}, nil } diff --git a/api/ws/handlers/expression.go b/api/ws/handlers/expression.go index cf36cdf1..6b6ae35f 100644 --- a/api/ws/handlers/expression.go +++ b/api/ws/handlers/expression.go @@ -15,23 +15,23 @@ import ( "go.mongodb.org/mongo-driver/mongo/writeconcern" ) -func HandleExpressionGetReq(req *protos.ExpressionGetReq, hctx wsHelpers.HandlerContext) (*protos.ExpressionGetResp, error) { +func HandleExpressionGetReq(req *protos.ExpressionGetReq, hctx wsHelpers.HandlerContext) ([]*protos.ExpressionGetResp, error) { dbItem, owner, err := wsHelpers.GetUserObjectById[protos.DataExpression](false, req.Id, protos.ObjectType_OT_EXPRESSION, dbCollections.ExpressionsName, hctx) if err != nil { return nil, err } dbItem.Owner = wsHelpers.MakeOwnerSummary(owner, hctx.SessUser, hctx.Svcs.MongoDB, hctx.Svcs.TimeStamper) - return &protos.ExpressionGetResp{ + return []*protos.ExpressionGetResp{&protos.ExpressionGetResp{ Expression: dbItem, - }, nil + }}, nil } -func HandleExpressionDeleteReq(req *protos.ExpressionDeleteReq, hctx wsHelpers.HandlerContext) (*protos.ExpressionDeleteResp, error) { +func HandleExpressionDeleteReq(req *protos.ExpressionDeleteReq, hctx wsHelpers.HandlerContext) ([]*protos.ExpressionDeleteResp, error) { return wsHelpers.DeleteUserObject[protos.ExpressionDeleteResp](req.Id, protos.ObjectType_OT_EXPRESSION, dbCollections.ExpressionsName, hctx) } -func HandleExpressionListReq(req *protos.ExpressionListReq, hctx wsHelpers.HandlerContext) (*protos.ExpressionListResp, error) { +func HandleExpressionListReq(req *protos.ExpressionListReq, hctx wsHelpers.HandlerContext) ([]*protos.ExpressionListResp, error) { filter, idToOwner, err := wsHelpers.MakeFilter(req.SearchParams, false, protos.ObjectType_OT_EXPRESSION, hctx) if err != nil { return nil, err @@ -68,9 +68,9 @@ func HandleExpressionListReq(req *protos.ExpressionListReq, hctx wsHelpers.Handl itemMap[item.Id] = item } - return &protos.ExpressionListResp{ + return []*protos.ExpressionListResp{&protos.ExpressionListResp{ Expressions: itemMap, - }, nil + }}, nil } func validateExpression(expr *protos.DataExpression) error { @@ -211,7 +211,7 @@ func updateExpression(expr *protos.DataExpression, hctx wsHelpers.HandlerContext return dbItem, nil } -func HandleExpressionWriteReq(req *protos.ExpressionWriteReq, hctx wsHelpers.HandlerContext) (*protos.ExpressionWriteResp, error) { +func HandleExpressionWriteReq(req *protos.ExpressionWriteReq, hctx wsHelpers.HandlerContext) ([]*protos.ExpressionWriteResp, error) { // Owner should never be accepted from API if req.Expression.Owner != nil { return nil, errorwithstatus.MakeBadRequestError(errors.New("Owner must be empty for write messages")) @@ -229,12 +229,12 @@ func HandleExpressionWriteReq(req *protos.ExpressionWriteReq, hctx wsHelpers.Han return nil, err } - return &protos.ExpressionWriteResp{ + return []*protos.ExpressionWriteResp{&protos.ExpressionWriteResp{ Expression: item, - }, nil + }}, nil } -func HandleExpressionWriteExecStatReq(req *protos.ExpressionWriteExecStatReq, hctx wsHelpers.HandlerContext) (*protos.ExpressionWriteExecStatResp, error) { +func HandleExpressionWriteExecStatReq(req *protos.ExpressionWriteExecStatReq, hctx wsHelpers.HandlerContext) ([]*protos.ExpressionWriteExecStatResp, error) { // Validate request if err := wsHelpers.CheckStringField(&req.Id, "Id", 0, wsHelpers.IdFieldMaxLength); err != nil { return nil, err @@ -270,14 +270,14 @@ func HandleExpressionWriteExecStatReq(req *protos.ExpressionWriteExecStatReq, hc hctx.Svcs.Log.Errorf("DataExpression ExecStatWrite UpdateByID result had unexpected counts %+v id: %v", result, req.Id) } - return &protos.ExpressionWriteExecStatResp{}, nil + return []*protos.ExpressionWriteExecStatResp{&protos.ExpressionWriteExecStatResp{}}, nil } func formExpressionDisplaySettingsID(user *protos.UserInfo, expressionId string) string { return user.Id + "-" + expressionId } -func HandleExpressionDisplaySettingsGetReq(req *protos.ExpressionDisplaySettingsGetReq, hctx wsHelpers.HandlerContext) (*protos.ExpressionDisplaySettingsGetResp, error) { +func HandleExpressionDisplaySettingsGetReq(req *protos.ExpressionDisplaySettingsGetReq, hctx wsHelpers.HandlerContext) ([]*protos.ExpressionDisplaySettingsGetResp, error) { // Validate request if len(req.Id) <= 0 { return nil, errorwithstatus.MakeBadRequestError(errors.New("Expression ID must be specified")) @@ -294,19 +294,19 @@ func HandleExpressionDisplaySettingsGetReq(req *protos.ExpressionDisplaySettings err := hctx.Svcs.MongoDB.Collection(dbCollections.UserExpressionDisplaySettings).FindOne(context.Background(), bson.M{"_id": displaySettingsId}).Decode(&displaySettings) if err != nil { // We don't care about errors. If it doesn't exist, we just return a blank one - return &protos.ExpressionDisplaySettingsGetResp{ + return []*protos.ExpressionDisplaySettingsGetResp{&protos.ExpressionDisplaySettingsGetResp{ DisplaySettings: &protos.ExpressionDisplaySettings{Id: req.Id}, - }, nil + }}, nil } // Set the ID back before returning it displaySettings.Id = req.Id - return &protos.ExpressionDisplaySettingsGetResp{ + return []*protos.ExpressionDisplaySettingsGetResp{&protos.ExpressionDisplaySettingsGetResp{ DisplaySettings: displaySettings, - }, nil + }}, nil } -func HandleExpressionDisplaySettingsWriteReq(req *protos.ExpressionDisplaySettingsWriteReq, hctx wsHelpers.HandlerContext) (*protos.ExpressionDisplaySettingsWriteResp, error) { +func HandleExpressionDisplaySettingsWriteReq(req *protos.ExpressionDisplaySettingsWriteReq, hctx wsHelpers.HandlerContext) ([]*protos.ExpressionDisplaySettingsWriteResp, error) { if len(req.Id) <= 0 { return nil, errorwithstatus.MakeBadRequestError(errors.New("Expression ID must be specified")) } @@ -376,7 +376,7 @@ func HandleExpressionDisplaySettingsWriteReq(req *protos.ExpressionDisplaySettin return nil, err } - return &protos.ExpressionDisplaySettingsWriteResp{ + return []*protos.ExpressionDisplaySettingsWriteResp{&protos.ExpressionDisplaySettingsWriteResp{ DisplaySettings: req.DisplaySettings, - }, nil + }}, nil } diff --git a/api/ws/handlers/image-beam-location.go b/api/ws/handlers/image-beam-location.go index 6e001aa9..680b46ab 100644 --- a/api/ws/handlers/image-beam-location.go +++ b/api/ws/handlers/image-beam-location.go @@ -14,7 +14,7 @@ import ( "go.mongodb.org/mongo-driver/mongo/options" ) -func HandleImageBeamLocationsReq(req *protos.ImageBeamLocationsReq, hctx wsHelpers.HandlerContext) (*protos.ImageBeamLocationsResp, error) { +func HandleImageBeamLocationsReq(req *protos.ImageBeamLocationsReq, hctx wsHelpers.HandlerContext) ([]*protos.ImageBeamLocationsResp, error) { ctx := context.TODO() var locs *protos.ImageLocations @@ -83,9 +83,9 @@ func HandleImageBeamLocationsReq(req *protos.ImageBeamLocationsReq, hctx wsHelpe } // Return the coordinates from DB record - return &protos.ImageBeamLocationsResp{ + return []*protos.ImageBeamLocationsResp{&protos.ImageBeamLocationsResp{ Locations: locs, - }, nil + }}, nil } func generateIJs(imageName string, scanId string, instrument protos.ScanInstrument, hctx wsHelpers.HandlerContext) (*protos.ImageLocations, error) { diff --git a/api/ws/handlers/image-coreg.go b/api/ws/handlers/image-coreg.go index 597a9737..bba2ea45 100644 --- a/api/ws/handlers/image-coreg.go +++ b/api/ws/handlers/image-coreg.go @@ -6,7 +6,7 @@ import ( protos "github.com/pixlise/core/v4/generated-protos" ) -func HandleImportMarsViewerImageReq(req *protos.ImportMarsViewerImageReq, hctx wsHelpers.HandlerContext) (*protos.ImportMarsViewerImageResp, error) { +func HandleImportMarsViewerImageReq(req *protos.ImportMarsViewerImageReq, hctx wsHelpers.HandlerContext) ([]*protos.ImportMarsViewerImageResp, error) { jobId := "" var err error @@ -15,7 +15,7 @@ func HandleImportMarsViewerImageReq(req *protos.ImportMarsViewerImageReq, hctx w return nil, err } - return &protos.ImportMarsViewerImageResp{ + return []*protos.ImportMarsViewerImageResp{&protos.ImportMarsViewerImageResp{ JobId: jobId, - }, nil + }}, nil } diff --git a/api/ws/handlers/image.go b/api/ws/handlers/image.go index 6ed4d35b..85b3753c 100644 --- a/api/ws/handlers/image.go +++ b/api/ws/handlers/image.go @@ -19,7 +19,7 @@ import ( "go.mongodb.org/mongo-driver/mongo/options" ) -func HandleImageListReq(req *protos.ImageListReq, hctx wsHelpers.HandlerContext) (*protos.ImageListResp, error) { +func HandleImageListReq(req *protos.ImageListReq, hctx wsHelpers.HandlerContext) ([]*protos.ImageListResp, error) { if err := wsHelpers.CheckFieldLength(req.ScanIds, "ScanIds", 1, 10); err != nil { return nil, err } @@ -54,12 +54,12 @@ func HandleImageListReq(req *protos.ImageListReq, hctx wsHelpers.HandlerContext) return nil, err } - return &protos.ImageListResp{ + return []*protos.ImageListResp{&protos.ImageListResp{ Images: items, - }, nil + }}, nil } -func HandleImageGetReq(req *protos.ImageGetReq, hctx wsHelpers.HandlerContext) (*protos.ImageGetResp, error) { +func HandleImageGetReq(req *protos.ImageGetReq, hctx wsHelpers.HandlerContext) ([]*protos.ImageGetResp, error) { if err := wsHelpers.CheckStringField(&req.ImageName, "ImageName", 1, 255); err != nil { return nil, err } @@ -107,19 +107,19 @@ func HandleImageGetReq(req *protos.ImageGetReq, hctx wsHelpers.HandlerContext) ( } } - return &protos.ImageGetResp{ + return []*protos.ImageGetResp{&protos.ImageGetResp{ Image: &img, - }, nil + }}, nil } -func HandleImageGetDefaultReq(req *protos.ImageGetDefaultReq, hctx wsHelpers.HandlerContext) (*protos.ImageGetDefaultResp, error) { +func HandleImageGetDefaultReq(req *protos.ImageGetDefaultReq, hctx wsHelpers.HandlerContext) ([]*protos.ImageGetDefaultResp, error) { /*if err := wsHelpers.CheckFieldLength(req.ScanIds, "ScanIds", 1, 10); err != nil { return nil, err }*/ if len(req.ScanIds) <= 0 { - return &protos.ImageGetDefaultResp{ + return []*protos.ImageGetDefaultResp{&protos.ImageGetDefaultResp{ DefaultImagesPerScanId: map[string]string{}, - }, nil + }}, nil } // Check that the user has access to all the scans in question @@ -152,12 +152,12 @@ func HandleImageGetDefaultReq(req *protos.ImageGetDefaultReq, hctx wsHelpers.Han result[item.ScanId] = item.DefaultImageFileName } - return &protos.ImageGetDefaultResp{ + return []*protos.ImageGetDefaultResp{&protos.ImageGetDefaultResp{ DefaultImagesPerScanId: result, - }, nil + }}, nil } -func HandleImageSetDefaultReq(req *protos.ImageSetDefaultReq, hctx wsHelpers.HandlerContext) (*protos.ImageSetDefaultResp, error) { +func HandleImageSetDefaultReq(req *protos.ImageSetDefaultReq, hctx wsHelpers.HandlerContext) ([]*protos.ImageSetDefaultResp, error) { if err := wsHelpers.CheckStringField(&req.ScanId, "ScanId", 1, wsHelpers.IdFieldMaxLength); err != nil { return nil, err } @@ -198,10 +198,10 @@ func HandleImageSetDefaultReq(req *protos.ImageSetDefaultReq, hctx wsHelpers.Han // Send out notifications so caches can be cleared hctx.Svcs.Notifier.SysNotifyScanImagesChanged([]string{req.ScanId}) - return &protos.ImageSetDefaultResp{}, nil + return []*protos.ImageSetDefaultResp{&protos.ImageSetDefaultResp{}}, nil } -func HandleImageDeleteReq(req *protos.ImageDeleteReq, hctx wsHelpers.HandlerContext) (*protos.ImageDeleteResp, error) { +func HandleImageDeleteReq(req *protos.ImageDeleteReq, hctx wsHelpers.HandlerContext) ([]*protos.ImageDeleteResp, error) { if err := wsHelpers.CheckStringField(&req.Name, "Name", 1, 255); err != nil { return nil, err } @@ -291,10 +291,10 @@ func HandleImageDeleteReq(req *protos.ImageDeleteReq, hctx wsHelpers.HandlerCont hctx.Svcs.Notifier.SysNotifyScanImagesChanged(scanIds) - return &protos.ImageDeleteResp{}, nil + return []*protos.ImageDeleteResp{&protos.ImageDeleteResp{}}, nil } -func HandleImageUploadReq(req *protos.ImageUploadReq, hctx wsHelpers.HandlerContext) (*protos.ImageUploadResp, error) { +func HandleImageUploadReq(req *protos.ImageUploadReq, hctx wsHelpers.HandlerContext) ([]*protos.ImageUploadResp, error) { if err := wsHelpers.CheckStringField(&req.Name, "Name", 1, 255); err != nil { return nil, err } @@ -428,10 +428,10 @@ func HandleImageUploadReq(req *protos.ImageUploadReq, hctx wsHelpers.HandlerCont hctx.Svcs.Notifier.NotifyNewScanImage(req.OriginScanId, req.OriginScanId, scanImage.ImagePath) hctx.Svcs.Notifier.SysNotifyScanImagesChanged([]string{req.OriginScanId}) - return &protos.ImageUploadResp{}, nil + return []*protos.ImageUploadResp{&protos.ImageUploadResp{}}, nil } -func HandleImageSetMatchTransformReq(req *protos.ImageSetMatchTransformReq, hctx wsHelpers.HandlerContext) (*protos.ImageSetMatchTransformResp, error) { +func HandleImageSetMatchTransformReq(req *protos.ImageSetMatchTransformReq, hctx wsHelpers.HandlerContext) ([]*protos.ImageSetMatchTransformResp, error) { if err := wsHelpers.CheckStringField(&req.ImageName, "ImageName", 1, 255); err != nil { return nil, err } @@ -503,5 +503,5 @@ func HandleImageSetMatchTransformReq(req *protos.ImageSetMatchTransformReq, hctx hctx.Svcs.Log.Errorf("ImageSetMatchTransformReq update result had unexpected match count %+v imageName: %v", updResult, req.ImageName) } - return &protos.ImageSetMatchTransformResp{}, nil + return []*protos.ImageSetMatchTransformResp{&protos.ImageSetMatchTransformResp{}}, nil } diff --git a/api/ws/handlers/log.go b/api/ws/handlers/log.go index 993b43a8..d556208c 100644 --- a/api/ws/handlers/log.go +++ b/api/ws/handlers/log.go @@ -16,7 +16,7 @@ import ( protos "github.com/pixlise/core/v4/generated-protos" ) -func HandleLogReadReq(req *protos.LogReadReq, hctx wsHelpers.HandlerContext) (*protos.LogReadResp, error) { +func HandleLogReadReq(req *protos.LogReadReq, hctx wsHelpers.HandlerContext) ([]*protos.LogReadResp, error) { if err := wsHelpers.CheckStringField(&req.LogStreamId, "LogStreamId", 1, 512); err != nil { return nil, err } @@ -35,23 +35,23 @@ func HandleLogReadReq(req *protos.LogReadReq, hctx wsHelpers.HandlerContext) (*p } } - return &protos.LogReadResp{ + return []*protos.LogReadResp{&protos.LogReadResp{ Entries: logs, - }, nil + }}, nil } -func HandleLogGetLevelReq(req *protos.LogGetLevelReq, hctx wsHelpers.HandlerContext) (*protos.LogGetLevelResp, error) { +func HandleLogGetLevelReq(req *protos.LogGetLevelReq, hctx wsHelpers.HandlerContext) ([]*protos.LogGetLevelResp, error) { name, err := logger.GetLogLevelName(hctx.Svcs.Log.GetLogLevel()) if err != nil { return nil, err } - return &protos.LogGetLevelResp{ + return []*protos.LogGetLevelResp{&protos.LogGetLevelResp{ LogLevelId: name, - }, nil + }}, nil } -func HandleLogSetLevelReq(req *protos.LogSetLevelReq, hctx wsHelpers.HandlerContext) (*protos.LogSetLevelResp, error) { +func HandleLogSetLevelReq(req *protos.LogSetLevelReq, hctx wsHelpers.HandlerContext) ([]*protos.LogSetLevelResp, error) { if err := wsHelpers.CheckStringField(&req.LogLevelId, "LogLevelId", 1, 10); err != nil { return nil, err } @@ -67,7 +67,7 @@ func HandleLogSetLevelReq(req *protos.LogSetLevelReq, hctx wsHelpers.HandlerCont // Not really an error, but we log in this level to ensure it always gets printed hctx.Svcs.Log.Errorf("User %v request changed log level to: %v", hctx.SessUser.User.Id, req.LogLevelId) - return &protos.LogSetLevelResp{LogLevelId: req.LogLevelId}, nil + return []*protos.LogSetLevelResp{&protos.LogSetLevelResp{LogLevelId: req.LogLevelId}}, nil } var cloudwatchSvc *cloudwatchlogs.CloudWatchLogs = nil diff --git a/api/ws/handlers/memoisation.go b/api/ws/handlers/memoisation.go index 4cd61f76..cc33f60d 100644 --- a/api/ws/handlers/memoisation.go +++ b/api/ws/handlers/memoisation.go @@ -13,7 +13,7 @@ import ( "go.mongodb.org/mongo-driver/mongo/options" ) -func HandleMemoiseGetReq(req *protos.MemoiseGetReq, hctx wsHelpers.HandlerContext) (*protos.MemoiseGetResp, error) { +func HandleMemoiseGetReq(req *protos.MemoiseGetReq, hctx wsHelpers.HandlerContext) ([]*protos.MemoiseGetResp, error) { // Read from DB, if not there, fail. We do limit key sizes though if err := wsHelpers.CheckStringField(&req.Key, "Key", 1, 1024); err != nil { return nil, err @@ -36,12 +36,12 @@ func HandleMemoiseGetReq(req *protos.MemoiseGetReq, hctx wsHelpers.HandlerContex return nil, err } - return &protos.MemoiseGetResp{ + return []*protos.MemoiseGetResp{&protos.MemoiseGetResp{ Item: item, - }, nil + }}, nil } -func HandleMemoiseWriteReq(req *protos.MemoiseWriteReq, hctx wsHelpers.HandlerContext) (*protos.MemoiseWriteResp, error) { +func HandleMemoiseWriteReq(req *protos.MemoiseWriteReq, hctx wsHelpers.HandlerContext) ([]*protos.MemoiseWriteResp, error) { // Here we overwrite freely, but we do limit key sizes though if err := wsHelpers.CheckStringField(&req.Key, "Key", 1, 1024); err != nil { return nil, err @@ -70,7 +70,7 @@ func HandleMemoiseWriteReq(req *protos.MemoiseWriteReq, hctx wsHelpers.HandlerCo hctx.Svcs.Log.Errorf("MemoiseWriteReq for: %v got unexpected DB write result: %+v", req.Key, result) } - return &protos.MemoiseWriteResp{ + return []*protos.MemoiseWriteResp{&protos.MemoiseWriteResp{ MemoTimeUnixSec: timestamp, - }, nil + }}, nil } diff --git a/api/ws/handlers/module.go b/api/ws/handlers/module.go index 87346ffb..445e450f 100644 --- a/api/ws/handlers/module.go +++ b/api/ws/handlers/module.go @@ -19,7 +19,7 @@ import ( "go.mongodb.org/mongo-driver/mongo/writeconcern" ) -func HandleDataModuleGetReq(req *protos.DataModuleGetReq, hctx wsHelpers.HandlerContext) (*protos.DataModuleGetResp, error) { +func HandleDataModuleGetReq(req *protos.DataModuleGetReq, hctx wsHelpers.HandlerContext) ([]*protos.DataModuleGetResp, error) { dbItem, owner, err := wsHelpers.GetUserObjectById[protos.DataModuleDB](false, req.Id, protos.ObjectType_OT_DATA_MODULE, dbCollections.ModulesName, hctx) if err != nil { return nil, err @@ -78,12 +78,12 @@ func HandleDataModuleGetReq(req *protos.DataModuleGetReq, hctx wsHelpers.Handler module.Versions = append(module.Versions, moduleVersion) } - return &protos.DataModuleGetResp{ + return []*protos.DataModuleGetResp{&protos.DataModuleGetResp{ Module: module, - }, nil + }}, nil } -func HandleDataModuleListReq(req *protos.DataModuleListReq, hctx wsHelpers.HandlerContext) (*protos.DataModuleListResp, error) { +func HandleDataModuleListReq(req *protos.DataModuleListReq, hctx wsHelpers.HandlerContext) ([]*protos.DataModuleListResp, error) { idToOwner, err := wsHelpers.ListAccessibleIDs(false, protos.ObjectType_OT_DATA_MODULE, hctx.Svcs, hctx.SessUser) if err != nil { return nil, err @@ -137,9 +137,9 @@ func HandleDataModuleListReq(req *protos.DataModuleListReq, hctx wsHelpers.Handl itemMap[item.Id] = itemWire } - return &protos.DataModuleListResp{ + return []*protos.DataModuleListResp{&protos.DataModuleListResp{ Modules: itemMap, - }, nil + }}, nil } func getModuleVersion(moduleID string, version *protos.SemanticVersion, db *mongo.Database) (*protos.DataModuleVersion, error) { @@ -386,7 +386,7 @@ func updateModule(id string, name string, comments string, hctx wsHelpers.Handle return result, nil } -func HandleDataModuleWriteReq(req *protos.DataModuleWriteReq, hctx wsHelpers.HandlerContext) (*protos.DataModuleWriteResp, error) { +func HandleDataModuleWriteReq(req *protos.DataModuleWriteReq, hctx wsHelpers.HandlerContext) ([]*protos.DataModuleWriteResp, error) { var item *protos.DataModule var err error @@ -403,9 +403,9 @@ func HandleDataModuleWriteReq(req *protos.DataModuleWriteReq, hctx wsHelpers.Han return nil, err } - return &protos.DataModuleWriteResp{ + return []*protos.DataModuleWriteResp{&protos.DataModuleWriteResp{ Module: item, - }, nil + }}, nil } // Some validation functions @@ -423,7 +423,7 @@ func isValidModuleName(name string) bool { return match } -func HandleDataModuleAddVersionReq(req *protos.DataModuleAddVersionReq, hctx wsHelpers.HandlerContext) (*protos.DataModuleAddVersionResp, error) { +func HandleDataModuleAddVersionReq(req *protos.DataModuleAddVersionReq, hctx wsHelpers.HandlerContext) ([]*protos.DataModuleAddVersionResp, error) { // Check that the version update field is a valid value if !utils.ItemInSlice(req.VersionUpdate, []protos.VersionField{protos.VersionField_MV_MAJOR, protos.VersionField_MV_MINOR, protos.VersionField_MV_PATCH}) { return nil, fmt.Errorf("Invalid version update field: %v", req.VersionUpdate) @@ -533,7 +533,7 @@ func HandleDataModuleAddVersionReq(req *protos.DataModuleAddVersionReq, hctx wsH module.Versions = append(module.Versions, returnVersion) } - return &protos.DataModuleAddVersionResp{ + return []*protos.DataModuleAddVersionResp{&protos.DataModuleAddVersionResp{ Module: module, - }, nil + }}, nil } diff --git a/api/ws/handlers/notification.go b/api/ws/handlers/notification.go index 59a83408..94118348 100644 --- a/api/ws/handlers/notification.go +++ b/api/ws/handlers/notification.go @@ -12,7 +12,7 @@ import ( "go.mongodb.org/mongo-driver/mongo/options" ) -func HandleNotificationReq(req *protos.NotificationReq, hctx wsHelpers.HandlerContext) (*protos.NotificationResp, error) { +func HandleNotificationReq(req *protos.NotificationReq, hctx wsHelpers.HandlerContext) ([]*protos.NotificationResp, error) { // Triggers a "subscription" to receive updates containing notifications for the session user // Could implement a "silent" mode, specify param in request, tell API to not send notifications for a certain period @@ -36,12 +36,12 @@ func HandleNotificationReq(req *protos.NotificationReq, hctx wsHelpers.HandlerCo } // Return the outstanding notifications - return &protos.NotificationResp{ + return []*protos.NotificationResp{&protos.NotificationResp{ Notification: notifications, - }, nil + }}, nil } -func HandleNotificationDismissReq(req *protos.NotificationDismissReq, hctx wsHelpers.HandlerContext) (*protos.NotificationDismissResp, error) { +func HandleNotificationDismissReq(req *protos.NotificationDismissReq, hctx wsHelpers.HandlerContext) ([]*protos.NotificationDismissResp, error) { // Find this in the DB and clear it if err := wsHelpers.CheckStringField(&req.Id, "Id", 1, wsHelpers.IdFieldMaxLength*2); err != nil { return nil, err @@ -56,10 +56,10 @@ func HandleNotificationDismissReq(req *protos.NotificationDismissReq, hctx wsHel return nil, err } - return &protos.NotificationDismissResp{}, nil + return []*protos.NotificationDismissResp{&protos.NotificationDismissResp{}}, nil } -func HandleSendUserNotificationReq(req *protos.SendUserNotificationReq, hctx wsHelpers.HandlerContext) (*protos.SendUserNotificationResp, error) { +func HandleSendUserNotificationReq(req *protos.SendUserNotificationReq, hctx wsHelpers.HandlerContext) ([]*protos.SendUserNotificationResp, error) { // Send from a user, need to define destination, could be group/user ids? // Probably messaging, subject+content, can send as email if not connected? // Think of load balance issue with multiple APIs running @@ -109,5 +109,5 @@ func HandleSendUserNotificationReq(req *protos.SendUserNotificationReq, hctx wsH ) } - return &protos.SendUserNotificationResp{}, nil + return []*protos.SendUserNotificationResp{&protos.SendUserNotificationResp{}}, nil } diff --git a/api/ws/handlers/ownership-access.go b/api/ws/handlers/ownership-access.go index 95db9f13..c2f3be23 100644 --- a/api/ws/handlers/ownership-access.go +++ b/api/ws/handlers/ownership-access.go @@ -10,7 +10,7 @@ import ( "go.mongodb.org/mongo-driver/bson" ) -func HandleGetOwnershipReq(req *protos.GetOwnershipReq, hctx wsHelpers.HandlerContext) (*protos.GetOwnershipResp, error) { +func HandleGetOwnershipReq(req *protos.GetOwnershipReq, hctx wsHelpers.HandlerContext) ([]*protos.GetOwnershipResp, error) { if err := wsHelpers.CheckStringField(&req.ObjectId, "ObjectId", 1, wsHelpers.IdFieldMaxLength*2 /* Tests have longer ids anyway... */); err != nil { return nil, err } @@ -20,9 +20,9 @@ func HandleGetOwnershipReq(req *protos.GetOwnershipReq, hctx wsHelpers.HandlerCo return nil, err } - return &protos.GetOwnershipResp{ + return []*protos.GetOwnershipResp{&protos.GetOwnershipResp{ Ownership: owner, - }, nil + }}, nil } func readToMap(ids []string, theMap *map[string]bool) { @@ -45,7 +45,7 @@ func deleteFromMap(ids []string, theMap *map[string]bool) { } } -func HandleObjectEditAccessReq(req *protos.ObjectEditAccessReq, hctx wsHelpers.HandlerContext) (*protos.ObjectEditAccessResp, error) { +func HandleObjectEditAccessReq(req *protos.ObjectEditAccessReq, hctx wsHelpers.HandlerContext) ([]*protos.ObjectEditAccessResp, error) { if err := wsHelpers.CheckStringField(&req.ObjectId, "ObjectId", 1, wsHelpers.IdFieldMaxLength*2 /* Tests have longer ids anyway... */); err != nil { return nil, err } @@ -138,7 +138,7 @@ func HandleObjectEditAccessReq(req *protos.ObjectEditAccessReq, hctx wsHelpers.H owner.Viewers.UserIds = viewerUserIds owner.Viewers.GroupIds = viewerGroupsIds - return &protos.ObjectEditAccessResp{ + return []*protos.ObjectEditAccessResp{&protos.ObjectEditAccessResp{ Ownership: owner, - }, nil + }}, nil } diff --git a/api/ws/handlers/piquant.go b/api/ws/handlers/piquant.go index 9432a771..83c75f1e 100644 --- a/api/ws/handlers/piquant.go +++ b/api/ws/handlers/piquant.go @@ -16,7 +16,7 @@ import ( "go.mongodb.org/mongo-driver/mongo/options" ) -func HandlePiquantConfigListReq(req *protos.PiquantConfigListReq, hctx wsHelpers.HandlerContext) (*protos.PiquantConfigListResp, error) { +func HandlePiquantConfigListReq(req *protos.PiquantConfigListReq, hctx wsHelpers.HandlerContext) ([]*protos.PiquantConfigListResp, error) { // Return a list of all piquant configs we have stored // TODO: Handle paging... this could eventually be > 1000 files, but that's a while away! paths, err := hctx.Svcs.FS.ListObjects(hctx.Svcs.Config.ConfigBucket, filepaths.RootDetectorConfig+"/") @@ -38,10 +38,10 @@ func HandlePiquantConfigListReq(req *protos.PiquantConfigListReq, hctx wsHelpers names := utils.GetMapKeys(configNamesFiltered) sort.Strings(names) - return &protos.PiquantConfigListResp{ConfigNames: names}, err + return []*protos.PiquantConfigListResp{&protos.PiquantConfigListResp{ConfigNames: names}}, err } -func HandlePiquantConfigVersionsListReq(req *protos.PiquantConfigVersionsListReq, hctx wsHelpers.HandlerContext) (*protos.PiquantConfigVersionsListResp, error) { +func HandlePiquantConfigVersionsListReq(req *protos.PiquantConfigVersionsListReq, hctx wsHelpers.HandlerContext) ([]*protos.PiquantConfigVersionsListResp, error) { if err := wsHelpers.CheckStringField(&req.ConfigId, "ConfigId", 1, wsHelpers.IdFieldMaxLength); err != nil { return nil, err } @@ -49,12 +49,12 @@ func HandlePiquantConfigVersionsListReq(req *protos.PiquantConfigVersionsListReq // Get a list of PIQUANT config versions too versions := piquant.GetPiquantConfigVersions(hctx.Svcs, req.ConfigId) - return &protos.PiquantConfigVersionsListResp{ + return []*protos.PiquantConfigVersionsListResp{&protos.PiquantConfigVersionsListResp{ Versions: versions, - }, nil + }}, nil } -func HandlePiquantConfigVersionReq(req *protos.PiquantConfigVersionReq, hctx wsHelpers.HandlerContext) (*protos.PiquantConfigVersionResp, error) { +func HandlePiquantConfigVersionReq(req *protos.PiquantConfigVersionReq, hctx wsHelpers.HandlerContext) ([]*protos.PiquantConfigVersionResp, error) { if err := wsHelpers.CheckStringField(&req.Version, "Version", 1, wsHelpers.IdFieldMaxLength); err != nil { return nil, err } @@ -67,25 +67,25 @@ func HandlePiquantConfigVersionReq(req *protos.PiquantConfigVersionReq, hctx wsH return nil, err } - return &protos.PiquantConfigVersionResp{ + return []*protos.PiquantConfigVersionResp{&protos.PiquantConfigVersionResp{ PiquantConfig: cfg, - }, nil + }}, nil } // TODO: need to query versions from github container registry or something similar??? -func HandlePiquantVersionListReq(req *protos.PiquantVersionListReq, hctx wsHelpers.HandlerContext) (*protos.PiquantVersionListResp, error) { +func HandlePiquantVersionListReq(req *protos.PiquantVersionListReq, hctx wsHelpers.HandlerContext) ([]*protos.PiquantVersionListResp, error) { return nil, errors.New("HandlePiquantVersionListReq not implemented yet") } -func HandlePiquantCurrentVersionReq(req *protos.PiquantCurrentVersionReq, hctx wsHelpers.HandlerContext) (*protos.PiquantCurrentVersionResp, error) { +func HandlePiquantCurrentVersionReq(req *protos.PiquantCurrentVersionReq, hctx wsHelpers.HandlerContext) ([]*protos.PiquantCurrentVersionResp, error) { ver, err := piquant.GetPiquantVersion(hctx.Svcs) if err != nil { return nil, err } - return &protos.PiquantCurrentVersionResp{PiquantVersion: ver}, nil + return []*protos.PiquantCurrentVersionResp{&protos.PiquantCurrentVersionResp{PiquantVersion: ver}}, nil } -func HandlePiquantWriteCurrentVersionReq(req *protos.PiquantWriteCurrentVersionReq, hctx wsHelpers.HandlerContext) (*protos.PiquantWriteCurrentVersionResp, error) { +func HandlePiquantWriteCurrentVersionReq(req *protos.PiquantWriteCurrentVersionReq, hctx wsHelpers.HandlerContext) ([]*protos.PiquantWriteCurrentVersionResp, error) { if err := wsHelpers.CheckStringField(&req.PiquantVersion, "PiquantVersion", 1, 100); err != nil { return nil, err } @@ -107,5 +107,5 @@ func HandlePiquantWriteCurrentVersionReq(req *protos.PiquantWriteCurrentVersionR hctx.Svcs.Log.Errorf("PiquantWriteCurrentVersionReq UpdateByID result had unexpected counts %+v", result) } - return &protos.PiquantWriteCurrentVersionResp{}, nil + return []*protos.PiquantWriteCurrentVersionResp{&protos.PiquantWriteCurrentVersionResp{}}, nil } diff --git a/api/ws/handlers/pseudo-intensities.go b/api/ws/handlers/pseudo-intensities.go index ac789fb6..6a96eb81 100644 --- a/api/ws/handlers/pseudo-intensities.go +++ b/api/ws/handlers/pseudo-intensities.go @@ -8,7 +8,7 @@ import ( protos "github.com/pixlise/core/v4/generated-protos" ) -func HandlePseudoIntensityReq(req *protos.PseudoIntensityReq, hctx wsHelpers.HandlerContext) (*protos.PseudoIntensityResp, error) { +func HandlePseudoIntensityReq(req *protos.PseudoIntensityReq, hctx wsHelpers.HandlerContext) ([]*protos.PseudoIntensityResp, error) { exprPB, indexes, err := beginDatasetFileReqForRange(req.ScanId, req.Entries, hctx) if err != nil { return nil, err @@ -48,8 +48,8 @@ func HandlePseudoIntensityReq(req *protos.PseudoIntensityReq, hctx wsHelpers.Han hctx.Svcs.Log.Errorf("Reading pseudointensities for scan %v: found more than 1 set of pseudos in %v PMCs", req.ScanId, tooManyPseudosLocations) } - return &protos.PseudoIntensityResp{ + return []*protos.PseudoIntensityResp{&protos.PseudoIntensityResp{ IntensityLabels: labels, Data: pseudoIntensities, - }, nil + }}, nil } diff --git a/api/ws/handlers/quantification-create.go b/api/ws/handlers/quantification-create.go index 45d86fff..4d23c49a 100644 --- a/api/ws/handlers/quantification-create.go +++ b/api/ws/handlers/quantification-create.go @@ -13,7 +13,7 @@ import ( protos "github.com/pixlise/core/v4/generated-protos" ) -func HandleQuantCreateReq(req *protos.QuantCreateReq, hctx wsHelpers.HandlerContext) (*protos.QuantCreateResp, error) { +func HandleQuantCreateReq(req *protos.QuantCreateReq, hctx wsHelpers.HandlerContext) ([]*protos.QuantCreateResp, error) { err := quantification.IsValidCreateParam(req.Params, hctx) if err != nil { return nil, errorwithstatus.MakeBadRequestError(err) @@ -46,7 +46,7 @@ func HandleQuantCreateReq(req *protos.QuantCreateReq, hctx wsHelpers.HandlerCont // If it's NOT a map command, we wait around for the result and pass it back in the response // but for map commands, we just pass back the generated job status if req.Params.Command == "map" { - return &protos.QuantCreateResp{Status: status}, nil + return []*protos.QuantCreateResp{&protos.QuantCreateResp{Status: status}}, nil } // Wait around for the output file to appear, or for the job to end up in an error state @@ -59,5 +59,5 @@ func HandleQuantCreateReq(req *protos.QuantCreateReq, hctx wsHelpers.HandlerCont return nil, errors.New("PIQUANT command: " + req.Params.Command + " failed.") } - return &protos.QuantCreateResp{ResultData: bytes}, nil + return []*protos.QuantCreateResp{&protos.QuantCreateResp{ResultData: bytes}}, nil } diff --git a/api/ws/handlers/quantification-management.go b/api/ws/handlers/quantification-management.go index 4546c741..8cf038e1 100644 --- a/api/ws/handlers/quantification-management.go +++ b/api/ws/handlers/quantification-management.go @@ -12,11 +12,11 @@ import ( protos "github.com/pixlise/core/v4/generated-protos" ) -func HandleQuantBlessReq(req *protos.QuantBlessReq, hctx wsHelpers.HandlerContext) (*protos.QuantBlessResp, error) { +func HandleQuantBlessReq(req *protos.QuantBlessReq, hctx wsHelpers.HandlerContext) ([]*protos.QuantBlessResp, error) { return nil, errors.New("HandleQuantBlessReq not implemented yet") } -func HandleQuantDeleteReq(req *protos.QuantDeleteReq, hctx wsHelpers.HandlerContext) (*protos.QuantDeleteResp, error) { +func HandleQuantDeleteReq(req *protos.QuantDeleteReq, hctx wsHelpers.HandlerContext) ([]*protos.QuantDeleteResp, error) { // Can't use the helper: DeleteUserObject because we also have to delete stuff from S3 and we need the scanId associated to find // the path. So here we do a get first, with edit priviledges required dbItem, _, err := wsHelpers.GetUserObjectById[protos.QuantificationSummary](true, req.QuantId, protos.ObjectType_OT_QUANTIFICATION, dbCollections.QuantificationsName, hctx) @@ -57,9 +57,9 @@ func HandleQuantDeleteReq(req *protos.QuantDeleteReq, hctx wsHelpers.HandlerCont // Notify of the change hctx.Svcs.Notifier.SysNotifyQuantChanged(req.QuantId) - return &protos.QuantDeleteResp{}, nil + return []*protos.QuantDeleteResp{&protos.QuantDeleteResp{}}, nil } -func HandleQuantPublishReq(req *protos.QuantPublishReq, hctx wsHelpers.HandlerContext) (*protos.QuantPublishResp, error) { +func HandleQuantPublishReq(req *protos.QuantPublishReq, hctx wsHelpers.HandlerContext) ([]*protos.QuantPublishResp, error) { return nil, errors.New("HandleQuantPublishReq not implemented yet") } diff --git a/api/ws/handlers/quantification-multi.go b/api/ws/handlers/quantification-multi.go index aea54ce3..c2b29bfd 100644 --- a/api/ws/handlers/quantification-multi.go +++ b/api/ws/handlers/quantification-multi.go @@ -14,7 +14,7 @@ import ( ) // Anyone can retrieve a quant z-stack if they have quant messaging permissions -func HandleQuantCombineListGetReq(req *protos.QuantCombineListGetReq, hctx wsHelpers.HandlerContext) (*protos.QuantCombineListGetResp, error) { +func HandleQuantCombineListGetReq(req *protos.QuantCombineListGetReq, hctx wsHelpers.HandlerContext) ([]*protos.QuantCombineListGetResp, error) { if err := wsHelpers.CheckStringField(&req.ScanId, "ScanId", 1, wsHelpers.IdFieldMaxLength); err != nil { return nil, err } @@ -39,13 +39,13 @@ func HandleQuantCombineListGetReq(req *protos.QuantCombineListGetReq, hctx wsHel return nil, err } - return &protos.QuantCombineListGetResp{ + return []*protos.QuantCombineListGetResp{&protos.QuantCombineListGetResp{ List: resultItem.List, - }, nil + }}, nil } // Anyone can save a quant z-stack if they have quant messaging permissions -func HandleQuantCombineListWriteReq(req *protos.QuantCombineListWriteReq, hctx wsHelpers.HandlerContext) (*protos.QuantCombineListWriteResp, error) { +func HandleQuantCombineListWriteReq(req *protos.QuantCombineListWriteReq, hctx wsHelpers.HandlerContext) ([]*protos.QuantCombineListWriteResp, error) { if err := wsHelpers.CheckStringField(&req.ScanId, "ScanId", 1, wsHelpers.IdFieldMaxLength); err != nil { return nil, err } @@ -74,10 +74,10 @@ func HandleQuantCombineListWriteReq(req *protos.QuantCombineListWriteReq, hctx w hctx.Svcs.Log.Errorf("MultiQuant Z-Stack insert %v inserted different id %v", zId, result.InsertedID) } - return &protos.QuantCombineListWriteResp{}, nil + return []*protos.QuantCombineListWriteResp{&protos.QuantCombineListWriteResp{}}, nil } -func HandleMultiQuantCompareReq(req *protos.MultiQuantCompareReq, hctx wsHelpers.HandlerContext) (*protos.MultiQuantCompareResp, error) { +func HandleMultiQuantCompareReq(req *protos.MultiQuantCompareReq, hctx wsHelpers.HandlerContext) ([]*protos.MultiQuantCompareResp, error) { // req.ScanId is checked in beginDatasetFileReq if len(req.QuantIds) <= 0 { @@ -101,13 +101,13 @@ func HandleMultiQuantCompareReq(req *protos.MultiQuantCompareReq, hctx wsHelpers return nil, err } - return &protos.MultiQuantCompareResp{ + return []*protos.MultiQuantCompareResp{&protos.MultiQuantCompareResp{ RoiId: req.ReqRoiId, QuantTables: tables, - }, nil + }}, nil } -func HandleQuantCombineReq(req *protos.QuantCombineReq, hctx wsHelpers.HandlerContext) (*protos.QuantCombineResp, error) { +func HandleQuantCombineReq(req *protos.QuantCombineReq, hctx wsHelpers.HandlerContext) ([]*protos.QuantCombineResp, error) { // Simple validation // NOTE: if only asking for a summary, we don't care about name being empty @@ -132,11 +132,11 @@ func HandleQuantCombineReq(req *protos.QuantCombineReq, hctx wsHelpers.HandlerCo if req.SummaryOnly { // We return a summary instead of forming a CSV summary := quantification.FormMultiQuantSummary(multiQuantData.DataPerDetectorPerPMC, multiQuantData.AllColumns, multiQuantData.PMCCount) - return &protos.QuantCombineResp{ + return []*protos.QuantCombineResp{&protos.QuantCombineResp{ CombineResult: &protos.QuantCombineResp_Summary{ Summary: summary, }, - }, nil + }}, nil } // Form a CSV @@ -152,9 +152,9 @@ func HandleQuantCombineReq(req *protos.QuantCombineReq, hctx wsHelpers.HandlerCo return nil, err } - return &protos.QuantCombineResp{ + return []*protos.QuantCombineResp{&protos.QuantCombineResp{ CombineResult: &protos.QuantCombineResp_JobId{ JobId: quantId, }, - }, nil + }}, nil } diff --git a/api/ws/handlers/quantification-retrieval.go b/api/ws/handlers/quantification-retrieval.go index 5af6fb39..27805f4a 100644 --- a/api/ws/handlers/quantification-retrieval.go +++ b/api/ws/handlers/quantification-retrieval.go @@ -11,7 +11,7 @@ import ( protos "github.com/pixlise/core/v4/generated-protos" ) -func HandleQuantListReq(req *protos.QuantListReq, hctx wsHelpers.HandlerContext) (*protos.QuantListResp, error) { +func HandleQuantListReq(req *protos.QuantListReq, hctx wsHelpers.HandlerContext) ([]*protos.QuantListResp, error) { items, idToOwner, err := quantification.ListUserQuants(req.SearchParams, hctx) if err != nil { return nil, err @@ -25,12 +25,12 @@ func HandleQuantListReq(req *protos.QuantListReq, hctx wsHelpers.HandlerContext) quants = append(quants, item) } - return &protos.QuantListResp{ + return []*protos.QuantListResp{&protos.QuantListResp{ Quants: quants, - }, nil + }}, nil } -func HandleQuantGetReq(req *protos.QuantGetReq, hctx wsHelpers.HandlerContext) (*protos.QuantGetResp, error) { +func HandleQuantGetReq(req *protos.QuantGetReq, hctx wsHelpers.HandlerContext) ([]*protos.QuantGetResp, error) { dbItem, ownerItem, err := wsHelpers.GetUserObjectById[protos.QuantificationSummary](false, req.QuantId, protos.ObjectType_OT_QUANTIFICATION, dbCollections.QuantificationsName, hctx) if err != nil { return nil, err @@ -51,13 +51,13 @@ func HandleQuantGetReq(req *protos.QuantGetReq, hctx wsHelpers.HandlerContext) ( dbItem.Owner = wsHelpers.MakeOwnerSummary(ownerItem, hctx.SessUser, hctx.Svcs.MongoDB, hctx.Svcs.TimeStamper) - return &protos.QuantGetResp{ + return []*protos.QuantGetResp{&protos.QuantGetResp{ Summary: dbItem, Data: quant, - }, nil + }}, nil } -func HandleQuantLastOutputGetReq(req *protos.QuantLastOutputGetReq, hctx wsHelpers.HandlerContext) (*protos.QuantLastOutputGetResp, error) { +func HandleQuantLastOutputGetReq(req *protos.QuantLastOutputGetReq, hctx wsHelpers.HandlerContext) ([]*protos.QuantLastOutputGetResp, error) { if err := wsHelpers.CheckStringField(&req.ScanId, "ScanId", 1, wsHelpers.IdFieldMaxLength); err != nil { return nil, err } @@ -92,6 +92,6 @@ func HandleQuantLastOutputGetReq(req *protos.QuantLastOutputGetReq, hctx wsHelpe } } - return &protos.QuantLastOutputGetResp{Output: string(result)}, nil + return []*protos.QuantLastOutputGetResp{&protos.QuantLastOutputGetResp{Output: string(result)}}, nil } diff --git a/api/ws/handlers/quantification-upload.go b/api/ws/handlers/quantification-upload.go index 0af194c8..7c71cfe8 100644 --- a/api/ws/handlers/quantification-upload.go +++ b/api/ws/handlers/quantification-upload.go @@ -22,7 +22,7 @@ import ( // ... // -func HandleQuantUploadReq(req *protos.QuantUploadReq, hctx wsHelpers.HandlerContext) (*protos.QuantUploadResp, error) { +func HandleQuantUploadReq(req *protos.QuantUploadReq, hctx wsHelpers.HandlerContext) ([]*protos.QuantUploadResp, error) { if err := wsHelpers.CheckStringField(&req.ScanId, "ScanId", 1, wsHelpers.IdFieldMaxLength); err != nil { return nil, err } @@ -53,7 +53,7 @@ func HandleQuantUploadReq(req *protos.QuantUploadReq, hctx wsHelpers.HandlerCont if err != nil { return nil, err } - return &protos.QuantUploadResp{CreatedQuantId: quantId}, nil + return []*protos.QuantUploadResp{&protos.QuantUploadResp{CreatedQuantId: quantId}}, nil } func parseQuantCSVColumns(csvRows []string) (map[string]int, error) { diff --git a/api/ws/handlers/roi.go b/api/ws/handlers/roi.go index eb31adab..5c446c3f 100644 --- a/api/ws/handlers/roi.go +++ b/api/ws/handlers/roi.go @@ -22,7 +22,7 @@ type IdOnly struct { Id string `bson:"_id"` } -func HandleRegionOfInterestGetReq(req *protos.RegionOfInterestGetReq, hctx wsHelpers.HandlerContext) (*protos.RegionOfInterestGetResp, error) { +func HandleRegionOfInterestGetReq(req *protos.RegionOfInterestGetReq, hctx wsHelpers.HandlerContext) ([]*protos.RegionOfInterestGetResp, error) { dbItem, owner, err := wsHelpers.GetUserObjectById[protos.ROIItem](false, req.Id, protos.ObjectType_OT_ROI, dbCollections.RegionsOfInterestName, hctx) if err != nil { return nil, err @@ -41,12 +41,12 @@ func HandleRegionOfInterestGetReq(req *protos.RegionOfInterestGetReq, hctx wsHel dbItem.MistROIItem = mistItem } - return &protos.RegionOfInterestGetResp{ + return []*protos.RegionOfInterestGetResp{&protos.RegionOfInterestGetResp{ RegionOfInterest: dbItem, - }, nil + }}, nil } -func HandleRegionOfInterestDeleteReq(req *protos.RegionOfInterestDeleteReq, hctx wsHelpers.HandlerContext) (*protos.RegionOfInterestDeleteResp, error) { +func HandleRegionOfInterestDeleteReq(req *protos.RegionOfInterestDeleteReq, hctx wsHelpers.HandlerContext) ([]*protos.RegionOfInterestDeleteResp, error) { if req.IsMIST { // Delete from MIST table _, err := hctx.Svcs.MongoDB.Collection(dbCollections.MistROIsName).DeleteOne(context.TODO(), bson.D{{Key: "_id", Value: req.Id}}) @@ -58,7 +58,7 @@ func HandleRegionOfInterestDeleteReq(req *protos.RegionOfInterestDeleteReq, hctx return wsHelpers.DeleteUserObject[protos.RegionOfInterestDeleteResp](req.Id, protos.ObjectType_OT_ROI, dbCollections.RegionsOfInterestName, hctx) } -func HandleRegionOfInterestListReq(req *protos.RegionOfInterestListReq, hctx wsHelpers.HandlerContext) (*protos.RegionOfInterestListResp, error) { +func HandleRegionOfInterestListReq(req *protos.RegionOfInterestListReq, hctx wsHelpers.HandlerContext) ([]*protos.RegionOfInterestListResp, error) { filter, idToOwner, err := wsHelpers.MakeFilter(req.SearchParams, false, protos.ObjectType_OT_ROI, hctx) if err != nil { return nil, err @@ -127,9 +127,9 @@ func HandleRegionOfInterestListReq(req *protos.RegionOfInterestListReq, hctx wsH rois[item.Id] = item } - return &protos.RegionOfInterestListResp{ + return []*protos.RegionOfInterestListResp{&protos.RegionOfInterestListResp{ RegionsOfInterest: rois, - }, nil + }}, nil } func validateROI(roi *protos.ROIItem) error { @@ -361,7 +361,7 @@ func updateROI(roi *protos.ROIItem, hctx wsHelpers.HandlerContext, editors *prot return dbItem, nil } -func HandleRegionOfInterestWriteReq(req *protos.RegionOfInterestWriteReq, hctx wsHelpers.HandlerContext) (*protos.RegionOfInterestWriteResp, error) { +func HandleRegionOfInterestWriteReq(req *protos.RegionOfInterestWriteReq, hctx wsHelpers.HandlerContext) ([]*protos.RegionOfInterestWriteResp, error) { // Owner should never be accepted from API if req.RegionOfInterest.Owner != nil { return nil, errorwithstatus.MakeBadRequestError(errors.New("Owner must be empty for write messages")) @@ -386,12 +386,12 @@ func HandleRegionOfInterestWriteReq(req *protos.RegionOfInterestWriteReq, hctx w return nil, err } - return &protos.RegionOfInterestWriteResp{ + return []*protos.RegionOfInterestWriteResp{&protos.RegionOfInterestWriteResp{ RegionOfInterest: item, - }, nil + }}, nil } -func HandleRegionOfInterestBulkWriteReq(req *protos.RegionOfInterestBulkWriteReq, hctx wsHelpers.HandlerContext) (*protos.RegionOfInterestBulkWriteResp, error) { +func HandleRegionOfInterestBulkWriteReq(req *protos.RegionOfInterestBulkWriteReq, hctx wsHelpers.HandlerContext) ([]*protos.RegionOfInterestBulkWriteResp, error) { if req.IsMIST && req.MistROIScanIdsToDelete != nil && len(req.MistROIScanIdsToDelete) > 0 { ctx := context.TODO() coll := hctx.Svcs.MongoDB.Collection(dbCollections.MistROIsName) @@ -541,12 +541,12 @@ func HandleRegionOfInterestBulkWriteReq(req *protos.RegionOfInterestBulkWriteReq writtenROIs = append(writtenROIs, item) } - return &protos.RegionOfInterestBulkWriteResp{ + return []*protos.RegionOfInterestBulkWriteResp{&protos.RegionOfInterestBulkWriteResp{ RegionsOfInterest: writtenROIs, - }, nil + }}, nil } -func HandleRegionOfInterestBulkDuplicateReq(req *protos.RegionOfInterestBulkDuplicateReq, hctx wsHelpers.HandlerContext) (*protos.RegionOfInterestBulkDuplicateResp, error) { +func HandleRegionOfInterestBulkDuplicateReq(req *protos.RegionOfInterestBulkDuplicateReq, hctx wsHelpers.HandlerContext) ([]*protos.RegionOfInterestBulkDuplicateResp, error) { // Get the ROIs to duplicate filter := bson.M{"_id": bson.M{"$in": req.Ids}} opts := options.Find() @@ -587,16 +587,16 @@ func HandleRegionOfInterestBulkDuplicateReq(req *protos.RegionOfInterestBulkDupl } } - return &protos.RegionOfInterestBulkDuplicateResp{ + return []*protos.RegionOfInterestBulkDuplicateResp{&protos.RegionOfInterestBulkDuplicateResp{ RegionsOfInterest: roiSummaries, - }, nil + }}, nil } func formROIUserConfigID(user *protos.UserInfo, roiId string) string { return user.Id + "-" + roiId } -func HandleRegionOfInterestDisplaySettingsWriteReq(req *protos.RegionOfInterestDisplaySettingsWriteReq, hctx wsHelpers.HandlerContext) (*protos.RegionOfInterestDisplaySettingsWriteResp, error) { +func HandleRegionOfInterestDisplaySettingsWriteReq(req *protos.RegionOfInterestDisplaySettingsWriteReq, hctx wsHelpers.HandlerContext) ([]*protos.RegionOfInterestDisplaySettingsWriteResp, error) { // Check that we have an id, current user, and display settings if len(req.Id) <= 0 { return nil, errorwithstatus.MakeBadRequestError(errors.New("ROI ID must be specified")) @@ -669,12 +669,12 @@ func HandleRegionOfInterestDisplaySettingsWriteReq(req *protos.RegionOfInterestD return nil, err } - return &protos.RegionOfInterestDisplaySettingsWriteResp{ + return []*protos.RegionOfInterestDisplaySettingsWriteResp{&protos.RegionOfInterestDisplaySettingsWriteResp{ DisplaySettings: req.DisplaySettings, - }, nil + }}, nil } -func HandleRegionOfInterestDisplaySettingsGetReq(req *protos.RegionOfInterestDisplaySettingsGetReq, hctx wsHelpers.HandlerContext) (*protos.RegionOfInterestDisplaySettingsGetResp, error) { +func HandleRegionOfInterestDisplaySettingsGetReq(req *protos.RegionOfInterestDisplaySettingsGetReq, hctx wsHelpers.HandlerContext) ([]*protos.RegionOfInterestDisplaySettingsGetResp, error) { // Check that we have an id, current user, and display settings if len(req.Id) <= 0 { return nil, errorwithstatus.MakeBadRequestError(errors.New("ROI ID must be specified")) @@ -692,7 +692,7 @@ func HandleRegionOfInterestDisplaySettingsGetReq(req *protos.RegionOfInterestDis return nil, err } - return &protos.RegionOfInterestDisplaySettingsGetResp{ + return []*protos.RegionOfInterestDisplaySettingsGetResp{&protos.RegionOfInterestDisplaySettingsGetResp{ DisplaySettings: displaySettings, - }, nil + }}, nil } diff --git a/api/ws/handlers/scan-beam-location.go b/api/ws/handlers/scan-beam-location.go index 7fac2c40..6b156a39 100644 --- a/api/ws/handlers/scan-beam-location.go +++ b/api/ws/handlers/scan-beam-location.go @@ -5,7 +5,7 @@ import ( protos "github.com/pixlise/core/v4/generated-protos" ) -func HandleScanBeamLocationsReq(req *protos.ScanBeamLocationsReq, hctx wsHelpers.HandlerContext) (*protos.ScanBeamLocationsResp, error) { +func HandleScanBeamLocationsReq(req *protos.ScanBeamLocationsReq, hctx wsHelpers.HandlerContext) ([]*protos.ScanBeamLocationsResp, error) { exprPB, indexes, err := beginDatasetFileReqForRange(req.ScanId, req.Entries, hctx) if err != nil { return nil, err @@ -28,7 +28,7 @@ func HandleScanBeamLocationsReq(req *protos.ScanBeamLocationsReq, hctx wsHelpers beams = append(beams, beamSave) } - return &protos.ScanBeamLocationsResp{ + return []*protos.ScanBeamLocationsResp{&protos.ScanBeamLocationsResp{ BeamLocations: beams, - }, nil + }}, nil } diff --git a/api/ws/handlers/scan-entry-metadata.go b/api/ws/handlers/scan-entry-metadata.go index a52f717d..bce5a948 100644 --- a/api/ws/handlers/scan-entry-metadata.go +++ b/api/ws/handlers/scan-entry-metadata.go @@ -7,7 +7,7 @@ import ( protos "github.com/pixlise/core/v4/generated-protos" ) -func HandleScanEntryMetadataReq(req *protos.ScanEntryMetadataReq, hctx wsHelpers.HandlerContext) (*protos.ScanEntryMetadataResp, error) { +func HandleScanEntryMetadataReq(req *protos.ScanEntryMetadataReq, hctx wsHelpers.HandlerContext) ([]*protos.ScanEntryMetadataResp, error) { exprPB, indexes, err := beginDatasetFileReqForRange(req.ScanId, req.Entries, hctx) if err != nil { return nil, err @@ -62,7 +62,7 @@ func HandleScanEntryMetadataReq(req *protos.ScanEntryMetadataReq, hctx wsHelpers entryMetas = append(entryMetas, metaSave) } - return &protos.ScanEntryMetadataResp{ + return []*protos.ScanEntryMetadataResp{&protos.ScanEntryMetadataResp{ Entries: entryMetas, - }, nil + }}, nil } diff --git a/api/ws/handlers/scan-entry.go b/api/ws/handlers/scan-entry.go index 3c93f26b..b47691ca 100644 --- a/api/ws/handlers/scan-entry.go +++ b/api/ws/handlers/scan-entry.go @@ -8,7 +8,7 @@ import ( protos "github.com/pixlise/core/v4/generated-protos" ) -func HandleScanEntryReq(req *protos.ScanEntryReq, hctx wsHelpers.HandlerContext) (*protos.ScanEntryResp, error) { +func HandleScanEntryReq(req *protos.ScanEntryReq, hctx wsHelpers.HandlerContext) ([]*protos.ScanEntryResp, error) { exprPB, indexes, err := beginDatasetFileReqForRange(req.ScanId, req.Entries, hctx) if err != nil { return nil, err @@ -95,7 +95,7 @@ func HandleScanEntryReq(req *protos.ScanEntryReq, hctx wsHelpers.HandlerContext) entries = append(entries, locSave) } - return &protos.ScanEntryResp{ + return []*protos.ScanEntryResp{&protos.ScanEntryResp{ Entries: entries, - }, nil + }}, nil } diff --git a/api/ws/handlers/scan.go b/api/ws/handlers/scan.go index 9d0fe002..e602c1f0 100644 --- a/api/ws/handlers/scan.go +++ b/api/ws/handlers/scan.go @@ -29,7 +29,7 @@ import ( "google.golang.org/protobuf/proto" ) -func HandleScanListReq(req *protos.ScanListReq, hctx wsHelpers.HandlerContext) (*protos.ScanListResp, error) { +func HandleScanListReq(req *protos.ScanListReq, hctx wsHelpers.HandlerContext) ([]*protos.ScanListResp, error) { idToOwner, err := wsHelpers.ListAccessibleIDs(false, protos.ObjectType_OT_SCAN, hctx.Svcs, hctx.SessUser) if err != nil { return nil, err @@ -105,12 +105,12 @@ func HandleScanListReq(req *protos.ScanListReq, hctx wsHelpers.HandlerContext) ( return nil, err } - return &protos.ScanListResp{ + return []*protos.ScanListResp{&protos.ScanListResp{ Scans: scans, - }, nil + }}, nil } -func HandleScanGetReq(req *protos.ScanGetReq, hctx wsHelpers.HandlerContext) (*protos.ScanGetResp, error) { +func HandleScanGetReq(req *protos.ScanGetReq, hctx wsHelpers.HandlerContext) ([]*protos.ScanGetResp, error) { // Check that we have an id, current user, and display settings if len(req.Id) <= 0 { return nil, errorwithstatus.MakeBadRequestError(errors.New("Scan ID must be specified")) @@ -128,12 +128,12 @@ func HandleScanGetReq(req *protos.ScanGetReq, hctx wsHelpers.HandlerContext) (*p dbItem.Owner = wsHelpers.MakeOwnerSummary(owner, hctx.SessUser, hctx.Svcs.MongoDB, hctx.Svcs.TimeStamper) - return &protos.ScanGetResp{ + return []*protos.ScanGetResp{&protos.ScanGetResp{ Scan: dbItem, - }, nil + }}, nil } -func HandleScanMetaLabelsAndTypesReq(req *protos.ScanMetaLabelsAndTypesReq, hctx wsHelpers.HandlerContext) (*protos.ScanMetaLabelsAndTypesResp, error) { +func HandleScanMetaLabelsAndTypesReq(req *protos.ScanMetaLabelsAndTypesReq, hctx wsHelpers.HandlerContext) ([]*protos.ScanMetaLabelsAndTypesResp, error) { exprPB, err := beginDatasetFileReq(req.ScanId, hctx) if err != nil { return nil, err @@ -151,10 +151,10 @@ func HandleScanMetaLabelsAndTypesReq(req *protos.ScanMetaLabelsAndTypesReq, hctx types = append(types, tScan) } - return &protos.ScanMetaLabelsAndTypesResp{ + return []*protos.ScanMetaLabelsAndTypesResp{&protos.ScanMetaLabelsAndTypesResp{ MetaLabels: exprPB.MetaLabels, MetaTypes: types, - }, nil + }}, nil } // Utility to call for any Req message that involves serving data out of a dataset.bin file @@ -201,7 +201,7 @@ func beginDatasetFileReq(scanId string, hctx wsHelpers.HandlerContext) (*protos. return exprPB, nil } -func HandleScanDeleteReq(req *protos.ScanDeleteReq, hctx wsHelpers.HandlerContext) (*protos.ScanDeleteResp, error) { +func HandleScanDeleteReq(req *protos.ScanDeleteReq, hctx wsHelpers.HandlerContext) ([]*protos.ScanDeleteResp, error) { // Check user has access dbItem, _, err := wsHelpers.GetUserObjectById[protos.ScanItem](true, req.ScanId, protos.ObjectType_OT_SCAN, dbCollections.ScansName, hctx) if err != nil { @@ -246,10 +246,10 @@ func HandleScanDeleteReq(req *protos.ScanDeleteReq, hctx wsHelpers.HandlerContex // Notify of our scan change hctx.Svcs.Notifier.SysNotifyScanChanged(req.ScanId) - return &protos.ScanDeleteResp{}, nil + return []*protos.ScanDeleteResp{&protos.ScanDeleteResp{}}, nil } -func HandleScanMetaWriteReq(req *protos.ScanMetaWriteReq, hctx wsHelpers.HandlerContext) (*protos.ScanMetaWriteResp, error) { +func HandleScanMetaWriteReq(req *protos.ScanMetaWriteReq, hctx wsHelpers.HandlerContext) ([]*protos.ScanMetaWriteResp, error) { if err := wsHelpers.CheckStringField(&req.Title, "Title", 1, 100); err != nil { return nil, err } @@ -288,10 +288,10 @@ func HandleScanMetaWriteReq(req *protos.ScanMetaWriteReq, hctx wsHelpers.Handler // Notify of our scan change hctx.Svcs.Notifier.SysNotifyScanChanged(req.ScanId) - return &protos.ScanMetaWriteResp{}, nil + return []*protos.ScanMetaWriteResp{&protos.ScanMetaWriteResp{}}, nil } -func HandleScanTriggerReImportReq(req *protos.ScanTriggerReImportReq, hctx wsHelpers.HandlerContext) (*protos.ScanTriggerReImportResp, error) { +func HandleScanTriggerReImportReq(req *protos.ScanTriggerReImportReq, hctx wsHelpers.HandlerContext) ([]*protos.ScanTriggerReImportResp, error) { if err := wsHelpers.CheckStringField(&req.ScanId, "ScanId", 1, 50); err != nil { return nil, err } @@ -319,14 +319,14 @@ func HandleScanTriggerReImportReq(req *protos.ScanTriggerReImportReq, hctx wsHel result, err := dataimport.TriggerDatasetReprocessViaSNS(hctx.Svcs.SNS, jobId, req.ScanId, hctx.Svcs.Config.DataSourceSNSTopic) hctx.Svcs.Log.Infof("Triggered dataset reprocess via SNS topic. Result: %v. Job ID: %v", result, jobId) - return &protos.ScanTriggerReImportResp{JobId: jobId}, err + return []*protos.ScanTriggerReImportResp{&protos.ScanTriggerReImportResp{JobId: jobId}}, err } // NOTE: before this is sent, we expect the PUT /scan endpoint to have been called and a zip uploaded already // // The same parameters passed there (scan id & file name) must be used with this request otherwise we // won't look up the zip correctly and fail. -func HandleScanUploadReq(req *protos.ScanUploadReq, hctx wsHelpers.HandlerContext) (*protos.ScanUploadResp, error) { +func HandleScanUploadReq(req *protos.ScanUploadReq, hctx wsHelpers.HandlerContext) ([]*protos.ScanUploadResp, error) { if err := wsHelpers.CheckStringField(&req.Id, "Id", 1, 50); err != nil { return nil, err } @@ -563,7 +563,7 @@ func HandleScanUploadReq(req *protos.ScanUploadReq, hctx wsHelpers.HandlerContex logger.Infof("Triggered dataset reprocess via SNS topic. Result: %v. Job ID: %v", result, jobId) - return &protos.ScanUploadResp{JobId: jobId}, nil + return []*protos.ScanUploadResp{&protos.ScanUploadResp{JobId: jobId}}, nil } type importUpdater struct { @@ -641,7 +641,7 @@ func (i *importUpdater) sendImportUpdate(status *protos.JobStatus) { } } -func HandleScanAutoShareReq(req *protos.ScanAutoShareReq, hctx wsHelpers.HandlerContext) (*protos.ScanAutoShareResp, error) { +func HandleScanAutoShareReq(req *protos.ScanAutoShareReq, hctx wsHelpers.HandlerContext) ([]*protos.ScanAutoShareResp, error) { if err := wsHelpers.CheckStringField(&req.Id, "Id", 1, 50); err != nil { return nil, err } @@ -667,12 +667,12 @@ func HandleScanAutoShareReq(req *protos.ScanAutoShareReq, hctx wsHelpers.Handler return nil, err } - return &protos.ScanAutoShareResp{ + return []*protos.ScanAutoShareResp{&protos.ScanAutoShareResp{ Entry: item, - }, nil + }}, nil } -func HandleScanAutoShareWriteReq(req *protos.ScanAutoShareWriteReq, hctx wsHelpers.HandlerContext) (*protos.ScanAutoShareWriteResp, error) { +func HandleScanAutoShareWriteReq(req *protos.ScanAutoShareWriteReq, hctx wsHelpers.HandlerContext) ([]*protos.ScanAutoShareWriteResp, error) { if err := wsHelpers.CheckStringField(&req.Entry.Id, "Id", 1, 50); err != nil { return nil, err } @@ -706,5 +706,5 @@ func HandleScanAutoShareWriteReq(req *protos.ScanAutoShareWriteReq, hctx wsHelpe } } - return &protos.ScanAutoShareWriteResp{}, nil + return []*protos.ScanAutoShareWriteResp{&protos.ScanAutoShareWriteResp{}}, nil } diff --git a/api/ws/handlers/screen-configuration.go b/api/ws/handlers/screen-configuration.go index 96e9625e..72433846 100644 --- a/api/ws/handlers/screen-configuration.go +++ b/api/ws/handlers/screen-configuration.go @@ -26,7 +26,7 @@ func formWidgetId(widget *protos.WidgetLayoutConfiguration, screenConfigId strin return screenConfigId + "-" + fmt.Sprint(layoutIndex) + "-" + positionId } -func HandleScreenConfigurationGetReq(req *protos.ScreenConfigurationGetReq, hctx wsHelpers.HandlerContext) (*protos.ScreenConfigurationGetResp, error) { +func HandleScreenConfigurationGetReq(req *protos.ScreenConfigurationGetReq, hctx wsHelpers.HandlerContext) ([]*protos.ScreenConfigurationGetResp, error) { configId := "" if req.Id != "" { configId = req.Id @@ -46,12 +46,12 @@ func HandleScreenConfigurationGetReq(req *protos.ScreenConfigurationGetReq, hctx screenConfig.Owner = wsHelpers.MakeOwnerSummary(owner, hctx.SessUser, hctx.Svcs.MongoDB, hctx.Svcs.TimeStamper) - return &protos.ScreenConfigurationGetResp{ + return []*protos.ScreenConfigurationGetResp{&protos.ScreenConfigurationGetResp{ ScreenConfiguration: screenConfig, - }, nil + }}, nil } -func HandleScreenConfigurationListReq(req *protos.ScreenConfigurationListReq, hctx wsHelpers.HandlerContext) (*protos.ScreenConfigurationListResp, error) { +func HandleScreenConfigurationListReq(req *protos.ScreenConfigurationListReq, hctx wsHelpers.HandlerContext) ([]*protos.ScreenConfigurationListResp, error) { filter, idToOwner, err := wsHelpers.MakeFilter(req.SearchParams, false, protos.ObjectType_OT_SCREEN_CONFIG, hctx) if err != nil { return nil, err @@ -80,9 +80,9 @@ func HandleScreenConfigurationListReq(req *protos.ScreenConfigurationListReq, hc screenConfig.Owner = wsHelpers.MakeOwnerSummary(owner, hctx.SessUser, hctx.Svcs.MongoDB, hctx.Svcs.TimeStamper) } - return &protos.ScreenConfigurationListResp{ + return []*protos.ScreenConfigurationListResp{&protos.ScreenConfigurationListResp{ ScreenConfigurations: result, - }, nil + }}, nil } func writeScreenConfiguration(screenConfig *protos.ScreenConfiguration, hctx wsHelpers.HandlerContext, updateExisting bool) (*protos.ScreenConfiguration, error) { @@ -268,7 +268,7 @@ func loadWidgetsForScreenConfiguration(screenConfig *protos.ScreenConfiguration, return screenConfig, nil } -func HandleScreenConfigurationWriteReq(req *protos.ScreenConfigurationWriteReq, hctx wsHelpers.HandlerContext) (*protos.ScreenConfigurationWriteResp, error) { +func HandleScreenConfigurationWriteReq(req *protos.ScreenConfigurationWriteReq, hctx wsHelpers.HandlerContext) ([]*protos.ScreenConfigurationWriteResp, error) { if req.ScreenConfiguration == nil { return nil, errors.New("screen configuration must be specified") } @@ -307,12 +307,12 @@ func HandleScreenConfigurationWriteReq(req *protos.ScreenConfigurationWriteReq, return nil, err } - return &protos.ScreenConfigurationWriteResp{ + return []*protos.ScreenConfigurationWriteResp{&protos.ScreenConfigurationWriteResp{ ScreenConfiguration: screenConfig, - }, nil + }}, nil } -func HandleScreenConfigurationDeleteReq(req *protos.ScreenConfigurationDeleteReq, hctx wsHelpers.HandlerContext) (*protos.ScreenConfigurationDeleteResp, error) { +func HandleScreenConfigurationDeleteReq(req *protos.ScreenConfigurationDeleteReq, hctx wsHelpers.HandlerContext) ([]*protos.ScreenConfigurationDeleteResp, error) { if req.Id == "" { return nil, errors.New("screen configuration id must be specified") } @@ -373,7 +373,7 @@ func HandleScreenConfigurationDeleteReq(req *protos.ScreenConfigurationDeleteReq return nil, err } - return &protos.ScreenConfigurationDeleteResp{ + return []*protos.ScreenConfigurationDeleteResp{&protos.ScreenConfigurationDeleteResp{ Id: req.Id, - }, nil + }}, nil } diff --git a/api/ws/handlers/selection-entry.go b/api/ws/handlers/selection-entry.go index 95ec31b7..e2a52368 100644 --- a/api/ws/handlers/selection-entry.go +++ b/api/ws/handlers/selection-entry.go @@ -13,7 +13,7 @@ import ( "go.mongodb.org/mongo-driver/mongo/options" ) -func HandleSelectedScanEntriesReq(req *protos.SelectedScanEntriesReq, hctx wsHelpers.HandlerContext) (*protos.SelectedScanEntriesResp, error) { +func HandleSelectedScanEntriesReq(req *protos.SelectedScanEntriesReq, hctx wsHelpers.HandlerContext) ([]*protos.SelectedScanEntriesResp, error) { // We read multiple scans and assemble a single response // If any have an error, we error the whole thing out @@ -37,13 +37,13 @@ func HandleSelectedScanEntriesReq(req *protos.SelectedScanEntriesReq, hctx wsHel result[scanId] = idxs } - return &protos.SelectedScanEntriesResp{ + return []*protos.SelectedScanEntriesResp{&protos.SelectedScanEntriesResp{ ScanIdEntryIndexes: result, - }, nil + }}, nil } // Allowing user to save multiple scans worth of entry indexes in one message -func HandleSelectedScanEntriesWriteReq(req *protos.SelectedScanEntriesWriteReq, hctx wsHelpers.HandlerContext) (*protos.SelectedScanEntriesWriteResp, error) { +func HandleSelectedScanEntriesWriteReq(req *protos.SelectedScanEntriesWriteReq, hctx wsHelpers.HandlerContext) ([]*protos.SelectedScanEntriesWriteResp, error) { // Cap it though for performance... if len(req.ScanIdEntryIndexes) > 10 { return nil, errors.New("Too many ScanIds written") @@ -56,7 +56,7 @@ func HandleSelectedScanEntriesWriteReq(req *protos.SelectedScanEntriesWriteReq, } } - return &protos.SelectedScanEntriesWriteResp{}, nil + return []*protos.SelectedScanEntriesWriteResp{&protos.SelectedScanEntriesWriteResp{}}, nil } func readSelection(id string, db *mongo.Database) (*protos.ScanEntryRange, error) { diff --git a/api/ws/handlers/selection-pixel.go b/api/ws/handlers/selection-pixel.go index a27af25e..5fea6f78 100644 --- a/api/ws/handlers/selection-pixel.go +++ b/api/ws/handlers/selection-pixel.go @@ -5,22 +5,22 @@ import ( protos "github.com/pixlise/core/v4/generated-protos" ) -func HandleSelectedImagePixelsReq(req *protos.SelectedImagePixelsReq, hctx wsHelpers.HandlerContext) (*protos.SelectedImagePixelsResp, error) { +func HandleSelectedImagePixelsReq(req *protos.SelectedImagePixelsReq, hctx wsHelpers.HandlerContext) ([]*protos.SelectedImagePixelsResp, error) { idxs, err := readSelection("pix_"+req.Image+"_"+hctx.SessUser.User.Id, hctx.Svcs.MongoDB) if err != nil { return nil, err } - return &protos.SelectedImagePixelsResp{ + return []*protos.SelectedImagePixelsResp{&protos.SelectedImagePixelsResp{ PixelIndexes: idxs, - }, nil + }}, nil } -func HandleSelectedImagePixelsWriteReq(req *protos.SelectedImagePixelsWriteReq, hctx wsHelpers.HandlerContext) (*protos.SelectedImagePixelsWriteResp, error) { +func HandleSelectedImagePixelsWriteReq(req *protos.SelectedImagePixelsWriteReq, hctx wsHelpers.HandlerContext) ([]*protos.SelectedImagePixelsWriteResp, error) { err := writeSelection("pix_"+req.Image+"_"+hctx.SessUser.User.Id, req.PixelIndexes, hctx.Svcs.MongoDB, hctx.Svcs.Log) if err != nil { return nil, err } - return &protos.SelectedImagePixelsWriteResp{}, nil + return []*protos.SelectedImagePixelsWriteResp{&protos.SelectedImagePixelsWriteResp{}}, nil } diff --git a/api/ws/handlers/spectrum.go b/api/ws/handlers/spectrum.go index 2f378f52..501b5c09 100644 --- a/api/ws/handlers/spectrum.go +++ b/api/ws/handlers/spectrum.go @@ -9,7 +9,7 @@ import ( protos "github.com/pixlise/core/v4/generated-protos" ) -func HandleSpectrumReq(req *protos.SpectrumReq, hctx wsHelpers.HandlerContext) (*protos.SpectrumResp, error) { +func HandleSpectrumReq(req *protos.SpectrumReq, hctx wsHelpers.HandlerContext) ([]*protos.SpectrumResp, error) { exprPB, indexes, err := beginDatasetFileReqForRange(req.ScanId, req.Entries, hctx) if err != nil { return nil, err @@ -48,7 +48,7 @@ func HandleSpectrumReq(req *protos.SpectrumReq, hctx wsHelpers.HandlerContext) ( // the channel count based on the detector here... channelCount := uint32(4096) - result := &protos.SpectrumResp{ + firstResponse := &protos.SpectrumResp{ SpectraPerLocation: spectra, ChannelCount: channelCount, NormalSpectraForScan: uint32(exprPB.NormalSpectra), @@ -57,7 +57,7 @@ func HandleSpectrumReq(req *protos.SpectrumReq, hctx wsHelpers.HandlerContext) ( for c, label := range exprPB.MetaLabels { if label == "LIVETIME" { - result.LiveTimeMetaIndex = uint32(c) + firstResponse.LiveTimeMetaIndex = uint32(c) break } } @@ -69,11 +69,37 @@ func HandleSpectrumReq(req *protos.SpectrumReq, hctx wsHelpers.HandlerContext) ( return nil, err } - result.BulkSpectra = bulkSpectra - result.MaxSpectra = maxSpectra + firstResponse.BulkSpectra = bulkSpectra + firstResponse.MaxSpectra = maxSpectra } - return result, nil + resps := []*protos.SpectrumResp{firstResponse} + + // If we have too many spectra in one message, break it up + maxSpectraPerMessage := 10 + if len(spectra) > maxSpectraPerMessage { + // Only add the first X to the first message + firstResponse.SpectraPerLocation = spectra[0:maxSpectraPerMessage] + + // Make more messages + for c := maxSpectraPerMessage; c < len(spectra); c += maxSpectraPerMessage { + end := c + maxSpectraPerMessage + if end > len(spectra) { + end = len(spectra) + } + + subsequentResp := &protos.SpectrumResp{ + SpectraPerLocation: spectra[c:end], + ChannelCount: firstResponse.ChannelCount, + NormalSpectraForScan: firstResponse.NormalSpectraForScan, + DwellSpectraForScan: firstResponse.DwellSpectraForScan, + LiveTimeMetaIndex: firstResponse.LiveTimeMetaIndex, + } + resps = append(resps, subsequentResp) + } + } + + return resps, nil } // Returns array of bulk, array of max, error diff --git a/api/ws/handlers/tag.go b/api/ws/handlers/tag.go index db37a1c9..4ec73aa5 100644 --- a/api/ws/handlers/tag.go +++ b/api/ws/handlers/tag.go @@ -62,7 +62,7 @@ func decorateTag(tag *protos.TagDB, db *mongo.Database, log logger.ILogger) (*pr return decoratedTag, nil } -func HandleTagCreateReq(req *protos.TagCreateReq, hctx wsHelpers.HandlerContext) (*protos.TagCreateResp, error) { +func HandleTagCreateReq(req *protos.TagCreateReq, hctx wsHelpers.HandlerContext) ([]*protos.TagCreateResp, error) { // Limit tags to 50 characters if err := wsHelpers.CheckStringField(&req.Name, "Name", 1, 50); err != nil { return nil, err @@ -99,10 +99,10 @@ func HandleTagCreateReq(req *protos.TagCreateReq, hctx wsHelpers.HandlerContext) return nil, err } - return &protos.TagCreateResp{Tag: resolvedTag}, nil + return []*protos.TagCreateResp{&protos.TagCreateResp{Tag: resolvedTag}}, nil } -func HandleTagDeleteReq(req *protos.TagDeleteReq, hctx wsHelpers.HandlerContext) (*protos.TagDeleteResp, error) { +func HandleTagDeleteReq(req *protos.TagDeleteReq, hctx wsHelpers.HandlerContext) ([]*protos.TagDeleteResp, error) { ctx := context.TODO() coll := hctx.Svcs.MongoDB.Collection(dbCollections.TagsName) @@ -127,10 +127,10 @@ func HandleTagDeleteReq(req *protos.TagDeleteReq, hctx wsHelpers.HandlerContext) return nil, err } - return &protos.TagDeleteResp{}, nil + return []*protos.TagDeleteResp{&protos.TagDeleteResp{}}, nil } -func HandleTagListReq(req *protos.TagListReq, hctx wsHelpers.HandlerContext) (*protos.TagListResp, error) { +func HandleTagListReq(req *protos.TagListReq, hctx wsHelpers.HandlerContext) ([]*protos.TagListResp, error) { ctx := context.TODO() coll := hctx.Svcs.MongoDB.Collection(dbCollections.TagsName) @@ -153,7 +153,5 @@ func HandleTagListReq(req *protos.TagListReq, hctx wsHelpers.HandlerContext) (*p decoratedTags = append(decoratedTags, decoratedTag) } - tagResponse := &protos.TagListResp{Tags: decoratedTags} - - return tagResponse, nil + return []*protos.TagListResp{&protos.TagListResp{Tags: decoratedTags}}, nil } diff --git a/api/ws/handlers/test.go b/api/ws/handlers/test.go index 72eb6cd8..c429d53e 100644 --- a/api/ws/handlers/test.go +++ b/api/ws/handlers/test.go @@ -7,6 +7,6 @@ import ( protos "github.com/pixlise/core/v4/generated-protos" ) -func HandleRunTestReq(req *protos.RunTestReq, hctx wsHelpers.HandlerContext) (*protos.RunTestResp, error) { +func HandleRunTestReq(req *protos.RunTestReq, hctx wsHelpers.HandlerContext) ([]*protos.RunTestResp, error) { return nil, errors.New("HandleRunTestReq not implemented yet") } diff --git a/api/ws/handlers/user-group-admins.go b/api/ws/handlers/user-group-admins.go index 99bb34eb..3572504a 100644 --- a/api/ws/handlers/user-group-admins.go +++ b/api/ws/handlers/user-group-admins.go @@ -12,26 +12,26 @@ import ( "go.mongodb.org/mongo-driver/bson" ) -func HandleUserGroupAddAdminReq(req *protos.UserGroupAddAdminReq, hctx wsHelpers.HandlerContext) (*protos.UserGroupAddAdminResp, error) { +func HandleUserGroupAddAdminReq(req *protos.UserGroupAddAdminReq, hctx wsHelpers.HandlerContext) ([]*protos.UserGroupAddAdminResp, error) { group, err := modifyGroupAdminList(req.GroupId, req.AdminUserId, true, hctx) if err != nil { return nil, err } - return &protos.UserGroupAddAdminResp{ + return []*protos.UserGroupAddAdminResp{&protos.UserGroupAddAdminResp{ Group: group, - }, nil + }}, nil } -func HandleUserGroupDeleteAdminReq(req *protos.UserGroupDeleteAdminReq, hctx wsHelpers.HandlerContext) (*protos.UserGroupDeleteAdminResp, error) { +func HandleUserGroupDeleteAdminReq(req *protos.UserGroupDeleteAdminReq, hctx wsHelpers.HandlerContext) ([]*protos.UserGroupDeleteAdminResp, error) { group, err := modifyGroupAdminList(req.GroupId, req.AdminUserId, false, hctx) if err != nil { return nil, err } - return &protos.UserGroupDeleteAdminResp{ + return []*protos.UserGroupDeleteAdminResp{&protos.UserGroupDeleteAdminResp{ Group: group, - }, nil + }}, nil } func modifyGroupAdminList(groupId string, adminUserId string, add bool, hctx wsHelpers.HandlerContext) (*protos.UserGroup, error) { diff --git a/api/ws/handlers/user-group-joining.go b/api/ws/handlers/user-group-joining.go index 0af86c06..91810d64 100644 --- a/api/ws/handlers/user-group-joining.go +++ b/api/ws/handlers/user-group-joining.go @@ -14,7 +14,7 @@ import ( "go.mongodb.org/mongo-driver/mongo/options" ) -func HandleUserGroupJoinReq(req *protos.UserGroupJoinReq, hctx wsHelpers.HandlerContext) (*protos.UserGroupJoinResp, error) { +func HandleUserGroupJoinReq(req *protos.UserGroupJoinReq, hctx wsHelpers.HandlerContext) ([]*protos.UserGroupJoinResp, error) { if err := wsHelpers.CheckStringField(&req.GroupId, "GroupId", 1, wsHelpers.IdFieldMaxLength); err != nil { return nil, err } @@ -67,10 +67,10 @@ A user named %v has just requested to join the group as a %v`, group.Name, hctx. "PIXLISE API", ) - return &protos.UserGroupJoinResp{}, nil + return []*protos.UserGroupJoinResp{&protos.UserGroupJoinResp{}}, nil } -func HandleUserGroupIgnoreJoinReq(req *protos.UserGroupIgnoreJoinReq, hctx wsHelpers.HandlerContext) (*protos.UserGroupIgnoreJoinResp, error) { +func HandleUserGroupIgnoreJoinReq(req *protos.UserGroupIgnoreJoinReq, hctx wsHelpers.HandlerContext) ([]*protos.UserGroupIgnoreJoinResp, error) { if err := wsHelpers.CheckStringField(&req.GroupId, "GroupId", 1, wsHelpers.IdFieldMaxLength); err != nil { return nil, err } @@ -100,10 +100,10 @@ func HandleUserGroupIgnoreJoinReq(req *protos.UserGroupIgnoreJoinReq, hctx wsHel hctx.Svcs.Log.Errorf("UserGroup Join Request Delete result had unexpected counts %+v id: %v", result, req.RequestId) } - return &protos.UserGroupIgnoreJoinResp{}, nil + return []*protos.UserGroupIgnoreJoinResp{&protos.UserGroupIgnoreJoinResp{}}, nil } -func HandleUserGroupJoinListReq(req *protos.UserGroupJoinListReq, hctx wsHelpers.HandlerContext) (*protos.UserGroupJoinListResp, error) { +func HandleUserGroupJoinListReq(req *protos.UserGroupJoinListReq, hctx wsHelpers.HandlerContext) ([]*protos.UserGroupJoinListResp, error) { if err := wsHelpers.CheckStringField(&req.GroupId, "GroupId", 1, wsHelpers.IdFieldMaxLength); err != nil { return nil, err } @@ -142,7 +142,7 @@ func HandleUserGroupJoinListReq(req *protos.UserGroupJoinListReq, hctx wsHelpers item.Details = userDBItem.Info } - return &protos.UserGroupJoinListResp{ + return []*protos.UserGroupJoinListResp{&protos.UserGroupJoinListResp{ Requests: items, - }, nil + }}, nil } diff --git a/api/ws/handlers/user-group-management.go b/api/ws/handlers/user-group-management.go index cd1290a8..adfc49ff 100644 --- a/api/ws/handlers/user-group-management.go +++ b/api/ws/handlers/user-group-management.go @@ -13,7 +13,7 @@ import ( "go.mongodb.org/mongo-driver/mongo/options" ) -func HandleUserGroupCreateReq(req *protos.UserGroupCreateReq, hctx wsHelpers.HandlerContext) (*protos.UserGroupCreateResp, error) { +func HandleUserGroupCreateReq(req *protos.UserGroupCreateReq, hctx wsHelpers.HandlerContext) ([]*protos.UserGroupCreateResp, error) { // Should only be called if we have admin rights, no other permission issues here if err := wsHelpers.CheckStringField(&req.Name, "Name", 1, 50); err != nil { return nil, err @@ -64,10 +64,10 @@ func HandleUserGroupCreateReq(req *protos.UserGroupCreateReq, hctx wsHelpers.Han return nil, err } - return &protos.UserGroupCreateResp{Group: groupSend}, nil + return []*protos.UserGroupCreateResp{&protos.UserGroupCreateResp{Group: groupSend}}, nil } -func HandleUserGroupDeleteReq(req *protos.UserGroupDeleteReq, hctx wsHelpers.HandlerContext) (*protos.UserGroupDeleteResp, error) { +func HandleUserGroupDeleteReq(req *protos.UserGroupDeleteReq, hctx wsHelpers.HandlerContext) ([]*protos.UserGroupDeleteResp, error) { // Should only be called if we have admin rights, no other permission issues here if err := wsHelpers.CheckStringField(&req.GroupId, "GroupId", 1, wsHelpers.IdFieldMaxLength); err != nil { return nil, err @@ -111,10 +111,10 @@ func HandleUserGroupDeleteReq(req *protos.UserGroupDeleteReq, hctx wsHelpers.Han hctx.Svcs.Log.Errorf("UserGroup Delete result had unexpected counts %+v id: %v", result, req.GroupId) } - return &protos.UserGroupDeleteResp{}, nil + return []*protos.UserGroupDeleteResp{&protos.UserGroupDeleteResp{}}, nil } -func HandleUserGroupSetNameReq(req *protos.UserGroupSetNameReq, hctx wsHelpers.HandlerContext) (*protos.UserGroupSetNameResp, error) { +func HandleUserGroupSetNameReq(req *protos.UserGroupSetNameReq, hctx wsHelpers.HandlerContext) ([]*protos.UserGroupSetNameResp, error) { // Should only be called if we have admin rights, no other permission issues here if err := wsHelpers.CheckStringField(&req.GroupId, "GroupId", 1, wsHelpers.IdFieldMaxLength); err != nil { return nil, err @@ -157,7 +157,7 @@ func HandleUserGroupSetNameReq(req *protos.UserGroupSetNameReq, hctx wsHelpers.H return nil, err } - return &protos.UserGroupSetNameResp{Group: groupSend}, nil + return []*protos.UserGroupSetNameResp{&protos.UserGroupSetNameResp{Group: groupSend}}, nil } func checkUserGroupNameExists(name string, ctx context.Context, coll *mongo.Collection) (bool, error, *mongo.SingleResult) { diff --git a/api/ws/handlers/user-group-membership.go b/api/ws/handlers/user-group-membership.go index 24869a63..c6509d18 100644 --- a/api/ws/handlers/user-group-membership.go +++ b/api/ws/handlers/user-group-membership.go @@ -16,48 +16,48 @@ import ( "go.mongodb.org/mongo-driver/mongo/options" ) -func HandleUserGroupAddViewerReq(req *protos.UserGroupAddViewerReq, hctx wsHelpers.HandlerContext) (*protos.UserGroupAddViewerResp, error) { +func HandleUserGroupAddViewerReq(req *protos.UserGroupAddViewerReq, hctx wsHelpers.HandlerContext) ([]*protos.UserGroupAddViewerResp, error) { group, err := modifyGroupMembershipList(req.GroupId, req.GetGroupViewerId(), req.GetUserViewerId(), true, true, hctx) if err != nil { return nil, err } - return &protos.UserGroupAddViewerResp{ + return []*protos.UserGroupAddViewerResp{&protos.UserGroupAddViewerResp{ Group: group, - }, nil + }}, nil } -func HandleUserGroupDeleteViewerReq(req *protos.UserGroupDeleteViewerReq, hctx wsHelpers.HandlerContext) (*protos.UserGroupDeleteViewerResp, error) { +func HandleUserGroupDeleteViewerReq(req *protos.UserGroupDeleteViewerReq, hctx wsHelpers.HandlerContext) ([]*protos.UserGroupDeleteViewerResp, error) { group, err := modifyGroupMembershipList(req.GroupId, req.GetGroupViewerId(), req.GetUserViewerId(), true, false, hctx) if err != nil { return nil, err } - return &protos.UserGroupDeleteViewerResp{ + return []*protos.UserGroupDeleteViewerResp{&protos.UserGroupDeleteViewerResp{ Group: group, - }, nil + }}, nil } -func HandleUserGroupAddMemberReq(req *protos.UserGroupAddMemberReq, hctx wsHelpers.HandlerContext) (*protos.UserGroupAddMemberResp, error) { +func HandleUserGroupAddMemberReq(req *protos.UserGroupAddMemberReq, hctx wsHelpers.HandlerContext) ([]*protos.UserGroupAddMemberResp, error) { group, err := modifyGroupMembershipList(req.GroupId, req.GetGroupMemberId(), req.GetUserMemberId(), false, true, hctx) if err != nil { return nil, err } - return &protos.UserGroupAddMemberResp{ + return []*protos.UserGroupAddMemberResp{&protos.UserGroupAddMemberResp{ Group: group, - }, nil + }}, nil } -func HandleUserGroupDeleteMemberReq(req *protos.UserGroupDeleteMemberReq, hctx wsHelpers.HandlerContext) (*protos.UserGroupDeleteMemberResp, error) { +func HandleUserGroupDeleteMemberReq(req *protos.UserGroupDeleteMemberReq, hctx wsHelpers.HandlerContext) ([]*protos.UserGroupDeleteMemberResp, error) { group, err := modifyGroupMembershipList(req.GroupId, req.GetGroupMemberId(), req.GetUserMemberId(), false, false, hctx) if err != nil { return nil, err } - return &protos.UserGroupDeleteMemberResp{ + return []*protos.UserGroupDeleteMemberResp{&protos.UserGroupDeleteMemberResp{ Group: group, - }, nil + }}, nil } // Does the job of the above... diff --git a/api/ws/handlers/user-group-retrieval.go b/api/ws/handlers/user-group-retrieval.go index 15960105..493ed2ad 100644 --- a/api/ws/handlers/user-group-retrieval.go +++ b/api/ws/handlers/user-group-retrieval.go @@ -13,7 +13,7 @@ import ( "go.mongodb.org/mongo-driver/mongo/options" ) -func HandleUserGroupListReq(req *protos.UserGroupListReq, hctx wsHelpers.HandlerContext) (*protos.UserGroupListResp, error) { +func HandleUserGroupListReq(req *protos.UserGroupListReq, hctx wsHelpers.HandlerContext) ([]*protos.UserGroupListResp, error) { // Should only be called if we have admin rights, so other permission issues here ctx := context.TODO() coll := hctx.Svcs.MongoDB.Collection(dbCollections.UserGroupsName) @@ -53,13 +53,13 @@ func HandleUserGroupListReq(req *protos.UserGroupListReq, hctx wsHelpers.Handler }) } - return &protos.UserGroupListResp{ + return []*protos.UserGroupListResp{&protos.UserGroupListResp{ GroupInfos: groupInfos, - }, nil + }}, nil } // Getting an individual user group - this should only be allowed for PIXLISE_ADMIN permissioned users, or group admins -func HandleUserGroupReq(req *protos.UserGroupReq, hctx wsHelpers.HandlerContext) (*protos.UserGroupResp, error) { +func HandleUserGroupReq(req *protos.UserGroupReq, hctx wsHelpers.HandlerContext) ([]*protos.UserGroupResp, error) { if err := wsHelpers.CheckStringField(&req.GroupId, "GroupId", 1, wsHelpers.IdFieldMaxLength); err != nil { return nil, err } @@ -89,12 +89,12 @@ func HandleUserGroupReq(req *protos.UserGroupReq, hctx wsHelpers.HandlerContext) return nil, err } - return &protos.UserGroupResp{ + return []*protos.UserGroupResp{&protos.UserGroupResp{ Group: decGroup, - }, nil + }}, nil } -func HandleUserGroupListJoinableReq(req *protos.UserGroupListJoinableReq, hctx wsHelpers.HandlerContext) (*protos.UserGroupListJoinableResp, error) { +func HandleUserGroupListJoinableReq(req *protos.UserGroupListJoinableReq, hctx wsHelpers.HandlerContext) ([]*protos.UserGroupListJoinableResp, error) { // Should only be called if we have admin rights, so other permission issues here ctx := context.TODO() coll := hctx.Svcs.MongoDB.Collection(dbCollections.UserGroupsName) @@ -175,7 +175,7 @@ func HandleUserGroupListJoinableReq(req *protos.UserGroupListJoinableReq, hctx w }) } - return &protos.UserGroupListJoinableResp{ + return []*protos.UserGroupListJoinableResp{&protos.UserGroupListJoinableResp{ Groups: groupSummaries, - }, nil + }}, nil } diff --git a/api/ws/handlers/user-management.go b/api/ws/handlers/user-management.go index adf9c1bb..21b9cbb1 100644 --- a/api/ws/handlers/user-management.go +++ b/api/ws/handlers/user-management.go @@ -13,7 +13,7 @@ import ( // ///////////////////////////////////////////////////////////////////// // Listing users from Auth0 -func HandleUserListReq(req *protos.UserListReq, hctx wsHelpers.HandlerContext) (*protos.UserListResp, error) { +func HandleUserListReq(req *protos.UserListReq, hctx wsHelpers.HandlerContext) ([]*protos.UserListResp, error) { auth0API, err := auth0login.InitAuth0ManagementAPI(hctx.Svcs.Config) if err != nil { return nil, err @@ -40,12 +40,12 @@ func HandleUserListReq(req *protos.UserListReq, hctx wsHelpers.HandlerContext) ( page++ } - return &protos.UserListResp{Details: users}, err + return []*protos.UserListResp{&protos.UserListResp{Details: users}}, err } // ///////////////////////////////////////////////////////////////////// // Getting a users roles -func HandleUserRolesListReq(req *protos.UserRolesListReq, hctx wsHelpers.HandlerContext) (*protos.UserRolesListResp, error) { +func HandleUserRolesListReq(req *protos.UserRolesListReq, hctx wsHelpers.HandlerContext) ([]*protos.UserRolesListResp, error) { if err := wsHelpers.CheckStringField(&req.UserId, "UserId", 5, wsHelpers.Auth0UserIdFieldMaxLength); err != nil { return nil, err } @@ -60,14 +60,14 @@ func HandleUserRolesListReq(req *protos.UserRolesListReq, hctx wsHelpers.Handler return nil, err } - return &protos.UserRolesListResp{ + return []*protos.UserRolesListResp{&protos.UserRolesListResp{ Roles: makeRoleList(gotRoles), - }, nil + }}, nil } // ///////////////////////////////////////////////////////////////////// // Managing a users roles -func HandleUserAddRoleReq(req *protos.UserAddRoleReq, hctx wsHelpers.HandlerContext) (*protos.UserAddRoleResp, error) { +func HandleUserAddRoleReq(req *protos.UserAddRoleReq, hctx wsHelpers.HandlerContext) ([]*protos.UserAddRoleResp, error) { if err := wsHelpers.CheckStringField(&req.UserId, "UserId", 5, wsHelpers.Auth0UserIdFieldMaxLength); err != nil { return nil, err } @@ -119,10 +119,13 @@ func HandleUserAddRoleReq(req *protos.UserAddRoleReq, hctx wsHelpers.HandlerCont } err = auth0API.User.AssignRoles(userID, &management.Role{ID: &roleID}) - return nil, err + if err != nil { + return nil, err + } + return []*protos.UserAddRoleResp{&protos.UserAddRoleResp{}}, nil } -func HandleUserDeleteRoleReq(req *protos.UserDeleteRoleReq, hctx wsHelpers.HandlerContext) (*protos.UserDeleteRoleResp, error) { +func HandleUserDeleteRoleReq(req *protos.UserDeleteRoleReq, hctx wsHelpers.HandlerContext) ([]*protos.UserDeleteRoleResp, error) { if err := wsHelpers.CheckStringField(&req.UserId, "UserId", 5, wsHelpers.Auth0UserIdFieldMaxLength); err != nil { return nil, err } @@ -136,12 +139,15 @@ func HandleUserDeleteRoleReq(req *protos.UserDeleteRoleReq, hctx wsHelpers.Handl } err = auth0API.User.RemoveRoles(req.UserId, &management.Role{ID: &req.RoleId}) - return nil, err + if err != nil { + return nil, err + } + return []*protos.UserDeleteRoleResp{&protos.UserDeleteRoleResp{}}, err } // ///////////////////////////////////////////////////////////////////// // Getting all user roles -func HandleUserRoleListReq(req *protos.UserRoleListReq, hctx wsHelpers.HandlerContext) (*protos.UserRoleListResp, error) { +func HandleUserRoleListReq(req *protos.UserRoleListReq, hctx wsHelpers.HandlerContext) ([]*protos.UserRoleListResp, error) { auth0API, err := auth0login.InitAuth0ManagementAPI(hctx.Svcs.Config) if err != nil { return nil, err @@ -153,9 +159,9 @@ func HandleUserRoleListReq(req *protos.UserRoleListReq, hctx wsHelpers.HandlerCo return nil, err } - return &protos.UserRoleListResp{ + return []*protos.UserRoleListResp{&protos.UserRoleListResp{ Roles: makeRoleList(gotRoles), - }, nil + }}, nil } // ///////////////////////////////////////////////////////////////////// diff --git a/api/ws/handlers/user-notification-setting.go b/api/ws/handlers/user-notification-setting.go index b2d00a8d..55b58c87 100644 --- a/api/ws/handlers/user-notification-setting.go +++ b/api/ws/handlers/user-notification-setting.go @@ -11,18 +11,18 @@ import ( "go.mongodb.org/mongo-driver/bson" ) -func HandleUserNotificationSettingsReq(req *protos.UserNotificationSettingsReq, hctx wsHelpers.HandlerContext) (*protos.UserNotificationSettingsResp, error) { +func HandleUserNotificationSettingsReq(req *protos.UserNotificationSettingsReq, hctx wsHelpers.HandlerContext) ([]*protos.UserNotificationSettingsResp, error) { userDBItem, err := wsHelpers.GetDBUser(hctx.SessUser.User.Id, hctx.Svcs.MongoDB) if err != nil { return nil, err } - return &protos.UserNotificationSettingsResp{ + return []*protos.UserNotificationSettingsResp{&protos.UserNotificationSettingsResp{ Notifications: userDBItem.NotificationSettings, - }, nil + }}, nil } -func HandleUserNotificationSettingsWriteReq(req *protos.UserNotificationSettingsWriteReq, hctx wsHelpers.HandlerContext) (*protos.UserNotificationSettingsWriteResp, error) { +func HandleUserNotificationSettingsWriteReq(req *protos.UserNotificationSettingsWriteReq, hctx wsHelpers.HandlerContext) ([]*protos.UserNotificationSettingsWriteResp, error) { if req.Notifications == nil || req.Notifications.TopicSettings == nil { return nil, errorwithstatus.MakeBadRequestError(errors.New("Notifications must be set")) } @@ -40,5 +40,5 @@ func HandleUserNotificationSettingsWriteReq(req *protos.UserNotificationSettings return nil, err } - return &protos.UserNotificationSettingsWriteResp{}, nil + return []*protos.UserNotificationSettingsWriteResp{&protos.UserNotificationSettingsWriteResp{}}, nil } diff --git a/api/ws/handlers/user.go b/api/ws/handlers/user.go index 05ffb0bc..15d70a9e 100644 --- a/api/ws/handlers/user.go +++ b/api/ws/handlers/user.go @@ -14,7 +14,7 @@ import ( "go.mongodb.org/mongo-driver/mongo" ) -func HandleUserDetailsReq(req *protos.UserDetailsReq, hctx wsHelpers.HandlerContext) (*protos.UserDetailsResp, error) { +func HandleUserDetailsReq(req *protos.UserDetailsReq, hctx wsHelpers.HandlerContext) ([]*protos.UserDetailsResp, error) { userDBItem, err := wsHelpers.GetDBUser(hctx.SessUser.User.Id, hctx.Svcs.MongoDB) if err != nil { return nil, err @@ -26,16 +26,16 @@ func HandleUserDetailsReq(req *protos.UserDetailsReq, hctx wsHelpers.HandlerCont // map doesn't help either! sort.Strings(perms) - return &protos.UserDetailsResp{ + return []*protos.UserDetailsResp{&protos.UserDetailsResp{ Details: &protos.UserDetails{ Info: userDBItem.Info, DataCollectionVersion: userDBItem.DataCollectionVersion, Permissions: perms, }, - }, nil + }}, nil } -func HandleUserDetailsWriteReq(req *protos.UserDetailsWriteReq, hctx wsHelpers.HandlerContext) (*protos.UserDetailsWriteResp, error) { +func HandleUserDetailsWriteReq(req *protos.UserDetailsWriteReq, hctx wsHelpers.HandlerContext) ([]*protos.UserDetailsWriteResp, error) { if &req.Name != nil && req.Name != "" { if err := wsHelpers.CheckStringField(&req.Name, "Name", 1, 50); err != nil { return nil, err @@ -94,10 +94,10 @@ func HandleUserDetailsWriteReq(req *protos.UserDetailsWriteReq, hctx wsHelpers.H // TODO: Trigger user details update (?) - return &protos.UserDetailsWriteResp{}, nil + return []*protos.UserDetailsWriteResp{&protos.UserDetailsWriteResp{}}, nil } -func HandleUserSearchReq(req *protos.UserSearchReq, hctx wsHelpers.HandlerContext) (*protos.UserSearchResp, error) { +func HandleUserSearchReq(req *protos.UserSearchReq, hctx wsHelpers.HandlerContext) ([]*protos.UserSearchResp, error) { if err := wsHelpers.CheckStringField(&req.SearchString, "SearchString", 0, 100); err != nil { return nil, err } @@ -115,9 +115,9 @@ func HandleUserSearchReq(req *protos.UserSearchReq, hctx wsHelpers.HandlerContex if err != nil { if err == mongo.ErrNoDocuments { // Silent error, just return empty - return &protos.UserSearchResp{ + return []*protos.UserSearchResp{&protos.UserSearchResp{ Users: []*protos.UserInfo{}, - }, nil + }}, nil } return nil, err @@ -134,7 +134,7 @@ func HandleUserSearchReq(req *protos.UserSearchReq, hctx wsHelpers.HandlerContex users = append(users, user.Info) } - return &protos.UserSearchResp{ + return []*protos.UserSearchResp{&protos.UserSearchResp{ Users: users, - }, nil + }}, nil } diff --git a/api/ws/handlers/widget-data.go b/api/ws/handlers/widget-data.go index 538a7762..1af4662e 100644 --- a/api/ws/handlers/widget-data.go +++ b/api/ws/handlers/widget-data.go @@ -10,7 +10,7 @@ import ( "go.mongodb.org/mongo-driver/bson" ) -func HandleWidgetDataGetReq(req *protos.WidgetDataGetReq, hctx wsHelpers.HandlerContext) (*protos.WidgetDataGetResp, error) { +func HandleWidgetDataGetReq(req *protos.WidgetDataGetReq, hctx wsHelpers.HandlerContext) ([]*protos.WidgetDataGetResp, error) { result := hctx.Svcs.MongoDB.Collection(dbCollections.WidgetDataName).FindOne(context.TODO(), bson.M{ "_id": req.Id, }) @@ -25,12 +25,12 @@ func HandleWidgetDataGetReq(req *protos.WidgetDataGetReq, hctx wsHelpers.Handler return nil, err } - return &protos.WidgetDataGetResp{ + return []*protos.WidgetDataGetResp{&protos.WidgetDataGetResp{ WidgetData: widgetData, - }, nil + }}, nil } -func HandleWidgetDataWriteReq(req *protos.WidgetDataWriteReq, hctx wsHelpers.HandlerContext) (*protos.WidgetDataWriteResp, error) { +func HandleWidgetDataWriteReq(req *protos.WidgetDataWriteReq, hctx wsHelpers.HandlerContext) ([]*protos.WidgetDataWriteResp, error) { if req.WidgetData.Id == "" { return nil, errors.New("widget data must have a predefined id to write to") } @@ -56,7 +56,7 @@ func HandleWidgetDataWriteReq(req *protos.WidgetDataWriteReq, hctx wsHelpers.Han return nil, err } - return &protos.WidgetDataWriteResp{ + return []*protos.WidgetDataWriteResp{&protos.WidgetDataWriteResp{ WidgetData: req.WidgetData, - }, nil + }}, nil } diff --git a/api/ws/ws.go b/api/ws/ws.go index 78031ec5..07be5bb0 100644 --- a/api/ws/ws.go +++ b/api/ws/ws.go @@ -165,24 +165,28 @@ func (ws *WSHandler) HandleMessage(s *melody.Session, msg []byte) { Svcs: ws.svcs, } - resp, err := ws.dispatchWSMessage(&wsmsg, ctx) + resps, err := ws.dispatchWSMessage(&wsmsg, ctx) if err != nil { fmt.Printf("HandleMessage: %v\n", err) } - if resp != nil { - // Set incoming message ID on the outgoing one - resp.MsgId = wsmsg.MsgId + if resps != nil && len(resps) > 0 { + for _, resp := range resps { + if resp != nil { + // Set incoming message ID on the outgoing one + resp.MsgId = wsmsg.MsgId - // Print out errors - if len(resp.ErrorText) > 0 { - fmt.Printf("Sending Response Error for msg id %v:\n %v\n", resp.MsgId-1, resp.ErrorText) - } + // Print out errors + if len(resp.ErrorText) > 0 { + fmt.Printf("Sending Response Error for msg id %v:\n %v\n", resp.MsgId-1, resp.ErrorText) + } - // Send - wsHelpers.SendForSession(s, resp) + // Send + wsHelpers.SendForSession(s, resp) + } + } } else { - fmt.Printf("WARNING: No response generated for request: %+v\n", resp) + fmt.Printf("WARNING: No response generated for request: %+v\n", wsmsg) } } diff --git a/api/ws/wsHelpers/db.go b/api/ws/wsHelpers/db.go index f4d52bf1..0138d6c0 100644 --- a/api/ws/wsHelpers/db.go +++ b/api/ws/wsHelpers/db.go @@ -14,7 +14,7 @@ import ( "go.mongodb.org/mongo-driver/mongo/writeconcern" ) -func DeleteUserObject[T any](objectId string, objectType protos.ObjectType, collectionName string, hctx HandlerContext) (*T, error) { +func DeleteUserObject[T any](objectId string, objectType protos.ObjectType, collectionName string, hctx HandlerContext) ([]*T, error) { ctx := context.TODO() _, err := CheckObjectAccess(true, objectId, objectType, hctx) @@ -63,7 +63,7 @@ func DeleteUserObject[T any](objectId string, objectType protos.ObjectType, coll // Delete responses are just empty msgs var resp T - return &resp, nil + return []*T{&resp}, nil } func GetUserObjectById[T any](forEditing bool, objectId string, objectType protos.ObjectType, collectionName string, hctx HandlerContext) (*T, *protos.OwnershipItem, error) { diff --git a/data-formats b/data-formats index c37dd2d9..0c1eb61d 160000 --- a/data-formats +++ b/data-formats @@ -1 +1 @@ -Subproject commit c37dd2d94a6564c613c11906cc47ff71ad09ab65 +Subproject commit 0c1eb61d24cad830d9932b8222f90583eb9f3aaa