Added account delete endpoint
This commit is contained in:
parent
35978f596e
commit
57e621681f
20
internal/database/account/delete.go
Normal file
20
internal/database/account/delete.go
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
package account
|
||||||
|
|
||||||
|
import "github.com/rs/zerolog/log"
|
||||||
|
|
||||||
|
// Delete a model by id
|
||||||
|
func (a *Account) DeleteByID(id int64) error {
|
||||||
|
// Store model
|
||||||
|
model := &Model{
|
||||||
|
ID: id,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete model
|
||||||
|
_, err := a.db.Delete(model)
|
||||||
|
if err != nil {
|
||||||
|
log.Err(err).Str("table", "account").Str("type", "id").Msg("Could not delete row")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
31
internal/router/api/v1/account/delete.go
Normal file
31
internal/router/api/v1/account/delete.go
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
package account
|
||||||
|
|
||||||
|
import (
|
||||||
|
"git.supernets.org/perp/gopay/internal/context"
|
||||||
|
)
|
||||||
|
|
||||||
|
// @summary Delete an account
|
||||||
|
// @tags account
|
||||||
|
// @accept json
|
||||||
|
// @produce json
|
||||||
|
// @success 204
|
||||||
|
// @response default {object} v1.Error "There was an error"
|
||||||
|
// @router /v1/account/delete [delete]
|
||||||
|
func Delete(ctx *context.Context) {
|
||||||
|
// Call middleware
|
||||||
|
ctx.GetAccount()
|
||||||
|
|
||||||
|
// Account not found
|
||||||
|
if ctx.Account == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete account
|
||||||
|
err := ctx.Database.Account.DeleteByID(ctx.Account.ID)
|
||||||
|
if err != nil {
|
||||||
|
ctx.Error(500, "InternalServerError")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.String(200, "")
|
||||||
|
}
|
@ -26,6 +26,7 @@ func Register(ctx *context.Context, engine *gin.Engine) {
|
|||||||
|
|
||||||
{
|
{
|
||||||
a := v1.Group("account")
|
a := v1.Group("account")
|
||||||
|
a.DELETE("delete", ctx.Register(account.Delete))
|
||||||
a.GET("", ctx.Register(account.Fetch))
|
a.GET("", ctx.Register(account.Fetch))
|
||||||
a.POST("login", ctx.Register(account.Login))
|
a.POST("login", ctx.Register(account.Login))
|
||||||
a.POST("register", ctx.Register(account.Register))
|
a.POST("register", ctx.Register(account.Register))
|
||||||
|
Loading…
Reference in New Issue
Block a user