fix: patch memo with resource list (#328)

fix: 修改memo时添加图片不显示
pull/330/head
Zeng1998 3 years ago committed by GitHub
parent 2a4fc7dcc3
commit fc5d5cf231
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -67,6 +67,9 @@ type MemoPatch struct {
// Domain specific fields // Domain specific fields
Content *string `json:"content"` Content *string `json:"content"`
Visibility *Visibility `json:"visibility"` Visibility *Visibility `json:"visibility"`
// Related fields
ResourceIDList []int `json:"resourceIdList"`
} }
type MemoFind struct { type MemoFind struct {

@ -116,6 +116,20 @@ func (s *Server) registerMemoRoutes(g *echo.Group) {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to patch memo").SetInternal(err) return echo.NewHTTPError(http.StatusInternalServerError, "Failed to patch memo").SetInternal(err)
} }
for _, resourceID := range memoPatch.ResourceIDList {
if _, err := s.Store.UpsertMemoResource(ctx, &api.MemoResourceUpsert{
MemoID: memo.ID,
ResourceID: resourceID,
}); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to upsert memo resource").SetInternal(err)
}
}
memo, err = s.Store.ComposeMemo(ctx, memo)
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to compose memo").SetInternal(err)
}
c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8) c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)
if err := json.NewEncoder(c.Response().Writer).Encode(composeResponse(memo)); err != nil { if err := json.NewEncoder(c.Response().Writer).Encode(composeResponse(memo)); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to encode memo response").SetInternal(err) return echo.NewHTTPError(http.StatusInternalServerError, "Failed to encode memo response").SetInternal(err)

@ -164,6 +164,7 @@ const MemoEditor: React.FC = () => {
await memoService.patchMemo({ await memoService.patchMemo({
id: prevMemo.id, id: prevMemo.id,
content, content,
resourceIdList: state.resourceList.map((resource) => resource.id),
}); });
} }
editorStateService.clearEditMemo(); editorStateService.clearEditMemo();

@ -30,6 +30,7 @@ interface MemoPatch {
createdTs?: TimeStamp; createdTs?: TimeStamp;
rowStatus?: RowStatus; rowStatus?: RowStatus;
content?: string; content?: string;
resourceIdList?: ResourceId[];
visibility?: Visibility; visibility?: Visibility;
} }

Loading…
Cancel
Save