Reworked pagination #6

Merged
danny-mhlv merged 0 commits from refs/pull/6/head into develop 2022-09-08 09:45:58 +00:00
danny-mhlv commented 2022-08-17 17:39:26 +00:00 (Migrated from 85.143.176.51:3000)

New pagination works on the side of the Elasticsearch. Still needs test-coverage and Swagger documentation coverage.

Made minor code clean-ups.

API URI versioning added.

Swagger documentation added.

Docker-compose problems fixed. Tests fixed.

Examples of API calls

Response structure

Structure of the API response is presented below. In general, API response for /papers/{uuid} endpoint is the single document and for /papers/search - is a page, which contains documents acquired through querying Elasticsearch (ontained in 'data' array property) and metadata, which provides additional information about current page (contained in 'meta' property).

  • Note: the API response structure is the same for both described endpoints.
{
	"data": [
        {...},
        {...},
        {...}
	],
	"meta": {
		"total": 3,
		"pagenum": 1,
		"order": "DESC",
		"hasNext": false,
		"hasPrev": false,
		"pagesize": 10
	}
}

Property 'data' holds an array of documents, returned from the Elasticsearch.

Property 'meta' holds an object of metadata for the page.

/papers/{uuid}

This example demonstrates the case of addressing the /papers/{uuid} endpoint.

Request

http://localhost:8085/papers/eeeb2d01-8315-454e-b33f-3d6caa25db42

Response

{
	"id": "491c559d-1d33-4f23-86c6-2c0f177d4add",
	"title": "H. R. Jothipala",
	"authors": [
		"PaperGen",
		"Danny"
	],
	"topic": "Physics",
	"summary": "Hettiarachchige Reginald Jothipala (Sinhala: එච්",
	"tags": [
		"Tag1",
		"Tag2",
		"Tag3"
	],
	"content": "Hettiarachchige Reginald Jothipala (Sinhala: එච්.ආර්. ජෝතිපාල; 12 February 1936 – 7 July 1987), popularly as H. R. Jothipala, was a Sri Lankan playback singer in the Sinhala cinema as well as a film a"
}

As you can see - when /papers/{uuid} endpoint is accessed - the result is the single document (paper).

/papers/search?

List of query parameters:

  • query (Mandatory, string)

  • page (Optional, number)

  • limit (Optional, number)

  • order (Optional, string, "asc"/"desc")

Example, provided below demonstrates the case of addressing the /papers/search? endpoint.

Request

http://localhost:8085/papers/search?query=a&page=1&limit=3&order=desc

Response

{
	"data": [
		{
			"_index": "papers",
			"_id": "27",
			"_score": 0.52969605,
			"_source": {
				"id": "491c559d-1d33-4f23-86c6-2c0f177d4add",
				"title": "H. R. Jothipala",
				"authors": [
					"PaperGen",
					"Danny"
				],
				"topic": "Physics",
				"summary": "Hettiarachchige Reginald Jothipala (Sinhala: එච්",
				"tags": [
					"Tag1",
					"Tag2",
					"Tag3"
				],
				"content": "Hettiarachchige Reginald Jothipala (Sinhala: එච්.ආර්. ජෝතිපාල; 12 February 1936 – 7 July 1987), popularly as H. R. Jothipala, was a Sri Lankan playback singer in the Sinhala cinema as well as a film a"
			}
		},
		{
			"_index": "papers",
			"_id": "20",
			"_score": 0.5266665,
			"_source": {
				"id": "2766f61d-39c0-4f77-925f-e7766bee280a",
				"title": "Complex number",
				"authors": [
					"PaperGen",
					"Danny"
				],
				"topic": "Mathematics",
				"summary": "In mathematics, a complex number is an element of a number system that extends the real numbers with a specific element denoted i, called the imaginary unit and satisfying the equation i2 = −1; every complex number can be expressed in the form a + bi, where a and b are real numbers",
				"tags": [
					"Tag1",
					"Tag2",
					"Tag3"
				],
				"content": "In mathematics, a complex number is an element of a number system that extends the real numbers with a specific element denoted i, called the imaginary unit and satisfying the equation i2 = −1; every "
			}
		},
		{
			"_index": "papers",
			"_id": "13",
			"_score": 0.5177823,
			"_source": {
				"id": "1e9c4e94-bc14-43ed-afec-9d00ec82f2ce",
				"title": "Zenith Z-100",
				"authors": [
					"PaperGen",
					"Danny"
				],
				"topic": "Computing",
				"summary": "The Z-100 computer is a personal computer made by Zenith Data Systems (ZDS)",
				"tags": [
					"Tag1",
					"Tag2",
					"Tag3"
				],
				"content": "The Z-100 computer is a personal computer made by Zenith Data Systems (ZDS). It was a competitor to the IBM PC.\n\n\n== Design ==\nThe Zenith Data Systems Z-100 is a pre-assembled version of the Heathkit "
			}
		}
	],
	"meta": {
		"total": 37,
		"pagenum": "1",
		"order": "DESC",
		"hasNext": true,
		"hasPrev": false,
		"pagesize": "3"
	}
}

