Packages
ami
0.2.9
0.3.9
0.3.8
retired
0.3.7
retired
0.3.6
retired
0.3.5
retired
0.3.4
retired
0.3.3
retired
0.3.2
retired
0.3.1
retired
0.3.0
retired
0.2.9
retired
0.2.8
retired
0.2.7
retired
0.2.6
retired
0.2.5
retired
0.2.3
retired
0.2.2
retired
0.2.1
retired
0.2.0
retired
0.1.9
retired
0.1.8
retired
0.1.7
retired
0.1.6
retired
0.1.5
retired
0.1.4
retired
Package containing all AMI Models shared between micro-services.
Retired package: Security issue - retiring
Current section
Files
Jump to
Current section
Files
lib/ami/teaser_image.ex
defmodule Ami.TeaserImage do
alias Ami.{
Repo
}
import Ecto.Query
use Ecto.Schema
schema "teaser_images" do
field(:name, :string)
field(:page_position, :integer)
field(:teaseable_id, :integer)
field(:teaseable_type, :string)
field(:file, :string)
end
def preload_teaser_images(struct, teasable_type) do
struct
|> Repo.preload(
teaser_images: from(ti in __MODULE__, where: ti.teaseable_type == ^teasable_type)
)
end
def preload_preview_images(struct, teasable_type) do
struct
|> Repo.preload(
teaser_images:
from(
ti in __MODULE__,
where: ti.teaseable_type == ^teasable_type,
where: ti.page_position == 4
)
)
end
def preload_main_teaser_images(struct, teasable_type) do
struct
|> Repo.preload(
teaser_images:
from(
ti in __MODULE__,
where: ti.teaseable_type == ^teasable_type,
where: ti.page_position == 0
)
)
end
def preload_detail_teaser_images(struct, teasable_type) do
struct
|> Repo.preload(
teaser_images:
from(
ti in __MODULE__,
where: ti.teaseable_type == ^teasable_type,
where: ti.page_position == 1
)
)
end
def preload_certificate_teaser_images(struct, teasable_type) do
struct
|> Repo.preload(
teaser_images:
from(
ti in __MODULE__,
where: ti.teaseable_type == ^teasable_type,
where: ti.page_position == 3
)
)
end
def preload_download_certificate_teaser_images(struct, teaseable_type) do
struct
|> Repo.preload(
teaser_images:
from(
ti in __MODULE__,
where: ti.teaseable_type == ^teaseable_type,
where: ti.page_position == 5
)
)
end
def teaser_image_from(list) do
ti = List.last(list)
if ti != nil,
do: "https://ami-aws-s3.s3.amazonaws.com/uploads/teaser_image/file/#{ti.id}/#{ti.file}"
end
end