Some checks are pending
Deploy BillAI / Deploy to Production (push) Waiting to run
- 将删除接口从 DELETE /api/bills/:id 改为 POST /api/bills/:id/delete 以兼容 SvelteKit 代理 - 分析页面组件 (TopExpenses/BillRecordsTable/DailyTrendChart) 支持删除并同步更新统计数据 - Review 接口改为直接查询 MongoDB 而非读取文件 - 软删除时记录 updated_at 时间戳 - 添加 .dockerignore 文件优化构建 - 完善 AGENTS.md 文档
43 lines
1.1 KiB
Go
43 lines
1.1 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 POST /api/bills/:id/delete 删除清洗后的账单记录
|
|
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: "删除成功"})
|
|
}
|