From dbc766a2c5bb62949a0c061717c718ab58a57a03 Mon Sep 17 00:00:00 2001 From: kalipso Date: Sat, 8 Aug 2026 16:21:55 +0200 Subject: [PATCH] fix: misc --- controllers/groupController.go | 12 +++++++++++- internal/api_client.go | 5 +++-- services/cardService.go | 15 +++++++++++++++ views/accessauths.html | 14 +++++++------- views/groups.html | 10 +++++++--- 5 files changed, 43 insertions(+), 13 deletions(-) diff --git a/controllers/groupController.go b/controllers/groupController.go index 9c4a176..e70c4ed 100644 --- a/controllers/groupController.go +++ b/controllers/groupController.go @@ -63,7 +63,7 @@ func (gc *GroupController) GroupHandler(c *gin.Context) { } if action == "addCard" { - cardName := c.PostForm("Name") + cardName := c.PostForm("name") _, err := services.Cards.Create(c, cardName, int32(id)) if err != nil { @@ -73,6 +73,16 @@ func (gc *GroupController) GroupHandler(c *gin.Context) { } } + if action == "deleteCard" { + err := services.Cards.Delete(c) + + 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)) diff --git a/internal/api_client.go b/internal/api_client.go index 58015a4..6341cfb 100644 --- a/internal/api_client.go +++ b/internal/api_client.go @@ -4,13 +4,14 @@ import ( "fmt" "git.dynamicdiscord.de/malobeo/portal/openapi" "github.com/gin-gonic/gin" + "os" ) func GetApiClient(c *gin.Context) *openapi.APIClient { configuration := openapi.NewConfiguration() //TODO: read from env - configuration.Host = "localhost:8000" - configuration.Scheme = "http" + configuration.Host = os.Getenv("GATEKEEPER_HOST") + configuration.Scheme = os.Getenv("GATEKEEPER_SCHEME") if c != nil { authToken, err := c.Cookie("Authorization") diff --git a/services/cardService.go b/services/cardService.go index 6b166ca..3fb800f 100644 --- a/services/cardService.go +++ b/services/cardService.go @@ -32,6 +32,21 @@ func (u *CardService) Create(c *gin.Context, name string, groupId int32) (*opena return resp, nil } +func (u *CardService) Delete(c *gin.Context) error { + apiClient := internal.GetApiClient(c) + + resp, r, err := apiClient.CardAPI.DelCardApiV1CardsDelete(context.Background()).Execute() + + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `CardAPI.DelCardApiV1CardsDelete``: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + return err + } + // response from `LoginForAccessTokenTokenPost`: Token + fmt.Fprintf(os.Stdout, "Response from `CardAPI.CreateCardCardsPost`: %v\n", resp) + return nil +} + func (u *CardService) GetCardsByGroup(c *gin.Context, groupId int32) ([]openapi.Card, error) { apiClient := internal.GetApiClient(c) diff --git a/views/accessauths.html b/views/accessauths.html index 13c5ddf..6378012 100644 --- a/views/accessauths.html +++ b/views/accessauths.html @@ -35,13 +35,13 @@
diff --git a/views/groups.html b/views/groups.html index 3d208d9..6a42183 100644 --- a/views/groups.html +++ b/views/groups.html @@ -21,12 +21,12 @@
-
+ {{ range .Cards }}
{{ .Name }} - {{ .CardSerial }}
-
@@ -34,13 +34,17 @@
-
+
+
+ +