From f6b2535cdb0e91659eb8e1601019c5f8a34419e8 Mon Sep 17 00:00:00 2001 From: yubo Date: Wed, 14 Apr 2021 12:48:26 +0800 Subject: [PATCH] bugfix: use InviteMustGet instead of InviteGet (#653) --- src/models/invite.go | 14 ++++++++++++++ src/modules/server/http/router_user.go | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/models/invite.go b/src/models/invite.go index a2569875..7a1c6d77 100644 --- a/src/models/invite.go +++ b/src/models/invite.go @@ -25,6 +25,20 @@ func InviteGet(where string, args ...interface{}) (*Invite, error) { return &obj, nil } +func InviteMustGet(where string, args ...interface{}) (*Invite, error) { + var obj Invite + has, err := DB["rdb"].Where(where, args...).Get(&obj) + if err != nil { + return nil, err + } + + if !has { + return nil, fmt.Errorf("invite not found") + } + + return &obj, nil +} + func InviteNew(token, creator string) error { now := time.Now().Unix() obj := Invite{ diff --git a/src/modules/server/http/router_user.go b/src/modules/server/http/router_user.go index d3f08d8c..1bbf5580 100644 --- a/src/modules/server/http/router_user.go +++ b/src/modules/server/http/router_user.go @@ -320,7 +320,7 @@ func userInvitePost(c *gin.Context) { return err } - inv, err := models.InviteGet("token=?", f.Token) + inv, err := models.InviteMustGet("token=?", f.Token) if err != nil { return err }