Skip to content

Commit

Permalink
Using new code gen, sending arrays of responses from each handler fun…
Browse files Browse the repository at this point in the history
…ction, not just limiting to one. This allows spectrum to be broken into multiple response messages
  • Loading branch information
Peter Nemere committed May 15, 2024
1 parent 2aec78d commit bbe9db1
Show file tree
Hide file tree
Showing 47 changed files with 396 additions and 362 deletions.
12 changes: 6 additions & 6 deletions api/ws/handlers/detector-config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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{}
Expand All @@ -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
}
6 changes: 3 additions & 3 deletions api/ws/handlers/diffraction-detected-peak.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -64,7 +64,7 @@ func HandleDetectedDiffractionPeaksReq(req *protos.DetectedDiffractionPeaksReq,
}
}

return &protos.DetectedDiffractionPeaksResp{
return []*protos.DetectedDiffractionPeaksResp{&protos.DetectedDiffractionPeaksResp{
PeaksPerLocation: diffPerLoc,
}, nil
}}, nil
}
18 changes: 9 additions & 9 deletions api/ws/handlers/diffraction-manual.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
Expand All @@ -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
}
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
18 changes: 9 additions & 9 deletions api/ws/handlers/diffraction-status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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()
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
12 changes: 6 additions & 6 deletions api/ws/handlers/doi.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
}
Expand Down Expand Up @@ -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
}
20 changes: 10 additions & 10 deletions api/ws/handlers/element-set.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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"))
Expand All @@ -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
}
4 changes: 2 additions & 2 deletions api/ws/handlers/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down Expand Up @@ -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
}
20 changes: 10 additions & 10 deletions api/ws/handlers/expression-group.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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"))
Expand All @@ -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
}
Loading

0 comments on commit bbe9db1

Please sign in to comment.