From 65bcbc9ceca744ad294ab9f44cacc3698517105d Mon Sep 17 00:00:00 2001 From: Vilsol Date: Sat, 6 Jan 2024 09:52:32 +0200 Subject: [PATCH] feat: tag descriptions --- db/postgres/postgres_types.go | 3 ++- gql/gql_types.go | 5 +++-- gql/resolver_tags.go | 17 ++++++++++------- .../sql/000025_add_tag_description.down.sql | 2 ++ .../sql/000025_add_tag_description.up.sql | 2 ++ schemas/tags.graphql | 12 +++++++++--- 6 files changed, 28 insertions(+), 13 deletions(-) create mode 100644 migrations/sql/000025_add_tag_description.down.sql create mode 100644 migrations/sql/000025_add_tag_description.up.sql diff --git a/db/postgres/postgres_types.go b/db/postgres/postgres_types.go index c09660ed..4d12da1d 100644 --- a/db/postgres/postgres_types.go +++ b/db/postgres/postgres_types.go @@ -169,7 +169,8 @@ type Announcement struct { type Tag struct { SMRModel - Name string `gorm:"type:varchar(24)"` + Name string `gorm:"type:varchar(24)"` + Description string `gorm:"type:varchar(512)"` Mods []Mod `gorm:"many2many:mod_tags"` } diff --git a/gql/gql_types.go b/gql/gql_types.go index 6d8d3960..43dc7191 100644 --- a/gql/gql_types.go +++ b/gql/gql_types.go @@ -199,8 +199,9 @@ func DBTagToGenerated(tag *postgres.Tag) *generated.Tag { return nil } return &generated.Tag{ - Name: tag.Name, - ID: tag.ID, + Name: tag.Name, + ID: tag.ID, + Description: tag.Description, } } diff --git a/gql/resolver_tags.go b/gql/resolver_tags.go index 8050dcfa..08d618fe 100644 --- a/gql/resolver_tags.go +++ b/gql/resolver_tags.go @@ -8,12 +8,13 @@ import ( "github.com/satisfactorymodding/smr-api/generated" ) -func (r *mutationResolver) CreateTag(ctx context.Context, tagName string) (*generated.Tag, error) { +func (r *mutationResolver) CreateTag(ctx context.Context, tagName string, description string) (*generated.Tag, error) { wrapper, newCtx := WrapMutationTrace(ctx, "createTag") defer wrapper.end() dbTag := &postgres.Tag{ - Name: tagName, + Name: tagName, + Description: description, } resultTag, err := postgres.CreateTag(newCtx, dbTag, true) @@ -23,15 +24,16 @@ func (r *mutationResolver) CreateTag(ctx context.Context, tagName string) (*gene return DBTagToGenerated(resultTag), nil } -func (r *mutationResolver) CreateMultipleTags(ctx context.Context, tagNames []string) ([]*generated.Tag, error) { +func (r *mutationResolver) CreateMultipleTags(ctx context.Context, tags []*generated.NewTag) ([]*generated.Tag, error) { wrapper, newCtx := WrapMutationTrace(ctx, "createMultipleTags") defer wrapper.end() - resultTags := make([]postgres.Tag, len(tagNames)) + resultTags := make([]postgres.Tag, len(tags)) - for i, tagName := range tagNames { + for i, tag := range tags { dbTag := &postgres.Tag{ - Name: tagName, + Name: tag.Name, + Description: tag.Description, } resultTag, err := postgres.CreateTag(newCtx, dbTag, false) @@ -60,7 +62,7 @@ func (r *mutationResolver) DeleteTag(ctx context.Context, id string) (bool, erro return true, nil } -func (r *mutationResolver) UpdateTag(ctx context.Context, id string, newName string) (*generated.Tag, error) { +func (r *mutationResolver) UpdateTag(ctx context.Context, id string, newName string, description string) (*generated.Tag, error) { wrapper, newCtx := WrapMutationTrace(ctx, "updateTag") defer wrapper.end() @@ -76,6 +78,7 @@ func (r *mutationResolver) UpdateTag(ctx context.Context, id string, newName str } SetStringINNOE(&newName, &dbTag.Name) + SetStringINNOE(&description, &dbTag.Description) postgres.Save(newCtx, &dbTag) diff --git a/migrations/sql/000025_add_tag_description.down.sql b/migrations/sql/000025_add_tag_description.down.sql new file mode 100644 index 00000000..91bd0f51 --- /dev/null +++ b/migrations/sql/000025_add_tag_description.down.sql @@ -0,0 +1,2 @@ +ALTER TABLE tags + DROP COLUMN description; diff --git a/migrations/sql/000025_add_tag_description.up.sql b/migrations/sql/000025_add_tag_description.up.sql new file mode 100644 index 00000000..5cf24be3 --- /dev/null +++ b/migrations/sql/000025_add_tag_description.up.sql @@ -0,0 +1,2 @@ +ALTER TABLE tags + ADD COLUMN IF NOT EXISTS description varchar(512); \ No newline at end of file diff --git a/schemas/tags.graphql b/schemas/tags.graphql index 6400b81a..a2a31f3d 100644 --- a/schemas/tags.graphql +++ b/schemas/tags.graphql @@ -4,6 +4,12 @@ scalar TagName type Tag { id: TagID! name: TagName! + description: String! +} + +input NewTag { + name: TagName! + description: String! } input TagFilter { @@ -22,8 +28,8 @@ extend type Query { ### Mutations extend type Mutation { - createTag(tagName: TagName!): Tag @isLoggedIn - createMultipleTags(tagNames: [TagName!]!): [Tag!]! @canManageTags @isLoggedIn - updateTag(tagID: TagID!, NewName: TagName!): Tag! @canManageTags @isLoggedIn + createTag(tagName: TagName!, description: String!): Tag @canManageTags @isLoggedIn + createMultipleTags(tagNames: [NewTag!]!): [Tag!]! @canManageTags @isLoggedIn + updateTag(tagID: TagID!, NewName: TagName!, description: String!): Tag! @canManageTags @isLoggedIn deleteTag(tagID: TagID!): Boolean! @canManageTags @isLoggedIn } \ No newline at end of file