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

Add search endpoint #135

Merged
merged 3 commits into from Nov 9, 2017
Merged

Add search endpoint #135

merged 3 commits into from Nov 9, 2017

Conversation

tbille
Copy link
Contributor

@tbille tbille commented Nov 8, 2017

Summary

Added the search endpoint on the server. It renders a temporary page that diplays a JSON of the searched result. For the moment the search response isn't modified from what I receive from the snapcraft search API.

QA

@webteam-app
Copy link

Starting demo at: http://snapcraft.io-pr-135.run.demo.haus/

@tbille
Copy link
Contributor Author

tbille commented Nov 8, 2017

@nottrobin I discussed with @bartaz I will add a commit to filter and normalize the informations I send to the template.

@tbille
Copy link
Contributor Author

tbille commented Nov 8, 2017

I have 2 bugs on the snap search API:
GET /api/v1/snaps/search?q=web&page=300001&size=2:

  • Returns a snap
  • Does not return the last link

Here is an example of what is returned:

{
	"_embedded": {
		"clickindex:package": [
			I HAVE 1 SNAP...
		]
	},
	"_links": {
		"first": {
			"href": "http://search.apps.ubuntu.com/api/v1/snaps/search?q=web&page=1&size=2"
		},
		"prev": {
			"href": "http://search.apps.ubuntu.com/api/v1/snaps/search?q=web&page=44&size=2"
		},
		"self": {
			"href": "http://search.apps.ubuntu.com/api/v1/snaps/search?q=web&page=300001&size=2"
		}
	}
}

Here is what I would expect:

{
	"_links": {
		"first": {
			"href": "http://search.apps.ubuntu.com/api/v1/snaps/search?page=1&size=2&q=web"
		},
		"last": {
			"href": "http://search.apps.ubuntu.com/api/v1/snaps/search?page=45&size=2&q=web"
		},
		"next": {
			"href": "http://search.apps.ubuntu.com/api/v1/snaps/search?page=300002&size=2&q=web"
		},
		"prev": {
			"href": "http://search.apps.ubuntu.com/api/v1/snaps/search?page=300000&size=2&q=web"
		},
		"self": {
			"href": "http://search.apps.ubuntu.com/api/v1/snaps/search?q=web&page=300001&size=2"
		}
	}
}

The prev, self at this point are not useful but the last argument is needed.

@nottrobin
Copy link
Contributor

I got a JSON decode error. I'll keep looking tomorrow.

@tbille
Copy link
Contributor Author

tbille commented Nov 9, 2017

This are the informations that are given to the template:

{
  "snaps": [
	{
		"aliases": null,
		"anon_download_url": "https://api.snapcraft.io/api/v1/snaps/download/EQPfyVOJF0AZNz9P2IJ6UKwldLFN5TzS_16.snap",
		"apps": [],
		"architecture": [
			"all"
		],
		"binary_filesize": 12288,
		"channel": "stable",
		"confinement": "strict",
		"contact": "mailto:snappy-devel@lists.ubuntu.com",
		"content": "application",
		"date_published": "2015-03-27T09:50:05.382385Z",
		"deltas": [],
		"description": "This is meant as a fun example for a snappy package.",
		"developer_id": "canonical",
		"developer_name": "Shared snappy store account",
		"download_sha3_384": "cab7ecbfd401b8977ec087435ca46505556db06fb82787532f4ed00fdda9233079b72e25f15e6033369c4314c55e6f2c",
		"download_sha512": "bf2fbe771fcce20377aa76b82fd237382b9e2279ede5d4cc9169095764f520495275acb01a354b5ada119c9612e8f52c63ba998576299dfb474eebdcb656b15f",
		"download_url": "https://api.snapcraft.io/api/v1/snaps/download/EQPfyVOJF0AZNz9P2IJ6UKwldLFN5TzS_16.snap",
		"epoch": "0",
		"icon_url": "https://dashboard.snapcraft.io/site_media/appmedia/2015/03/xkcd.svg.png",
		"last_updated": "2016-04-22T08:58:09.205478+00:00",
		"license": "MIT",
		"name": "xkcd-webserver.canonical",
		"origin": "canonical",
		"package_name": "xkcd-webserver",
		"prices": {},
		"private": false,
		"publisher": "Canonical",
		"ratings_average": 0,
		"release": [
			"16"
		],
		"revision": 16,
		"screenshot_urls": [],
		"snap_id": "EQPfyVOJF0AZNz9P2IJ6UKwldLFN5TzS",
		"summary": "Show random XKCD compic via a build-in webserver",
		"support_url": "mailto:snappy-devel@lists.ubuntu.com",
		"title": "xkcd-webserver",
		"version": "16.04-6"
	},
	...
],
"links": {
	"first": "http://0.0.0.0:8004/search?q=web&limit=2&offset=0",
	"prev": "http://0.0.0.0:8004/search?q=web&limit=2&offset=10",
	"last": "http://0.0.0.0:8004/search?q=web&limit=2&offset=88",
	"self": "http://0.0.0.0:8004/search?q=web&limit=2&offset=12",
	"next": "http://0.0.0.0:8004/search?q=web&limit=2&offset=14"
}

Copy link
Contributor

@nottrobin nottrobin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just two small suggestions. Basically it works fine for me.


{% block title %}{{ snap_title }} — Linux software in the Snap Store{% endblock %}

{% block content %}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we give the frontends slightly more to work with, with a template something like this?

{% block content %}
  <ul>
  {% for snap in snaps %}
    <li>
      <h3>{{ snap.title }}</h1>
      <table>
        {% for key, value in snap.items() %}
          <tr>
            <th>{{ key }}</th>
            <td>{{ value }}</td>
          </tr>
        {% endfor %}
      </table>
    </li>
  {% endfor %}

  <nav>
    {% if links.first %}<a href="{{ links.first }}">First</a>{% endif %}
    {% if links.prev %}<a href="{{ links.prev }}">Previous</a>{% endif %}
    {% if links.next %}<a href="{{ links.next }}">Next</a>{% endif %}
    {% if links.last %}<a href="{{ links.last }}">Last</a>{% endif %}
  </nav>
{% endblock %}

@@ -0,0 +1,7 @@
{% extends "_layout.html" %}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mind if we call this file simply "search.html"?

@tbille
Copy link
Contributor Author

tbille commented Nov 9, 2017

Basic template added #113

Copy link
Contributor

@nottrobin nottrobin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, works a charm. Good work 👍 🥘 🧀

@tbille tbille merged commit 01c7098 into canonical:master Nov 9, 2017
@tbille tbille deleted the add-search branch November 9, 2017 11:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants