Skip to content

Commit

Permalink
Merge pull request #2144 from keboola/ph-PSGO-882
Browse files Browse the repository at this point in the history
feat: Add data app template filter
  • Loading branch information
hosekpeter authored Nov 19, 2024
2 parents 753e6ed + b491145 commit e375dc2
Show file tree
Hide file tree
Showing 21 changed files with 358 additions and 8 deletions.
10 changes: 9 additions & 1 deletion api/templates/design.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,11 @@ var _ = Service("templates", func() {
Meta("openapi:summary", "List templates in the repository")
Description("List all templates defined in the repository.")
Result(Templates)
Payload(RepositoryRequest)
Payload(TemplatesRequest)
HTTP(func() {
GET("/repositories/{repository}/templates")
Meta("openapi:tag:template")
Param("filter")
Response(StatusOK)
RepositoryNotFoundError()
})
Expand Down Expand Up @@ -567,6 +568,13 @@ var TemplateRequest = Type("TemplateRequest", func() {
Required("template")
})

var TemplatesRequest = Type("TemplatesRequest", func() {
Extend(RepositoryRequest)
Attribute("filter", String, "The 'filter' attribute specifies the category of templates to retrieve from the repository.", func() {
Enum("keboola.components", "keboola.data-apps")
})
})

var TemplateVersionRequest = Type("TemplateVersionRequest", func() {
Extend(TemplateRequest)
templateVersionAttr()
Expand Down

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

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

3 changes: 3 additions & 0 deletions internal/pkg/service/templates/api/gen/templates/service.go

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

2 changes: 1 addition & 1 deletion internal/pkg/service/templates/api/openapi/openapi.json

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions internal/pkg/service/templates/api/openapi/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,14 @@ paths:
description: List all templates defined in the repository.
operationId: TemplatesIndex
parameters:
- name: filter
in: query
description: The 'filter' attribute specifies the category of templates to retrieve from the repository.
required: false
type: string
enum:
- keboola.components
- keboola.data-apps
- name: repository
in: path
description: Name of the template repository. Use "keboola" for default Keboola repository.
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/service/templates/api/openapi/openapi3.json

Large diffs are not rendered by default.

31 changes: 31 additions & 0 deletions internal/pkg/service/templates/api/openapi/openapi3.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,18 @@ paths:
description: List all templates defined in the repository.
operationId: TemplatesIndex
parameters:
- name: filter
in: query
description: The 'filter' attribute specifies the category of templates to retrieve from the repository.
allowEmptyValue: true
schema:
type: string
description: The 'filter' attribute specifies the category of templates to retrieve from the repository.
example: keboola.data-apps
enum:
- keboola.components
- keboola.data-apps
example: keboola.data-apps
- name: repository
in: path
description: Name of the template repository. Use "keboola" for default Keboola repository.
Expand Down Expand Up @@ -4032,6 +4044,25 @@ components:
required:
- repository
- templates
TemplatesRequest:
type: object
properties:
filter:
type: string
description: The 'filter' attribute specifies the category of templates to retrieve from the repository.
example: keboola.data-apps
enum:
- keboola.components
- keboola.data-apps
repository:
type: string
description: Name of the template repository. Use "keboola" for default Keboola repository.
example: keboola
example:
filter: keboola.data-apps
repository: keboola
required:
- repository
UpdateInstanceRequest:
type: object
properties:
Expand Down
27 changes: 26 additions & 1 deletion internal/pkg/service/templates/api/service/mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package service
import (
"context"
"fmt"
"slices"
"sort"
"time"

Expand All @@ -25,6 +26,11 @@ import (
"github.com/keboola/keboola-as-code/internal/pkg/utils/errors"
)

const (
KeboolaDataApps = "keboola.data-apps"
KeboolaComponents = "keboola.components"
)

type Mapper struct {
apiHost string
}
Expand Down Expand Up @@ -119,7 +125,7 @@ func RepositoryResponse(ctx context.Context, d dependencies.ProjectRequestScope,
}
}

func TemplatesResponse(ctx context.Context, d dependencies.ProjectRequestScope, repo *repository.Repository, templates []repository.TemplateRecord) (out *Templates, err error) {
func TemplatesResponse(ctx context.Context, d dependencies.ProjectRequestScope, repo *repository.Repository, templates []repository.TemplateRecord, filterBy *string) (out *Templates, err error) {
ctx, span := d.Telemetry().Tracer().Start(ctx, "api.server.templates.mapper.TemplatesResponse")
defer span.End(&err)

Expand All @@ -130,6 +136,25 @@ func TemplatesResponse(ctx context.Context, d dependencies.ProjectRequestScope,
continue
}

if filterBy != nil && *filterBy != "" {
t, found := tmpl.DefaultVersion()
if !found {
continue
}

filterString := *filterBy
switch filterString {
case KeboolaDataApps:
if !slices.Contains(t.Components, filterString) {
continue
}
case KeboolaComponents:
if slices.Contains(t.Components, KeboolaDataApps) {
continue
}
}
}

if !hasRequirements(tmpl, d) {
continue
}
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/service/templates/api/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (s *service) TemplatesIndex(ctx context.Context, d dependencies.ProjectRequ
if err != nil {
return nil, err
}
return TemplatesResponse(ctx, d, repo, repo.Templates())
return TemplatesResponse(ctx, d, repo, repo.Templates(), payload.Filter)
}

func (s *service) TemplateIndex(ctx context.Context, d dependencies.ProjectRequestScope, payload *TemplateIndexPayload) (res *TemplateDetail, err error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,32 @@
"categories": [
"Other"
],
"components": [
"keboola.wr-%s",
"foo.bar",
"keboola.data-apps"
],
"versions": [
{
"version": "1.2.3",
"stable": false,
"description": ""
}
]
},
{
"id": "my-template-id-6",
"name": "My Template-snowflake-6",
"deprecated": false,
"author": {
"name": "Example Author",
"url": "https://example.com"
},
"description": "Full workflow to ...",
"defaultVersion": "1.2.3",
"categories": [
"Other"
],
"components": [
"keboola.wr-%s",
"foo.bar"
Expand All @@ -58,6 +84,32 @@
"description": ""
}
]
},
{
"id": "my-template-id-7",
"name": "My Template-snowflake-7",
"deprecated": false,
"author": {
"name": "Example Author",
"url": "https://example.com"
},
"description": "Full workflow to ...",
"defaultVersion": "1.2.3",
"categories": [
"Other"
],
"components": [
"keboola.wr-%s",
"foo.bar",
"keboola.data-apps"
],
"versions": [
{
"version": "1.2.3",
"stable": false,
"description": ""
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
200
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"repository": {
"name": "keboola",
"url": "%s/test/templates/api/repositories/template-list-filter/repository",
"ref": "",
"author": {
"name": "Example Author",
"url": "https://example.com"
}
},
"templates": [
{
"id": "my-template-id-5",
"name": "My Template-snowflake-5",
"deprecated": false,
"author": {
"name": "Example Author",
"url": "https://example.com"
},
"description": "Full workflow to ...",
"defaultVersion": "1.2.3",
"categories": [
"Other"
],
"components": [
"keboola.wr-%s",
"foo.bar",
"keboola.data-apps"
],
"versions": [
{
"version": "1.2.3",
"stable": false,
"description": ""
}
]
},
{
"id": "my-template-id-7",
"name": "My Template-snowflake-7",
"deprecated": false,
"author": {
"name": "Example Author",
"url": "https://example.com"
},
"description": "Full workflow to ...",
"defaultVersion": "1.2.3",
"categories": [
"Other"
],
"components": [
"keboola.wr-%s",
"foo.bar",
"keboola.data-apps"
],
"versions": [
{
"version": "1.2.3",
"stable": false,
"description": ""
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"path": "/v1/repositories/keboola/templates?filter=keboola.data-apps",
"method": "GET",
"headers": {
"Content-Type": "application/json",
"X-StorageApi-Token": "%%TEST_KBC_STORAGE_API_TOKEN%%"
},
"body": {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
200
Loading

0 comments on commit e375dc2

Please sign in to comment.