Files
billai/server/handler/delete_bill.go
clz bacbabc0a5 feat: 添加账单软删除功能
- 新增删除按钮(带二次确认)到账单详情抽屉
- 后端实现软删除(设置 is_deleted 标记)
- 所有查询方法自动过滤已删除记录
- 账单列表和复核页面都支持删除
- 版本更新至 1.2.0
2026-01-25 18:49:07 +08:00

43 lines
1.0 KiB
Go

package handler
import (
"net/http"
"strings"
"github.com/gin-gonic/gin"
"billai-server/repository"
)
type DeleteBillResponse struct {
Result bool `json:"result"`
Message string `json:"message,omitempty"`
}
// DeleteBill DELETE /api/bills/:id 删除清洗后的账单记录
func DeleteBill(c *gin.Context) {
id := strings.TrimSpace(c.Param("id"))
if id == "" {
c.JSON(http.StatusBadRequest, DeleteBillResponse{Result: false, Message: "缺少账单 ID"})
return
}
repo := repository.GetRepository()
if repo == nil {
c.JSON(http.StatusInternalServerError, DeleteBillResponse{Result: false, Message: "数据库未连接"})
return
}
err := repo.DeleteCleanedBillByID(id)
if err != nil {
if err == repository.ErrNotFound {
c.JSON(http.StatusNotFound, DeleteBillResponse{Result: false, Message: "账单不存在"})
return
}
c.JSON(http.StatusInternalServerError, DeleteBillResponse{Result: false, Message: "删除失败: " + err.Error()})
return
}
c.JSON(http.StatusOK, DeleteBillResponse{Result: true, Message: "删除成功"})
}