Skip to content

Commit 65bcbc9

Browse files
committed
feat: tag descriptions
1 parent b35adb7 commit 65bcbc9

File tree

6 files changed

+28
-13
lines changed

6 files changed

+28
-13
lines changed

db/postgres/postgres_types.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,8 @@ type Announcement struct {
169169
type Tag struct {
170170
SMRModel
171171

172-
Name string `gorm:"type:varchar(24)"`
172+
Name string `gorm:"type:varchar(24)"`
173+
Description string `gorm:"type:varchar(512)"`
173174

174175
Mods []Mod `gorm:"many2many:mod_tags"`
175176
}

gql/gql_types.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,9 @@ func DBTagToGenerated(tag *postgres.Tag) *generated.Tag {
199199
return nil
200200
}
201201
return &generated.Tag{
202-
Name: tag.Name,
203-
ID: tag.ID,
202+
Name: tag.Name,
203+
ID: tag.ID,
204+
Description: tag.Description,
204205
}
205206
}
206207

gql/resolver_tags.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@ import (
88
"github.com/satisfactorymodding/smr-api/generated"
99
)
1010

11-
func (r *mutationResolver) CreateTag(ctx context.Context, tagName string) (*generated.Tag, error) {
11+
func (r *mutationResolver) CreateTag(ctx context.Context, tagName string, description string) (*generated.Tag, error) {
1212
wrapper, newCtx := WrapMutationTrace(ctx, "createTag")
1313
defer wrapper.end()
1414

1515
dbTag := &postgres.Tag{
16-
Name: tagName,
16+
Name: tagName,
17+
Description: description,
1718
}
1819

1920
resultTag, err := postgres.CreateTag(newCtx, dbTag, true)
@@ -23,15 +24,16 @@ func (r *mutationResolver) CreateTag(ctx context.Context, tagName string) (*gene
2324
return DBTagToGenerated(resultTag), nil
2425
}
2526

26-
func (r *mutationResolver) CreateMultipleTags(ctx context.Context, tagNames []string) ([]*generated.Tag, error) {
27+
func (r *mutationResolver) CreateMultipleTags(ctx context.Context, tags []*generated.NewTag) ([]*generated.Tag, error) {
2728
wrapper, newCtx := WrapMutationTrace(ctx, "createMultipleTags")
2829
defer wrapper.end()
2930

30-
resultTags := make([]postgres.Tag, len(tagNames))
31+
resultTags := make([]postgres.Tag, len(tags))
3132

32-
for i, tagName := range tagNames {
33+
for i, tag := range tags {
3334
dbTag := &postgres.Tag{
34-
Name: tagName,
35+
Name: tag.Name,
36+
Description: tag.Description,
3537
}
3638

3739
resultTag, err := postgres.CreateTag(newCtx, dbTag, false)
@@ -60,7 +62,7 @@ func (r *mutationResolver) DeleteTag(ctx context.Context, id string) (bool, erro
6062
return true, nil
6163
}
6264

63-
func (r *mutationResolver) UpdateTag(ctx context.Context, id string, newName string) (*generated.Tag, error) {
65+
func (r *mutationResolver) UpdateTag(ctx context.Context, id string, newName string, description string) (*generated.Tag, error) {
6466
wrapper, newCtx := WrapMutationTrace(ctx, "updateTag")
6567
defer wrapper.end()
6668

@@ -76,6 +78,7 @@ func (r *mutationResolver) UpdateTag(ctx context.Context, id string, newName str
7678
}
7779

7880
SetStringINNOE(&newName, &dbTag.Name)
81+
SetStringINNOE(&description, &dbTag.Description)
7982

8083
postgres.Save(newCtx, &dbTag)
8184

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ALTER TABLE tags
2+
DROP COLUMN description;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ALTER TABLE tags
2+
ADD COLUMN IF NOT EXISTS description varchar(512);

schemas/tags.graphql

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ scalar TagName
44
type Tag {
55
id: TagID!
66
name: TagName!
7+
description: String!
8+
}
9+
10+
input NewTag {
11+
name: TagName!
12+
description: String!
713
}
814

915
input TagFilter {
@@ -22,8 +28,8 @@ extend type Query {
2228
### Mutations
2329

2430
extend type Mutation {
25-
createTag(tagName: TagName!): Tag @isLoggedIn
26-
createMultipleTags(tagNames: [TagName!]!): [Tag!]! @canManageTags @isLoggedIn
27-
updateTag(tagID: TagID!, NewName: TagName!): Tag! @canManageTags @isLoggedIn
31+
createTag(tagName: TagName!, description: String!): Tag @canManageTags @isLoggedIn
32+
createMultipleTags(tagNames: [NewTag!]!): [Tag!]! @canManageTags @isLoggedIn
33+
updateTag(tagID: TagID!, NewName: TagName!, description: String!): Tag! @canManageTags @isLoggedIn
2834
deleteTag(tagID: TagID!): Boolean! @canManageTags @isLoggedIn
2935
}

0 commit comments

Comments
 (0)