fix
This commit is contained in:
@@ -14,5 +14,7 @@ type Config struct {
|
||||
ApiHost string
|
||||
EncryptKey string
|
||||
VerificationToken string
|
||||
AppId string
|
||||
AppSecret string
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
Path: "/api/feishu/webhook",
|
||||
Handler: WebhookHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/api/feishu/sync_feishu_departments",
|
||||
Handler: SyncFeiShuGroupsHandler(serverCtx),
|
||||
},
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"reflect"
|
||||
|
||||
"fusenapi/utils/basic"
|
||||
|
||||
"fusenapi/server/feishu-sync/internal/logic"
|
||||
"fusenapi/server/feishu-sync/internal/svc"
|
||||
"fusenapi/server/feishu-sync/internal/types"
|
||||
)
|
||||
|
||||
func SyncFeiShuGroupsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
var req types.Request
|
||||
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// 创建一个业务逻辑层实例
|
||||
l := logic.NewSyncFeiShuGroupsLogic(r.Context(), svcCtx)
|
||||
|
||||
rl := reflect.ValueOf(l)
|
||||
basic.BeforeLogic(w, r, rl)
|
||||
|
||||
resp := l.SyncFeiShuGroups(&req, userinfo)
|
||||
|
||||
if !basic.AfterLogic(w, r, rl, resp) {
|
||||
basic.NormalAfterLogic(w, r, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
57
server/feishu-sync/internal/logic/syncfeishugroupslogic.go
Normal file
57
server/feishu-sync/internal/logic/syncfeishugroupslogic.go
Normal file
@@ -0,0 +1,57 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
"fusenapi/utils/feishu"
|
||||
"log"
|
||||
|
||||
"context"
|
||||
|
||||
"fusenapi/server/feishu-sync/internal/svc"
|
||||
"fusenapi/server/feishu-sync/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type SyncFeiShuGroupsLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewSyncFeiShuGroupsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SyncFeiShuGroupsLogic {
|
||||
return &SyncFeiShuGroupsLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
// 处理进入前逻辑w,r
|
||||
// func (l *SyncFeiShuGroupsLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
|
||||
// }
|
||||
|
||||
func (l *SyncFeiShuGroupsLogic) SyncFeiShuGroups(req *types.Request, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
feishuApi := &feishu.FeiShuApi{
|
||||
AppId: l.svcCtx.Config.FeiShu.AppId,
|
||||
AppSecret: l.svcCtx.Config.FeiShu.AppSecret,
|
||||
ApiHost: l.svcCtx.Config.FeiShu.ApiHost,
|
||||
}
|
||||
token, err := feishuApi.GetTenantAccessToken()
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
users, err := feishuApi.FindUsersByDepartment(token.TenantAccessToken)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
fmt.Println(users)
|
||||
return resp.SetStatus(basic.CodeOK)
|
||||
}
|
||||
|
||||
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
|
||||
// func (l *SyncFeiShuGroupsLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
|
||||
// // httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
// }
|
||||
Reference in New Issue
Block a user