Skip to content

armgit / memos

Public Imported from GitHub
0

Memos is an open-source, self-hosted note-taking app that brings your everyday thoughts together in a personal timeline. Your data stays yours, and you choose what to keep private or share.

feat: add `linkedMemoAmount` to resource

steven85dc29bfb9d8
diff --git a/api/resource.go b/api/resource.go
index f232aa775..11dc157a6 100644
--- a/api/resource.go
+++ b/api/resource.go
@@ -13,6 +13,9 @@ type Resource struct {
Blob []byte `json:"-"`
Type string `json:"type"`
Size int64 `json:"size"`
+
+ // Related fields
+ LinkedMemoAmount int `json:"linkedMemoAmount"`
}
type ResourceCreate struct {
diff --git a/server/resource.go b/server/resource.go
index 5f4e0ed23..04f3abe28 100644
--- a/server/resource.go
+++ b/server/resource.go
@@ -80,6 +80,16 @@ func (s *Server) registerResourceRoutes(g *echo.Group) {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to fetch resource list").SetInternal(err)
}
+ for _, resource := range list {
+ memoResoureceList, err := s.Store.FindMemoResourceList(ctx, &api.MemoResourceFind{
+ ResourceID: &resource.ID,
+ })
+ if err != nil {
+ return echo.NewHTTPError(http.StatusInternalServerError, "Failed to find memo resource list").SetInternal(err)
+ }
+ resource.LinkedMemoAmount = len(memoResoureceList)
+ }
+
c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)
if err := json.NewEncoder(c.Response().Writer).Encode(composeResponse(list)); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to encode resource list response").SetInternal(err)
diff --git a/store/resource.go b/store/resource.go
index ba90ce2d5..9e386edf4 100644
--- a/store/resource.go
+++ b/store/resource.go
@@ -223,7 +223,7 @@ func findResourceList(ctx context.Context, tx *sql.Tx, find *api.ResourceFind) (
updated_ts
FROM resource
WHERE ` + strings.Join(where, " AND ") + `
- ORDER BY created_ts DESC
+ ORDER BY id DESC
`
rows, err := tx.QueryContext(ctx, query, args...)
if err != nil {