Skip to content
This repository has been archived by the owner on Dec 8, 2023. It is now read-only.

Commit

Permalink
fix some issues about editor api, and all basic api urls
Browse files Browse the repository at this point in the history
  • Loading branch information
shahryarjb committed Apr 8, 2022
1 parent c1c422f commit 2926700
Show file tree
Hide file tree
Showing 3 changed files with 1,460 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -252,13 +252,16 @@ defmodule MishkaApiWeb.ContentController do
end

def links(conn, %{"page" => page, "filters" => %{"status" => status} = params}) when status in ["active", "archived"] do
filters = Map.take(params, BlogLink.allowed_fields(:string))
BlogLink.links(conditions: {page, 30}, filters: Map.merge(filters, %{"status" => status}))
filters =
Map.take(params, BlogLink.allowed_fields(:string))
|> MishkaDatabase.convert_string_map_to_atom_map()
BlogLink.links(conditions: {page, 30}, filters: filters)
|> MishkaApi.ContentProtocol.links(conn, BlogLink.allowed_fields(:atom))
end

def editor_links(conn, %{"page" => page, "filters" => params}) when is_map(params) do
filters = Map.take(params, BlogLink.allowed_fields(:string))
|> MishkaDatabase.convert_string_map_to_atom_map()
BlogLink.links(conditions: {page, 30}, filters: filters)
|> MishkaApi.ContentProtocol.links(conn, BlogLink.allowed_fields(:atom))
end
Expand Down
3 changes: 2 additions & 1 deletion apps/mishka_content/lib/blog/link.ex
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ defmodule MishkaContent.Blog.BlogLink do

@spec links([{:conditions, {integer() | String.t(), integer() | String.t()}} | {:filters, map()}, ...]) :: any
def links(conditions: {page, page_size}, filters: filters) do
from(link in BlogLink) |> convert_filters_to_where(filters)
from(link in BlogLink)
|> convert_filters_to_where(filters)
|> fields()
|> MishkaDatabase.Repo.paginate(page: page, page_size: page_size)
rescue
Expand Down
Loading

0 comments on commit 2926700

Please sign in to comment.