Skip to content

Commit

Permalink
refactor: renamed non-standard package aliases and field names. (#549)
Browse files Browse the repository at this point in the history
* fix: fix uncurrent err handle.

* refactor: renamed non-standard aliases and field names.
  • Loading branch information
mo3et authored Jun 7, 2024
1 parent 4f4ece4 commit 07f7853
Show file tree
Hide file tree
Showing 35 changed files with 296 additions and 276 deletions.
51 changes: 26 additions & 25 deletions internal/api/chat/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,26 @@
package chat

import (
"github.com/openimsdk/chat/internal/api/util"
"io"
"time"

"github.com/openimsdk/chat/internal/api/util"

"github.com/gin-gonic/gin"
"github.com/openimsdk/chat/pkg/common/apistruct"
chatconstant "github.com/openimsdk/chat/pkg/common/constant"
"github.com/openimsdk/chat/pkg/common/constant"
"github.com/openimsdk/chat/pkg/common/imapi"
"github.com/openimsdk/chat/pkg/common/mctx"
"github.com/openimsdk/chat/pkg/protocol/admin"
"github.com/openimsdk/chat/pkg/protocol/chat"
"github.com/openimsdk/protocol/constant"
chatpb "github.com/openimsdk/chat/pkg/protocol/chat"
constantpb "github.com/openimsdk/protocol/constant"
"github.com/openimsdk/protocol/sdkws"
"github.com/openimsdk/tools/a2r"
"github.com/openimsdk/tools/apiresp"
"github.com/openimsdk/tools/errs"
)

func New(chatClient chat.ChatClient, adminClient admin.AdminClient, imApiCaller imapi.CallerInterface, api *util.Api) *Api {
func New(chatClient chatpb.ChatClient, adminClient admin.AdminClient, imApiCaller imapi.CallerInterface, api *util.Api) *Api {
return &Api{
Api: api,
chatClient: chatClient,
Expand All @@ -44,15 +45,15 @@ func New(chatClient chat.ChatClient, adminClient admin.AdminClient, imApiCaller

type Api struct {
*util.Api
chatClient chat.ChatClient
chatClient chatpb.ChatClient
adminClient admin.AdminClient
imApiCaller imapi.CallerInterface
}

// ################## ACCOUNT ##################

func (o *Api) SendVerifyCode(c *gin.Context) {
req, err := a2r.ParseRequest[chat.SendVerifyCodeReq](c)
req, err := a2r.ParseRequest[chatpb.SendVerifyCodeReq](c)
if err != nil {
apiresp.GinError(c, err)
return
Expand All @@ -72,11 +73,11 @@ func (o *Api) SendVerifyCode(c *gin.Context) {
}

func (o *Api) VerifyCode(c *gin.Context) {
a2r.Call(chat.ChatClient.VerifyCode, o.chatClient, c)
a2r.Call(chatpb.ChatClient.VerifyCode, o.chatClient, c)
}

func (o *Api) RegisterUser(c *gin.Context) {
req, err := a2r.ParseRequest[chat.RegisterUserReq](c)
req, err := a2r.ParseRequest[chatpb.RegisterUserReq](c)
if err != nil {
apiresp.GinError(c, err)
return
Expand Down Expand Up @@ -130,7 +131,7 @@ func (o *Api) RegisterUser(c *gin.Context) {
}

func (o *Api) Login(c *gin.Context) {
req, err := a2r.ParseRequest[chat.LoginReq](c)
req, err := a2r.ParseRequest[chatpb.LoginReq](c)
if err != nil {
apiresp.GinError(c, err)
return
Expand Down Expand Up @@ -159,17 +160,17 @@ func (o *Api) Login(c *gin.Context) {
}

func (o *Api) ResetPassword(c *gin.Context) {
a2r.Call(chat.ChatClient.ResetPassword, o.chatClient, c)
a2r.Call(chatpb.ChatClient.ResetPassword, o.chatClient, c)
}

func (o *Api) ChangePassword(c *gin.Context) {
a2r.Call(chat.ChatClient.ChangePassword, o.chatClient, c)
a2r.Call(chatpb.ChatClient.ChangePassword, o.chatClient, c)
}

// ################## USER ##################

func (o *Api) UpdateUserInfo(c *gin.Context) {
req, err := a2r.ParseRequest[chat.UpdateUserInfoReq](c)
req, err := a2r.ParseRequest[chatpb.UpdateUserInfoReq](c)
if err != nil {
apiresp.GinError(c, err)
return
Expand All @@ -185,10 +186,10 @@ func (o *Api) UpdateUserInfo(c *gin.Context) {
return
}
var imToken string
if opUserType == chatconstant.NormalUser {
if opUserType == constant.NormalUser {
imToken, err = o.imApiCaller.ImAdminTokenWithDefaultAdmin(c)
} else if opUserType == chatconstant.AdminUser {
imToken, err = o.imApiCaller.UserToken(c, o.GetDefaultIMAdminUserID(), constant.AdminPlatformID)
} else if opUserType == constant.AdminUser {
imToken, err = o.imApiCaller.UserToken(c, o.GetDefaultIMAdminUserID(), constantpb.AdminPlatformID)
} else {
apiresp.GinError(c, errs.ErrArgs.WrapMsg("opUserType unknown"))
return
Expand Down Expand Up @@ -220,23 +221,23 @@ func (o *Api) UpdateUserInfo(c *gin.Context) {
}

func (o *Api) FindUserPublicInfo(c *gin.Context) {
a2r.Call(chat.ChatClient.FindUserPublicInfo, o.chatClient, c)
a2r.Call(chatpb.ChatClient.FindUserPublicInfo, o.chatClient, c)
}

func (o *Api) FindUserFullInfo(c *gin.Context) {
a2r.Call(chat.ChatClient.FindUserFullInfo, o.chatClient, c)
a2r.Call(chatpb.ChatClient.FindUserFullInfo, o.chatClient, c)
}

func (o *Api) SearchUserFullInfo(c *gin.Context) {
a2r.Call(chat.ChatClient.SearchUserFullInfo, o.chatClient, c)
a2r.Call(chatpb.ChatClient.SearchUserFullInfo, o.chatClient, c)
}

func (o *Api) SearchUserPublicInfo(c *gin.Context) {
a2r.Call(chat.ChatClient.SearchUserPublicInfo, o.chatClient, c)
a2r.Call(chatpb.ChatClient.SearchUserPublicInfo, o.chatClient, c)
}

func (o *Api) GetTokenForVideoMeeting(c *gin.Context) {
a2r.Call(chat.ChatClient.GetTokenForVideoMeeting, o.chatClient, c)
a2r.Call(chatpb.ChatClient.GetTokenForVideoMeeting, o.chatClient, c)
}

// ################## APPLET ##################
Expand All @@ -259,8 +260,8 @@ func (o *Api) OpenIMCallback(c *gin.Context) {
apiresp.GinError(c, err)
return
}
req := &chat.OpenIMCallbackReq{
Command: c.Query(constant.CallbackCommand),
req := &chatpb.OpenIMCallbackReq{
Command: c.Query(constantpb.CallbackCommand),
Body: string(body),
}
if _, err := o.chatClient.OpenIMCallback(c, req); err != nil {
Expand All @@ -273,7 +274,7 @@ func (o *Api) OpenIMCallback(c *gin.Context) {
func (o *Api) SearchFriend(c *gin.Context) {
req, err := a2r.ParseRequest[struct {
UserID string `json:"userID"`
chat.SearchUserInfoReq
chatpb.SearchUserInfoReq
}](c)
if err != nil {
apiresp.GinError(c, err)
Expand All @@ -293,7 +294,7 @@ func (o *Api) SearchFriend(c *gin.Context) {
return
}
if len(userIDs) == 0 {
apiresp.GinSuccess(c, &chat.SearchUserInfoResp{})
apiresp.GinSuccess(c, &chatpb.SearchUserInfoResp{})
return
}
req.SearchUserInfoReq.UserIDs = userIDs
Expand Down
1 change: 1 addition & 0 deletions internal/api/chat/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package chat
import (
"context"
"fmt"

"github.com/gin-gonic/gin"
chatmw "github.com/openimsdk/chat/internal/api/mw"
"github.com/openimsdk/chat/internal/api/util"
Expand Down
6 changes: 3 additions & 3 deletions internal/api/mw/mw.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"github.com/gin-gonic/gin"
"github.com/openimsdk/chat/pkg/common/constant"
"github.com/openimsdk/chat/pkg/protocol/admin"
constant2 "github.com/openimsdk/protocol/constant"
constantpb "github.com/openimsdk/protocol/constant"
"github.com/openimsdk/tools/apiresp"
"github.com/openimsdk/tools/errs"
)
Expand Down Expand Up @@ -66,8 +66,8 @@ func (o *MW) isValidToken(c *gin.Context, userID string, token string) error {
}
if v, ok := resp.TokensMap[token]; ok {
switch v {
case constant2.NormalToken:
case constant2.KickedToken:
case constantpb.NormalToken:
case constantpb.KickedToken:
return errs.ErrTokenExpired.Wrap()
default:
return errs.ErrTokenUnknown.Wrap()
Expand Down
11 changes: 6 additions & 5 deletions internal/rpc/admin/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@ package admin
import (
"context"
"fmt"
"math/rand"
"time"

"github.com/openimsdk/tools/errs"
"github.com/openimsdk/tools/mcontext"
"github.com/openimsdk/tools/utils/datautil"
"math/rand"
"time"

"github.com/openimsdk/chat/pkg/common/constant"
"github.com/openimsdk/chat/pkg/common/db/dbutil"
admin2 "github.com/openimsdk/chat/pkg/common/db/table/admin"
admindb "github.com/openimsdk/chat/pkg/common/db/table/admin"
"github.com/openimsdk/chat/pkg/common/mctx"
"github.com/openimsdk/chat/pkg/eerrs"
"github.com/openimsdk/chat/pkg/protocol/admin"
Expand Down Expand Up @@ -77,7 +78,7 @@ func (o *adminServer) AddAdminAccount(ctx context.Context, req *admin.AddAdminAc
return nil, errs.ErrDuplicateKey.WrapMsg("the account is registered")
}

adm := &admin2.Admin{
adm := &admindb.Admin{
Account: req.Account,
Password: req.Password,
FaceURL: req.FaceURL,
Expand All @@ -86,7 +87,7 @@ func (o *adminServer) AddAdminAccount(ctx context.Context, req *admin.AddAdminAc
Level: 80,
CreateTime: time.Now(),
}
if err = o.Database.AddAdminAccount(ctx, []*admin2.Admin{adm}); err != nil {
if err = o.Database.AddAdminAccount(ctx, []*admindb.Admin{adm}); err != nil {
return nil, err
}
return &admin.AddAdminAccountResp{}, nil
Expand Down
11 changes: 6 additions & 5 deletions internal/rpc/admin/applet.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@ package admin

import (
"context"
"github.com/openimsdk/tools/utils/datautil"
"strings"
"time"

"github.com/openimsdk/tools/utils/datautil"

"github.com/google/uuid"
"github.com/openimsdk/tools/errs"

"github.com/openimsdk/chat/pkg/common/constant"
admin2 "github.com/openimsdk/chat/pkg/common/db/table/admin"
admindb "github.com/openimsdk/chat/pkg/common/db/table/admin"
"github.com/openimsdk/chat/pkg/common/mctx"
"github.com/openimsdk/chat/pkg/protocol/admin"
"github.com/openimsdk/chat/pkg/protocol/common"
Expand All @@ -43,7 +44,7 @@ func (o *adminServer) AddApplet(ctx context.Context, req *admin.AddAppletReq) (*
if !(req.Status == constant.StatusOnShelf || req.Status == constant.StatusUnShelf) {
return nil, errs.ErrArgs.WrapMsg("invalid status")
}
m := admin2.Applet{
m := admindb.Applet{
ID: req.Id,
Name: req.Name,
AppID: req.AppID,
Expand All @@ -59,7 +60,7 @@ func (o *adminServer) AddApplet(ctx context.Context, req *admin.AddAppletReq) (*
if m.ID == "" {
m.ID = uuid.New().String()
}
if err := o.Database.CreateApplet(ctx, []*admin2.Applet{&m}); err != nil {
if err := o.Database.CreateApplet(ctx, []*admindb.Applet{&m}); err != nil {
return nil, err
}
return &admin.AddAppletResp{}, nil
Expand All @@ -76,7 +77,7 @@ func (o *adminServer) DelApplet(ctx context.Context, req *admin.DelAppletReq) (*
if err != nil {
return nil, err
}
if ids := datautil.Single(req.AppletIds, datautil.Slice(applets, func(e *admin2.Applet) string { return e.ID })); len(ids) > 0 {
if ids := datautil.Single(req.AppletIds, datautil.Slice(applets, func(e *admindb.Applet) string { return e.ID })); len(ids) > 0 {
return nil, errs.ErrArgs.WrapMsg("ids not found: " + strings.Join(ids, ", "))
}
if err := o.Database.DelApplet(ctx, req.AppletIds); err != nil {
Expand Down
1 change: 1 addition & 0 deletions internal/rpc/admin/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package admin

import (
"context"

"github.com/openimsdk/chat/pkg/common/db/dbutil"
"github.com/openimsdk/chat/pkg/eerrs"
"github.com/openimsdk/chat/pkg/protocol/admin"
Expand Down
19 changes: 10 additions & 9 deletions internal/rpc/admin/invitation.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ package admin

import (
"context"
"github.com/openimsdk/tools/utils/datautil"
"math/rand"
"strings"
"time"

"github.com/openimsdk/tools/utils/datautil"

"github.com/openimsdk/tools/errs"

admin2 "github.com/openimsdk/chat/pkg/common/db/table/admin"
admindb "github.com/openimsdk/chat/pkg/common/db/table/admin"
"github.com/openimsdk/chat/pkg/common/mctx"
"github.com/openimsdk/chat/pkg/eerrs"
"github.com/openimsdk/chat/pkg/protocol/admin"
Expand All @@ -44,13 +45,13 @@ func (o *adminServer) AddInvitationCode(ctx context.Context, req *admin.AddInvit
return nil, err
}
if len(irs) > 0 {
ids := datautil.Slice(irs, func(info *admin2.InvitationRegister) string { return info.InvitationCode })
ids := datautil.Slice(irs, func(info *admindb.InvitationRegister) string { return info.InvitationCode })
return nil, errs.ErrArgs.WrapMsg("code existed", "ids", ids)
}
now := time.Now()
codes := make([]*admin2.InvitationRegister, 0, len(req.Codes))
codes := make([]*admindb.InvitationRegister, 0, len(req.Codes))
for _, code := range req.Codes {
codes = append(codes, &admin2.InvitationRegister{
codes = append(codes, &admindb.InvitationRegister{
InvitationCode: code,
UsedByUserID: "",
CreateTime: now,
Expand All @@ -73,7 +74,7 @@ func (o *adminServer) GenInvitationCode(ctx context.Context, req *admin.GenInvit
req.Chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
}
now := time.Now()
invitationRegisters := make([]*admin2.InvitationRegister, 0, req.Num)
invitationRegisters := make([]*admindb.InvitationRegister, 0, req.Num)
codes := make([]string, 0, req.Num)
for i := int32(0); i < req.Num; i++ {
buf := make([]byte, req.Len)
Expand All @@ -82,7 +83,7 @@ func (o *adminServer) GenInvitationCode(ctx context.Context, req *admin.GenInvit
buf[i] = req.Chars[b%byte(len(req.Chars))]
}
codes = append(codes, string(buf))
invitationRegisters = append(invitationRegisters, &admin2.InvitationRegister{
invitationRegisters = append(invitationRegisters, &admindb.InvitationRegister{
InvitationCode: string(buf),
UsedByUserID: "",
CreateTime: now,
Expand All @@ -96,7 +97,7 @@ func (o *adminServer) GenInvitationCode(ctx context.Context, req *admin.GenInvit
return nil, err
}
if len(irs) > 0 {
ids := datautil.Single(codes, datautil.Slice(irs, func(ir *admin2.InvitationRegister) string { return ir.InvitationCode }))
ids := datautil.Single(codes, datautil.Slice(irs, func(ir *admindb.InvitationRegister) string { return ir.InvitationCode }))
return nil, errs.ErrArgs.WrapMsg(strings.Join(ids, ", "))
}
if err := o.Database.CreatInvitationRegister(ctx, invitationRegisters); err != nil {
Expand Down Expand Up @@ -173,7 +174,7 @@ func (o *adminServer) DelInvitationCode(ctx context.Context, req *admin.DelInvit
return nil, err
}
if len(irs) != len(req.Codes) {
ids := datautil.Single(req.Codes, datautil.Slice(irs, func(ir *admin2.InvitationRegister) string { return ir.InvitationCode }))
ids := datautil.Single(req.Codes, datautil.Slice(irs, func(ir *admindb.InvitationRegister) string { return ir.InvitationCode }))
return nil, errs.ErrArgs.WrapMsg("code not found " + strings.Join(ids, ", "))
}
if err := o.Database.DelInvitationRegister(ctx, req.Codes); err != nil {
Expand Down
6 changes: 3 additions & 3 deletions internal/rpc/admin/ip_forbidden.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"context"
"time"

admin2 "github.com/openimsdk/chat/pkg/common/db/table/admin"
admindb "github.com/openimsdk/chat/pkg/common/db/table/admin"
"github.com/openimsdk/chat/pkg/common/mctx"
"github.com/openimsdk/chat/pkg/protocol/admin"
)
Expand Down Expand Up @@ -51,9 +51,9 @@ func (o *adminServer) AddIPForbidden(ctx context.Context, req *admin.AddIPForbid
return nil, err
}
now := time.Now()
tables := make([]*admin2.IPForbidden, 0, len(req.Forbiddens))
tables := make([]*admindb.IPForbidden, 0, len(req.Forbiddens))
for _, forbidden := range req.Forbiddens {
tables = append(tables, &admin2.IPForbidden{
tables = append(tables, &admindb.IPForbidden{
IP: forbidden.Ip,
LimitLogin: forbidden.LimitLogin,
LimitRegister: forbidden.LimitRegister,
Expand Down
Loading

0 comments on commit 07f7853

Please sign in to comment.