123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- package web
- import (
- "log"
- "net/http"
- "net/url"
- "strings"
- "github.com/gin-contrib/sessions"
- "github.com/gin-gonic/gin"
- csrf "github.com/utrack/gin-csrf"
- "code.osinet.fr/fgm/sqs_demo/back/services/redriver"
- )
- func makeDeleteHandler(rd redriver.Redriver) gin.HandlerFunc {
- type IDList struct {
- ID string `form:"id"`
- }
- const prefix = "id-"
- parseIDs := func(q url.Values) []string {
- var ids []string
- for k, vs := range q {
-
- if pos := strings.Index(k, prefix); pos == -1 || len(vs) != 1 || vs[0] != "on" {
- continue
- }
- b, a, found := strings.Cut(k, prefix)
- if b == "" && found {
- ids = append(ids, a)
- }
- }
- return ids
- }
- return func(c *gin.Context) {
- qName := c.Param("name")
- ids := parseIDs(c.Request.URL.Query())
- sess := sessions.Default(c)
- flashes := sess.Flashes()
- token := csrf.GetToken(c)
- sess.Save()
- log.Println(ids)
- c.HTML(http.StatusOK, "confirm", gin.H{
- "flashes": flashes,
- "question": "Do you confirm this deletion request ?",
- "description": "These messages cannot be recovered after that step",
- "list": ids,
- "cancel": "Cancel",
- "confirm": "Delete",
- "csrf": token,
- "redirect": "/queue/" + qName,
- })
- }
- return nil
- }
- func makeDeleteConfirmHandler(rd redriver.Redriver) gin.HandlerFunc {
- return func(c *gin.Context) {
- c.JSON(http.StatusServiceUnavailable, gin.H{
- "message": "deletion confirmation",
- "error": "not implemented",
- })
- }
- }
|