mirror of
https://github.com/ordinary-dev/phoenix
synced 2024-09-20 03:40:29 +05:00
30 lines
592 B
Go
30 lines
592 B
Go
package views
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/ordinary-dev/phoenix/config"
|
|
"github.com/ordinary-dev/phoenix/database"
|
|
"gorm.io/gorm"
|
|
"net/http"
|
|
)
|
|
|
|
func ShowMainPage(cfg *config.Config, db *gorm.DB) gin.HandlerFunc {
|
|
return func(ctx *gin.Context) {
|
|
// Get a list of groups with links
|
|
var groups []database.Group
|
|
result := db.
|
|
Model(&database.Group{}).
|
|
Preload("Links").
|
|
Find(&groups)
|
|
|
|
if result.Error != nil {
|
|
ShowError(ctx, cfg, result.Error)
|
|
return
|
|
}
|
|
|
|
Render(ctx, cfg, http.StatusOK, "index.html.tmpl", gin.H{
|
|
"groups": groups,
|
|
})
|
|
}
|
|
}
|