From 6f138ac63893aef50e1a2bc61792457adc93a1be Mon Sep 17 00:00:00 2001 From: Ivan Ivanov Date: Mon, 16 Dec 2024 13:24:06 +0200 Subject: [PATCH] Start working on metric_registry_export --- config/dev.exs | 3 +++ .../metric/registry/change_suggestion.ex | 6 ----- .../controllers/metric_registry_controller.ex | 25 ++++++++++++++++++- lib/sanbase_web/router.ex | 3 +-- 4 files changed, 28 insertions(+), 9 deletions(-) diff --git a/config/dev.exs b/config/dev.exs index 8297eee63..e04e4e466 100644 --- a/config/dev.exs +++ b/config/dev.exs @@ -58,6 +58,9 @@ config :sanbase, Sanbase.KafkaExporter, producer: Sanbase.InMemoryKafka.Producer # with. When running the app locally these values are overridden by the values # in the .env.dev or dev.secret.exs files, which are ignored by git and not # published in the repository. Please do not report these as security issues. +# To create the user for your local env: +# In psql: CREATE ROLE postgres WITH LOGIN SUPERUSER PASSWORD 'postgres'; +# In the terminal: mix ecto.setup config :sanbase, Sanbase.Repo, username: "postgres", password: "postgres", diff --git a/lib/sanbase/metric/registry/change_suggestion.ex b/lib/sanbase/metric/registry/change_suggestion.ex index 929c617f6..9ac19898b 100644 --- a/lib/sanbase/metric/registry/change_suggestion.ex +++ b/lib/sanbase/metric/registry/change_suggestion.ex @@ -138,13 +138,7 @@ defmodule Sanbase.Metric.Registry.ChangeSuggestion do # only after the DB changes are commited and not from insite the transaction. If the event # is emitted from inside the transaction, the event handler can be invoked before the DB # changes are commited and this handler will have no effect. -<<<<<<< HEAD - Sanbase.Metric.Registry.update(metric_registry, params, emit_event?: false) -||||||| parent of 51db0b335 (Add is_verified toggle to Metric Registry LiveView) - Sanbase.Metric.Registry.update(metric_registry, params, emit_event?: true) -======= Sanbase.Metric.Registry.update(metric_registry, params, emit_event: true) ->>>>>>> 51db0b335 (Add is_verified toggle to Metric Registry LiveView) end def create_change_suggestion(%Registry{} = registry, params, notes, submitted_by) do diff --git a/lib/sanbase_web/controllers/metric_registry_controller.ex b/lib/sanbase_web/controllers/metric_registry_controller.ex index a9377c269..e49d30038 100644 --- a/lib/sanbase_web/controllers/metric_registry_controller.ex +++ b/lib/sanbase_web/controllers/metric_registry_controller.ex @@ -3,11 +3,34 @@ defmodule SanbaseWeb.MetricRegistryController do def export_json(conn, _params) do conn - |> resp(200, "ok") + |> resp(200, get_metric_registry_json()) |> send_resp() end defp get_metric_registry_json() do Sanbase.Metric.Registry.all() + |> Enum.take(1) + |> Enum.map(&transform/1) + + # |> Enum.map(&Jason.encode!/1) + # |> Enum.intersperse("\n") + end + + defp transform(struct) when is_struct(struct) do + struct + |> Map.from_struct() + |> Map.drop([:__meta__, :inserted_at, :updated_at, :change_suggestions]) + |> Map.new(fn + {k, v} when is_list(v) -> + {k, Enum.map(v, &transform/1)} + + {k, v} when is_map(v) -> + {k, transform(v)} + + {k, v} -> + {k, v} + end) end + + defp transform(data), do: data end diff --git a/lib/sanbase_web/router.ex b/lib/sanbase_web/router.ex index 40d8b77d3..df998e674 100644 --- a/lib/sanbase_web/router.ex +++ b/lib/sanbase_web/router.ex @@ -90,8 +90,6 @@ defmodule SanbaseWeb.Router do live("/metric_registry/sync", MetricRegistrySyncLive, :new) end - get("/metric_registry_export", MetricRegistryController, :export_json) - scope "/" do pipe_through(:api) @@ -183,6 +181,7 @@ defmodule SanbaseWeb.Router do end scope "/", SanbaseWeb do + get("/metric_registry_export", MetricRegistryController, :export_json) get("/api_metric_name_mapping", MetricNameController, :api_metric_name_mapping) get("/projects_data", DataController, :projects_data) get("/projects_twitter_handles", DataController, :projects_twitter_handles)