feat: WIP group handling

This commit is contained in:
2026-06-25 12:38:52 +02:00
parent a07940df20
commit 2c3afacf85
3 changed files with 109 additions and 3 deletions

View File

@@ -0,0 +1,51 @@
package controllers
import (
"fmt"
"net/http"
"github.com/gin-gonic/gin"
"git.dynamicdiscord.de/malobeo/portal/services"
)
type GroupController struct{}
func (gc *GroupController) GroupView(c *gin.Context) {
groups, err := services.Groups.GetAll(c)
if err != nil {
c.HTML(http.StatusBadRequest, "groups.html", gin.H{"data": gin.H{"error": err}})
}
data := CreateSessionData(c, gin.H{
"groups": groups,
})
if err != nil {
c.HTML(http.StatusBadRequest, "groups.html", data)
}
c.HTML(http.StatusOK, "groups.html", data)
}
func (gc *GroupController) AddGroupHandler(c *gin.Context) {
name := c.PostForm("name")
if len(name) == 0 {
fmt.Println("Adding group with empty name is forbidden")
c.HTML(http.StatusBadRequest, "groups.html", gin.H{"error": "Cant create group without name"})
return
}
err := services.Groups.Create(c, name)
if err != nil {
fmt.Println(err)
c.HTML(http.StatusBadRequest, "groups.html", gin.H{"error": err})
return
}
gc.GroupView(c)
}