adding delete self, required by ios

This commit is contained in:
Roland Osborne 2022-10-26 21:58:06 -07:00
parent d582198596
commit 0ada72a343
2 changed files with 96 additions and 0 deletions

View File

@ -0,0 +1,89 @@
package databag
import (
"databag/internal/store"
"gorm.io/gorm"
"net/http"
"os"
)
//RemoveProfile removes account
func RemoveProfile(w http.ResponseWriter, r *http.Request) {
account, code, err := ParamAgentToken(r, true)
if err != nil {
PrintMsg(r)
ErrResponse(w, code, err)
return
}
err = store.DB.Transaction(func(tx *gorm.DB) error {
if res := tx.Where("account_id = ?", account.ID).Delete(&store.Tag{}).Error; res != nil {
return res
}
if res := tx.Where("account_id = ?", account.ID).Delete(&store.TagSlot{}).Error; res != nil {
return res
}
if res := tx.Where("account_id = ?", account.ID).Delete(&store.Asset{}).Error; res != nil {
return res
}
if res := tx.Where("account_id = ?", account.ID).Delete(&store.Topic{}).Error; res != nil {
return res
}
if res := tx.Where("account_id = ?", account.ID).Delete(&store.TopicSlot{}).Error; res != nil {
return res
}
if res := tx.Where("account_id = ?", account.ID).Delete(&store.ChannelSlot{}).Error; res != nil {
return res
}
if res := tx.Where("account_id = ?", account.ID).Delete(&store.Channel{}).Error; res != nil {
return res
}
if res := tx.Where("account_id = ?", account.ID).Delete(&store.Article{}).Error; res != nil {
return res
}
if res := tx.Where("account_id = ?", account.ID).Delete(&store.ArticleSlot{}).Error; res != nil {
return res
}
if res := tx.Where("account_id = ?", account.ID).Delete(&store.CardSlot{}).Error; res != nil {
return res
}
if res := tx.Where("account_id = ?", account.ID).Delete(&store.Card{}).Error; res != nil {
return res
}
if res := tx.Where("account_id = ?", account.ID).Delete(&store.Group{}).Error; res != nil {
return res
}
if res := tx.Where("account_id = ?", account.ID).Delete(&store.GroupData{}).Error; res != nil {
return res
}
if res := tx.Where("account_id = ?", account.ID).Delete(&store.Group{}).Error; res != nil {
return res
}
if res := tx.Where("account_id = ?", account.ID).Delete(&store.App{}).Error; res != nil {
return res
}
if res := tx.Where("account_id = ?", account.ID).Delete(&store.AccountToken{}).Error; res != nil {
return res
}
if res := tx.Delete(&store.AccountDetail{}, account.AccountDetailID).Error; res != nil {
return res
}
if res := tx.Delete(account).Error; res != nil {
return res
}
return nil
})
if err != nil {
ErrResponse(w, http.StatusInternalServerError, err)
return
}
// delete asset files
path := getStrConfigValue(CNFAssetPath, APPDefaultPath) + "/" + account.GUID
if err = os.RemoveAll(path); err != nil {
ErrMsg(err)
}
WriteResponse(w, nil)
}

View File

@ -734,6 +734,13 @@ var endpoints = routes{
SetProfileImage,
},
route{
"RemoveProfile",
strings.ToUpper("Delete"),
"/profile",
RemoveProfile,
},
route{
"Status",
strings.ToUpper("Get"),