just need to add creating services, deploying them, and showing logs
This commit is contained in:
parent
a3a4af7965
commit
023ad47ae4
6 changed files with 99 additions and 29 deletions
|
|
@ -9,7 +9,7 @@ defmodule EzcontainerRailway.Application do
|
|||
def start(_type, _args) do
|
||||
children = [
|
||||
EzcontainerRailwayWeb.Telemetry,
|
||||
# EzcontainerRailway.Repo,
|
||||
EzcontainerRailway.Repo,
|
||||
{DNSCluster, query: Application.get_env(:ezcontainer_railway, :dns_cluster_query) || :ignore},
|
||||
{Phoenix.PubSub, name: EzcontainerRailway.PubSub},
|
||||
# Start the Finch HTTP client for sending emails
|
||||
|
|
|
|||
|
|
@ -3,6 +3,19 @@ defmodule EzcontainerRailway.Projects do
|
|||
|
||||
alias EzcontainerRailway.Repo
|
||||
alias EzcontainerRailway.Project
|
||||
alias EzcontainerRailway.Railway
|
||||
|
||||
def get_project_by_token(token) do
|
||||
{:ok, user_id} = Railway.get_user_id(token)
|
||||
|
||||
get_project_by_user_id(user_id)
|
||||
|
||||
Repo.one(
|
||||
from p in Project,
|
||||
where: p.user_id == ^user_id,
|
||||
limit: 1
|
||||
)
|
||||
end
|
||||
|
||||
def get_project_by_user_id(user_id) do
|
||||
Repo.one(
|
||||
|
|
@ -11,4 +24,13 @@ defmodule EzcontainerRailway.Projects do
|
|||
limit: 1
|
||||
)
|
||||
end
|
||||
|
||||
def create_project(token) do
|
||||
{:ok, project_id} = Railway.create_project(token)
|
||||
{:ok, user_id} = Railway.get_user_id(token)
|
||||
|
||||
%Project{}
|
||||
|> Project.changeset(%{user_id: user_id, project_id: project_id})
|
||||
|> Repo.insert!
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
defmodule EzcontainerRailway.Railway do
|
||||
alias EzcontainerRailway.GraphqlClient
|
||||
def get_projects(token) do
|
||||
GraphqlClient.query(
|
||||
resp = GraphqlClient.query(
|
||||
"""
|
||||
query {
|
||||
projects {
|
||||
|
|
@ -15,7 +15,12 @@ defmodule EzcontainerRailway.Railway do
|
|||
}
|
||||
""",
|
||||
token: token
|
||||
)
|
||||
) |> format_response
|
||||
|
||||
case resp do
|
||||
{:error, _} -> resp
|
||||
{:ok, data} -> {:ok, data["projects"]["edges"]}
|
||||
end
|
||||
end
|
||||
|
||||
def create_service(container, token) when is_map(container) do
|
||||
|
|
@ -26,41 +31,51 @@ defmodule EzcontainerRailway.Railway do
|
|||
)
|
||||
end
|
||||
|
||||
def create_project(name, token) do
|
||||
GraphqlClient.query(
|
||||
def create_project(token) do
|
||||
resp = GraphqlClient.query(
|
||||
"""
|
||||
mutation {
|
||||
projectCreate(input: {name: $name}) {
|
||||
projectCreate(input: {}) {
|
||||
id
|
||||
name
|
||||
}
|
||||
}
|
||||
""",
|
||||
token: token,
|
||||
variables: %{ "name" => name }
|
||||
token: token
|
||||
)
|
||||
|> format_response
|
||||
end
|
||||
|
||||
def is_token_valid?(token) do
|
||||
resp = get_projects(token).body
|
||||
|
||||
if has_errors?(resp) do
|
||||
false
|
||||
else
|
||||
true
|
||||
case resp do
|
||||
{:error, _} -> resp
|
||||
{:ok, data} -> {:ok, data["projectCreate"]["id"]}
|
||||
end
|
||||
end
|
||||
|
||||
def has_errors?(resp) when is_map(resp) do
|
||||
def get_user_id(token) do
|
||||
{:ok, resp} = GraphqlClient.query(
|
||||
"""
|
||||
query {
|
||||
me {
|
||||
id
|
||||
}
|
||||
}
|
||||
""",
|
||||
token: token
|
||||
)
|
||||
|> format_response
|
||||
|
||||
{:ok, resp["me"]["id"]}
|
||||
end
|
||||
|
||||
def has_errors?(resp) do
|
||||
has_errors_in_array?(resp["errors"])
|
||||
end
|
||||
|
||||
defp format_response(resp) when is_map(resp) do
|
||||
if has_errors?(resp) do
|
||||
{:error, resp["error"]}
|
||||
if has_errors?(resp.body) do
|
||||
{:error, resp.body["errors"]}
|
||||
else
|
||||
{:ok, resp["data"]}
|
||||
{:ok, resp.body["data"]}
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue