-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Handle app Logo in database and auth provider (#510)
- Loading branch information
1 parent
177abac
commit 2cd4dcc
Showing
15 changed files
with
601 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
defmodule Lenra.Apps.Image do | ||
@moduledoc """ | ||
The image schema. | ||
""" | ||
|
||
use Lenra.Schema | ||
import Ecto.Changeset | ||
alias Lenra.Accounts.User | ||
|
||
@type t :: %__MODULE__{} | ||
|
||
@derive {Jason.Encoder, | ||
only: [ | ||
:data, | ||
:type, | ||
:creator_id | ||
]} | ||
schema "images" do | ||
field(:data, :binary) | ||
field(:type, :string) | ||
belongs_to(:creator, User) | ||
|
||
timestamps() | ||
end | ||
|
||
def changeset(image, params \\ %{}) do | ||
image | ||
|> cast(params, [:data, :type]) | ||
|> validate_required([:data, :type, :creator_id]) | ||
|> foreign_key_constraint(:creator_id) | ||
end | ||
|
||
def new(creator_id, params) do | ||
%__MODULE__{ | ||
creator_id: creator_id | ||
} | ||
|> __MODULE__.changeset(params) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
defmodule Lenra.Apps.Logo do | ||
@moduledoc """ | ||
The logo schema. | ||
""" | ||
|
||
use Lenra.Schema | ||
import Ecto.Changeset | ||
alias Lenra.Apps.App | ||
alias Lenra.Apps.Environment | ||
alias Lenra.Apps.Image | ||
|
||
@type t :: %__MODULE__{} | ||
|
||
@derive {Jason.Encoder, | ||
only: [ | ||
:application_id, | ||
:environment_id, | ||
:image_id | ||
]} | ||
schema "logos" do | ||
belongs_to(:application, App) | ||
belongs_to(:environment, Environment) | ||
belongs_to(:image, Image) | ||
|
||
timestamps() | ||
end | ||
|
||
def changeset(logo, params) do | ||
logo | ||
|> cast(params, [:image_id]) | ||
|> validate_required([:application_id, :image_id]) | ||
|> foreign_key_constraint(:application_id) | ||
|> foreign_key_constraint(:environment_id) | ||
|> foreign_key_constraint(:image_id) | ||
end | ||
|
||
def new(application_id, environment_id, params \\ %{}) do | ||
%__MODULE__{ | ||
application_id: application_id, | ||
environment_id: environment_id | ||
} | ||
|> __MODULE__.changeset(params) | ||
end | ||
end |
21 changes: 21 additions & 0 deletions
21
apps/lenra/priv/repo/migrations/20231206131107_manage_app_and_env_logo.exs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
defmodule Lenra.Repo.Migrations.ManageAppAndEnvLogo do | ||
use Ecto.Migration | ||
|
||
def change do | ||
create table(:images) do | ||
add(:creator_id, references(:users)) | ||
add(:data, :binary) | ||
add(:type, :string) | ||
timestamps() | ||
end | ||
|
||
create table(:logos) do | ||
add(:application_id, references(:applications)) | ||
add(:environment_id, references(:applications), null: true) | ||
add(:image_id, references(:images)) | ||
timestamps() | ||
end | ||
|
||
create(unique_index(:logos, [:application_id, :environment_id], name: :logos_application_id_environment_id_index)) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.