Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Tags] add show name for tag category #242

Merged
merged 1 commit into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
SET statement_timeout = 0;

--bun:split

ALTER TABLE tag_categories DROP COLUMN IF EXISTS show_name;

--bun:split

ALTER TABLE tag_categories DROP COLUMN IF EXISTS enabled;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
SET statement_timeout = 0;

--bun:split

ALTER TABLE tag_categories ADD COLUMN IF NOT EXISTS show_name VARCHAR;

--bun:split

ALTER TABLE tag_categories ADD COLUMN IF NOT EXISTS enabled BOOLEAN DEFAULT true;
8 changes: 5 additions & 3 deletions builder/store/database/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,11 @@ type Tag struct {

// TagCategory represents the category of tags
type TagCategory struct {
ID int64 `bun:",pk,autoincrement" json:"id"`
Name string `bun:",notnull" json:"name" yaml:"name"`
Scope TagScope `bun:",notnull" json:"scope" yaml:"scope"`
ID int64 `bun:",pk,autoincrement" json:"id"`
Name string `bun:",notnull" json:"name" yaml:"name"`
ShowName string `bun:"" json:"show_name" yaml:"show_name"`
Scope TagScope `bun:",notnull" json:"scope" yaml:"scope"`
Enabled bool `bun:"default:true" json:"enabled" yaml:"enabled"`
}

// Alltags returns all tags in the database
Expand Down
16 changes: 11 additions & 5 deletions builder/store/database/tag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -642,18 +642,22 @@ func TestTagStore_Category_CURD(t *testing.T) {
total := len(categories)

catetory, err := ts.CreateCategory(ctx, database.TagCategory{
Name: "test-category",
Scope: "test-scope",
Name: "test-category",
Scope: "test-scope",
ShowName: "测试分类",
Enabled: true,
})
require.Empty(t, err)
require.NotEmpty(t, catetory)

id := catetory.ID

catetory, err = ts.UpdateCategory(ctx, database.TagCategory{
ID: 1,
Name: "test-category1",
Scope: "test-scope1",
ID: 1,
Name: "test-category1",
Scope: "test-scope1",
ShowName: "测试分类1",
Enabled: false,
})
require.Empty(t, err)
require.NotEmpty(t, catetory)
Expand All @@ -663,6 +667,8 @@ func TestTagStore_Category_CURD(t *testing.T) {
require.NotEmpty(t, categories)
require.Equal(t, "test-category1", categories[0].Name)
require.Equal(t, "test-scope1", string(categories[0].Scope))
require.Equal(t, "测试分类1", categories[0].ShowName)
require.Equal(t, false, categories[0].Enabled)

err = ts.DeleteCategory(ctx, id)
require.Empty(t, err)
Expand Down
6 changes: 4 additions & 2 deletions common/types/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ type CreateTag struct {
type UpdateTag CreateTag

type CreateCategory struct {
Name string `json:"name" binding:"required"`
Scope string `json:"scope" binding:"required"`
Name string `json:"name" binding:"required"`
Scope string `json:"scope" binding:"required"`
ShowName string `json:"show_name"`
Enabled bool `json:"enabled"`
}

type UpdateCategory CreateCategory
14 changes: 9 additions & 5 deletions component/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,10 @@ func (c *tagComponentImpl) CreateCategory(ctx context.Context, username string,
}

newCategory := database.TagCategory{
Name: req.Name,
Scope: database.TagScope(req.Scope),
Name: req.Name,
ShowName: req.ShowName,
Scope: database.TagScope(req.Scope),
Enabled: req.Enabled,
}

category, err := c.tagStore.CreateCategory(ctx, newCategory)
Expand All @@ -332,9 +334,11 @@ func (c *tagComponentImpl) UpdateCategory(ctx context.Context, username string,
}

newCategory := database.TagCategory{
ID: id,
Name: req.Name,
Scope: database.TagScope(req.Scope),
ID: id,
Name: req.Name,
ShowName: req.ShowName,
Scope: database.TagScope(req.Scope),
Enabled: req.Enabled,
}

category, err := c.tagStore.UpdateCategory(ctx, newCategory)
Expand Down
21 changes: 21 additions & 0 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -15550,6 +15550,9 @@ const docTemplate = `{
"database.TagCategory": {
"type": "object",
"properties": {
"enabled": {
"type": "boolean"
},
"id": {
"type": "integer"
},
Expand All @@ -15558,6 +15561,9 @@ const docTemplate = `{
},
"scope": {
"$ref": "#/definitions/database.TagScope"
},
"show_name": {
"type": "string"
}
}
},
Expand Down Expand Up @@ -16184,11 +16190,17 @@ const docTemplate = `{
"scope"
],
"properties": {
"enabled": {
"type": "boolean"
},
"name": {
"type": "string"
},
"scope": {
"type": "string"
},
"show_name": {
"type": "string"
}
}
},
Expand Down Expand Up @@ -18114,6 +18126,9 @@ const docTemplate = `{
"secrets": {
"type": "string"
},
"sensitive_check_status": {
"type": "string"
},
"sku": {
"type": "string"
},
Expand Down Expand Up @@ -18256,11 +18271,17 @@ const docTemplate = `{
"scope"
],
"properties": {
"enabled": {
"type": "boolean"
},
"name": {
"type": "string"
},
"scope": {
"type": "string"
},
"show_name": {
"type": "string"
}
}
},
Expand Down
21 changes: 21 additions & 0 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -15539,6 +15539,9 @@
"database.TagCategory": {
"type": "object",
"properties": {
"enabled": {
"type": "boolean"
},
"id": {
"type": "integer"
},
Expand All @@ -15547,6 +15550,9 @@
},
"scope": {
"$ref": "#/definitions/database.TagScope"
},
"show_name": {
"type": "string"
}
}
},
Expand Down Expand Up @@ -16173,11 +16179,17 @@
"scope"
],
"properties": {
"enabled": {
"type": "boolean"
},
"name": {
"type": "string"
},
"scope": {
"type": "string"
},
"show_name": {
"type": "string"
}
}
},
Expand Down Expand Up @@ -18103,6 +18115,9 @@
"secrets": {
"type": "string"
},
"sensitive_check_status": {
"type": "string"
},
"sku": {
"type": "string"
},
Expand Down Expand Up @@ -18245,11 +18260,17 @@
"scope"
],
"properties": {
"enabled": {
"type": "boolean"
},
"name": {
"type": "string"
},
"scope": {
"type": "string"
},
"show_name": {
"type": "string"
}
}
},
Expand Down
14 changes: 14 additions & 0 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -362,12 +362,16 @@ definitions:
type: object
database.TagCategory:
properties:
enabled:
type: boolean
id:
type: integer
name:
type: string
scope:
$ref: '#/definitions/database.TagScope'
show_name:
type: string
type: object
database.TagScope:
enum:
Expand Down Expand Up @@ -788,10 +792,14 @@ definitions:
type: object
types.CreateCategory:
properties:
enabled:
type: boolean
name:
type: string
scope:
type: string
show_name:
type: string
required:
- name
- scope
Expand Down Expand Up @@ -2103,6 +2111,8 @@ definitions:
type: string
secrets:
type: string
sensitive_check_status:
type: string
sku:
type: string
source:
Expand Down Expand Up @@ -2196,10 +2206,14 @@ definitions:
- TaskTypeLeaderBoard
types.UpdateCategory:
properties:
enabled:
type: boolean
name:
type: string
scope:
type: string
show_name:
type: string
required:
- name
- scope
Expand Down
Loading