Hello,
The backend and frontend are separate in my project , either backend or frontend are phoenix, at first I want to create Pagination in my project backend which is web service which works with Json
, not render Html.
Step One
my code for getting all category’s info in my project is :
query = from u in "cms_post_category",
where: u.group_acl in ^group_acl,
order_by: u.inserted_at,
select: %{
title: u.title,
status: u.status,
language: u.language,
group_acl: u.group_acl,
description: u.description,
seo_alias_link: u.seo_alias_link,
seo_words: u.seo_words,
seo_description: u.seo_description,
seo_language: u.seo_language,
seo_language_link: u.seo_language_link,
pic_x1_link: u.pic_x1_link,
pic_x2_link: u.pic_x2_link,
pic_x3_link: u.pic_x3_link,
}
Repo.all(query)
Now how do I edit it for Pagination ? for example I edited it like this which have an 500 error :
def load_all_category_info(group_acl, pagenumber) do
query = from u in "cms_post_category",
where: u.group_acl in ^group_acl,
order_by: u.inserted_at,
select: %{
title: u.title,
status: u.status,
language: u.language,
group_acl: u.group_acl,
description: u.description,
seo_alias_link: u.seo_alias_link,
seo_words: u.seo_words,
seo_description: u.seo_description,
seo_language: u.seo_language,
seo_language_link: u.seo_language_link,
pic_x1_link: u.pic_x1_link,
pic_x2_link: u.pic_x2_link,
pic_x3_link: u.pic_x3_link,
}
Repo.paginate(query, pagenumber)
end
I think I am mistaken because I have an 500 error , based on its source https://github.com/drewolson/scrivener_ecto , page number should be a map , but which map’s params does its dock mean ? what do I write in it ?
my error :
** (exit) an exception was raised:
** (Protocol.UndefinedError) protocol Enumerable not implemented for "2". This protocol is implemented for: DBConnection.PrepareStream, DBConnection.Stream, Date.Range, Ecto.Adapters.SQL.Stream, File.Stream, Function, GenEvent.Stream, HashDict, HashSet, IO.Stream, List, Map, MapSet, Postgrex.Stream, Range, Stream
Step Two
After your guidance which helps me to fix this , what should I do in the frontend of my project which receives Json
from my backend Json
creator ?
Please help me to fix this . Unfortunately, all of tutorials which exist in internet speak about Render Html in Phoenix , not Json
api.