Skip to content

Commit

Permalink
feat: tag descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
Vilsol committed Jan 6, 2024
1 parent b35adb7 commit 65bcbc9
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 13 deletions.
3 changes: 2 additions & 1 deletion db/postgres/postgres_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
Expand Down
5 changes: 3 additions & 2 deletions gql/gql_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand Down
17 changes: 10 additions & 7 deletions gql/resolver_tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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()

Expand All @@ -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)

Expand Down
2 changes: 2 additions & 0 deletions migrations/sql/000025_add_tag_description.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE tags
DROP COLUMN description;
2 changes: 2 additions & 0 deletions migrations/sql/000025_add_tag_description.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE tags
ADD COLUMN IF NOT EXISTS description varchar(512);
12 changes: 9 additions & 3 deletions schemas/tags.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ scalar TagName
type Tag {
id: TagID!
name: TagName!
description: String!
}

input NewTag {
name: TagName!
description: String!
}

input TagFilter {
Expand All @@ -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
}

0 comments on commit 65bcbc9

Please sign in to comment.