Created
May 3, 2018 08:49
-
-
Save shahryarjb/d844e30b291febb5898ce1e96377ef05 to your computer and use it in GitHub Desktop.
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
def load_posts_by_category_alias(category_alias, group_acl) do | |
category = fetch_posts_by_category_alias(category_alias, group_acl) | |
|> Enum.find(& &1.seo_alias_link == "#{category_alias}") | |
post = category | |
|> Map.fetch!(:cms_post) | |
for %TrangellCmsService.Cms.Db.Post{} = p <- post do | |
%{ | |
title: p.title, | |
status: p.status, | |
post_type: p.post_type, | |
download_ext_link: p.download_ext_link, | |
price: p.price, | |
pic_x1_link: p.pic_x1_link, | |
pic_x2_link: p.pic_x2_link, | |
pic_x3_link: p.pic_x3_link, | |
group_acl: p.group_acl, | |
description: p.description, | |
changelog: p.changelog, | |
changelog_category: p.changelog_category, | |
plugin: p.plugin, | |
plugin_category: p.plugin_category, | |
discourse: p.discourse, | |
discourse_link: p.discourse_link, | |
screen_shot: p.screen_shot, | |
screen_shot_category: p.screen_shot_category, | |
learn: p.learn, | |
learn_category: p.learn_category, | |
seo_tag: p.seo_tag, | |
seo_alias_link: p.seo_alias_link, | |
seo_words: p.seo_words, | |
seo_description: p.seo_description, | |
seo_language: p.seo_language, | |
seo_language_link: p.seo_language_link, | |
category_title: category.title, | |
category_status: category.status, | |
category_language: category.language, | |
category_group_acl: category.group_acl, | |
category_seo_alias_link: category.seo_alias_link, | |
category_pic_x1_link: category.pic_x1_link, | |
category_pic_x2_link: category.pic_x2_link, | |
category_pic_x3_link: category.pic_x3_link, | |
} | |
end | |
end | |
defp fetch_posts_by_category_alias(seo_alias_link, "admin") do | |
Repo.all from p in PostCategory, | |
join: c in assoc(p, :cms_post), | |
where: p.seo_alias_link == ^seo_alias_link, | |
order_by: p.inserted_at, | |
limit: 10, | |
preload: [cms_post: c] | |
end | |
defp fetch_posts_by_category_alias(seo_alias_link, group_acl) do | |
Repo.all from p in PostCategory, | |
join: c in assoc(p, :cms_post), | |
where: p.seo_alias_link == ^seo_alias_link, | |
where: p.group_acl == ^group_acl, | |
where: c.group_acl == ^group_acl, | |
order_by: p.inserted_at, | |
limit: 10, | |
preload: [cms_post: c] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment