feat: add title field to shortcut

This commit is contained in:
Steven 2023-07-31 21:53:06 +08:00
parent 714889433f
commit e6ece43231
7 changed files with 45 additions and 4 deletions

View File

@ -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),

View File

@ -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 '',

View File

@ -0,0 +1 @@
ALTER TABLE shortcut ADD COLUMN title TEXT NOT NULL DEFAULT '';

View File

@ -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 '',

View File

@ -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,

View File

@ -27,6 +27,7 @@ const CreateShortcutDialog: React.FC<Props> = (props: Props) => {
shortcutCreate: {
name: "",
link: "",
title: "",
description: "",
visibility: "PRIVATE",
tags: [],
@ -85,6 +86,14 @@ const CreateShortcutDialog: React.FC<Props> = (props: Props) => {
});
};
const handleTitleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
setPartialState({
shortcutCreate: Object.assign(state.shortcutCreate, {
title: e.target.value,
}),
});
};
const handleVisibilityInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
setPartialState({
shortcutCreate: Object.assign(state.shortcutCreate, {
@ -184,6 +193,18 @@ const CreateShortcutDialog: React.FC<Props> = (props: Props) => {
</Button>
</div>
<div className="overflow-y-auto overflow-x-hidden">
<div className="w-full flex flex-col justify-start items-start mb-3">
<span className="mb-2">Title</span>
<div className="relative w-full">
<Input
className="w-full"
type="text"
placeholder="Title"
value={state.shortcutCreate.title}
onChange={handleTitleInputChange}
/>
</div>
</div>
<div className="w-full flex flex-col justify-start items-start mb-3">
<span className="mb-2">Name</span>
<div className="relative w-full">

View File

@ -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[];