package forms import ( dbclient "github.com/TicketsBot/GoPanel/database" "github.com/TicketsBot/GoPanel/utils" "github.com/gin-gonic/gin" "strconv" ) func UpdateForm(ctx *gin.Context) { guildId := ctx.Keys["guildid"].(uint64) var data createFormBody if err := ctx.BindJSON(&data); err != nil { ctx.JSON(400, utils.ErrorJson(err)) return } if len(data.Title) > 45 { ctx.JSON(400, utils.ErrorStr("Title is too long")) return } formId, err := strconv.Atoi(ctx.Param("form_id")) if err != nil { ctx.JSON(400, utils.ErrorStr("Invalid form ID")) return } form, ok, err := dbclient.Client.Forms.Get(formId) if err != nil { ctx.JSON(500, utils.ErrorJson(err)) return } if !ok { ctx.JSON(404, utils.ErrorStr("Form not found")) return } if form.GuildId != guildId { ctx.JSON(403, utils.ErrorStr("Form does not belong to this guild")) return } if err := dbclient.Client.Forms.UpdateTitle(formId, data.Title); err != nil { ctx.JSON(500, utils.ErrorJson(err)) return } ctx.JSON(200, utils.SuccessResponse) }