feat: implement memo relation server (#1618)

This commit is contained in:
boojack
2023-05-01 16:09:41 +08:00
committed by GitHub
parent 6e6aae6649
commit b6564bcd77
9 changed files with 276 additions and 8 deletions

View File

@ -11,6 +11,7 @@ import (
"github.com/pkg/errors"
"github.com/usememos/memos/api"
"github.com/usememos/memos/common"
"github.com/usememos/memos/store"
"github.com/labstack/echo/v4"
)
@ -101,6 +102,18 @@ func (s *Server) registerMemoRoutes(g *echo.Group) {
}
}
if s.Profile.IsDev() {
for _, memoRelationUpsert := range memoCreate.MemoRelationList {
if _, err := s.Store.UpsertMemoRelation(ctx, &store.MemoRelationMessage{
MemoID: memo.ID,
RelatedMemoID: memoRelationUpsert.RelatedMemoID,
Type: store.MemoRelationType(memoRelationUpsert.Type),
}); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to upsert memo relation").SetInternal(err)
}
}
}
memo, err = s.Store.ComposeMemo(ctx, memo)
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to compose memo").SetInternal(err)
@ -157,6 +170,18 @@ func (s *Server) registerMemoRoutes(g *echo.Group) {
}
}
if s.Profile.IsDev() {
for _, memoRelationUpsert := range memoPatch.MemoRelationList {
if _, err := s.Store.UpsertMemoRelation(ctx, &store.MemoRelationMessage{
MemoID: memo.ID,
RelatedMemoID: memoRelationUpsert.RelatedMemoID,
Type: store.MemoRelationType(memoRelationUpsert.Type),
}); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to upsert memo relation").SetInternal(err)
}
}
}
memo, err = s.Store.ComposeMemo(ctx, memo)
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to compose memo").SetInternal(err)