Skip to content

Commit

Permalink
Adds a relation between Resources and Categories
Browse files Browse the repository at this point in the history
 - This patch updates the design of Resources by adding
   an array of Categories for the following API's

     - /query
     - /resources
     - /resource/<resourceID>

 - Updates the model of Category and Resource by creating
   many to many relation

 - Adds a migration to update the relation between category
   and resources

 - Updates the resources tests which adds category array in
   the response of query, list and resource by id API's

Signed-off-by: Puneet Punamiya <ppunamiy@redhat.com>
  • Loading branch information
PuneetPunamiya authored and tekton-robot committed Jun 30, 2021
1 parent a950c5e commit eaaf8ef
Show file tree
Hide file tree
Showing 42 changed files with 1,016 additions and 58 deletions.
4 changes: 4 additions & 0 deletions api/design/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ var _ = Service("resource", func() {
Attribute("kinds", ArrayOf(String), "Kinds of resource to filter by", func() {
Example([]string{"task", "pipelines"})
})
Attribute("categories", ArrayOf(String), "Category associated with a resource to filter by", func() {
Example([]string{"build", "tools"})
})
Attribute("tags", ArrayOf(String), "Tags associated with a resource to filter by", func() {
Example([]string{"image", "build"})
})
Expand All @@ -64,6 +67,7 @@ var _ = Service("resource", func() {

Param("name")
Param("catalogs")
Param("categories")
Param("kinds")
Param("tags")
Param("limit")
Expand Down
13 changes: 12 additions & 1 deletion api/design/types/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ var Category = Type("Category", func() {
Required("id", "name")
})

var Categories = ArrayOf(Category)

var Catalog = ResultType("application/vnd.hub.catalog", "Catalog", func() {
Attribute("id", UInt, "ID is the unique id of the catalog", func() {
Example("id", 1)
Expand Down Expand Up @@ -172,6 +174,13 @@ var ResourceData = ResultType("application/vnd.hub.resource.data", "ResourceData
Value(Val{"id": 1, "name": "tekton", "type": "community"})
})
})
Attribute("categories", Categories, "Categories related to resource", func() {
Example("categories", func() {
Value([]Val{
{"id": 1, "name": "image-build"},
})
})
})
Attribute("kind", String, "Kind of resource", func() {
Example("kind", "task")
})
Expand Down Expand Up @@ -227,6 +236,7 @@ var ResourceData = ResultType("application/vnd.hub.resource.data", "ResourceData
Attribute("catalog", func() {
View("min")
})
Attribute("categories")
Attribute("kind")
Attribute("latestVersion")
Attribute("tags")
Expand All @@ -237,6 +247,7 @@ var ResourceData = ResultType("application/vnd.hub.resource.data", "ResourceData
Attribute("id")
Attribute("name")
Attribute("catalog")
Attribute("categories")
Attribute("kind")
Attribute("latestVersion")
Attribute("tags")
Expand All @@ -246,7 +257,7 @@ var ResourceData = ResultType("application/vnd.hub.resource.data", "ResourceData
})
})

Required("id", "name", "catalog", "kind", "latestVersion", "tags", "rating", "versions")
Required("id", "name", "catalog", "categories", "kind", "latestVersion", "tags", "rating", "versions")
})

var Versions = ResultType("application/vnd.hub.versions", "Versions", func() {
Expand Down
23 changes: 14 additions & 9 deletions api/gen/http/cli/hub/cli.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/gen/http/openapi.json

Large diffs are not rendered by default.

62 changes: 62 additions & 0 deletions api/gen/http/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,14 @@ paths:
items:
type: string
collectionFormat: multi
- name: categories
in: query
description: Category associated with a resource to filter by
required: false
type: array
items:
type: string
collectionFormat: multi
- name: kinds
in: query
description: Kinds of resource to filter by
Expand Down Expand Up @@ -2357,6 +2365,9 @@ definitions:
id: 1
name: tekton
type: community
categories:
- id: 1
name: image-build
id: 1
kind: task
latestVersion:
Expand Down Expand Up @@ -2605,6 +2616,9 @@ definitions:
id: 1
name: tekton
type: community
categories:
- id: 1
name: image-build
id: 1
kind: task
latestVersion:
Expand Down Expand Up @@ -2756,6 +2770,14 @@ definitions:
properties:
catalog:
$ref: '#/definitions/CatalogResponseBodyMin'
categories:
type: array
items:
$ref: '#/definitions/CategoryResponseBody'
description: Categories related to resource
example:
- id: 1
name: image-build
id:
type: integer
description: ID is the unique id of the resource
Expand Down Expand Up @@ -2800,6 +2822,9 @@ definitions:
id: 1
name: tekton
type: community
categories:
- id: 1
name: image-build
id: 1
kind: task
latestVersion:
Expand All @@ -2826,6 +2851,7 @@ definitions:
- id
- name
- catalog
- categories
- kind
- latestVersion
- tags
Expand Down Expand Up @@ -2889,6 +2915,14 @@ definitions:
properties:
catalog:
$ref: '#/definitions/CatalogResponseBodyMin'
categories:
type: array
items:
$ref: '#/definitions/CategoryResponseBody'
description: Categories related to resource
example:
- id: 1
name: image-build
id:
type: integer
description: ID is the unique id of the resource
Expand Down Expand Up @@ -2924,6 +2958,9 @@ definitions:
id: 1
name: tekton
type: community
categories:
- id: 1
name: image-build
id: 1
kind: task
latestVersion:
Expand All @@ -2945,6 +2982,7 @@ definitions:
- id
- name
- catalog
- categories
- kind
- latestVersion
- tags
Expand All @@ -2962,6 +3000,9 @@ definitions:
id: 1
name: tekton
type: community
categories:
- id: 1
name: image-build
id: 1
kind: task
latestVersion:
Expand All @@ -2988,6 +3029,9 @@ definitions:
id: 1
name: tekton
type: community
categories:
- id: 1
name: image-build
id: 1
kind: task
latestVersion:
Expand All @@ -3014,6 +3058,9 @@ definitions:
id: 1
name: tekton
type: community
categories:
- id: 1
name: image-build
id: 1
kind: task
latestVersion:
Expand All @@ -3040,6 +3087,9 @@ definitions:
id: 1
name: tekton
type: community
categories:
- id: 1
name: image-build
id: 1
kind: task
latestVersion:
Expand Down Expand Up @@ -3120,6 +3170,9 @@ definitions:
id: 1
name: tekton
type: community
categories:
- id: 1
name: image-build
id: 1
kind: task
latestVersion:
Expand All @@ -3141,6 +3194,9 @@ definitions:
id: 1
name: tekton
type: community
categories:
- id: 1
name: image-build
id: 1
kind: task
latestVersion:
Expand Down Expand Up @@ -3308,6 +3364,9 @@ definitions:
id: 1
name: tekton
type: community
categories:
- id: 1
name: image-build
id: 1
kind: task
latestVersion:
Expand All @@ -3329,6 +3388,9 @@ definitions:
id: 1
name: tekton
type: community
categories:
- id: 1
name: image-build
id: 1
kind: task
latestVersion:
Expand Down
2 changes: 1 addition & 1 deletion api/gen/http/openapi3.json

Large diffs are not rendered by default.

Loading

0 comments on commit eaaf8ef

Please sign in to comment.