(c *gin.Context)
| 14 | ) |
| 15 | |
| 16 | func MetadataAPI(c *gin.Context) { |
| 17 | // Get migrate instance |
| 18 | ecPtr, ok := c.Get("ec") |
| 19 | if !ok { |
| 20 | return |
| 21 | } |
| 22 | |
| 23 | // Convert to url.URL |
| 24 | ec, ok := ecPtr.(*cli.ExecutionContext) |
| 25 | if !ok { |
| 26 | c.JSON(http.StatusInternalServerError, &Response{Code: "internal_error", Message: "cannot get execution context"}) |
| 27 | return |
| 28 | } |
| 29 | t, err := migrate.NewMigrate(ec, false, "", hasura.SourceKindPG) |
| 30 | if err != nil { |
| 31 | c.JSON(http.StatusInternalServerError, &Response{Code: "internal_error", Message: err.Error()}) |
| 32 | return |
| 33 | } |
| 34 | mdHandler := projectmetadata.NewHandlerFromEC(ec) |
| 35 | // Switch on request method |
| 36 | switch c.Request.Method { |
| 37 | case "GET": |
| 38 | var files map[string][]byte |
| 39 | files, err = mdHandler.ExportMetadata() |
| 40 | if err != nil { |
| 41 | if strings.HasPrefix(err.Error(), DataAPIError) { |
| 42 | c.JSON(http.StatusInternalServerError, &Response{Code: "data_api_error", Message: err.Error()}) |
| 43 | return |
| 44 | } |
| 45 | |
| 46 | c.JSON(http.StatusInternalServerError, &Response{Code: "internal_error", Message: err.Error()}) |
| 47 | return |
| 48 | } |
| 49 | |
| 50 | queryValues := c.Request.URL.Query() |
| 51 | export := queryValues.Get("export") |
| 52 | if export == "true" { |
| 53 | err := mdHandler.WriteMetadata(files) |
| 54 | if err != nil { |
| 55 | c.JSON(http.StatusInternalServerError, &Response{Code: "internal_error", Message: err.Error()}) |
| 56 | return |
| 57 | } |
| 58 | } |
| 59 | c.JSON(http.StatusOK, &gin.H{"metadata": "Success"}) |
| 60 | case "POST": |
| 61 | var request Request |
| 62 | |
| 63 | // Bind Request body to Request struct |
| 64 | if c.BindJSON(&request) != nil { |
| 65 | c.JSON(http.StatusInternalServerError, &Response{Code: "internal_error", Message: "Something went wrong"}) |
| 66 | return |
| 67 | } |
| 68 | |
| 69 | err := t.Query(request.Up) |
| 70 | if err != nil { |
| 71 | if strings.HasPrefix(err.Error(), DataAPIError) { |
| 72 | c.JSON(http.StatusInternalServerError, &Response{Code: "data_api_error", Message: err.Error()}) |
| 73 | return |
nothing calls this directly
no test coverage detected