Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions lib/digistab_store/store.ex
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,10 @@ defmodule DigistabStore.Store do
end

def list_products(_preload? = true) do
list_products()
|> Repo.preload([:tags, :status, :category, :photos])
Product
|> order_by([p], p.inserted_at)
|> preload([:tags, :status, :category, :photos])
|> Repo.all()
end

@doc """
Expand Down Expand Up @@ -110,8 +112,6 @@ defmodule DigistabStore.Store do
"""
@spec search_products(binary()) :: [Product.t()]
def search_products(product_name) do
# Just for User Experience
:timer.sleep(1000)
search_term = "%#{product_name}%"

from(p in Product,
Expand Down Expand Up @@ -179,8 +179,10 @@ defmodule DigistabStore.Store do
end

def get_product!(id, _preload? = true) do
get_product!(id)
|> preload_product!()
Product
|> where(id: ^id)
|> preload([:tags, :status, :category, :photos])
|> Repo.one!()
end

@doc """
Expand Down Expand Up @@ -269,7 +271,7 @@ defmodule DigistabStore.Store do
|> Product.changeset(attrs)
end

def change_product_price(%Product{} = product, attrs \\ %{}) do
def change_product_price(%Product{} = product, attrs \\ %{}) do
product
|> Repo.preload([:status, :category])
|> Product.price_changeset(attrs)
Expand Down
2 changes: 0 additions & 2 deletions lib/digistab_store_web/live/products/index.ex
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,6 @@ defmodule DigistabStoreWeb.ProductLive.Index do
end

def handle_info({:handle_category, id}, socket) do
:timer.sleep(1000)

socket =
socket
|> assign(loading: false)
Expand Down
Loading