Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Add private API endpoints for memory share CRUD

AmanRajSinghMouryacdc106d22454
diff --git a/server/pkg/api/memory_share.go b/server/pkg/api/memory_share.go
new file mode 100644
index 0000000000..ef9ecd7f89
--- /dev/null
+++ b/server/pkg/api/memory_share.go
@@ -0,0 +1,86 @@
+package api
+
+import (
+ "net/http"
+ "strconv"
+
+ "github.com/ente-io/museum/ente"
+ "github.com/ente-io/museum/pkg/controller/memory_share"
+ "github.com/ente-io/museum/pkg/utils/auth"
+ "github.com/ente-io/museum/pkg/utils/handler"
+ "github.com/ente-io/stacktrace"
+ "github.com/gin-gonic/gin"
+)
+
+// MemoryShareHandler exposes request handlers for memory share operations
+type MemoryShareHandler struct {
+ Controller *memory_share.Controller
+}
+
+// Create creates a new memory share
+func (h *MemoryShareHandler) Create(c *gin.Context) {
+ var req ente.CreateMemoryShareRequest
+ if err := c.ShouldBindJSON(&req); err != nil {
+ handler.Error(c, stacktrace.Propagate(ente.ErrBadRequest, "invalid request body"))
+ return
+ }
+
+ userID := auth.GetUserID(c.Request.Header)
+ resp, err := h.Controller.Create(c, userID, req)
+ if err != nil {
+ handler.Error(c, stacktrace.Propagate(err, "failed to create memory share"))
+ return
+ }
+
+ c.JSON(http.StatusOK, resp)
+}
+
+// List returns all memory shares for the authenticated user
+func (h *MemoryShareHandler) List(c *gin.Context) {
+ userID := auth.GetUserID(c.Request.Header)
+ resp, err := h.Controller.List(c, userID)
+ if err != nil {
+ handler.Error(c, stacktrace.Propagate(err, "failed to list memory shares"))
+ return
+ }
+
+ c.JSON(http.StatusOK, resp)
+}
+
+// Delete soft-deletes a memory share
+func (h *MemoryShareHandler) Delete(c *gin.Context) {
+ shareID, err := strconv.ParseInt(c.Param("shareID"), 10, 64)
+ if err != nil {
+ handler.Error(c, stacktrace.Propagate(ente.ErrBadRequest, "invalid share ID"))
+ return
+ }
+
+ userID := auth.GetUserID(c.Request.Header)
+ err = h.Controller.Delete(c, userID, shareID)
+ if err != nil {
+ handler.Error(c, stacktrace.Propagate(err, "failed to delete memory share"))
+ return
+ }
+
+ c.JSON(http.StatusOK, gin.H{})
+}
+
+// GetByID returns a memory share by ID (for owner only)
+func (h *MemoryShareHandler) GetByID(c *gin.Context) {
+ shareID, err := strconv.ParseInt(c.Param("shareID"), 10, 64)
+ if err != nil {
+ handler.Error(c, stacktrace.Propagate(ente.ErrBadRequest, "invalid share ID"))
+ return
+ }
+
+ userID := auth.GetUserID(c.Request.Header)
+ share, err := h.Controller.GetByID(c, userID, shareID)
+ if err != nil {
+ handler.Error(c, stacktrace.Propagate(err, "failed to get memory share"))
+ return
+ }
+
+ c.JSON(http.StatusOK, gin.H{
+ "memoryShare": share,
+ })
+}