Take body

This commit is contained in:
rxdn 2021-08-13 11:46:32 +01:00
parent 115debd941
commit f5dff928b7
5 changed files with 26 additions and 20 deletions

View File

@ -2,29 +2,31 @@ package api
import (
"github.com/TicketsBot/GoPanel/database"
"github.com/TicketsBot/GoPanel/utils"
"github.com/gin-gonic/gin"
)
func DeleteTag(ctx *gin.Context) {
guildId := ctx.Keys["guildid"].(uint64)
tagId := ctx.Param("tag")
if tagId == "" || len(tagId) > 16 {
ctx.JSON(400, gin.H{
"success": false,
"error": "Invalid tag",
})
type Body struct {
TagId string `json:"tag_id"`
}
var body Body
if err := ctx.BindJSON(&body); err != nil {
ctx.JSON(400, utils.ErrorJson(err))
return
}
if err := database.Client.Tag.Delete(guildId, tagId); err != nil {
ctx.JSON(500, gin.H{
"success": false,
"error": err.Error(),
})
if body.TagId == "" || len(body.TagId) > 16 {
ctx.JSON(400, utils.ErrorStr("Invalid tag"))
return
}
if err := database.Client.Tag.Delete(guildId, body.TagId); err != nil {
ctx.JSON(500, utils.ErrorJson(err))
} else {
ctx.JSON(200, gin.H{
"success": true,
})
ctx.JSON(200, utils.SuccessResponse)
}
}

View File

@ -84,7 +84,8 @@ func StartServer() {
guildAuthApiAdmin.PATCH("/multipanels/:panelid", api_panels.MultiPanelUpdate)
guildAuthApiAdmin.DELETE("/multipanels/:panelid", api_panels.MultiPanelDelete)
guildAuthApiSupport.GET("/transcripts", createLimiter(5, 5 * time.Second), createLimiter(20, time.Minute), api_transcripts.ListTranscripts)
// Should be a GET, but easier to take a body for development purposes
guildAuthApiSupport.POST("/transcripts", createLimiter(5, 5 * time.Second), createLimiter(20, time.Minute), api_transcripts.ListTranscripts)
// Allow regular users to get their own transcripts, make sure you check perms inside
guildApiNoAuth.GET("/transcripts/:ticketId", createLimiter(10, 10 * time.Second), api_transcripts.GetTranscriptHandler)
@ -95,7 +96,7 @@ func StartServer() {
guildAuthApiSupport.GET("/tags", api_tags.TagsListHandler)
guildAuthApiSupport.PUT("/tags", api_tags.CreateTag)
guildAuthApiSupport.DELETE("/tags/:tag", api_tags.DeleteTag)
guildAuthApiSupport.DELETE("/tags", api_tags.DeleteTag)
guildAuthApiAdmin.GET("/claimsettings", api_settings.GetClaimSettings)
guildAuthApiAdmin.POST("/claimsettings", api_settings.PostClaimSettings)

View File

@ -88,7 +88,11 @@
}
async function deleteTag(id) {
const res = await axios.delete(`${API_URL}/api/${guildId}/tags/${id}`);
const data = {
tag_id: id
};
const res = await axios.delete(`${API_URL}/api/${guildId}/tags`, {data: data});
if (res.status !== 200) {
notifyError(res.data.error);
return;

View File

@ -176,8 +176,7 @@
}
async function loadData(paginationSettings) {
let query = buildQuery(paginationSettings);
const res = await axios.get(`${API_URL}/api/${guildId}/transcripts?${query.toString()}`);
const res = await axios.post(`${API_URL}/api/${guildId}/transcripts`, paginationSettings);
if (res.status !== 200) {
notifyError(res.data.error);
return false;

2
go.mod
View File

@ -6,7 +6,7 @@ require (
github.com/BurntSushi/toml v0.3.1
github.com/TicketsBot/archiverclient v0.0.0-20210220155137-a562b2f1bbbb
github.com/TicketsBot/common v0.0.0-20210727134627-35eb7ed03a44
github.com/TicketsBot/database v0.0.0-20210808170243-bcb4f117ed18
github.com/TicketsBot/database v0.0.0-20210809170854-748ae1fff443
github.com/TicketsBot/worker v0.0.0-20210727130432-3df3cd1246a3
github.com/apex/log v1.1.2
github.com/boj/redistore v0.0.0-20180917114910-cd5dcc76aeff // indirect