Skip to content
This repository has been archived by the owner on Nov 1, 2024. It is now read-only.

Commit

Permalink
fetch pa for teams from teamkatalogen api with cache
Browse files Browse the repository at this point in the history
  • Loading branch information
erikvatt committed Dec 5, 2023
1 parent a4be208 commit d7e2e01
Show file tree
Hide file tree
Showing 19 changed files with 70 additions and 234 deletions.
4 changes: 2 additions & 2 deletions pkg/database/dataproducts.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ func (r *Repo) GetDataproductsByGroups(ctx context.Context, groups []string) ([]
return dps, nil
}

func (r *Repo) GetDataproductByProductArea(ctx context.Context, paID string) ([]*models.Dataproduct, error) {
dps, err := r.querier.GetDataproductsByProductArea(ctx, sql.NullString{String: paID, Valid: true})
func (r *Repo) GetDataproductByProductArea(ctx context.Context, teamIDs []string) ([]*models.Dataproduct, error) {
dps, err := r.querier.GetDataproductsByProductArea(ctx, teamIDs)
if err != nil {
return nil, err
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/database/gensql/dataproducts.sql.go

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

6 changes: 3 additions & 3 deletions pkg/database/gensql/insight_products.sql.go

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

5 changes: 0 additions & 5 deletions pkg/database/gensql/models.go

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

6 changes: 3 additions & 3 deletions pkg/database/gensql/quarto.sql.go

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

12 changes: 4 additions & 8 deletions pkg/database/gensql/querier.go

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

6 changes: 3 additions & 3 deletions pkg/database/gensql/stories.sql.go

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

90 changes: 0 additions & 90 deletions pkg/database/gensql/teamcatalog_mapping.sql.go

This file was deleted.

23 changes: 0 additions & 23 deletions pkg/database/group.go

This file was deleted.

4 changes: 2 additions & 2 deletions pkg/database/insight_product.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ func (r *Repo) UpdateInsightProductMetadata(ctx context.Context, id uuid.UUID, n
return InsightProductSQLToGraphql(&dbProduct), nil
}

func (r *Repo) GetInsightProductsByProductArea(ctx context.Context, productAreaID string) ([]*models.InsightProduct, error) {
dbProducts, err := r.querier.GetInsightProductsByProductArea(ctx, ptrToNullString(&productAreaID))
func (r *Repo) GetInsightProductsByProductArea(ctx context.Context, teamsInPA []string) ([]*models.InsightProduct, error) {
dbProducts, err := r.querier.GetInsightProductsByProductArea(ctx, teamsInPA)
if err != nil {
return nil, err
}
Expand Down
27 changes: 3 additions & 24 deletions pkg/database/quarto.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,8 @@ func (r *Repo) GetQuartoStories(ctx context.Context) ([]*models.QuartoStory, err
return quartoGraphqls, err
}

func (r *Repo) GetQuartoStoriesByProductArea(ctx context.Context, paID string) ([]*models.QuartoStory, error) {
stories, err := r.querier.GetQuartoStoriesByProductArea(
ctx, sql.NullString{String: paID, Valid: true})
func (r *Repo) GetQuartoStoriesByProductArea(ctx context.Context, teamsInPA []string) ([]*models.QuartoStory, error) {
stories, err := r.querier.GetQuartoStoriesByProductArea(ctx, teamsInPA)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -109,13 +108,7 @@ func (r *Repo) GetQuartoStoriesByGroups(ctx context.Context, groups []string) ([
func (r *Repo) UpdateQuartoStoryMetadata(ctx context.Context, id uuid.UUID, name string, description string, keywords []string, teamkatalogenURL *string, productAreaID *string, teamID *string, group string) (
*models.QuartoStory, error,
) {
tx, err := r.db.Begin()
if err != nil {
return nil, err
}
querier := r.querier.WithTx(tx)

dbStory, err := querier.UpdateQuartoStory(ctx, gensql.UpdateQuartoStoryParams{
dbStory, err := r.querier.UpdateQuartoStory(ctx, gensql.UpdateQuartoStoryParams{
ID: id,
Name: name,
Description: description,
Expand All @@ -125,20 +118,6 @@ func (r *Repo) UpdateQuartoStoryMetadata(ctx context.Context, id uuid.UUID, name
OwnerGroup: group,
})
if err != nil {
if err := tx.Rollback(); err != nil {
r.log.WithError(err).Error("rolling back quarto metadata update")
}
return nil, err
}

if err := r.CreateTeamProductAreaMappingIfNotExists(ctx, tx, teamID, productAreaID); err != nil {
if err := tx.Rollback(); err != nil {
r.log.WithError(err).Error("rolling back quarto metadata update")
}
return nil, err
}

if err := tx.Commit(); err != nil {
return nil, err
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/database/queries/dataproducts.sql
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ ORDER BY last_modified DESC;
-- name: GetDataproductsByProductArea :many
SELECT *
FROM dataproducts
WHERE team_id = ANY(SELECT team_id FROM team_productarea_mapping WHERE product_area_id = @product_area_id)
WHERE team_id = ANY(@team_id::text[])
ORDER BY created DESC;

-- name: GetDataproductsByTeam :many
Expand Down
2 changes: 1 addition & 1 deletion pkg/database/queries/insight_products.sql
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ SELECT
FROM
insight_product
WHERE
team_id = ANY(SELECT team_id FROM team_productarea_mapping WHERE product_area_id = @product_area_id)
team_id = ANY(@team_id::text[])
ORDER BY
last_modified DESC;

Expand Down
2 changes: 1 addition & 1 deletion pkg/database/queries/quarto.sql
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ ORDER BY last_modified DESC;
-- name: GetQuartoStoriesByProductArea :many
SELECT *
FROM quarto_stories
WHERE team_id = ANY(SELECT team_id FROM team_productarea_mapping WHERE product_area_id = @product_area_id)
WHERE team_id = ANY(@team_id::text[])
ORDER BY last_modified DESC;

-- name: GetQuartoStoriesByTeam :many
Expand Down
2 changes: 1 addition & 1 deletion pkg/database/queries/stories.sql
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ ORDER BY created DESC;
-- name: GetStoriesByProductArea :many
SELECT *
FROM stories
WHERE team_id = ANY(SELECT team_id FROM team_productarea_mapping WHERE product_area_id = @product_area_id)
WHERE team_id = ANY(@team_id::text[])
ORDER BY created DESC;

-- name: GetStoriesByTeam :many
Expand Down
22 changes: 0 additions & 22 deletions pkg/database/queries/teamcatalog_mapping.sql

This file was deleted.

Loading

0 comments on commit d7e2e01

Please sign in to comment.