Jump to content

How to extend REST API?


BomAle

Recommended Posts

I would know how is possible to extend for example \applications\forums\api\topics.php by adding other params such as in this case "tags" (string, comma-delimited list of tags that must have or contain into a topic)

	/**
	 * GET /forums/topics
	 * Get list of topics
	 *
	 * @apiparam	string	forums			Comma-delimited list of forum IDs
	 * @apiparam	string	authors			Comma-delimited list of member IDs - if provided, only topics started by those members are returned
	 * @apiparam	int		hasBestAnswer	If 1, only topics with a best answer are returned, if 0 only without
	 * @apiparam	int		hasPoll			If 1, only topics with a poll are returned, if 0 only without
	 * @apiparam	int		locked			If 1, only topics which are locked are returned, if 0 only unlocked
	 * @apiparam	int		hidden			If 1, only topics which are hidden are returned, if 0 only not hidden
	 * @apiparam	int		pinned			If 1, only topics which are pinned are returned, if 0 only not pinned
	 * @apiparam	int		featured		If 1, only topics which are featured are returned, if 0 only not featured
	 * @apiparam	int		archived		If 1, only topics which are archived are returned, if 0 only not archived
	 * @apiparam	string	sortBy			What to sort by. Can be 'date', 'title' or leave unspecified for ID
	 * @apiparam	string	sortDir			Sort direction. Can be 'asc' or 'desc' - defaults to 'asc'
	 * @apiparam	int		page			Page number
	 * @return		\IPS\Api\PaginatedResponse<IPS\forums\Topic>
	 */
	public function GETindex()
	{
		/* Init */
		$where = array();
		
		/* Has best answer */
		if ( isset( \IPS\Request::i()->hasBestAnswer ) )
		{
			if ( \IPS\Request::i()->hasBestAnswer )
			{
				$where[] = array( "topic_answered_pid>0" );
			}
			else
			{
				$where[] = array( "topic_answered_pid=0" );
			}
		}
		
		/* Archived */
		if ( isset( \IPS\Request::i()->archived ) )
		{
			if ( \IPS\Request::i()->archived )
			{
				$where[] = array( \IPS\Db::i()->in( 'topic_archive_status', array( \IPS\forums\Topic::ARCHIVE_DONE, \IPS\forums\Topic::ARCHIVE_WORKING, \IPS\forums\Topic::ARCHIVE_RESTORE ) ) );
			}
			else
			{
				$where[] = array( \IPS\Db::i()->in( 'topic_archive_status', array( \IPS\forums\Topic::ARCHIVE_NOT, \IPS\forums\Topic::ARCHIVE_EXCLUDE ) ) );
			}
		}
		
		/* Return */
		return $this->_list( $where, 'forums' );
	}

How I could change the documentation on admin cp?

the "_list" function is located on system\Content\Api\ItemController.php... is this possible to extend via Plugin ?

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...