package fastgpt import ( "context" "github.com/zeromicro/go-zero/core/errorx" "strconv" "wechat-api/internal/svc" "wechat-api/internal/types" "github.com/zeromicro/go-zero/core/logx" ) type GetAppsListLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext } func NewGetAppsListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetAppsListLogic { return &GetAppsListLogic{ Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx} } func (l *GetAppsListLogic) GetAppsList(req *types.AppsListReq) (resp *types.AppsListResp, err error) { organizationId := l.ctx.Value("organizationId").(uint64) organizationIdStr := strconv.FormatUint(organizationId, 10) user, err := l.svcCtx.MongoModel.UsersModel.FindOneByUsername(context.TODO(), organizationIdStr) if err != nil { return nil, errorx.NewInvalidArgumentError("fastgpt get list failed " + err.Error()) } teamMember, err := l.svcCtx.MongoModel.TeamMembersModel.FindOneByUserId(context.TODO(), user.ID) if err != nil { return nil, errorx.NewInvalidArgumentError("fastgpt get list failed " + err.Error()) } data, err := l.svcCtx.MongoModel.AppsModel.FindAll(context.TODO(), teamMember.TeamID, req.Type, req.Keyword) if err != nil { return nil, errorx.NewInvalidArgumentError("fastgpt get list failed " + err.Error()) } var appList []*types.AppsListRespInfo if data != nil { for _, app := range data { appList = append(appList, &types.AppsListRespInfo{ Id: app.ID.String(), TeamId: app.TeamID.String(), TmbId: app.TmbID.String(), Avatar: app.Avatar, Name: app.Name, Intro: app.Intro, }) } } return &types.AppsListResp{Data: appList}, nil }