feat: add file move and trash retention
This commit is contained in:
@@ -156,10 +156,38 @@ func (h *NodeHandler) Update(w http.ResponseWriter, r *http.Request) {
|
||||
writeJSON(w, http.StatusOK, node)
|
||||
}
|
||||
|
||||
func (h *NodeHandler) Move(w http.ResponseWriter, r *http.Request) {
|
||||
var req model.MoveNodeRequest
|
||||
if err := decodeJSON(r, &req); err != nil {
|
||||
writeError(w, http.StatusBadRequest, "invalid json")
|
||||
return
|
||||
}
|
||||
userID := commonmw.GetUserID(r.Context())
|
||||
if !h.requireWritableParent(w, r, userID, req.ParentID) {
|
||||
return
|
||||
}
|
||||
node, err := h.repo.Move(r.Context(), chi.URLParam(r, "id"), userID, subordinates(r), req.ParentID)
|
||||
if errors.Is(err, repository.ErrNotFound) {
|
||||
writeError(w, http.StatusNotFound, "file not found")
|
||||
return
|
||||
}
|
||||
if errors.Is(err, model.ErrInvalidMove) {
|
||||
writeError(w, http.StatusBadRequest, "folder cannot be moved inside itself")
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
writeInternalError(w, r, err, "failed to move file")
|
||||
return
|
||||
}
|
||||
h.repo.Audit(r.Context(), userID, "files.node_move", "files_node", node.ID, "{}")
|
||||
writeJSON(w, http.StatusOK, node)
|
||||
}
|
||||
|
||||
func (h *NodeHandler) Delete(w http.ResponseWriter, r *http.Request) {
|
||||
userID := commonmw.GetUserID(r.Context())
|
||||
id := chi.URLParam(r, "id")
|
||||
if err := h.repo.SoftDelete(r.Context(), id, userID); errors.Is(err, repository.ErrNotFound) {
|
||||
purgeAfter := time.Now().Add(30 * 24 * time.Hour)
|
||||
if err := h.repo.SoftDelete(r.Context(), id, userID, purgeAfter); errors.Is(err, repository.ErrNotFound) {
|
||||
writeError(w, http.StatusNotFound, "file not found")
|
||||
return
|
||||
} else if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user