Skip to content

Commit

Permalink
chore: add list all environment tags storage interface
Browse files Browse the repository at this point in the history
Signed-off-by: Alessandro Yuichi Okimoto <[email protected]>
  • Loading branch information
cre8ivejp committed Jan 21, 2025
1 parent aeabf7e commit 3f6b2aa
Show file tree
Hide file tree
Showing 11 changed files with 456 additions and 16 deletions.
4 changes: 2 additions & 2 deletions manifests/bucketeer/charts/web/values.yaml

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions pkg/tag/storage/mock/tag.go

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

11 changes: 11 additions & 0 deletions pkg/tag/storage/sql/select_all_environment_tags.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
SELECT
env.id AS environment_id,
tag.id,
tag.name,
tag.created_at,
tag.updated_at,
tag.entity_type,
tag.environment_id
FROM tag
JOIN environment_v2 env ON tag.environment_id = env.id
ORDER BY env.id, tag.name;
43 changes: 43 additions & 0 deletions pkg/tag/storage/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ var (
selectTagSQL string
//go:embed sql/select_tags.sql
selectTagsSQL string
//go:embed sql/select_all_environment_tags.sql
selectAllEnvironmentTagsSQL string
//go:embed sql/count_tags.sql
countTagsSQL string
//go:embed sql/delete_tag.sql
Expand All @@ -51,6 +53,7 @@ type TagStorage interface {
orders []*mysql.Order,
limit, offset int,
) ([]*proto.Tag, int, int64, error)
ListAllEnvironmentTags(ctx context.Context) ([]*proto.EnvironmentTag, error)
DeleteTag(ctx context.Context, id, environmentId string) error
}

Expand Down Expand Up @@ -151,6 +154,46 @@ func (s *tagStorage) ListTags(
return tags, nextOffset, totalCount, nil
}

func (s *tagStorage) ListAllEnvironmentTags(ctx context.Context) ([]*proto.EnvironmentTag, error) {
rows, err := s.qe.QueryContext(ctx, selectAllEnvironmentTagsSQL)
if err != nil {
return nil, err
}
defer rows.Close()
envTags := map[string][]*proto.Tag{}
for rows.Next() {
var entityType int32
var envID string
tag := proto.Tag{}
err := rows.Scan(
&envID,
&tag.Id,
&tag.Name,
&tag.CreatedAt,
&tag.UpdatedAt,
&entityType,
&tag.EnvironmentId,
)
if err != nil {
return nil, err
}
tag.EntityType = proto.Tag_EntityType(entityType)
envTags[envID] = append(envTags[envID], &tag)
}
if rows.Err() != nil {
return nil, err
}
environmentTags := make([]*proto.EnvironmentTag, 0, len(envTags))
for key, tags := range envTags {
envTag := &proto.EnvironmentTag{
EnvironmentId: key,
Tags: tags,
}
environmentTags = append(environmentTags, envTag)
}
return environmentTags, nil
}

func (s *tagStorage) DeleteTag(ctx context.Context, id, environmentId string) error {
result, err := s.qe.ExecContext(ctx, deleteTagSQL, id)
if err != nil {
Expand Down
Binary file modified proto/auditlog/proto_descriptor.pb
Binary file not shown.
16 changes: 16 additions & 0 deletions proto/proto.lock
Original file line number Diff line number Diff line change
Expand Up @@ -33066,6 +33066,22 @@
"type": "string"
}
]
},
{
"name": "EnvironmentTag",
"fields": [
{
"id": 1,
"name": "environment_id",
"type": "string"
},
{
"id": 2,
"name": "tags",
"type": "Tag",
"is_repeated": true
}
]
}
],
"package": {
Expand Down
Binary file modified proto/tag/proto_descriptor.pb
Binary file not shown.
103 changes: 89 additions & 14 deletions proto/tag/tag.pb.go

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

5 changes: 5 additions & 0 deletions proto/tag/tag.proto
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,8 @@ message Tag {
EntityType entity_type = 5;
string environment_id = 6;
}

message EnvironmentTag {
string environment_id = 1;
repeated Tag tags = 2;
}
37 changes: 37 additions & 0 deletions ui/web-v2/src/proto/tag/tag_pb.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,40 @@ export namespace Tag {

export const EntityType: EntityTypeMap;
}

export class EnvironmentTag extends jspb.Message {
getEnvironmentId(): string;
setEnvironmentId(value: string): void;

clearTagsList(): void;
getTagsList(): Array<Tag>;
setTagsList(value: Array<Tag>): void;
addTags(value?: Tag, index?: number): Tag;

serializeBinary(): Uint8Array;
toObject(includeInstance?: boolean): EnvironmentTag.AsObject;
static toObject(
includeInstance: boolean,
msg: EnvironmentTag
): EnvironmentTag.AsObject;
static extensions: { [key: number]: jspb.ExtensionFieldInfo<jspb.Message> };
static extensionsBinary: {
[key: number]: jspb.ExtensionFieldBinaryInfo<jspb.Message>;
};
static serializeBinaryToWriter(
message: EnvironmentTag,
writer: jspb.BinaryWriter
): void;
static deserializeBinary(bytes: Uint8Array): EnvironmentTag;
static deserializeBinaryFromReader(
message: EnvironmentTag,
reader: jspb.BinaryReader
): EnvironmentTag;
}

export namespace EnvironmentTag {
export type AsObject = {
environmentId: string;
tagsList: Array<Tag.AsObject>;
};
}
Loading

0 comments on commit 3f6b2aa

Please sign in to comment.