migrations

This commit is contained in:
rxdn 2021-05-28 13:08:13 +01:00
parent 7336d50d62
commit 90d6b5f72a
4 changed files with 19 additions and 23 deletions

View File

@ -137,7 +137,7 @@ func CreatePanel(ctx *gin.Context) {
// string is role ID or "user" to mention the ticket opener // string is role ID or "user" to mention the ticket opener
for _, mention := range data.Mentions { for _, mention := range data.Mentions {
if mention == "user" { if mention == "user" {
if err = dbclient.Client.PanelUserMention.Set(msgId, true); err != nil { if err = dbclient.Client.PanelUserMention.Set(panelId, true); err != nil {
ctx.AbortWithStatusJSON(500, gin.H{ ctx.AbortWithStatusJSON(500, gin.H{
"success": false, "success": false,
"error": err.Error(), "error": err.Error(),
@ -157,7 +157,7 @@ func CreatePanel(ctx *gin.Context) {
// should we check the role is a valid role in the guild? // should we check the role is a valid role in the guild?
// not too much of an issue if it isnt // not too much of an issue if it isnt
if err = dbclient.Client.PanelRoleMentions.Add(msgId, roleId); err != nil { if err = dbclient.Client.PanelRoleMentions.Add(panelId, roleId); err != nil {
ctx.AbortWithStatusJSON(500, gin.H{ ctx.AbortWithStatusJSON(500, gin.H{
"success": false, "success": false,
"error": err.Error(), "error": err.Error(),
@ -214,7 +214,7 @@ func (p *panelBody) doValidations(ctx *gin.Context, guildId uint64) bool {
if !p.verifyTitle() { if !p.verifyTitle() {
ctx.AbortWithStatusJSON(400, gin.H{ ctx.AbortWithStatusJSON(400, gin.H{
"success": false, "success": false,
"error": "Panel titles must be between 1 - 255 characters in length", "error": "Panel titles must be between 1 - 80 characters in length",
}) })
return false return false
} }
@ -266,7 +266,7 @@ func (p *panelBody) doValidations(ctx *gin.Context, guildId uint64) bool {
} }
func (p *panelBody) verifyTitle() bool { func (p *panelBody) verifyTitle() bool {
return len(p.Title) > 0 && len(p.Title) < 256 return len(p.Title) > 0 && len(p.Title) <= 80
} }
func (p *panelBody) verifyContent() bool { func (p *panelBody) verifyContent() bool {

View File

@ -48,7 +48,7 @@ func ListPanels(ctx *gin.Context) {
var mentions []string var mentions []string
// get role mentions // get role mentions
roles, err := dbclient.Client.PanelRoleMentions.GetRoles(p.MessageId) roles, err := dbclient.Client.PanelRoleMentions.GetRoles(p.PanelId)
if err != nil { if err != nil {
return err return err
} }
@ -59,7 +59,7 @@ func ListPanels(ctx *gin.Context) {
} }
// get if we should mention the ticket opener // get if we should mention the ticket opener
shouldMention, err := dbclient.Client.PanelUserMention.ShouldMentionUser(p.MessageId) shouldMention, err := dbclient.Client.PanelUserMention.ShouldMentionUser(p.PanelId)
if err != nil { if err != nil {
return err return err
} }

View File

@ -166,24 +166,16 @@ func UpdatePanel(ctx *gin.Context) {
// insert role mention data // insert role mention data
// delete old data // delete old data
if err = dbclient.Client.PanelRoleMentions.DeleteAll(newMessageId); err != nil { if err = dbclient.Client.PanelRoleMentions.DeleteAll(panel.PanelId); err != nil {
ctx.AbortWithStatusJSON(500, utils.ErrorJson(err))
return
}
// TODO: Reduce to 1 query
if err = dbclient.Client.PanelUserMention.Set(newMessageId, false); err != nil {
ctx.AbortWithStatusJSON(500, utils.ErrorJson(err)) ctx.AbortWithStatusJSON(500, utils.ErrorJson(err))
return return
} }
// string is role ID or "user" to mention the ticket opener // string is role ID or "user" to mention the ticket opener
var shouldMentionUser bool
for _, mention := range data.Mentions { for _, mention := range data.Mentions {
if mention == "user" { if mention == "user" {
if err = dbclient.Client.PanelUserMention.Set(newMessageId, true); err != nil { shouldMentionUser = true
ctx.AbortWithStatusJSON(500, utils.ErrorJson(err))
return
}
} else { } else {
roleId, err := strconv.ParseUint(mention, 10, 64) roleId, err := strconv.ParseUint(mention, 10, 64)
if err != nil { if err != nil {
@ -193,14 +185,18 @@ func UpdatePanel(ctx *gin.Context) {
// should we check the role is a valid role in the guild? // should we check the role is a valid role in the guild?
// not too much of an issue if it isnt // not too much of an issue if it isnt
if err = dbclient.Client.PanelRoleMentions.Add(panel.PanelId, roleId); err != nil {
if err = dbclient.Client.PanelRoleMentions.Add(newMessageId, roleId); err != nil {
ctx.AbortWithStatusJSON(500, utils.ErrorJson(err)) ctx.AbortWithStatusJSON(500, utils.ErrorJson(err))
return return
} }
} }
} }
if err = dbclient.Client.PanelUserMention.Set(panel.PanelId, shouldMentionUser); err != nil {
ctx.AbortWithStatusJSON(500, utils.ErrorJson(err))
return
}
// insert support teams // insert support teams
// TODO: Stop race conditions - 1 transaction // TODO: Stop race conditions - 1 transaction
// delete teams // delete teams

8
go.mod
View File

@ -5,9 +5,9 @@ go 1.14
require ( require (
github.com/BurntSushi/toml v0.3.1 github.com/BurntSushi/toml v0.3.1
github.com/TicketsBot/archiverclient v0.0.0-20210220155137-a562b2f1bbbb github.com/TicketsBot/archiverclient v0.0.0-20210220155137-a562b2f1bbbb
github.com/TicketsBot/common v0.0.0-20210508230445-142f7765b87f github.com/TicketsBot/common v0.0.0-20210527174309-f7344004ae32
github.com/TicketsBot/database v0.0.0-20210526225555-040a69389e53 github.com/TicketsBot/database v0.0.0-20210528120222-49534148fc63
github.com/TicketsBot/worker v0.0.0-20210526230503-cf3fa42fed99 github.com/TicketsBot/worker v0.0.0-20210528120548-e0e37646be05
github.com/apex/log v1.1.2 github.com/apex/log v1.1.2
github.com/boj/redistore v0.0.0-20180917114910-cd5dcc76aeff // indirect github.com/boj/redistore v0.0.0-20180917114910-cd5dcc76aeff // indirect
github.com/dgrijalva/jwt-go v3.2.0+incompatible github.com/dgrijalva/jwt-go v3.2.0+incompatible
@ -21,7 +21,7 @@ require (
github.com/jackc/pgx/v4 v4.7.1 github.com/jackc/pgx/v4 v4.7.1
github.com/pasztorpisti/qs v0.0.0-20171216220353-8d6c33ee906c github.com/pasztorpisti/qs v0.0.0-20171216220353-8d6c33ee906c
github.com/pkg/errors v0.9.1 github.com/pkg/errors v0.9.1
github.com/rxdn/gdl v0.0.0-20210527124215-63f4791eb845 github.com/rxdn/gdl v0.0.0-20210527190730-a6b87abf7fc8
github.com/sirupsen/logrus v1.5.0 github.com/sirupsen/logrus v1.5.0
github.com/ulule/limiter/v3 v3.5.0 github.com/ulule/limiter/v3 v3.5.0
golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a