How to query within a collection?

I’m looking for some help in modelling the following problem with JSON:API v1.0. I have the following data structure that contains an array of sectionIds. They are in the order in which they were completed:

ApplicationProgress: [sectionG, sectionZ, sectionA]

In terms of resources I believe I have “Section” and “ProgressEntry”. Each ProgressEntry will have a one-to-one relationship with a Section.

I’d like to be able to query within the collection e.g.

Get the first item in the collection:

GET /progress-entries?filter[first]

{
    "data": {
        "type": "progress-entries",
        "id": "progressL",
        "attributes": {
            "sectionId": "sectionG"
        },
        "relationships": {
            "section": {
                "links": {
                    "related": "http://example.com/sections/sectionG"
                }
            }
        }
    },
    "included": [
        {
            "links": {
                "self": "http://example.com/sections/sectionG"
            },
            "type": "sections",
            "id": "sectionG",
            "attributes": {
                "id": "sectionG",
                "title": "Some title"
            }
        }
    ]
}

Get the previous ProgressEntry given a relative ProgressEntry. So in the following example find a ProgressEntry whose sectionId attribute equals “sectionZ” and then get the previous entry (sectionG):

GET /progress-entries?filter[attributes][sectionId]=sectionZ&filterAction=getPreviousEntry

{
    "data": {
        "type": "progress-entries",
        "id": "progressL",
        "attributes": {
            "sectionId": "sectionG"
        },
        "relationships": {
            "section": {
                "links": {
                    "related": "http://example.com/sections/sectionG"
                }
            }
        }
    },
    "included": [
        {
            "links": {
                "self": "http://example.com/sections/sectionG"
            },
            "type": "sections",
            "id": "sectionG",
            "attributes": {
                "id": "sectionG",
                "title": "Some title"
            }
        }
    ]
}

What would be the most appropriate way to do this using JSON:API v1.0?

@jelhan I noticed you had commented on my stackoverflow issue. I’ve tried to add more detail to this question as I think i have a better understanding. Your thoughts would be very much appreciated?

Hi @webstacker . My approach on this would be to actually have each ProgressEntry point to the next and previous ProgressEntry. So having 2 aditional relations: a “prev” and a “next”.

Something like the structure bellow

{
    "data": {
        "type": "progress-entries",
            "id": "progressL",
            "attributes": {
            "sectionId": "sectionG"
        },
        "relationships": {
            "section": {
                "links": {
                    "related": "http://example.com/sections/sectionG"
                }
            },
            "prev": {
                "data":{
                    "id":"prev_id",
                        "type": "progress-entries"
                }
            },
            "next": {
                "data":{
                    "id":"next_id",
                        "type": "progress-entries"
                }
            },
        }
    },
    "included": [
        {
            "links": {
                "self": "http://example.com/sections/sectionG"
            },
            "type": "sections",
            "id": "sectionG",
            "attributes": {
                "id": "sectionG",
                "title": "Some title"
            }
        }
    ]
}

And then you would be able to easily navigate between them using such a request:
GET /progress-entries?filter[attributes][sectionId]=sectionZ&filter[relations][prev]=prev_id

@apiator Thanks for your advise. I hadn’t thought of creating “self relationships”. I assume that’s permitted by the spec? These self relationships wouldn’t be static, for example, sectionG’s next is currently sectionZ, however a user could go back and complete a different section, meaning sectionG’s next could be sectionT. I guess that shouldn’t be a problem?

I had a similar suggestion by @jelhan , but instead of providing the next/prev as “relationships”, they proposed using cursor based pagination. I’d rather stick with v1.0 of the spec if possible. Do you have any thoughts on this approach? I think v1.0 of the spec would also permit this given:

JSON:API is agnostic about the pagination strategy