mirror of
https://github.com/nicksherron/bashhub-server.git
synced 2025-11-01 07:35:57 +08:00
delete command added
This commit is contained in:
parent
2e393c97e0
commit
3f1fbb4294
2 changed files with 27 additions and 0 deletions
|
|
@ -98,6 +98,7 @@ func dbInit() {
|
|||
gormdb.Model(&User{}).AddIndex("idx_user", "username")
|
||||
gormdb.Model(&System{}).AddIndex("idx_mac", "mac")
|
||||
gormdb.Model(&Command{}).AddIndex("idx_user_command_created", "user_id, created, command")
|
||||
gormdb.Model(&Command{}).AddIndex("idx_user_uuid", "user_id, uuid")
|
||||
// Just need gorm for migration and index creation.
|
||||
gormdb.Close()
|
||||
}
|
||||
|
|
@ -205,6 +206,7 @@ func (cmd Command) commandInsert() int64 {
|
|||
}
|
||||
return inserted
|
||||
}
|
||||
|
||||
//TODO: make this less complicated. It's the epitome of a cluster fuck.
|
||||
func (cmd Command) commandGet() []Query {
|
||||
var results []Query
|
||||
|
|
@ -458,6 +460,21 @@ func (cmd Command) commandGetUUID() Query {
|
|||
return result
|
||||
}
|
||||
|
||||
func (cmd Command) commandDelete() int64 {
|
||||
res, err := db.Exec(`DELETE FROM commands
|
||||
WHERE "user_id" = $1
|
||||
AND "uuid" = $2 `, cmd.User.ID, cmd.Uuid)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
inserted, err := res.RowsAffected()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
return inserted
|
||||
|
||||
}
|
||||
|
||||
func (sys System) systemInsert() int64 {
|
||||
|
||||
t := time.Now().Unix()
|
||||
|
|
|
|||
|
|
@ -286,6 +286,16 @@ func Run() {
|
|||
command.commandInsert()
|
||||
})
|
||||
|
||||
r.DELETE("/api/v1/command/:uuid", func(c *gin.Context) {
|
||||
var command Command
|
||||
var user User
|
||||
claims := jwt.ExtractClaims(c)
|
||||
user.Username = claims["username"].(string)
|
||||
command.User.ID = user.userGetId()
|
||||
command.Uuid = c.Param("uuid")
|
||||
command.commandDelete()
|
||||
})
|
||||
|
||||
r.POST("/api/v1/system", func(c *gin.Context) {
|
||||
var system System
|
||||
var user User
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue