52 lines
1005 B
Go
52 lines
1005 B
Go
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)
|
|
}
|