Skip to content
This repository has been archived by the owner on Dec 7, 2022. It is now read-only.

Support {id, href} by creating an IdentifierField #3575

Closed
wants to merge 1 commit into from

Conversation

werwty
Copy link
Contributor

@werwty werwty commented Aug 3, 2018

Using this new IdentifierField, relations are displayed with both pk and href. This allows bindings users to use the returned pk, and allows UI users to still be able to click hrefs.

{
    "id": "b3e5e4ad-91ba-4536-b62d-087df10e8921",
    "_href": "http://pulp3.dev:8000/pulp/api/v3/tasks/b3e5e4ad-91ba-4536-b62d-087df10e8921/",
    "created": "2018-08-03T15:51:16.694787Z",
    "state": "completed",
    "started_at": "2018-08-03T15:59:43.302492Z",
    "finished_at": "2018-08-03T15:59:45.579150Z",
    "non_fatal_errors": [],
    "error": null,
    "worker": {
        "_href": "http://pulp3.dev:8000/pulp/api/v3/workers/3/",
        "pk": 3
    },
    "parent": null,
    "spawned_tasks": [],
    "progress_reports": [
        {
            "message": "Add Content",
            "state": "completed",
            "total": 3,
            "done": 3,
            "suffix": "",
            "task": {
                "_href": "http://pulp3.dev:8000/pulp/api/v3/tasks/b3e5e4ad-91ba-4536-b62d-087df10e8921/",
                "pk": "b3e5e4ad-91ba-4536-b62d-087df10e8921"
            }
        },
        {
            "message": "Remove Content",
            "state": "completed",
            "total": 0,
            "done": 0,
            "suffix": "",
            "task": {
                "_href": "http://pulp3.dev:8000/pulp/api/v3/tasks/b3e5e4ad-91ba-4536-b62d-087df10e8921/",
                "pk": "b3e5e4ad-91ba-4536-b62d-087df10e8921"
            }
        }
    ],
    "created_resources": [
        {
            "_href": "http://pulp3.dev:8000/pulp/api/v3/repositories/1/versions/1/",
            "pk": 1,
            "number": 1
        }
    ]
}

Schema-wise this field is shown as:

worker:{  
    type:"object",
    properties:{  
        _href:{  
            type:"string",
            format:"uri"
        },
        pk:{  
            type:"string"
        }
    },
    additionalProperties:true
}

You can see the full schema here: https://gist.github.com/werwty/e445cbd2ac11a237b3971d65bb861a17

There's one more issue left with this implementation:
RepositoryPublishURLSerializer is still using the NestedHyperlinkedRelatedField (have to pass in href for now). This can be fixed by unnesting repoversion, or updateing NestedIdentifierField to take an object {'pk': 1, 'number': 1} as well as an url /repositories/1/version/1/

@pep8speaks
Copy link

pep8speaks commented Aug 3, 2018

Hello @werwty! Thanks for updating the PR.

Cheers ! There are no PEP8 issues in this Pull Request. 🍻

Comment last updated on August 03, 2018 at 20:03 Hours UTC

Update CreatedResourceSerializer to support id and href
@werwty
Copy link
Contributor Author

werwty commented Aug 6, 2018

I updated the /repositories/{id}/versions/{number}/ to also show a summary of content:

{
    "id": 1,
    "_href": "http://pulp3.dev:8000/pulp/api/v3/repositories/1/versions/1/",
    "created": "2018-08-03T15:59:43.350013Z",
    "_content_href": "http://pulp3.dev:8000/pulp/api/v3/repositories/1/versions/1/content/",
    "_added_href": "http://pulp3.dev:8000/pulp/api/v3/repositories/1/versions/1/added_content/",
    "_removed_href": "http://pulp3.dev:8000/pulp/api/v3/repositories/1/versions/1/removed_content/",
    "number": 1,
    "content_summary": {
        "file": 3
    },
    "added_content": [
        {
            "_href": "http://pulp3.dev:8000/pulp/api/v3/content/file/files/1/",
            "id": 1,
            "type": "file"
        },
        {
            "_href": "http://pulp3.dev:8000/pulp/api/v3/content/file/files/2/",
            "id": 2,
            "type": "file"
        },
        {
            "_href": "http://pulp3.dev:8000/pulp/api/v3/content/file/files/3/",
            "id": 3,
            "type": "file"
        }
    ],
    "removed_content": [],
    "content": [
        {
            "_href": "http://pulp3.dev:8000/pulp/api/v3/content/file/files/1/",
            "id": 1,
            "type": "file"
        },
        {
            "_href": "http://pulp3.dev:8000/pulp/api/v3/content/file/files/2/",
            "id": 2,
            "type": "file"
        },
        {
            "_href": "http://pulp3.dev:8000/pulp/api/v3/content/file/files/3/",
            "id": 3,
            "type": "file"
        }
    ]
}

I actually don't think this is necessary, since the bindings will have enough information to access /added_content, removed_content and content endpoints. But one aspect we did discuss was for the user to have some way of accessing content information from this endpoint, and this shows that it is possible.

@werwty
Copy link
Contributor Author

werwty commented Aug 16, 2018

We have decided to move forward with supporting only _hrefs as seen in this PR: #3561

@werwty werwty closed this Aug 16, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
2 participants