john-bodley commented on code in PR #22332:
URL: https://github.com/apache/superset/pull/22332#discussion_r1041582792


##########
superset/datasets/columns/api.py:
##########
@@ -36,14 +38,99 @@
 class DatasetColumnsRestApi(BaseSupersetModelRestApi):
     datamodel = SQLAInterface(TableColumn)
 
-    include_route_methods = {"delete"}
+    allow_browser_login = True
     class_permission_name = "Dataset"
+    include_route_methods = {RouteMethod.DELETE, RouteMethod.GET, 
RouteMethod.GET_LIST}
     method_permission_name = MODEL_API_RW_METHOD_PERMISSION_MAP
-
+    list_columns = [  # See DatasetRestApi.show_select_columns.
+        "advanced_data_type",
+        "changed_on",
+        "column_name",
+        "created_on",
+        "description",
+        "expression",
+        "filterable",
+        "groupby",
+        "id",
+        "is_active",
+        "extra",
+        "is_dttm",
+        "python_date_format",
+        "type",
+        "uuid",
+        "verbose_name",
+    ]
+    search_columns = ["table_id"]
+    max_page_size = -1
+    openapi_spec_tag = "Datasets"
     resource_name = "dataset"
-    allow_browser_login = True
 
-    openapi_spec_tag = "Datasets"
+    @expose("/<int:pk>/column", methods=["GET"])
+    @protect()
+    @safe
+    @permission_name("get")
+    @rison(get_list_schema)
+    def get_list(  # pylint: disable=arguments-differ
+        self,
+        pk: int,
+        **kwargs: Any,
+    ) -> Response:
+        """Get a list of dataset columns
+        ---
+        get:
+          description: >-
+            Get a list of dataset columns
+          parameters:
+          - in: path
+            schema:
+              type: integer
+            description: The dataset id for these columns
+            name: pk
+          - in: query
+            name: q
+            content:
+              application/json:
+                schema:
+                  $ref: '#/components/schemas/get_list_schema'
+          responses:
+            200:
+              description: Columns from dataset
+              content:
+                application/json:
+                  schema:
+                    type: object
+                    properties:
+                      ids:
+                        description: >-
+                          A list of column ids
+                        type: array
+                        items:
+                          type: string
+                      count:
+                        description: >-
+                          The total record count on the backend
+                        type: number
+                      result:
+                        description: >-
+                          The result from the get list query
+                        type: array
+                        items:
+                          $ref: 
'#/components/schemas/{{self.__class__.__name__}}.get_list'  # pylint: 
disable=line-too-long
+            400:
+              $ref: '#/components/responses/400'
+            401:
+              $ref: '#/components/responses/401'
+            422:
+              $ref: '#/components/responses/422'
+            500:
+              $ref: '#/components/responses/500'
+        """
+
+        rison_data = kwargs.setdefault("rison", {})
+        rison_data.setdefault("filters", [])
+        rison_data["filters"].append({"col": "table_id", "opr": "eq", "value": 
pk})
+        rison_data["page_size"] = -1
+        return self.get_list_headless(**kwargs)

Review Comment:
   @dpgaspar, @michael-s-molina, or @villebro I would love your input on this 
as I'm not overly familiar with the new FAB API and/or how best to define said 
endpoint. I came across the pattern by prodding around.



##########
superset/datasets/columns/api.py:
##########
@@ -36,14 +38,99 @@
 class DatasetColumnsRestApi(BaseSupersetModelRestApi):
     datamodel = SQLAInterface(TableColumn)
 
-    include_route_methods = {"delete"}
+    allow_browser_login = True
     class_permission_name = "Dataset"
+    include_route_methods = {RouteMethod.DELETE, RouteMethod.GET, 
RouteMethod.GET_LIST}
     method_permission_name = MODEL_API_RW_METHOD_PERMISSION_MAP
-
+    list_columns = [  # See DatasetRestApi.show_select_columns.

Review Comment:
   I'm not overly sure the difference between `list_columns` and `show_columns` 
but I thought that it was prudent that the `table_columns` columns returned was 
consistent with the columns field in the `/api/v1/dataset` response.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@superset.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@superset.apache.org
For additional commands, e-mail: notifications-h...@superset.apache.org

Reply via email to