Skip to content

Commit

Permalink
cleanup: remove Employees and BadgeSerials after 2024-10-03 from sandbox
Browse files Browse the repository at this point in the history
  • Loading branch information
mathcolo committed Oct 24, 2024
1 parent b19f110 commit 9ac34e6
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
18 changes: 18 additions & 0 deletions lib/orbit_web/controllers/admin/admin_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,24 @@ defmodule OrbitWeb.Admin.AdminController do
]
)

@spec get_remove(Plug.Conn.t(), map()) :: Plug.Conn.t()
def get_remove(conn, _params) do
render(conn, :remove, layout: false)
end

@remove_after_timestamp ~N[2024-10-03 00:00:00]

@spec post_remove(Plug.Conn.t(), map()) :: Plug.Conn.t()
def post_remove(conn, _params) do
{count_bs, _} =
Repo.delete_all(from(bs in BadgeSerial, where: bs.inserted_at > ^@remove_after_timestamp))

{count_e, _} =
Repo.delete_all(from(e in Employee, where: e.inserted_at > ^@remove_after_timestamp))

text(conn, "Removed #{count_bs} BadgeSerial(s), #{count_e} Employee(s).")
end

@spec get_employee(Plug.Conn.t(), map()) :: Plug.Conn.t()
def get_employee(conn, _params) do
render(conn, :employee, layout: false)
Expand Down
7 changes: 7 additions & 0 deletions lib/orbit_web/controllers/admin/remove.html.heex
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<h1>admin/remove</h1>

<.form for={%{}} action={~p"/admin/remove"} method="post">
<button class="rounded border border-solid border-black hover:bg-gray-200 p-1" type="submit">
Remove data
</button>
</.form>
3 changes: 3 additions & 0 deletions lib/orbit_web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ defmodule OrbitWeb.Router do
pipe_through :accepts_html
pipe_through :authenticated

get "/admin/remove", Admin.AdminController, :get_remove
post "/admin/remove", Admin.AdminController, :post_remove

get "/admin/employee", Admin.AdminController, :get_employee
post "/admin/employee", Admin.AdminController, :post_employee
delete "/admin/employee", Admin.AdminController, :delete_employee
Expand Down

0 comments on commit 9ac34e6

Please sign in to comment.