golang-lib/web/auth/api_my_delete.go

36 lines
826 B
Go
Raw Permalink Normal View History

2021-06-30 15:55:34 +02:00
package auth
import (
"net/http"
2023-10-23 21:40:10 +02:00
"codeberg.org/genofire/golang-lib/web"
2021-06-30 15:55:34 +02:00
"github.com/gin-gonic/gin"
)
// @Summary Delete own User
// @Description delete current loggedin user
// @Tags auth
// @Accept json
// @Produce json
// @Success 200 {object} bool "true if deleted"
// @Failure 401 {object} web.HTTPError
// @Failure 500 {object} web.HTTPError
// @Router /api/v1/my/profil [delete]
// @Security ApiKeyAuth
func apiMyDelete(r *gin.Engine, ws *web.Service) {
r.DELETE("/api/v1/my/profil", func(c *gin.Context) {
id, ok := GetCurrentUserID(c)
if !ok {
return
}
if err := ws.DB.Delete(&User{ID: id}).Error; err != nil {
c.JSON(http.StatusInternalServerError, web.HTTPError{
2021-07-22 18:16:05 +02:00
Message: web.ErrAPIInternalDatabase.Error(),
Error: err.Error(),
})
return
}
c.JSON(http.StatusOK, true)
2021-06-30 15:55:34 +02:00
})
}