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
This commit is contained in:
+38
-6
@@ -278,9 +278,25 @@ func (s *Server) handleCreateBinding(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) handleDeleteBinding(c *gin.Context) {
|
func (s *Server) handleDeleteBinding(c *gin.Context) {
|
||||||
_ = c.Param("id")
|
id := c.Param("id")
|
||||||
// TODO: Convert to uint and delete
|
if id == "" {
|
||||||
c.JSON(http.StatusOK, gin.H{"message": "Binding deleted"})
|
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) {
|
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) {
|
func (s *Server) handleDeleteRecord(c *gin.Context) {
|
||||||
_ = c.Param("id")
|
id := c.Param("id")
|
||||||
// TODO: Convert to uint and delete
|
if id == "" {
|
||||||
c.JSON(http.StatusOK, gin.H{"message": "Record deleted"})
|
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) {
|
func (s *Server) handleGetLogs(c *gin.Context) {
|
||||||
|
|||||||
Reference in New Issue
Block a user