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 Columns endpoint #303

Merged
merged 31 commits into from
Jul 2, 2021
Merged

Add Columns endpoint #303

merged 31 commits into from
Jul 2, 2021

Conversation

mathemancer
Copy link
Contributor

@mathemancer mathemancer commented Jun 29, 2021

Fixes #199

This adds a column API to perform CRUD operations on table columns. These can be accessed via:

http://server.address/api/v0/tables/<table_id>/columns/
http://server.address/api/v0/tables/<table_id>/columns/<column_idx>

Here, <column_idx> is the index of the column in the column list associated with the table in question (indexed from zero).

Technical details

  • POST requests to add columns need at least name and type keys. Optionally, one can also use nullable (this takes a boolean).

Note that a DELETE which removes a column from any place except the last will result in indices of columns to the right of that which was removed decrementing by one.

Screenshots

Checklist

  • My pull request has a descriptive title (not a vague title like Update index.md).
  • My pull request targets the master branch of the repository
  • My commit messages follow best practices.
  • My code follows the established code style of the repository.
  • I added tests for the changes I made (if applicable).
  • I added or updated documentation (if applicable).
  • I tried running the project locally and verified that there are no
    visible errors.

Developer Certificate of Origin

Developer Certificate of Origin
Developer Certificate of Origin
Version 1.1

Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
1 Letterman Drive
Suite D4700
San Francisco, CA, 94129

Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.


Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.

@mathemancer mathemancer changed the title Column endpoint Add Columns endpoint Jul 1, 2021
@mathemancer mathemancer marked this pull request as ready for review July 1, 2021 17:39
@mathemancer mathemancer requested review from a team, kgodey and pavish July 1, 2021 17:39
Copy link
Contributor

@eito-fis eito-fis left a comment

Choose a reason for hiding this comment

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

Some small questions about handling 404s, but overall looks good to me!

if type(e.orig) == UndefinedFunction:
raise ValidationError("This type cast is not implemented")
else:
raise ValidationError
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we also catch an IndexError here, like in retrieve()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea, will do.


def destroy(self, request, pk=None, table_pk=None):
table = Table.objects.get(id=table_pk)
table.drop_column(pk)
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above, should we catch IndexError?

Copy link
Contributor

@kgodey kgodey left a comment

Choose a reason for hiding this comment

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

@mathemancer Looks great! I added a comment. I'll leave it up to you to fix and merge.

mathesar/urls.py Outdated
records_router.register(r'records', api.RecordViewSet, basename='table-records')
records_router.register(r'records', api.RecordViewSet, basename='table-record')

columns_router = routers.NestedSimpleRouter(router, r'tables', lookup='table')
Copy link
Contributor

Choose a reason for hiding this comment

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

Can't you rename the records_router to table_router or something like that and register both the records and columns to the same router rather than making a new one?

@kgodey kgodey merged commit d400d6c into master Jul 2, 2021
@kgodey kgodey deleted the column_endpoint branch July 2, 2021 17:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

Create a Column API
3 participants