mirror of
https://github.com/aykhans/slash-e.git
synced 2025-04-18 21:19:44 +00:00
feat: update shortcut api with tag field
This commit is contained in:
parent
6f94473c8f
commit
5785b50c62
@ -6,6 +6,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/boojack/shortify/store"
|
"github.com/boojack/shortify/store"
|
||||||
|
|
||||||
@ -51,6 +52,7 @@ type Shortcut struct {
|
|||||||
Link string `json:"link"`
|
Link string `json:"link"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
Visibility Visibility `json:"visibility"`
|
Visibility Visibility `json:"visibility"`
|
||||||
|
Tags []string `json:"tags"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CreateShortcutRequest struct {
|
type CreateShortcutRequest struct {
|
||||||
@ -58,6 +60,7 @@ type CreateShortcutRequest struct {
|
|||||||
Link string `json:"link"`
|
Link string `json:"link"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
Visibility Visibility `json:"visibility"`
|
Visibility Visibility `json:"visibility"`
|
||||||
|
Tags []string `json:"tags"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type PatchShortcutRequest struct {
|
type PatchShortcutRequest struct {
|
||||||
@ -66,6 +69,7 @@ type PatchShortcutRequest struct {
|
|||||||
Link *string `json:"link"`
|
Link *string `json:"link"`
|
||||||
Description *string `json:"description"`
|
Description *string `json:"description"`
|
||||||
Visibility *Visibility `json:"visibility"`
|
Visibility *Visibility `json:"visibility"`
|
||||||
|
Tags []string `json:"tags"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *APIV1Service) registerShortcutRoutes(g *echo.Group) {
|
func (s *APIV1Service) registerShortcutRoutes(g *echo.Group) {
|
||||||
@ -86,6 +90,7 @@ func (s *APIV1Service) registerShortcutRoutes(g *echo.Group) {
|
|||||||
Link: create.Link,
|
Link: create.Link,
|
||||||
Description: create.Description,
|
Description: create.Description,
|
||||||
Visibility: convertVisibilityToStore(create.Visibility),
|
Visibility: convertVisibilityToStore(create.Visibility),
|
||||||
|
Tag: strings.Join(create.Tags, " "),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to create shortcut").SetInternal(err)
|
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to create shortcut").SetInternal(err)
|
||||||
@ -139,6 +144,10 @@ func (s *APIV1Service) registerShortcutRoutes(g *echo.Group) {
|
|||||||
if patch.Visibility != nil {
|
if patch.Visibility != nil {
|
||||||
shortcutUpdate.Visibility = (*store.Visibility)(patch.Visibility)
|
shortcutUpdate.Visibility = (*store.Visibility)(patch.Visibility)
|
||||||
}
|
}
|
||||||
|
if patch.Tags != nil {
|
||||||
|
tag := strings.Join(patch.Tags, " ")
|
||||||
|
shortcutUpdate.Tag = &tag
|
||||||
|
}
|
||||||
shortcut, err = s.Store.UpdateShortcut(ctx, shortcutUpdate)
|
shortcut, err = s.Store.UpdateShortcut(ctx, shortcutUpdate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to patch shortcut").SetInternal(err)
|
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to patch shortcut").SetInternal(err)
|
||||||
@ -267,5 +276,6 @@ func convertShortcutFromStore(shortcut *store.Shortcut) *Shortcut {
|
|||||||
Description: shortcut.Description,
|
Description: shortcut.Description,
|
||||||
Visibility: Visibility(shortcut.Visibility),
|
Visibility: Visibility(shortcut.Visibility),
|
||||||
RowStatus: RowStatus(shortcut.RowStatus),
|
RowStatus: RowStatus(shortcut.RowStatus),
|
||||||
|
Tags: strings.Split(shortcut.Tag, " "),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user