misc
This commit is contained in:
@@ -7,11 +7,22 @@ import (
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"git.dynamicdiscord.de/malobeo/portal/openapi"
|
||||
"git.dynamicdiscord.de/malobeo/portal/services"
|
||||
)
|
||||
|
||||
type AccessAuthController struct{}
|
||||
|
||||
type GroupWrapper struct {
|
||||
Name string
|
||||
Id int32
|
||||
}
|
||||
|
||||
type AccessAuthWithGroup struct {
|
||||
AccessAuth openapi.AccessAuthorizationResponse
|
||||
Groups []GroupWrapper
|
||||
}
|
||||
|
||||
func (gc *AccessAuthController) AccessAuthView(c *gin.Context) {
|
||||
accessAuths, err := services.AccessAuths.GetAll(c)
|
||||
|
||||
@@ -19,8 +30,32 @@ func (gc *AccessAuthController) AccessAuthView(c *gin.Context) {
|
||||
c.HTML(http.StatusBadRequest, "accessauths.html", gin.H{"data": gin.H{"error": err}})
|
||||
}
|
||||
|
||||
aaWrapper := []AccessAuthWithGroup{}
|
||||
for _, accessAuth := range accessAuths {
|
||||
|
||||
groupWrapper := []GroupWrapper{}
|
||||
for _, group := range accessAuth.Groups {
|
||||
groupWrapper = append(groupWrapper, GroupWrapper{
|
||||
Name: group.Name,
|
||||
Id: *group.Id.Get(),
|
||||
})
|
||||
|
||||
}
|
||||
aaWrapper = append(aaWrapper, AccessAuthWithGroup{
|
||||
AccessAuth: accessAuth,
|
||||
Groups: groupWrapper,
|
||||
})
|
||||
}
|
||||
|
||||
groups, err := services.Groups.GetAll(c)
|
||||
|
||||
if err != nil {
|
||||
c.HTML(http.StatusBadRequest, "accessauths.html", gin.H{"data": gin.H{"error": err}})
|
||||
}
|
||||
|
||||
data := CreateSessionData(c, gin.H{
|
||||
"accessAuths": accessAuths,
|
||||
"accessAuths": aaWrapper,
|
||||
"groups": groups,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
@@ -54,6 +89,8 @@ func (gc *AccessAuthController) AddAccessAuthHandler(c *gin.Context) {
|
||||
func (gc *AccessAuthController) AccessAuthHandler(c *gin.Context) {
|
||||
action := c.PostForm("action")
|
||||
idStr := c.Param("id")
|
||||
fmt.Println("AA ID: ")
|
||||
fmt.Println(idStr)
|
||||
id, err := strconv.Atoi(idStr)
|
||||
|
||||
if err != nil {
|
||||
@@ -63,10 +100,12 @@ func (gc *AccessAuthController) AccessAuthHandler(c *gin.Context) {
|
||||
}
|
||||
|
||||
if action == "createTimetable" {
|
||||
fmt.Println(c)
|
||||
weekdayStr := c.PostForm("weekday")
|
||||
starttime := c.PostForm("starttime")
|
||||
durationStr := c.PostForm("duration")
|
||||
duration, err := strconv.Atoi(durationStr)
|
||||
fmt.Printf("Creating timetable with %s, %s, %d", weekdayStr, starttime, duration)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
c.HTML(http.StatusBadRequest, "accessauths.html", gin.H{"error": err})
|
||||
@@ -89,6 +128,70 @@ func (gc *AccessAuthController) AccessAuthHandler(c *gin.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
if action == "addGroups" {
|
||||
fmt.Println("ADD GROUp")
|
||||
groupIds := c.PostFormArray("groups[]")
|
||||
|
||||
for _, groupIdStr := range groupIds {
|
||||
groupId, err := strconv.Atoi(groupIdStr)
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
c.HTML(http.StatusBadRequest, "accessauths.html", gin.H{"error": err})
|
||||
return
|
||||
}
|
||||
|
||||
err = services.AccessAuths.AddGroup(c, int32(id), int32(groupId))
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
c.HTML(http.StatusBadRequest, "accessauths.html", gin.H{"error": err})
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if action == "removeGroup" {
|
||||
fmt.Println("REMOVE GROUp")
|
||||
fmt.Println(c)
|
||||
groupIdStr := c.PostForm("groupId")
|
||||
fmt.Println(groupIdStr)
|
||||
groupId, err := strconv.Atoi(groupIdStr)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
c.HTML(http.StatusBadRequest, "accessauths.html", gin.H{"error": err})
|
||||
return
|
||||
}
|
||||
|
||||
err = services.AccessAuths.RemoveGroup(c, int32(id), int32(groupId))
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
c.HTML(http.StatusBadRequest, "accessauths.html", gin.H{"error": err})
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if action == "activate" {
|
||||
_, err := services.AccessAuths.SetActive(c, int32(id), true)
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
c.HTML(http.StatusBadRequest, "accessauths.html", gin.H{"error": err})
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if action == "deactivate" {
|
||||
_, err := services.AccessAuths.SetActive(c, int32(id), false)
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
c.HTML(http.StatusBadRequest, "accessauths.html", gin.H{"error": err})
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if action == "delete" {
|
||||
err := services.AccessAuths.Delete(c, int32(id))
|
||||
|
||||
|
||||
@@ -62,6 +62,17 @@ func (gc *GroupController) GroupHandler(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if action == "addCard" {
|
||||
cardName := c.PostForm("Name")
|
||||
_, err := services.Cards.Create(c, cardName, int32(id))
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
c.HTML(http.StatusBadRequest, "accessauths.html", gin.H{"error": err})
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if action == "delete" {
|
||||
err := services.Groups.Delete(c, int32(id))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user