Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.0] Add author to output and filter options to com_content API #28382

Merged
merged 1 commit into from
Mar 20, 2020

Conversation

wilsonge
Copy link
Contributor

Summary of Changes

  • Allows relations to be shown in the list view of the API
  • Adds filters for author id, category id, state and search into the articles api (for now starting with these and we can expand and move them to other components)
  • Adds author relationship to the output of articles
  • Fixes category relationship being shown as an articles type instead of categories type

Testing Instructions

  1. Test the filters endpoint with e.g.

JROOT_URL/api/index.php/v1/content/article?filter[search]=tag

which will search for the string 'tag'

JROOT_URL/api/index.php/v1/content/article?filter[state]=0

will search for unpublished articles

  1. Test the relationships for category and author are output in both the item and list views of the article output and have the correct type.

Documentation Changes Required

Yes:

  1. How to implement filters in APIs
  2. What filters are available in core components

@wilsonge wilsonge added this to the Joomla 4.0 milestone Mar 17, 2020
@wilsonge wilsonge changed the title Add author to output and filter options to com_content [4.0] Add author to output and filter options to com_content API Mar 17, 2020
@wilsonge
Copy link
Contributor Author

@alikon this should port over some of the work you were doing on filters

@alikon
Copy link
Contributor

alikon commented Mar 19, 2020

@wilsonge please have a look at this silly one #28384 to prevent conflict

@alikon
Copy link
Contributor

alikon commented Mar 20, 2020

a couple of things :

{
  "links": {
    "self": "http:\/\/localhost\/jbs4\/api\/index.php\/v1\/content\/article?filter%5Bstate%5D=0",
    "first": "http:\/\/localhost\/jbs4\/api\/index.php\/v1\/content\/article?filter[state]=0&page[offset]=0&page[limit]=20",
    "next": "http:\/\/localhost\/jbs4\/api\/index.php\/v1\/content\/article?filter[state]=0&page[offset]=-20&page[limit]=20",
    "previous": "http:\/\/localhost\/jbs4\/api\/index.php\/v1\/content\/article?filter[state]=0&page[offset]=0&page[limit]=20",
    "last": "http:\/\/localhost\/jbs4\/api\/index.php\/v1\/content\/article?filter[state]=0&page[offset]=-20&page[limit]=20"
  },
  "data": [],
  "meta": {
    "total-pages": 0
  }
}

should not it be something like this ?

{
  "errors": [
    {
      "title": "Resource not found",
      "code": 404
    }
  ]
}

@alikon
Copy link
Contributor

alikon commented Mar 20, 2020

a funny thing is that we have relations on the api response and not in the database 🤣

@wilsonge
Copy link
Contributor Author

should not this show a conflict file cause of #28384 touching api/components/com_content/src/View/Articles/JsonapiView.php

No because it's different lines in the file - if i'd modified the same lines of code as you it would cause a conflicts

calling JROOT_URL/api/index.php/v1/content/article?filter[state]=0 without unpublished give me this response

In my opinion no - because the URL is valid - it's just no data matches the filter criteria.

@alikon
Copy link
Contributor

alikon commented Mar 20, 2020

thanks for reply
it works well so let's move on

@alikon
Copy link
Contributor

alikon commented Mar 20, 2020

I have tested this item ✅ successfully on 759417d


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/28382.

@alikon
Copy link
Contributor

alikon commented Mar 20, 2020

tip for those who want to search on content (fulltext) suppose you would search for word mundi

the call is:
JROOT_URL/api/index.php/v1/content/article?filter[search]=CONTENT:mundi

@wilsonge wilsonge merged commit c162ada into joomla:4.0-dev Mar 20, 2020
@wilsonge
Copy link
Contributor Author

@alikon can you do the language PR as it's own thing and let's discuss there whether to use PK or the language code for filtering

@alikon
Copy link
Contributor

alikon commented Mar 20, 2020

yes for sure

@alikon
Copy link
Contributor

alikon commented Mar 20, 2020

see #28406

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants