From 7d54c165a90529e36f69d58415b1241bb5992026 Mon Sep 17 00:00:00 2001 From: CNBUGS AI Date: Fri, 24 Apr 2026 17:42:33 +0800 Subject: [PATCH] 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 --- internal/web/server.go | 44 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/internal/web/server.go b/internal/web/server.go index 3300194..4453422 100644 --- a/internal/web/server.go +++ b/internal/web/server.go @@ -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) {