mirror of
https://github.com/aykhans/slash-e.git
synced 2025-04-20 14:01:24 +00:00
chore: fix update shortcut
This commit is contained in:
parent
0c2283a831
commit
c449669793
@ -182,7 +182,7 @@ func (s *APIV1Service) registerShortcutRoutes(g *echo.Group) {
|
|||||||
shortcutUpdate.Tag = &tag
|
shortcutUpdate.Tag = &tag
|
||||||
}
|
}
|
||||||
if patch.OpenGraphMetadata != nil {
|
if patch.OpenGraphMetadata != nil {
|
||||||
shortcutUpdate.OpenGraphMetadata = &store.OpenGraphMetadata{
|
shortcutUpdate.OpenGraphMetadata = &storepb.OpenGraphMetadata{
|
||||||
Title: patch.OpenGraphMetadata.Title,
|
Title: patch.OpenGraphMetadata.Title,
|
||||||
Description: patch.OpenGraphMetadata.Description,
|
Description: patch.OpenGraphMetadata.Description,
|
||||||
Image: patch.OpenGraphMetadata.Image,
|
Image: patch.OpenGraphMetadata.Image,
|
||||||
|
@ -143,9 +143,13 @@ func (s *APIV2Service) UpdateShortcut(ctx context.Context, request *apiv2pb.Upda
|
|||||||
return nil, status.Errorf(codes.PermissionDenied, "Permission denied")
|
return nil, status.Errorf(codes.PermissionDenied, "Permission denied")
|
||||||
}
|
}
|
||||||
|
|
||||||
update := &store.UpdateShortcut{}
|
update := &store.UpdateShortcut{
|
||||||
|
ID: shortcut.Id,
|
||||||
|
}
|
||||||
for _, path := range request.UpdateMask.Paths {
|
for _, path := range request.UpdateMask.Paths {
|
||||||
switch path {
|
switch path {
|
||||||
|
case "name":
|
||||||
|
update.Name = &request.Shortcut.Name
|
||||||
case "link":
|
case "link":
|
||||||
update.Link = &request.Shortcut.Link
|
update.Link = &request.Shortcut.Link
|
||||||
case "title":
|
case "title":
|
||||||
@ -160,7 +164,7 @@ func (s *APIV2Service) UpdateShortcut(ctx context.Context, request *apiv2pb.Upda
|
|||||||
update.Visibility = &visibility
|
update.Visibility = &visibility
|
||||||
case "og_metadata":
|
case "og_metadata":
|
||||||
if request.Shortcut.OgMetadata != nil {
|
if request.Shortcut.OgMetadata != nil {
|
||||||
update.OpenGraphMetadata = &store.OpenGraphMetadata{
|
update.OpenGraphMetadata = &storepb.OpenGraphMetadata{
|
||||||
Title: request.Shortcut.OgMetadata.Title,
|
Title: request.Shortcut.OgMetadata.Title,
|
||||||
Description: request.Shortcut.OgMetadata.Description,
|
Description: request.Shortcut.OgMetadata.Description,
|
||||||
Image: request.Shortcut.OgMetadata.Image,
|
Image: request.Shortcut.OgMetadata.Image,
|
||||||
|
@ -3,22 +3,15 @@ package store
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"encoding/json"
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
"google.golang.org/protobuf/encoding/protojson"
|
"google.golang.org/protobuf/encoding/protojson"
|
||||||
|
|
||||||
storepb "github.com/boojack/slash/proto/gen/store"
|
storepb "github.com/boojack/slash/proto/gen/store"
|
||||||
)
|
)
|
||||||
|
|
||||||
type OpenGraphMetadata struct {
|
|
||||||
Title string `json:"title"`
|
|
||||||
Description string `json:"description"`
|
|
||||||
Image string `json:"image"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type UpdateShortcut struct {
|
type UpdateShortcut struct {
|
||||||
ID int32
|
ID int32
|
||||||
|
|
||||||
@ -29,7 +22,7 @@ type UpdateShortcut struct {
|
|||||||
Description *string
|
Description *string
|
||||||
Visibility *Visibility
|
Visibility *Visibility
|
||||||
Tag *string
|
Tag *string
|
||||||
OpenGraphMetadata *OpenGraphMetadata
|
OpenGraphMetadata *storepb.OpenGraphMetadata
|
||||||
}
|
}
|
||||||
|
|
||||||
type FindShortcut struct {
|
type FindShortcut struct {
|
||||||
@ -105,9 +98,9 @@ func (s *Store) UpdateShortcut(ctx context.Context, update *UpdateShortcut) (*st
|
|||||||
set, args = append(set, "tag = ?"), append(args, *update.Tag)
|
set, args = append(set, "tag = ?"), append(args, *update.Tag)
|
||||||
}
|
}
|
||||||
if update.OpenGraphMetadata != nil {
|
if update.OpenGraphMetadata != nil {
|
||||||
openGraphMetadataBytes, err := json.Marshal(update.OpenGraphMetadata)
|
openGraphMetadataBytes, err := protojson.Marshal(update.OpenGraphMetadata)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, errors.Wrap(err, "Failed to marshal activity payload")
|
||||||
}
|
}
|
||||||
set, args = append(set, "og_metadata = ?"), append(args, string(openGraphMetadataBytes))
|
set, args = append(set, "og_metadata = ?"), append(args, string(openGraphMetadataBytes))
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user