mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-13 13:35:59 +08:00
add
This commit is contained in:
@@ -86,6 +86,7 @@ type config struct {
|
||||
OpenImGroupName string `yaml:"openImGroupName"`
|
||||
OpenImAuthName string `yaml:"openImAuthName"`
|
||||
OpenImMessageCMSName string `yaml:"openImMessageCMSName"`
|
||||
OpenImAdminCMSName string `yaml:"openImAdminCMSName"`
|
||||
}
|
||||
Etcd struct {
|
||||
EtcdSchema string `yaml:"etcdSchema"`
|
||||
|
||||
@@ -15,7 +15,7 @@ var (
|
||||
// ErrMysql = ErrInfo{100, ""}
|
||||
// ErrMongo = ErrInfo{110, ""}
|
||||
// ErrRedis = ErrInfo{120, ""}
|
||||
ErrParseToken = ErrInfo{200, ParseTokenMsg.Error()}
|
||||
ErrParseToken = ErrInfo{700, ParseTokenMsg.Error()}
|
||||
// ErrCreateToken = ErrInfo{201, "Create token failed"}
|
||||
// ErrAppServerKey = ErrInfo{300, "key error"}
|
||||
ErrTencentCredential = ErrInfo{400, ThirdPartyMsg.Error()}
|
||||
|
||||
@@ -12,6 +12,18 @@ func GetChatLog(chatLog db.ChatLog, pageNumber, showNumber int32) ([]db.ChatLog,
|
||||
return chatLogs, err
|
||||
}
|
||||
dbConn.LogMode(true)
|
||||
err = dbConn.Table("chat_logs").Where(fmt.Sprintf(" content like '%%%s%%' ", chatLog.Content)).Limit(showNumber).Offset(showNumber * (pageNumber - 1)).Find(&chatLogs).Error
|
||||
err = dbConn.Table("chat_logs").Where(fmt.Sprintf(" content like '%%%s%%'", chatLog.Content)).
|
||||
Limit(showNumber).Offset(showNumber * (pageNumber - 1)).Find(&chatLogs).Error
|
||||
return chatLogs, err
|
||||
}
|
||||
|
||||
func GetChatLogCount(chatLog db.ChatLog) (int64, error) {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
var count int64
|
||||
if err != nil {
|
||||
return count, err
|
||||
}
|
||||
dbConn.LogMode(true)
|
||||
err = dbConn.Table("chat_logs").Where(fmt.Sprintf(" content like '%%%s%%' and ", chatLog.Content)).Count(&count).Error
|
||||
return count, err
|
||||
}
|
||||
@@ -159,7 +159,7 @@ func UserIsBlock(userId string) (bool, error) {
|
||||
return false, err
|
||||
}
|
||||
var user db.BlackList
|
||||
rows := dbConn.Table("black_list").Where("uid=?", userId).First(&user).RowsAffected
|
||||
rows := dbConn.Table("black_lists").Where("uid=?", userId).First(&user).RowsAffected
|
||||
if rows >= 1 {
|
||||
return true, nil
|
||||
}
|
||||
@@ -183,7 +183,7 @@ func BlockUser(userId, endDisableTime string) error {
|
||||
return constant.ErrDB
|
||||
}
|
||||
var blockUser db.BlackList
|
||||
dbConn.Table("black_list").Where("uid=?", userId).First(&blockUser)
|
||||
dbConn.Table("black_lists").Where("uid=?", userId).First(&blockUser)
|
||||
if blockUser.UserId != "" {
|
||||
dbConn.Model(&blockUser).Where("uid=?", blockUser.UserId).Update("end_disable_time", end)
|
||||
return nil
|
||||
@@ -222,7 +222,7 @@ func GetBlockUserById(userId string) (BlockUserInfo, error) {
|
||||
if err != nil {
|
||||
return blockUserInfo, err
|
||||
}
|
||||
if err = dbConn.Table("black_list").Where("uid=?", userId).Find(&blockUser).Error; err != nil {
|
||||
if err = dbConn.Table("black_lists").Where("uid=?", userId).Find(&blockUser).Error; err != nil {
|
||||
return blockUserInfo, err
|
||||
}
|
||||
user := db.Users{
|
||||
|
||||
@@ -2,15 +2,14 @@ package http
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"fmt"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
|
||||
|
||||
//"Open_IM/pkg/cms_api_struct"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
)
|
||||
|
||||
type BaseResp struct {
|
||||
@@ -20,32 +19,15 @@ type BaseResp struct {
|
||||
}
|
||||
|
||||
func RespHttp200(ctx *gin.Context, err error, data interface{}) {
|
||||
var resp BaseResp
|
||||
if v, ok := err.(constant.ErrInfo); ok {
|
||||
resp.Code = v.Code()
|
||||
resp.ErrMsg = v.Error()
|
||||
} else {
|
||||
resp.Code = constant.ErrServer.Code()
|
||||
resp.ErrMsg = constant.ErrServer.Error()
|
||||
}
|
||||
resp.Data=data
|
||||
ctx.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
// warp error
|
||||
func WarpError(err constant.ErrInfo) error {
|
||||
return status.Error(codes.Code(err.ErrCode), err.ErrMsg)
|
||||
}
|
||||
|
||||
// parse error from server
|
||||
func RespHttp200S(ctx *gin.Context, err error, data interface{}) {
|
||||
var resp BaseResp
|
||||
switch e := err.(type) {
|
||||
case constant.ErrInfo:
|
||||
resp.Code = e.ErrCode
|
||||
resp.ErrMsg = e.ErrMsg
|
||||
default:
|
||||
s, ok := status.FromError(err)
|
||||
if !ok {
|
||||
fmt.Println("need grpc format error")
|
||||
return
|
||||
}
|
||||
resp.Code = int32(s.Code())
|
||||
@@ -55,6 +37,7 @@ func RespHttp200S(ctx *gin.Context, err error, data interface{}) {
|
||||
ctx.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
//func CheckErr(pb interface{}) constant.ErrInfo{
|
||||
//
|
||||
//}
|
||||
// warp error
|
||||
func WrapError(err constant.ErrInfo) error {
|
||||
return status.Error(codes.Code(err.ErrCode), err.ErrMsg)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user