From 55e35dd327694435d81bb1a1d96a5b34485b1ec8 Mon Sep 17 00:00:00 2001 From: rxdn <29165304+rxdn@users.noreply.github.com> Date: Thu, 4 Aug 2022 22:24:06 +0100 Subject: [PATCH] Bump DB + Update messages --- .../endpoints/api/panel/multipaneldelete.go | 4 ++-- .../endpoints/api/panel/multipanelresend.go | 4 ++-- app/http/endpoints/api/panel/paneldelete.go | 5 +++++ app/http/endpoints/api/panel/panelresend.go | 18 ++++++++++-------- go.mod | 2 +- go.sum | 2 ++ 6 files changed, 22 insertions(+), 13 deletions(-) diff --git a/app/http/endpoints/api/panel/multipaneldelete.go b/app/http/endpoints/api/panel/multipaneldelete.go index 38cf4be..aaefad1 100644 --- a/app/http/endpoints/api/panel/multipaneldelete.go +++ b/app/http/endpoints/api/panel/multipaneldelete.go @@ -29,12 +29,12 @@ func MultiPanelDelete(ctx *gin.Context) { panel, ok, err := dbclient.Client.MultiPanels.Get(multiPanelId) if !ok { - ctx.JSON(404, utils.ErrorJson(errors.New("No panel with matching ID found"))) + ctx.JSON(404, utils.ErrorStr("No panel with matching ID found")) return } if panel.GuildId != guildId { - ctx.JSON(403, utils.ErrorJson(errors.New("Guild ID doesn't match"))) + ctx.JSON(403, utils.ErrorStr("Guild ID doesn't match")) return } diff --git a/app/http/endpoints/api/panel/multipanelresend.go b/app/http/endpoints/api/panel/multipanelresend.go index db19433..2907b52 100644 --- a/app/http/endpoints/api/panel/multipanelresend.go +++ b/app/http/endpoints/api/panel/multipanelresend.go @@ -32,13 +32,13 @@ func MultiPanelResend(ctx *gin.Context) { // check panel exists if !ok { - ctx.JSON(404, utils.ErrorJson(errors.New("No panel with the provided ID found"))) + ctx.JSON(404, utils.ErrorStr("No panel with the provided ID found")) return } // check panel is in the same guild if guildId != multiPanel.GuildId { - ctx.JSON(403, utils.ErrorJson(errors.New("Guild ID doesn't match"))) + ctx.JSON(403, utils.ErrorStr("Guild ID doesn't match")) return } diff --git a/app/http/endpoints/api/panel/paneldelete.go b/app/http/endpoints/api/panel/paneldelete.go index e585c3e..f49d304 100644 --- a/app/http/endpoints/api/panel/paneldelete.go +++ b/app/http/endpoints/api/panel/paneldelete.go @@ -32,6 +32,11 @@ func DeletePanel(ctx *gin.Context) { return } + if panel.PanelId == 0 { + ctx.JSON(404, utils.ErrorStr("Panel not found")) + return + } + // verify panel belongs to guild if panel.GuildId != guildId { ctx.JSON(403, utils.ErrorStr("Guild ID doesn't match")) diff --git a/app/http/endpoints/api/panel/panelresend.go b/app/http/endpoints/api/panel/panelresend.go index a55157f..41aa012 100644 --- a/app/http/endpoints/api/panel/panelresend.go +++ b/app/http/endpoints/api/panel/panelresend.go @@ -18,29 +18,31 @@ func ResendPanel(ctx *gin.Context) { botContext, err := botcontext.ContextForGuild(guildId) if err != nil { - ctx.AbortWithStatusJSON(500, utils.ErrorJson(err)) + ctx.JSON(500, utils.ErrorJson(err)) return } panelId, err := strconv.Atoi(ctx.Param("panelid")) if err != nil { - ctx.AbortWithStatusJSON(400, utils.ErrorJson(err)) + ctx.JSON(400, utils.ErrorJson(err)) return } // get existing panel, err := dbclient.Client.Panel.GetById(panelId) if err != nil { - ctx.AbortWithStatusJSON(500, utils.ErrorJson(err)) + ctx.JSON(500, utils.ErrorJson(err)) + return + } + + if panel.PanelId == 0 { + ctx.JSON(404, utils.ErrorStr("Panel not found")) return } // check guild ID matches if panel.GuildId != guildId { - ctx.AbortWithStatusJSON(400, gin.H{ - "success": false, - "error": "Guild ID does not match", - }) + ctx.JSON(403, utils.ErrorStr("Guild ID doesn't match")) return } @@ -73,7 +75,7 @@ func ResendPanel(ctx *gin.Context) { } if err = dbclient.Client.Panel.UpdateMessageId(panel.PanelId, msgId); err != nil { - ctx.AbortWithStatusJSON(500, utils.ErrorJson(err)) + ctx.JSON(500, utils.ErrorJson(err)) return } diff --git a/go.mod b/go.mod index 6d87587..a90b3d5 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/BurntSushi/toml v0.3.1 github.com/TicketsBot/archiverclient v0.0.0-20220326163414-558fd52746dc github.com/TicketsBot/common v0.0.0-20220703211704-f792aa9f0c42 - github.com/TicketsBot/database v0.0.0-20220803192010-3003f6bfcb73 + github.com/TicketsBot/database v0.0.0-20220804212316-6ff58741a775 github.com/TicketsBot/logarchiver v0.0.0-20220326162808-cdf0310f5e1c github.com/TicketsBot/worker v0.0.0-20220802140902-30ca73aea6b8 github.com/apex/log v1.1.2 diff --git a/go.sum b/go.sum index 147d438..044893d 100644 --- a/go.sum +++ b/go.sum @@ -41,6 +41,8 @@ github.com/TicketsBot/common v0.0.0-20220703211704-f792aa9f0c42 h1:3/qnbrEfL8gqS github.com/TicketsBot/common v0.0.0-20220703211704-f792aa9f0c42/go.mod h1:WxHh6bY7KhIqdayeOp5f0Zj2NNi/7QqCQfMEqHnpdAM= github.com/TicketsBot/database v0.0.0-20220803192010-3003f6bfcb73 h1:+KDNvovOyjYRIhoZvP2thtGvjQ4EI56Cf7rgXsQDhPE= github.com/TicketsBot/database v0.0.0-20220803192010-3003f6bfcb73/go.mod h1:gAtOoQKZfCkQ4AoNWQUSl51Fnlqk+odzD/hZ1e1sXyI= +github.com/TicketsBot/database v0.0.0-20220804212316-6ff58741a775 h1:QQwI2vEzGJmYESktKxDACA3EdtTBJWwo5elRcDxncbQ= +github.com/TicketsBot/database v0.0.0-20220804212316-6ff58741a775/go.mod h1:gAtOoQKZfCkQ4AoNWQUSl51Fnlqk+odzD/hZ1e1sXyI= github.com/TicketsBot/logarchiver v0.0.0-20220326162808-cdf0310f5e1c h1:OqGjFH6mbE6gd+NqI2ARJdtH3UUvhiAkD0r0fhGJK2s= github.com/TicketsBot/logarchiver v0.0.0-20220326162808-cdf0310f5e1c/go.mod h1:jgi2OXQKsd5nUnTIRkwvPmeuD/i7OhN68LKMssuQY1c= github.com/TicketsBot/ttlcache v1.6.1-0.20200405150101-acc18e37b261 h1:NHD5GB6cjlkpZFjC76Yli2S63/J2nhr8MuE6KlYJpQM=