Here - the 'data' property holds 3 elements (limit per page is specified in the appropriate query parameter). This limit is also present in 'meta' property, as 'pagesize'.

New pagination works on the side of the Elasticsearch. Still needs test-coverage and Swagger documentation coverage. Made minor code clean-ups. API URI versioning added. Swagger documentation added. Docker-compose problems fixed. Tests fixed. # Examples of API calls ## Response structure Structure of the API response is presented below. In general, API response for **/papers/{uuid}** endpoint is the single **document** and for **/papers/search** - is a page, which contains **documents** acquired through querying Elasticsearch (ontained in 'data' array property) and **metadata**, which provides additional information about current page (contained in 'meta' property). * *Note: the API response structure is the same for both described endpoints.* ```json { "data": [ {...}, {...}, {...} ], "meta": { "total": 3, "pagenum": 1, "order": "DESC", "hasNext": false, "hasPrev": false, "pagesize": 10 } } ``` Property 'data' holds an array of documents, returned from the Elasticsearch. Property 'meta' holds an object of metadata for the page. ## /papers/{uuid} This example demonstrates the case of addressing the ***/papers/{uuid}*** endpoint. ***Request*** ```url http://localhost:8085/papers/eeeb2d01-8315-454e-b33f-3d6caa25db42 ``` ***Response*** ```json { "id": "491c559d-1d33-4f23-86c6-2c0f177d4add", "title": "H. R. Jothipala", "authors": [ "PaperGen", "Danny" ], "topic": "Physics", "summary": "Hettiarachchige Reginald Jothipala (Sinhala: එච්", "tags": [ "Tag1", "Tag2", "Tag3" ], "content": "Hettiarachchige Reginald Jothipala (Sinhala: එච්.ආර්. ජෝතිපාල; 12 February 1936 – 7 July 1987), popularly as H. R. Jothipala, was a Sri Lankan playback singer in the Sinhala cinema as well as a film a" } ``` As you can see - when ***/papers/{uuid}*** endpoint is accessed - the result is the **single** document (paper). ## /papers/search? List of query parameters: * query (Mandatory, string) * page (Optional, number) * limit (Optional, number) * order (Optional, string, "asc"/"desc") Example, provided below demonstrates the case of addressing the ***/papers/search?*** endpoint. ***Request*** ```url http://localhost:8085/papers/search?query=a&page=1&limit=3&order=desc ``` ***Response*** ```json { "data": [ { "_index": "papers", "_id": "27", "_score": 0.52969605, "_source": { "id": "491c559d-1d33-4f23-86c6-2c0f177d4add", "title": "H. R. Jothipala", "authors": [ "PaperGen", "Danny" ], "topic": "Physics", "summary": "Hettiarachchige Reginald Jothipala (Sinhala: එච්", "tags": [ "Tag1", "Tag2", "Tag3" ], "content": "Hettiarachchige Reginald Jothipala (Sinhala: එච්.ආර්. ජෝතිපාල; 12 February 1936 – 7 July 1987), popularly as H. R. Jothipala, was a Sri Lankan playback singer in the Sinhala cinema as well as a film a" } }, { "_index": "papers", "_id": "20", "_score": 0.5266665, "_source": { "id": "2766f61d-39c0-4f77-925f-e7766bee280a", "title": "Complex number", "authors": [ "PaperGen", "Danny" ], "topic": "Mathematics", "summary": "In mathematics, a complex number is an element of a number system that extends the real numbers with a specific element denoted i, called the imaginary unit and satisfying the equation i2 = −1; every complex number can be expressed in the form a + bi, where a and b are real numbers", "tags": [ "Tag1", "Tag2", "Tag3" ], "content": "In mathematics, a complex number is an element of a number system that extends the real numbers with a specific element denoted i, called the imaginary unit and satisfying the equation i2 = −1; every " } }, { "_index": "papers", "_id": "13", "_score": 0.5177823, "_source": { "id": "1e9c4e94-bc14-43ed-afec-9d00ec82f2ce", "title": "Zenith Z-100", "authors": [ "PaperGen", "Danny" ], "topic": "Computing", "summary": "The Z-100 computer is a personal computer made by Zenith Data Systems (ZDS)", "tags": [ "Tag1", "Tag2", "Tag3" ], "content": "The Z-100 computer is a personal computer made by Zenith Data Systems (ZDS). It was a competitor to the IBM PC.\n\n\n== Design ==\nThe Zenith Data Systems Z-100 is a pre-assembled version of the Heathkit " } } ], "meta": { "total": 37, "pagenum": "1", "order": "DESC", "hasNext": true, "hasPrev": false, "pagesize": "3" } } ``` Here - the 'data' property holds 3 elements (***limit*** per page is specified in the appropriate query parameter). This limit is also present in 'meta' property, as 'pagesize'.
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Scipaper/Backend#6
No description provided.