databag/net/server/internal/api_setAccountSearchable.go

42 lines
905 B
Go
Raw Normal View History

2022-03-09 06:39:02 +00:00
package databag
import (
"net/http"
2022-03-25 07:33:22 +00:00
"gorm.io/gorm"
2022-03-09 06:39:02 +00:00
"databag/internal/store"
)
func SetAccountSearchable(w http.ResponseWriter, r *http.Request) {
2022-03-25 07:33:22 +00:00
account, code, err := ParamAgentToken(r, true);
2022-03-09 06:39:02 +00:00
if err != nil {
ErrResponse(w, code, err)
return
}
var flag bool
if err := ParseRequest(r, w, &flag); err != nil {
ErrResponse(w, http.StatusBadRequest, err)
return
}
2022-03-25 07:33:22 +00:00
err = store.DB.Transaction(func(tx *gorm.DB) error {
if res := tx.Model(account).Update("searchable", flag).Error; res != nil {
ErrResponse(w, http.StatusInternalServerError, res)
return res
}
if res := tx.Model(&account).Update("account_revision", account.AccountRevision + 1).Error; res != nil {
return res
}
return nil
})
if err != nil {
2022-03-09 06:39:02 +00:00
ErrResponse(w, http.StatusInternalServerError, err)
return
}
2022-03-25 07:33:22 +00:00
SetStatus(account)
2022-03-09 06:39:02 +00:00
WriteResponse(w, nil)
}