mirror of
https://github.com/balzack/databag.git
synced 2025-02-15 21:19:16 +00:00
added account id to records for batch delete
This commit is contained in:
parent
3a0409c002
commit
5609704760
@ -25,6 +25,7 @@ func AddArticle(w http.ResponseWriter, r *http.Request) {
|
|||||||
err = store.DB.Transaction(func(tx *gorm.DB) error {
|
err = store.DB.Transaction(func(tx *gorm.DB) error {
|
||||||
|
|
||||||
article := &store.Article{}
|
article := &store.Article{}
|
||||||
|
article.AccountID = account.ID
|
||||||
article.Data = subject.Data
|
article.Data = subject.Data
|
||||||
article.DataType = subject.DataType
|
article.DataType = subject.DataType
|
||||||
if res := tx.Save(article).Error; res != nil {
|
if res := tx.Save(article).Error; res != nil {
|
||||||
|
@ -25,6 +25,7 @@ func AddChannel(w http.ResponseWriter, r *http.Request) {
|
|||||||
err = store.DB.Transaction(func(tx *gorm.DB) error {
|
err = store.DB.Transaction(func(tx *gorm.DB) error {
|
||||||
|
|
||||||
channel := &store.Channel{}
|
channel := &store.Channel{}
|
||||||
|
channel.AccountID = account.ID
|
||||||
channel.Data = subject.Data
|
channel.Data = subject.Data
|
||||||
channel.DataType = subject.DataType
|
channel.DataType = subject.DataType
|
||||||
channel.DetailRevision = account.ChannelRevision + 1
|
channel.DetailRevision = account.ChannelRevision + 1
|
||||||
|
@ -36,6 +36,7 @@ func AddChannelTopic(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
topic := &store.Topic{}
|
topic := &store.Topic{}
|
||||||
|
topic.AccountID = act.ID
|
||||||
topic.ChannelID = channelSlot.Channel.ID
|
topic.ChannelID = channelSlot.Channel.ID
|
||||||
topic.TopicSlotID = topicSlot.ID
|
topic.TopicSlotID = topicSlot.ID
|
||||||
topic.Data = subject.Data
|
topic.Data = subject.Data
|
||||||
|
@ -57,6 +57,7 @@ func AddChannelTopicTag(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
tag := &store.Tag{}
|
tag := &store.Tag{}
|
||||||
|
tag.AccountID = act.ID
|
||||||
tag.ChannelID = channelSlot.Channel.ID
|
tag.ChannelID = channelSlot.Channel.ID
|
||||||
tag.TopicID = topicSlot.Topic.ID
|
tag.TopicID = topicSlot.Topic.ID
|
||||||
tag.TagSlotID = tagSlot.ID
|
tag.TagSlotID = tagSlot.ID
|
||||||
|
@ -26,12 +26,14 @@ func AddGroup(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
data := &store.GroupData{
|
data := &store.GroupData{
|
||||||
Data: subject.Data,
|
Data: subject.Data,
|
||||||
|
AccountID: account.ID,
|
||||||
}
|
}
|
||||||
if res := tx.Save(data).Error; res != nil {
|
if res := tx.Save(data).Error; res != nil {
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
group := &store.Group{}
|
group := &store.Group{}
|
||||||
|
group.AccountID = account.ID
|
||||||
group.GroupDataID = data.ID
|
group.GroupDataID = data.ID
|
||||||
group.DataType = subject.DataType
|
group.DataType = subject.DataType
|
||||||
if res := tx.Save(group).Error; res != nil {
|
if res := tx.Save(group).Error; res != nil {
|
||||||
|
@ -18,9 +18,5 @@ func ImportAccount(w http.ResponseWriter, r *http.Request) {
|
|||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
}
|
}
|
||||||
|
|
||||||
func RemoveNodeAccount(w http.ResponseWriter, r *http.Request) {
|
|
||||||
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
108
net/server/internal/api_removeNodeAccount.go
Normal file
108
net/server/internal/api_removeNodeAccount.go
Normal file
@ -0,0 +1,108 @@
|
|||||||
|
package databag
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"errors"
|
||||||
|
"strconv"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
"net/http"
|
||||||
|
"databag/internal/store"
|
||||||
|
"github.com/gorilla/mux"
|
||||||
|
)
|
||||||
|
|
||||||
|
func RemoveNodeAccount(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
|
// get referenced account id
|
||||||
|
params := mux.Vars(r)
|
||||||
|
accountId, res := strconv.ParseUint(params["accountId"], 10, 32)
|
||||||
|
if res != nil {
|
||||||
|
ErrResponse(w, http.StatusBadRequest, res)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := AdminLogin(r); err != nil {
|
||||||
|
ErrResponse(w, http.StatusUnauthorized, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var account store.Account
|
||||||
|
if err := store.DB.First(&account, accountId).Error; err != nil {
|
||||||
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
|
ErrResponse(w, http.StatusNotFound, err)
|
||||||
|
} else {
|
||||||
|
ErrResponse(w, http.StatusInternalServerError, err)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err := store.DB.Transaction(func(tx *gorm.DB) error {
|
||||||
|
if res := tx.Where("account_id = ?", accountId).Delete(&store.Tag{}).Error; res != nil {
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
if res := tx.Where("account_id = ?", accountId).Delete(&store.TagSlot{}).Error; res != nil {
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
if res := tx.Where("account_id = ?", accountId).Delete(&store.Asset{}).Error; res != nil {
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
if res := tx.Where("account_id = ?", accountId).Delete(&store.Topic{}).Error; res != nil {
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
if res := tx.Where("account_id = ?", accountId).Delete(&store.TopicSlot{}).Error; res != nil {
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
if res := tx.Where("account_id = ?", accountId).Delete(&store.ChannelSlot{}).Error; res != nil {
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
if res := tx.Where("account_id = ?", accountId).Delete(&store.Channel{}).Error; res != nil {
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
if res := tx.Where("account_id = ?", accountId).Delete(&store.Article{}).Error; res != nil {
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
if res := tx.Where("account_id = ?", accountId).Delete(&store.ArticleSlot{}).Error; res != nil {
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
if res := tx.Where("account_id = ?", accountId).Delete(&store.CardSlot{}).Error; res != nil {
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
if res := tx.Where("account_id = ?", accountId).Delete(&store.Card{}).Error; res != nil {
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
if res := tx.Where("account_id = ?", accountId).Delete(&store.Group{}).Error; res != nil {
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
if res := tx.Where("account_id = ?", accountId).Delete(&store.GroupData{}).Error; res != nil {
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
if res := tx.Where("account_id = ?", accountId).Delete(&store.Group{}).Error; res != nil {
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
if res := tx.Where("account_id = ?", accountId).Delete(&store.App{}).Error; res != nil {
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
if res := tx.Where("account_id = ?", accountId).Delete(&store.AccountDetail{}).Error; res != nil {
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
if res := tx.Where("account_id = ?", accountId).Delete(&store.Account{}).Error; res != nil {
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
if res := tx.Where("account_id = ?", accountId).Delete(&store.AccountToken{}).Error; res != nil {
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
ErrResponse(w, http.StatusInternalServerError, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// delete asset files
|
||||||
|
path := getStrConfigValue(CONFIG_ASSETPATH, ".") + "/" + account.Guid
|
||||||
|
if err = os.RemoveAll(path); err != nil {
|
||||||
|
ErrMsg(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
WriteResponse(w, nil)
|
||||||
|
}
|
||||||
|
|
@ -110,6 +110,7 @@ type GroupSlot struct {
|
|||||||
type Group struct {
|
type Group struct {
|
||||||
ID uint `gorm:"primaryKey;not null;unique;autoIncrement"`
|
ID uint `gorm:"primaryKey;not null;unique;autoIncrement"`
|
||||||
GroupDataID uint `gorm:"not null;index:groupdata"`
|
GroupDataID uint `gorm:"not null;index:groupdata"`
|
||||||
|
AccountID uint
|
||||||
DataType string `gorm:"index"`
|
DataType string `gorm:"index"`
|
||||||
Created int64 `gorm:"autoCreateTime"`
|
Created int64 `gorm:"autoCreateTime"`
|
||||||
Updated int64 `gorm:"autoUpdateTime"`
|
Updated int64 `gorm:"autoUpdateTime"`
|
||||||
@ -123,6 +124,7 @@ type Group struct {
|
|||||||
type GroupData struct {
|
type GroupData struct {
|
||||||
ID uint `gorm:"primaryKey;not null;unique;autoIncrement"`
|
ID uint `gorm:"primaryKey;not null;unique;autoIncrement"`
|
||||||
Data string
|
Data string
|
||||||
|
AccountID uint
|
||||||
}
|
}
|
||||||
|
|
||||||
type CardSlot struct {
|
type CardSlot struct {
|
||||||
@ -177,6 +179,7 @@ type ArticleSlot struct {
|
|||||||
|
|
||||||
type Article struct {
|
type Article struct {
|
||||||
ID uint `gorm:"primaryKey;not null;unique;autoIncrement"`
|
ID uint `gorm:"primaryKey;not null;unique;autoIncrement"`
|
||||||
|
AccountID uint
|
||||||
DataType string `gorm:"index"`
|
DataType string `gorm:"index"`
|
||||||
Data string
|
Data string
|
||||||
Created int64 `gorm:"autoCreateTime"`
|
Created int64 `gorm:"autoCreateTime"`
|
||||||
@ -197,6 +200,7 @@ type ChannelSlot struct {
|
|||||||
|
|
||||||
type Channel struct {
|
type Channel struct {
|
||||||
ID uint `gorm:"primaryKey;not null;unique;autoIncrement"`
|
ID uint `gorm:"primaryKey;not null;unique;autoIncrement"`
|
||||||
|
AccountID uint
|
||||||
TopicRevision int64 `gorm:"not null"`
|
TopicRevision int64 `gorm:"not null"`
|
||||||
DetailRevision int64 `gorm:"not null"`
|
DetailRevision int64 `gorm:"not null"`
|
||||||
DataType string `gorm:"index"`
|
DataType string `gorm:"index"`
|
||||||
@ -223,6 +227,7 @@ type TopicSlot struct {
|
|||||||
type Topic struct {
|
type Topic struct {
|
||||||
ID uint `gorm:"primaryKey;not null;unique;autoIncrement"`
|
ID uint `gorm:"primaryKey;not null;unique;autoIncrement"`
|
||||||
DetailRevision int64 `gorm:"not null"`
|
DetailRevision int64 `gorm:"not null"`
|
||||||
|
AccountID uint
|
||||||
ChannelID uint
|
ChannelID uint
|
||||||
TopicSlotID uint `gorm:"not null;index:topictopicslot,unique"`
|
TopicSlotID uint `gorm:"not null;index:topictopicslot,unique"`
|
||||||
Guid string
|
Guid string
|
||||||
@ -274,6 +279,7 @@ type TagSlot struct {
|
|||||||
type Tag struct {
|
type Tag struct {
|
||||||
ID uint `gorm:"primaryKey;not null;unique;autoIncrement"`
|
ID uint `gorm:"primaryKey;not null;unique;autoIncrement"`
|
||||||
TagSlotID uint `gorm:"not null;index:tagtagslot,unique"`
|
TagSlotID uint `gorm:"not null;index:tagtagslot,unique"`
|
||||||
|
AccountID uint
|
||||||
ChannelID uint `gorm:"not null;index:channeltag"`
|
ChannelID uint `gorm:"not null;index:channeltag"`
|
||||||
TopicID uint `gorm:"not null;index:topictag"`
|
TopicID uint `gorm:"not null;index:topictag"`
|
||||||
Guid string `gorm:"not null"`
|
Guid string `gorm:"not null"`
|
||||||
|
Loading…
Reference in New Issue
Block a user