mirror of
https://github.com/Dvorinka/MyClubServer.git
synced 2026-06-04 02:32:57 +00:00
dev day #63
This commit is contained in:
@@ -108,15 +108,28 @@ func (nc *NavigationController) CreateNavigationItem(c *gin.Context) {
|
||||
// If no display order is set, put it at the end
|
||||
if item.DisplayOrder == 0 {
|
||||
var maxOrder int
|
||||
nc.DB.Model(&models.NavigationItem{}).
|
||||
Where("parent_id IS NULL").
|
||||
Select("COALESCE(MAX(display_order), -1) + 1").
|
||||
Scan(&maxOrder)
|
||||
query := nc.DB.Model(&models.NavigationItem{})
|
||||
|
||||
// Calculate max order for items at the same level (same parent) and same admin status
|
||||
if item.ParentID == nil {
|
||||
query = query.Where("parent_id IS NULL")
|
||||
} else {
|
||||
query = query.Where("parent_id = ?", *item.ParentID)
|
||||
}
|
||||
|
||||
// Also consider requires_admin to keep frontend and admin items separate
|
||||
query = query.Where("requires_admin = ?", item.RequiresAdmin)
|
||||
|
||||
query.Select("COALESCE(MAX(display_order), -1) + 1").Scan(&maxOrder)
|
||||
item.DisplayOrder = maxOrder
|
||||
}
|
||||
|
||||
if err := nc.DB.Create(&item).Error; err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to create navigation item"})
|
||||
// Log the actual error for debugging
|
||||
c.JSON(http.StatusInternalServerError, gin.H{
|
||||
"error": "Failed to create navigation item",
|
||||
"details": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -169,7 +182,10 @@ func (nc *NavigationController) UpdateNavigationItem(c *gin.Context) {
|
||||
item.RequiresAdmin = updates.RequiresAdmin
|
||||
|
||||
if err := nc.DB.Save(&item).Error; err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to update navigation item"})
|
||||
c.JSON(http.StatusInternalServerError, gin.H{
|
||||
"error": "Failed to update navigation item",
|
||||
"details": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user