Skip to content

Commit

Permalink
Start working on metric_registry_export
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanIvanoff committed Dec 16, 2024
1 parent 6899801 commit 6f138ac
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 9 deletions.
3 changes: 3 additions & 0 deletions config/dev.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 0 additions & 6 deletions lib/sanbase/metric/registry/change_suggestion.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 24 additions & 1 deletion lib/sanbase_web/controllers/metric_registry_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 1 addition & 2 deletions lib/sanbase_web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 6f138ac

Please sign in to comment.