Skip to content

Commit

Permalink
fix dataset routes
Browse files Browse the repository at this point in the history
  • Loading branch information
v-rocheleau committed Aug 23, 2023
1 parent 7075ca3 commit 485d66a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,12 @@ func main() {
gam.ValidatePotentialGenotypeQueryParameter)

// --- Dataset
e.GET("/datasets/:dataset/summary", variantsMvc.GetDatasetSummary)
e.GET("/datasets/:dataset/data-types", variantsMvc.GetDatasetDataTypes)
e.GET("/datasets/:dataset/summary", variantsMvc.GetDatasetSummary,
// middleware
gam.MandateDatasetPathParam)
e.GET("/datasets/:dataset/data-types", variantsMvc.GetDatasetDataTypes,
// middleware
gam.MandateDatasetPathParam)

// TODO: refactor (deduplicate) --
e.GET("/variants/ingestion/run", variantsMvc.VariantsIngest,
Expand Down
16 changes: 16 additions & 0 deletions src/api/middleware/datasetMiddleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,22 @@ func MandateDatasetAttribute(next echo.HandlerFunc) echo.HandlerFunc {
}
}

func MandateDatasetPathParam(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
dataset := c.Param("dataset")
if !utils.IsValidUUID(dataset) {
fmt.Printf("Invalid dataset %s\n", dataset)

return c.JSON(http.StatusBadRequest, errors.CreateSimpleBadRequest(fmt.Sprintf("invalid dataset %s - please provide a valid uuid", dataset)))
}

gc := c.(*contexts.GohanContext)
gc.Dataset = uuid.MustParse(dataset)

return next(gc)
}
}

/*
Echo middleware to ensure a `dataset` HTTP query parameter is valid if provided
*/
Expand Down
2 changes: 1 addition & 1 deletion src/api/mvc/variants/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,13 +453,13 @@ func GetAllVariantIngestionRequests(c echo.Context) error {
}

func GetDatasetSummary(c echo.Context) error {
fmt.Printf("[%s] - GetDatasetSummary hit!\n", time.Now())

gc := c.(*contexts.GohanContext)
cfg := gc.Config
es := gc.Es7Client

dataset := gc.Dataset
fmt.Printf("[%s] - GetDatasetSummary hit: [%s]!\n", time.Now(), dataset.String())

// parallelize these two es queries

Expand Down

0 comments on commit 485d66a

Please sign in to comment.