Skip to content

Commit

Permalink
Added image default get/set capability with tests, also fixed pseudoi…
Browse files Browse the repository at this point in the history
…ntensity+diffraction broken tests
  • Loading branch information
Peter Nemere committed Oct 27, 2023
1 parent d892f10 commit 0fc5d7d
Show file tree
Hide file tree
Showing 9 changed files with 1,696 additions and 1,312 deletions.
1 change: 1 addition & 0 deletions api/dbCollections/collections.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const QuantificationZStacksName = "quantificationZStacks"
const RegionsOfInterestName = "regionsOfInterest"
const UserROIDisplaySettings = "userROIDisplaySettings"
const ScansName = "scans"
const ScanDefaultImagesName = "scanDefaultImages"
const SelectionName = "selection"
const TagsName = "tags"
const UserGroupsName = "userGroups"
Expand Down
79 changes: 76 additions & 3 deletions api/ws/handlers/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,85 @@ func HandleImageListReq(req *protos.ImageListReq, hctx wsHelpers.HandlerContext)
}, nil
}

func HandleImageDeleteReq(req *protos.ImageDeleteReq, hctx wsHelpers.HandlerContext) (*protos.ImageDeleteResp, error) {
return nil, errors.New("HandleImageDeleteReq not implemented yet")
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
}

// Check that the user has access to all the scans in question
for _, scanId := range req.ScanIds {
_, err := wsHelpers.CheckObjectAccess(false, scanId, protos.ObjectType_OT_SCAN, hctx)
if err != nil {
return nil, err
}
}

ctx := context.TODO()
coll := hctx.Svcs.MongoDB.Collection(dbCollections.ScanDefaultImagesName)

filter := bson.M{"_id": bson.M{"$in": req.ScanIds}}
opts := options.Find()

cursor, err := coll.Find(ctx, filter, opts)
if err != nil {
return nil, err
}

items := []*protos.ScanImageDefaultDB{}
err = cursor.All(context.TODO(), &items)
if err != nil {
return nil, err
}

result := map[string]string{}
for _, item := range items {
result[item.ScanId] = item.DefaultImageFileName
}

return &protos.ImageGetDefaultResp{
DefaultImagesPerScanId: result,
}, nil
}

func HandleImageSetDefaultReq(req *protos.ImageSetDefaultReq, hctx wsHelpers.HandlerContext) (*protos.ImageSetDefaultResp, error) {
return nil, errors.New("HandleImageSetDefaultReq not implemented yet")
if err := wsHelpers.CheckStringField(&req.ScanId, "ScanId", 1, wsHelpers.IdFieldMaxLength); err != nil {
return nil, err
}

if err := wsHelpers.CheckStringField(&req.DefaultImageFileName, "DefaultImageFileName", 1, 255); err != nil {
return nil, err
}

// Write to DB
ctx := context.TODO()
coll := hctx.Svcs.MongoDB.Collection(dbCollections.ScanDefaultImagesName)

filter := bson.D{{"_id", req.ScanId}}
opt := options.Update().SetUpsert(true)

data := bson.D{
{"$set", bson.D{
{"scanId", req.ScanId},
{"defaultImageFileName", req.DefaultImageFileName},
}},
}

result, err := coll.UpdateOne(ctx, filter, data, opt)
if err != nil {
return nil, err
}

if result.MatchedCount != 1 {
hctx.Svcs.Log.Errorf("ImageSetDefaultReq UpdateOne result had unexpected counts %+v id: %v", result, req.ScanId)
}

return &protos.ImageSetDefaultResp{}, nil
}

func HandleImageDeleteReq(req *protos.ImageDeleteReq, hctx wsHelpers.HandlerContext) (*protos.ImageDeleteResp, error) {
return nil, errors.New("HandleImageDeleteReq not implemented yet")
}

func HandleImageUploadReq(req *protos.ImageUploadReq, hctx wsHelpers.HandlerContext) (*protos.ImageUploadResp, error) {
return nil, errors.New("HandleImageUploadReq not implemented yet")
}
Loading

0 comments on commit 0fc5d7d

Please sign in to comment.