2022-03-09 06:39:02 +00:00
|
|
|
package databag
|
|
|
|
|
|
|
|
import (
|
2022-07-22 19:28:14 +00:00
|
|
|
"databag/internal/store"
|
|
|
|
"gorm.io/gorm"
|
|
|
|
"net/http"
|
2022-03-09 06:39:02 +00:00
|
|
|
)
|
|
|
|
|
2022-07-29 21:50:40 +00:00
|
|
|
//SetAccountSearchable sets public visibility of account
|
2022-03-09 06:39:02 +00:00
|
|
|
func SetAccountSearchable(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
2022-07-22 19:28:14 +00:00
|
|
|
account, code, err := ParamAgentToken(r, true)
|
|
|
|
if err != nil {
|
|
|
|
ErrResponse(w, code, err)
|
|
|
|
return
|
|
|
|
}
|
2022-03-09 06:39:02 +00:00
|
|
|
|
2022-07-22 19:28:14 +00:00
|
|
|
var flag bool
|
|
|
|
if err := ParseRequest(r, w, &flag); err != nil {
|
|
|
|
ErrResponse(w, http.StatusBadRequest, err)
|
|
|
|
return
|
|
|
|
}
|
2022-03-09 06:39:02 +00:00
|
|
|
|
2022-07-22 19:28:14 +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
|
|
|
|
}
|
2023-08-30 17:11:18 +00:00
|
|
|
account.AccountRevision += 1;
|
|
|
|
if res := tx.Model(&account).Update("account_revision", account.AccountRevision).Error; res != nil {
|
2022-07-22 19:28:14 +00:00
|
|
|
return res
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
ErrResponse(w, http.StatusInternalServerError, err)
|
|
|
|
return
|
|
|
|
}
|
2022-03-09 06:39:02 +00:00
|
|
|
|
2022-07-22 19:28:14 +00:00
|
|
|
SetStatus(account)
|
|
|
|
WriteResponse(w, nil)
|
2022-03-09 06:39:02 +00:00
|
|
|
}
|