Selaa lähdekoodia

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 1 kuukausi sitten
vanhempi
sitoutus
7d54c165a9
1 muutettua tiedostoa jossa 38 lisäystä ja 6 poistoa
  1. 38 6
      internal/web/server.go

+ 38 - 6
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) {