feat: WIP group handling
This commit is contained in:
51
controllers/groupController.go
Normal file
51
controllers/groupController.go
Normal 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)
|
||||
}
|
||||
Reference in New Issue
Block a user