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

Commit

Permalink
changed to fetching product area id from teamkatalog api with our cache
Browse files Browse the repository at this point in the history
  • Loading branch information
erikvatt committed Dec 5, 2023
1 parent 23d29b7 commit a4be208
Show file tree
Hide file tree
Showing 19 changed files with 114 additions and 245 deletions.
3 changes: 0 additions & 3 deletions cmd/nada-backend/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"github.com/navikt/nada-backend/pkg/httpwithcache"
"github.com/navikt/nada-backend/pkg/metabase"
"github.com/navikt/nada-backend/pkg/polly"
"github.com/navikt/nada-backend/pkg/productareaupdater"
"github.com/navikt/nada-backend/pkg/slack"
"github.com/navikt/nada-backend/pkg/story"
"github.com/navikt/nada-backend/pkg/teamkatalogen"
Expand All @@ -46,7 +45,6 @@ var (

const (
TeamProjectsUpdateFrequency = 60 * time.Minute
ProductAreaUpdateFrequency = 10 * time.Minute
AccessEnsurerFrequency = 5 * time.Minute
MetabaseUpdateFrequency = 1 * time.Hour
StoryDraftCleanerFrequency = 24 * time.Hour
Expand Down Expand Up @@ -126,7 +124,6 @@ func main() {
amplitudeClient = amplitude.NewMock()
if !cfg.MockAuth {
teamcatalogue = teamkatalogen.New(cfg.TeamkatalogenURL)
go productareaupdater.New(repo, teamcatalogue, log.WithField("subsystem", "productareaupdater")).Run(ctx, ProductAreaUpdateFrequency)

teamProjectsUpdater = teamprojectsupdater.NewTeamProjectsUpdater(ctx, cfg.ConsoleURL, cfg.ConsoleAPIKey, http.DefaultClient, repo)
go teamProjectsUpdater.Run(ctx, TeamProjectsUpdateFrequency)
Expand Down
43 changes: 2 additions & 41 deletions pkg/database/dataproducts.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,7 @@ func (r *Repo) GetDataproduct(ctx context.Context, id uuid.UUID) (*models.Datapr
}

func (r *Repo) CreateDataproduct(ctx context.Context, dp models.NewDataproduct, user *auth.User) (*models.Dataproduct, error) {
tx, err := r.db.Begin()
if err != nil {
return nil, err
}

querier := r.querier.WithTx(tx)

dataproduct, err := querier.CreateDataproduct(ctx, gensql.CreateDataproductParams{
dataproduct, err := r.querier.CreateDataproduct(ctx, gensql.CreateDataproductParams{
Name: dp.Name,
Description: ptrToNullString(dp.Description),
OwnerGroup: dp.Group,
Expand All @@ -101,35 +94,14 @@ func (r *Repo) CreateDataproduct(ctx context.Context, dp models.NewDataproduct,
TeamID: ptrToNullString(dp.TeamID),
})
if err != nil {
if err := tx.Rollback(); err != nil {
r.log.WithError(err).Error("rolling back dataproduct creation")
}
return nil, err
}

if err := r.CreateTeamProductAreaMappingIfNotExists(ctx, tx, dp.TeamID, dp.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
}

return dataproductFromSQL(dataproduct), nil
}

func (r *Repo) UpdateDataproduct(ctx context.Context, id uuid.UUID, new models.UpdateDataproduct) (*models.Dataproduct, error) {
tx, err := r.db.Begin()
if err != nil {
return nil, err
}

querier := r.querier.WithTx(tx)

res, err := querier.UpdateDataproduct(ctx, gensql.UpdateDataproductParams{
res, err := r.querier.UpdateDataproduct(ctx, gensql.UpdateDataproductParams{
Name: new.Name,
Description: ptrToNullString(new.Description),
ID: id,
Expand All @@ -142,17 +114,6 @@ func (r *Repo) UpdateDataproduct(ctx context.Context, id uuid.UUID, new models.U
return nil, fmt.Errorf("updating dataproduct in database: %w", err)
}

if err := r.CreateTeamProductAreaMappingIfNotExists(ctx, tx, new.TeamID, new.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
}

return dataproductFromSQL(res), nil
}

Expand Down
37 changes: 11 additions & 26 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.

1 change: 0 additions & 1 deletion pkg/database/gensql/models.go

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

8 changes: 4 additions & 4 deletions pkg/database/insight_product.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ func (r *Repo) CreateInsightProduct(ctx context.Context, creator string,
Keywords: newInsightProduct.Keywords,
OwnerGroup: newInsightProduct.Group,
TeamkatalogenUrl: ptrToNullString(newInsightProduct.TeamkatalogenURL),
ProductAreaID: ptrToNullString(newInsightProduct.ProductAreaID),
TeamID: ptrToNullString(newInsightProduct.TeamID),
Type: newInsightProduct.Type,
Link: newInsightProduct.Link,
})
if err != nil {
return nil, err
}

return InsightProductSQLToGraphql(&insightProductSQL), err
return InsightProductSQLToGraphql(&insightProductSQL), nil
}

func (r *Repo) GetInsightProduct(ctx context.Context, id uuid.UUID) (*models.InsightProduct, error) {
Expand Down Expand Up @@ -61,7 +63,6 @@ func (r *Repo) UpdateInsightProductMetadata(ctx context.Context, id uuid.UUID, n
Description: ptrToNullString(&description),
Keywords: keywords,
TeamkatalogenUrl: ptrToNullString(teamkatalogenURL),
ProductAreaID: ptrToNullString(productAreaID),
TeamID: ptrToNullString(teamID),
Type: insightProductType,
Link: link,
Expand Down Expand Up @@ -129,7 +130,6 @@ func InsightProductSQLToGraphql(insightProductSQL *gensql.InsightProduct) *model
Type: insightProductSQL.Type,
Keywords: insightProductSQL.Keywords,
TeamkatalogenURL: nullStringToPtr(insightProductSQL.TeamkatalogenUrl),
ProductAreaID: nullStringToPtr(insightProductSQL.ProductAreaID),
TeamID: nullStringToPtr(insightProductSQL.TeamID),
Group: insightProductSQL.Group,
Link: insightProductSQL.Link,
Expand Down
11 changes: 11 additions & 0 deletions pkg/database/migrations/0078_remove_product_area_id.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-- +goose Up
ALTER TABLE dataproducts DROP COLUMN product_area_id;
ALTER TABLE quarto_stories DROP COLUMN product_area_id;
ALTER TABLE stories DROP COLUMN product_area_id;
ALTER TABLE insight_product DROP COLUMN product_area_id;

-- +goose Down
ALTER TABLE dataproducts ADD COLUMN product_area_id TEXT;
ALTER TABLE quarto_stories ADD COLUMN product_area_id TEXT;
ALTER TABLE stories ADD COLUMN product_area_id TEXT;
ALTER TABLE insight_product ADD COLUMN product_area_id TEXT;
36 changes: 0 additions & 36 deletions pkg/database/migrations/0078_team_pa_mapping_table.sql

This file was deleted.

Loading

0 comments on commit a4be208

Please sign in to comment.