diff --git a/api/v1/shortcut.go b/api/v1/shortcut.go index f92c14d..8791681 100644 --- a/api/v1/shortcut.go +++ b/api/v1/shortcut.go @@ -49,6 +49,7 @@ type Shortcut struct { // Domain specific fields Name string `json:"name"` Link string `json:"link"` + Title string `json:"title"` Description string `json:"description"` Visibility Visibility `json:"visibility"` Tags []string `json:"tags"` @@ -59,6 +60,7 @@ type Shortcut struct { type CreateShortcutRequest struct { Name string `json:"name"` Link string `json:"link"` + Title string `json:"title"` Description string `json:"description"` Visibility Visibility `json:"visibility"` Tags []string `json:"tags"` @@ -69,6 +71,7 @@ type PatchShortcutRequest struct { RowStatus *RowStatus `json:"rowStatus"` Name *string `json:"name"` Link *string `json:"link"` + Title *string `json:"title"` Description *string `json:"description"` Visibility *Visibility `json:"visibility"` Tags []string `json:"tags"` @@ -91,6 +94,7 @@ func (s *APIV1Service) registerShortcutRoutes(g *echo.Group) { CreatorID: userID, Name: strings.ToLower(create.Name), Link: create.Link, + Title: create.Title, Description: create.Description, Visibility: store.Visibility(create.Visibility.String()), Tag: strings.Join(create.Tags, " "), @@ -158,6 +162,7 @@ func (s *APIV1Service) registerShortcutRoutes(g *echo.Group) { ID: shortcutID, Name: patch.Name, Link: patch.Link, + Title: patch.Title, Description: patch.Description, } if patch.RowStatus != nil { @@ -332,6 +337,7 @@ func convertShortcutFromStore(shortcut *store.Shortcut) *Shortcut { CreatorID: shortcut.CreatorID, Name: shortcut.Name, Link: shortcut.Link, + Title: shortcut.Title, Description: shortcut.Description, Visibility: Visibility(shortcut.Visibility), RowStatus: RowStatus(shortcut.RowStatus), diff --git a/store/db/migration/dev/LATEST__SCHEMA.sql b/store/db/migration/dev/LATEST__SCHEMA.sql index 0c2f815..8ab7fc2 100644 --- a/store/db/migration/dev/LATEST__SCHEMA.sql +++ b/store/db/migration/dev/LATEST__SCHEMA.sql @@ -41,6 +41,7 @@ CREATE TABLE shortcut ( row_status TEXT NOT NULL CHECK (row_status IN ('NORMAL', 'ARCHIVED')) DEFAULT 'NORMAL', name TEXT NOT NULL UNIQUE, link TEXT NOT NULL, + title TEXT NOT NULL DEFAULT '', description TEXT NOT NULL DEFAULT '', visibility TEXT NOT NULL CHECK (visibility IN ('PRIVATE', 'WORKSPACE', 'PUBLIC')) DEFAULT 'PRIVATE', tag TEXT NOT NULL DEFAULT '', diff --git a/store/db/migration/prod/0.4/00__add_shortcut_title.sql b/store/db/migration/prod/0.4/00__add_shortcut_title.sql new file mode 100644 index 0000000..499ee5d --- /dev/null +++ b/store/db/migration/prod/0.4/00__add_shortcut_title.sql @@ -0,0 +1 @@ +ALTER TABLE shortcut ADD COLUMN title TEXT NOT NULL DEFAULT ''; diff --git a/store/db/migration/prod/LATEST__SCHEMA.sql b/store/db/migration/prod/LATEST__SCHEMA.sql index 0c2f815..8ab7fc2 100644 --- a/store/db/migration/prod/LATEST__SCHEMA.sql +++ b/store/db/migration/prod/LATEST__SCHEMA.sql @@ -41,6 +41,7 @@ CREATE TABLE shortcut ( row_status TEXT NOT NULL CHECK (row_status IN ('NORMAL', 'ARCHIVED')) DEFAULT 'NORMAL', name TEXT NOT NULL UNIQUE, link TEXT NOT NULL, + title TEXT NOT NULL DEFAULT '', description TEXT NOT NULL DEFAULT '', visibility TEXT NOT NULL CHECK (visibility IN ('PRIVATE', 'WORKSPACE', 'PUBLIC')) DEFAULT 'PRIVATE', tag TEXT NOT NULL DEFAULT '', diff --git a/store/shortcut.go b/store/shortcut.go index 9741906..e4f514b 100644 --- a/store/shortcut.go +++ b/store/shortcut.go @@ -50,6 +50,7 @@ type Shortcut struct { // Domain specific fields Name string Link string + Title string Description string Visibility Visibility Tag string @@ -62,6 +63,7 @@ type UpdateShortcut struct { RowStatus *RowStatus Name *string Link *string + Title *string Description *string Visibility *Visibility Tag *string @@ -82,9 +84,9 @@ type DeleteShortcut struct { } func (s *Store) CreateShortcut(ctx context.Context, create *Shortcut) (*Shortcut, error) { - set := []string{"creator_id", "name", "link", "description", "visibility", "tag"} - args := []any{create.CreatorID, create.Name, create.Link, create.Description, create.Visibility, create.Tag} - placeholder := []string{"?", "?", "?", "?", "?", "?"} + set := []string{"creator_id", "name", "link", "title", "description", "visibility", "tag"} + args := []any{create.CreatorID, create.Name, create.Link, create.Title, create.Description, create.Visibility, create.Tag} + placeholder := []string{"?", "?", "?", "?", "?", "?", "?"} if create.OpenGraphMetadata != nil { set = append(set, "og_metadata") openGraphMetadataBytes, err := json.Marshal(create.OpenGraphMetadata) @@ -125,6 +127,9 @@ func (s *Store) UpdateShortcut(ctx context.Context, update *UpdateShortcut) (*Sh if update.Link != nil { set, args = append(set, "link = ?"), append(args, *update.Link) } + if update.Title != nil { + set, args = append(set, "title = ?"), append(args, *update.Title) + } if update.Description != nil { set, args = append(set, "description = ?"), append(args, *update.Description) } @@ -152,7 +157,7 @@ func (s *Store) UpdateShortcut(ctx context.Context, update *UpdateShortcut) (*Sh ` + strings.Join(set, ", ") + ` WHERE id = ? - RETURNING id, creator_id, created_ts, updated_ts, row_status, name, link, description, visibility, tag, og_metadata + RETURNING id, creator_id, created_ts, updated_ts, row_status, name, link, title, description, visibility, tag, og_metadata ` shortcut := &Shortcut{} openGraphMetadataString := "" @@ -164,6 +169,7 @@ func (s *Store) UpdateShortcut(ctx context.Context, update *UpdateShortcut) (*Sh &shortcut.RowStatus, &shortcut.Name, &shortcut.Link, + &shortcut.Title, &shortcut.Description, &shortcut.Visibility, &shortcut.Tag, @@ -217,6 +223,7 @@ func (s *Store) ListShortcuts(ctx context.Context, find *FindShortcut) ([]*Short row_status, name, link, + title, description, visibility, tag, @@ -243,6 +250,7 @@ func (s *Store) ListShortcuts(ctx context.Context, find *FindShortcut) ([]*Short &shortcut.RowStatus, &shortcut.Name, &shortcut.Link, + &shortcut.Title, &shortcut.Description, &shortcut.Visibility, &shortcut.Tag, diff --git a/web/src/components/CreateShortcutDialog.tsx b/web/src/components/CreateShortcutDialog.tsx index 5713b9b..47904d6 100644 --- a/web/src/components/CreateShortcutDialog.tsx +++ b/web/src/components/CreateShortcutDialog.tsx @@ -27,6 +27,7 @@ const CreateShortcutDialog: React.FC = (props: Props) => { shortcutCreate: { name: "", link: "", + title: "", description: "", visibility: "PRIVATE", tags: [], @@ -85,6 +86,14 @@ const CreateShortcutDialog: React.FC = (props: Props) => { }); }; + const handleTitleInputChange = (e: React.ChangeEvent) => { + setPartialState({ + shortcutCreate: Object.assign(state.shortcutCreate, { + title: e.target.value, + }), + }); + }; + const handleVisibilityInputChange = (e: React.ChangeEvent) => { setPartialState({ shortcutCreate: Object.assign(state.shortcutCreate, { @@ -184,6 +193,18 @@ const CreateShortcutDialog: React.FC = (props: Props) => {
+
+ Title +
+ +
+
Name
diff --git a/web/src/types/modules/shortcut.d.ts b/web/src/types/modules/shortcut.d.ts index 72897a8..8f53aca 100644 --- a/web/src/types/modules/shortcut.d.ts +++ b/web/src/types/modules/shortcut.d.ts @@ -19,6 +19,7 @@ interface Shortcut { name: string; link: string; + title: string; description: string; visibility: Visibility; tags: string[]; @@ -29,6 +30,7 @@ interface Shortcut { interface ShortcutCreate { name: string; link: string; + title: string; description: string; visibility: Visibility; tags: string[]; @@ -40,6 +42,7 @@ interface ShortcutPatch { name?: string; link?: string; + title?: string; description?: string; visibility?: Visibility; tags?: string[];