phoenix/views/index.go

27 lines
464 B
Go
Raw Normal View History

2023-04-09 11:22:48 +05:00
package views
import (
"github.com/gin-gonic/gin"
2023-07-22 15:24:01 +05:00
"github.com/ordinary-dev/phoenix/database"
2023-04-09 11:22:48 +05:00
"gorm.io/gorm"
"net/http"
)
func ShowMainPage(c *gin.Context, db *gorm.DB) {
// Get a list of groups with links
2023-07-22 15:24:01 +05:00
var groups []database.Group
result := db.
2023-07-22 15:24:01 +05:00
Model(&database.Group{}).
Preload("Links").
Find(&groups)
if result.Error != nil {
ShowError(c, result.Error)
2023-04-09 11:22:48 +05:00
return
}
c.HTML(http.StatusOK, "index.html.tmpl", gin.H{
"groups": groups,
})
}