parent
c0b49ff219
commit
6553ada66f
@ -0,0 +1,55 @@
|
|||||||
|
package clientInit
|
||||||
|
|
||||||
|
import (
|
||||||
|
api "Open_IM/pkg/base_info"
|
||||||
|
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||||
|
"Open_IM/pkg/common/log"
|
||||||
|
"Open_IM/pkg/utils"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
)
|
||||||
|
|
||||||
|
func SetClientInitConfig(c *gin.Context) {
|
||||||
|
var req api.SetClientInitConfigReq
|
||||||
|
var resp api.SetClientInitConfigResp
|
||||||
|
if err := c.BindJSON(&req); err != nil {
|
||||||
|
log.NewError("0", utils.GetSelfFuncName(), err.Error())
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req)
|
||||||
|
m := make(map[string]interface{})
|
||||||
|
if req.DiscoverPageURL != nil {
|
||||||
|
m["discover_page_url"] = *req.DiscoverPageURL
|
||||||
|
}
|
||||||
|
if len(m) > 0 {
|
||||||
|
err := imdb.SetClientInitConfig(m)
|
||||||
|
if err != nil {
|
||||||
|
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error())
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp)
|
||||||
|
c.JSON(http.StatusOK, resp)
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetClientInitConfig(c *gin.Context) {
|
||||||
|
var req api.GetClientInitConfigReq
|
||||||
|
var resp api.GetClientInitConfigResp
|
||||||
|
if err := c.BindJSON(&req); err != nil {
|
||||||
|
log.NewError("0", utils.GetSelfFuncName(), err.Error())
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req)
|
||||||
|
config, err := imdb.GetClientInitConfig()
|
||||||
|
if err != nil {
|
||||||
|
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error())
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
|
||||||
|
}
|
||||||
|
resp.Data.DiscoverPageURL = config.DiscoverPageURL
|
||||||
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp ", resp)
|
||||||
|
c.JSON(http.StatusOK, resp)
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
package base_info
|
||||||
|
|
||||||
|
type SetClientInitConfigReq struct {
|
||||||
|
OperationID string `json:"operationID" binding:"required"`
|
||||||
|
DiscoverPageURL *string `json:"discoverPageURL"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type SetClientInitConfigResp struct {
|
||||||
|
CommResp
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetClientInitConfigReq struct {
|
||||||
|
OperationID string `json:"operationID" binding:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetClientInitConfigResp struct {
|
||||||
|
CommResp
|
||||||
|
Data struct {
|
||||||
|
DiscoverPageURL string `json:"discoverPageURL"`
|
||||||
|
} `json:"data"`
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
package im_mysql_model
|
||||||
|
|
||||||
|
import "Open_IM/pkg/common/db"
|
||||||
|
|
||||||
|
func SetClientInitConfig(m map[string]interface{}) error {
|
||||||
|
result := db.DB.MysqlDB.DefaultGormDB().Model(&db.ClientInitConfig{}).Updates(m)
|
||||||
|
if result.Error != nil {
|
||||||
|
return result.Error
|
||||||
|
}
|
||||||
|
if result.RowsAffected == 1 {
|
||||||
|
err := db.DB.MysqlDB.DefaultGormDB().Model(&db.ClientInitConfig{}).Create(m).Error
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetClientInitConfig() (db.ClientInitConfig, error) {
|
||||||
|
var config db.ClientInitConfig
|
||||||
|
err := db.DB.MysqlDB.DefaultGormDB().Model((&db.ClientInitConfig{})).First(&config).Error
|
||||||
|
return config, err
|
||||||
|
}
|
Loading…
Reference in new issue