/
remove.go
42 lines (33 loc) · 994 Bytes
/
remove.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package vault
import (
"github.com/Liphium/station/backend/database"
"github.com/Liphium/station/backend/entities/account/properties"
"github.com/Liphium/station/backend/util"
"github.com/gofiber/fiber/v2"
"gorm.io/gorm"
)
type removeRequest struct {
ID string `json:"id"`
}
// Route: /account/vault/remove
func removeEntry(c *fiber.Ctx) error {
// Parse request
var req removeRequest
if err := util.BodyParser(c, &req); err != nil {
return util.InvalidRequest(c)
}
// Check if entry exists
accId := util.GetAcc(c)
var entry properties.VaultEntry
if err := database.DBConn.Where("id = ? AND account = ?", req.ID, accId).Take(&entry).Error; err != nil {
if err == gorm.ErrRecordNotFound {
return util.FailedRequest(c, "not.found", nil)
}
return util.FailedRequest(c, "server.error", err)
}
// Delete entry
if err := database.DBConn.Delete(&entry).Error; err != nil {
return util.FailedRequest(c, "server.error", err)
}
return util.SuccessfulRequest(c)
}