Fix DNS record and static binding deletion

- Implement actual deletion in handleDeleteRecord (was just returning success)
- Implement actual deletion in handleDeleteBinding (was just returning success)
- Add proper ID validation and error handling
- Check rows affected and return 404 if not found
这个提交包含在:
CNBUGS AI
2026-04-24 17:42:33 +08:00
父节点 5bb84c159a
当前提交 7d54c165a9
+38 -6
查看文件
@@ -278,9 +278,25 @@ func (s *Server) handleCreateBinding(c *gin.Context) {
}
func (s *Server) handleDeleteBinding(c *gin.Context) {
_ = c.Param("id")
// TODO: Convert to uint and delete
c.JSON(http.StatusOK, gin.H{"message": "Binding deleted"})
id := c.Param("id")
if id == "" {
c.JSON(http.StatusBadRequest, gin.H{"error": "ID is required"})
return
}
// Delete from database
result := s.db.Where("id = ?", id).Delete(&db.DHCPStaticBinding{})
if result.Error != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": result.Error.Error()})
return
}
if result.RowsAffected == 0 {
c.JSON(http.StatusNotFound, gin.H{"error": "Binding not found"})
return
}
c.JSON(http.StatusOK, gin.H{"message": "Binding deleted successfully"})
}
func (s *Server) handleEvictClient(c *gin.Context) {
@@ -338,9 +354,25 @@ func (s *Server) handleCreateRecord(c *gin.Context) {
}
func (s *Server) handleDeleteRecord(c *gin.Context) {
_ = c.Param("id")
// TODO: Convert to uint and delete
c.JSON(http.StatusOK, gin.H{"message": "Record deleted"})
id := c.Param("id")
if id == "" {
c.JSON(http.StatusBadRequest, gin.H{"error": "ID is required"})
return
}
// Delete from database
result := s.db.Where("id = ?", id).Delete(&db.DNSRecord{})
if result.Error != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": result.Error.Error()})
return
}
if result.RowsAffected == 0 {
c.JSON(http.StatusNotFound, gin.H{"error": "Record not found"})
return
}
c.JSON(http.StatusOK, gin.H{"message": "Record deleted successfully"})
}
func (s *Server) handleGetLogs(c *gin.Context) {