Skip to content

Instantly share code, notes, and snippets.

...
def MyApp.Management.Project do
...
many_to_many(
:users,
User,
join_through: "user_project",
on_replace: :delete
)
...
def MyApp.Accounts.User do
...
def changeset_update_projects(%User{} = user, projects) do
user
|> cast(%{}, @required_fields)
# associate projects to the user
|> put_assoc(:projects, projects)
end
...
end
def upsert_user_projects(user, project_ids) when is_list(project_ids) do
projects =
Project
|> where([project], project.id in ^project_ids)
|> Repo.all()
with {:ok, _struct} <-
user
|> User.changeset_update_projects(projects)
|> Repo.update() do
defmodule MyApp.TaskSupervisor do
use DynamicSupervisor
alias MyApp.Management
alias MyApp.WorkerStateStorage
def start_link(arg) do
DynamicSupervisor.start_link(__MODULE__, arg, name: __MODULE__)
end
defmodule MyApp.TaskWorker do
use GenServer, restart: :transient
alias MyApp.Notify
alias MyApp.Management
alias MyApp.WorkerStateStorage
# client
defmodule MyApp.StarterWorker do
@moduledoc """
Start lost children
"""
use GenServer
def start_link() do
GenServer.start_link(__MODULE__, [])
end
AWSTemplateFormatVersion: "2010-09-09"
Description: "Static website hosting with S3 and CloudFront"
Parameters:
BucketName:
Type: String
Default: "a-proper-bucket-name"
Resources:
# Create the bucket to contain the website HTML
AWSTemplateFormatVersion: "2010-09-09"
Description: "Static website hosting with S3 and CloudFront"
Parameters:
BucketName:
Type: String
Default: "a-proper-bucket-name"
Resources:
# Create the bucket to contain the website HTML
{
"key": "graphiql",
"lastId": 4,
"tabIds": [
"tab1",
"tab2",
"tab3",
"tab4"
],
"closedTabs": [],
def connect(%{"token" => token}, socket) do
with {:ok, user_id} <-
Phoenix.Token.verify(PhoenixAbsintheAuthenticatedSubscriptionsWeb.Endpoint, "user sesion", token,
max_age: 86_400
),
%Accounts.User{} = current_user <- Accounts.lookup_user(user_id) do
socket =
Absinthe.Phoenix.Socket.put_options(socket,
context: %{
current_user: current_user