Skip to content

Commit

Permalink
style:调整代码结构
Browse files Browse the repository at this point in the history
  • Loading branch information
zhengzi committed Mar 19, 2023
1 parent ee35e83 commit 84349f0
Show file tree
Hide file tree
Showing 19 changed files with 439 additions and 294 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@
*.out

# Dependency directories (remove the comment below to include it)
# vendor/
# vendor/

config.json
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Go 实现的 [teambition](https://www.teambition.com/) Open Api 集合
- 创建任务关联 :x:
- 删除任务关联 :x:
- 更新自由任务优先级 :x:
- 查询项目任务 :x:
- 查询项目任务 :heavy_check_mark:
- 归档任务(移入回收站) :x:
- 评论任务 :x:
- 更新任务标题 :x:
Expand All @@ -87,7 +87,7 @@ Go 实现的 [teambition](https://www.teambition.com/) Open Api 集合
- 更新任务备注 :x:
- 获取任务关联列表 :x:
- 更新任务优先级 :x:
- 查询任务详情 :x:
- 查询任务详情 :heavy_check_mark:
- 更新任务开始时间 :x:
- 更新任务标签 :x:
- 更新任务状态 :x:
Expand All @@ -112,11 +112,11 @@ Go 实现的 [teambition](https://www.teambition.com/) Open Api 集合
- 获取一定时间内订阅的指定用户的计划工时聚合数 :x:
- 创建实际工时 :x:
- 获取单个实际工时详情 :x:
- 获取单个任务的实际工时列表 :x:
- 获取单个任务的实际工时列表 :heavy_check_mark:
- 获取单个任务的实际工时总和 :x:
- 获取一定时间内订阅的指定用户的实际工时聚合数据 :x:
- 获取用户所有计划工时详情数据 :x:
- 获取用户所有实际工时详情数据 :x:
- 获取用户所有实际工时详情数据 :heavy_check_mark:
- 更新计划工时单条记录 :x:
- 更新实际工时单条记录 :x:
- 删除实际工时单条记录 :x:
Expand Down Expand Up @@ -163,7 +163,7 @@ Go 实现的 [teambition](https://www.teambition.com/) Open Api 集合
- 查询项目状态和状态历史 :x:
- 恢复归档项目 :x:
- 归档项目 :x:
- 搜索项目标签 :x:
- 搜索项目标签 :heavy_check_mark:
- 创建项目工作流 :x:
- 删除项目工作流 :x:
- 更新项目工作流 :x:
Expand Down
7 changes: 0 additions & 7 deletions example/example.go

This file was deleted.

53 changes: 34 additions & 19 deletions teambition-api/api_contacts_dept.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package teambitionapi

import "fmt"
import (
"fmt"

"github.com/pkg/errors"
)

type Dept struct {
AncestorIDS []string `json:"ancestorIds"` // 所有祖先部门 ID 列表,ancestorIds[0] 为直接父部门,ancestorIds[1] 为父部门的父部门,以此类推
Expand All @@ -14,37 +18,48 @@ type Dept struct {
}

// 获取企业部门列表
//
// GET https://open.teambition.com/api/org/departments
// 接口地址: https://open.teambition.com/docs/apis/6321c6ce912d20d3b5a48bbc
// @param orgId 企业ID
// @param pageToken 分页标识
// @param pageSize 分页大小
func GetOrgDepartments(orgId string, pageToken string, pageSize int) (resp Response[[]Dept], err error) {
_, resp, err = Get[[]Dept](fmt.Sprintf("/org/departments?orgId=%s&pageToken=%s&pageSize=%d", orgId, pageToken, pageSize), nil)
return resp, err
func (c *Client) GetOrgDepartments(orgId string, pageToken string, pageSize int) (resp *Response[[]Dept], err error) {
resp, err = Get[[]Dept](c, fmt.Sprintf("/org/departments?orgId=%s&pageToken=%s&pageSize=%d", orgId, pageToken, pageSize), nil)
if err != nil {
return nil, errors.WithStack(err)
}
return
}

// 获取部门成员列表
// GET https://open.teambition.com/api/departments/members
// 接口地址: https://open.teambition.com/docs/apis/6321c6ce912d20d3b5a48bfc
// @param orgId 企业ID
// @param deptId 部门ID
// @param omitSubDepartment 是否忽略子孙部门成员
// @param pageToken 分页标识
// @param pageSize 分页大小
func GetDeptMembers(orgId string, deptId string, omitSubDepartment bool, pageToken string, pageSize int) (resp Response[[]Member], err error) {
_, resp, err = Get[[]Member](fmt.Sprintf("/departments/members?orgId=%s&deptId=%s&omitSubDepartment=%t&pageToken=%s&pageSize=%d", orgId, deptId, omitSubDepartment, pageToken, pageSize), nil)
return resp, err
// 获取部门成员列表
// GET https://open.teambition.com/api/departments/members
// 接口地址: https://open.teambition.com/docs/apis/6321c6ce912d20d3b5a48bfc
// @param orgId 企业ID
// @param deptId 部门ID
// @param omitSubDepartment 是否忽略子孙部门成员
// @param pageToken 分页标识
// @param pageSize 分页大小
func (c *Client) GetDeptMembers(orgId string, deptId string, omitSubDepartment bool, pageToken string, pageSize int) (resp *Response[[]Member], err error) {
resp, err = Get[[]Member](c, fmt.Sprintf("/departments/members?orgId=%s&deptId=%s&omitSubDepartment=%t&pageToken=%s&pageSize=%d", orgId, deptId, omitSubDepartment, pageToken, pageSize), nil)
if err != nil {
return nil, errors.WithStack(err)
}
return
}

// 获取用户加入的企业部门列表
//
// GET https://open.teambition.com/api/user/joinedDepartments
// 接口地址: https://open.teambition.com/docs/apis/6321c6ce912d20d3b5a48c30
// @param orgId 企业ID
// @param userId 用户ID
// @param pageToken 分页标识
// @param pageSize 分页大小
func GetUserJoinedDepartments(orgId string, userId string, pageToken string, pageSize int) (resp Response[[]Dept], err error) {
_, resp, err = Get[[]Dept](fmt.Sprintf("/user/joinedDepartments?orgId=%s&userId=%s&pageToken=%s&pageSize=%d", orgId, userId, pageToken, pageSize), nil)
return resp, err
}
func (c *Client) GetUserJoinedDepartments(orgId string, userId string, pageToken string, pageSize int) (resp *Response[[]Dept], err error) {
resp, err = Get[[]Dept](c, fmt.Sprintf("/user/joinedDepartments?orgId=%s&userId=%s&pageToken=%s&pageSize=%d", orgId, userId, pageToken, pageSize), nil)
if err != nil {
return nil, errors.WithStack(err)
}
return
}
30 changes: 21 additions & 9 deletions teambition-api/api_contacts_member.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package teambitionapi

import "fmt"
import (
"fmt"

"github.com/pkg/errors"
)

type Member struct {
UserID string `json:"userId"` // 用户 ID
Expand All @@ -27,17 +31,23 @@ type Member struct {
// GET https://open.teambition.com/api/org/admins
// 接口地址: https://open.teambition.com/docs/apis/6321c6ce912d20d3b5a48974
// @param orgId 企业ID 必填
func GetOrgAdmins(orgId string) (members []Member, err error) {
members, _, err = Get[[]Member](fmt.Sprintf("/org/admins?orgId=%s", orgId), nil)
func (c *Client) GetOrgAdmins(orgId string) (resp *Response[[]Member], err error) {
resp, err = Get[[]Member](c, fmt.Sprintf("/org/admins?orgId=%s", orgId), nil)
if err != nil {
return nil, errors.WithStack(err)
}
return
}

// 获取企业拥有者
// GET https://open.teambition.com/api/org/owners
// 接口地址:https://open.teambition.com/docs/apis/6321c6ce912d20d3b5a489be
// @param orgId 企业ID 必填
func GetOrgOwners(orgId string) (members []Member, err error) {
members, _, err = Get[[]Member](fmt.Sprintf("/org/owners?orgId=%s", orgId), nil)
func (c *Client) GetOrgOwners(orgId string) (resp *Response[[]Member], err error) {
resp, err = Get[[]Member](c, fmt.Sprintf("/org/owners?orgId=%s", orgId), nil)
if err != nil {
return nil, errors.WithStack(err)
}
return
}

Expand All @@ -48,8 +58,10 @@ func GetOrgOwners(orgId string) (members []Member, err error) {
// @param pageToken 分页标记,第一次请求不填或者空字符串,表示从头开始遍历;分页查询结果还有更多项时返回 nextPageToken,下次遍历可采用该 nextPageToken 入参 pageToken 获取查询结果,示例值:"cfcb90voe9jct71bqkfg"
// @param pageSize 分页大小,默认值 10
// @param filter 该参数用于指定查询范围,initiate:新加入的成员,disabled:已禁用的成员,enabled:未禁用的成员,external:外部成员
func GetOrgMembers(orgId string, pageToken string, pageSize int, filter string) (members []Member, count int64, nextPageToken string, err error) {
members, resp, err := Get[[]Member](fmt.Sprintf("/org/member/list?orgId=%s&pageToken=%s&pageSize=%d&filter=%s", orgId, pageToken, pageSize, filter), nil)

return members, resp.TotalSize, resp.NextPageToken, err
func (c *Client) GetOrgMembers(orgId string, pageToken string, pageSize int, filter string) (resp *Response[[]Member], err error) {
resp, err = Get[[]Member](c, fmt.Sprintf("/org/member/list?orgId=%s&pageToken=%s&pageSize=%d&filter=%s", orgId, pageToken, pageSize, filter), nil)
if err != nil {
return nil, errors.WithStack(err)
}
return
}
16 changes: 1 addition & 15 deletions teambition-api/api_contacts_member_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,10 @@ package teambitionapi_test

import (
"testing"

teambition "github.com/kexin8/teambition-sdk-go"
example "github.com/kexin8/teambition-sdk-go/example"
teambitionapi "github.com/kexin8/teambition-sdk-go/teambition-api"
)

var (
orgId = example.OrgId
appId = example.AppId
appSecret = example.AppSecret
)

func init() {
teambitionapi.NewClient(teambition.NewOptions(orgId, appId, appSecret))
}

func TestGetOrgAdmins(t *testing.T) {
members, err := teambitionapi.GetOrgAdmins(orgId)
members, err := tbapi.GetOrgAdmins(orgId)
if err != nil {
t.Error(err)
}
Expand Down
41 changes: 29 additions & 12 deletions teambition-api/api_org.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package teambitionapi

import "fmt"
import (
"fmt"

"github.com/pkg/errors"
)

// Org 企业信息
type Org struct {
Expand Down Expand Up @@ -48,12 +52,15 @@ type Scenariofield struct {
Required bool `json:"required"` // 是否必填
}

//获取企业信息
// 获取企业信息
// GET https://open.teambition.com/api/org/info
// 接口地址: https://open.teambition.com/docs/apis/6321c6ce912d20d3b5a488f4
// @param orgId 企业ID
func GetOrgInfo(orgId string) (orgDomain Org, err error) {
orgDomain, _, err = Get[Org](fmt.Sprintf("/org/info?orgId=%s", orgId), nil)
func (c *Client) GetOrgInfo(orgId string) (resp *Response[Org], err error) {
resp, err = Get[Org](c, fmt.Sprintf("/org/info?orgId=%s", orgId), nil)
if err != nil {
return nil, errors.WithStack(err)
}
return
}

Expand All @@ -64,17 +71,23 @@ func GetOrgInfo(orgId string) (orgDomain Org, err error) {
// @param categoryIds 自定义字段分类ID集合,逗号组合
// @param pageToken 分页标识
// @param pageSize 分页大小(默认50)
func V3CustomFieldCategorySearch(q, categoryIds, pageToken string, pageSize int) (data CustomFieldCategory, nextPageToken string, err error) {
data, resp, err := Get[CustomFieldCategory](fmt.Sprintf("/v3/customfield-category/search?q=%s&categoryIds=%s&pageToken=%s&pageSize=%d", q, categoryIds, pageToken, pageSize), nil)
return data, resp.NextPageToken, err
func (c *Client) V3CustomFieldCategorySearch(q, categoryIds, pageToken string, pageSize int) (resp *Response[CustomFieldCategory], err error) {
resp, err = Get[CustomFieldCategory](c, fmt.Sprintf("/v3/customfield-category/search?q=%s&categoryIds=%s&pageToken=%s&pageSize=%d", q, categoryIds, pageToken, pageSize), nil)
if err != nil {
return nil, errors.WithStack(err)
}
return
}

// 根据自定义字段分类统计自定义字段数
// GET https://open.teambition.com/api/v3/customfield/count-by-category
// 接口地址: https://open.teambition.com/docs/apis/63ee3ea2912d20d3b543ee9c
// @param categoryIds 自定义字段分类ID集合,逗号组合,未分类可使用 uncategory
func V3CustomFieldCountByCategory(categoryIds string) (data Category, err error) {
data, _, err = Get[Category](fmt.Sprintf("/v3/customfield/count-by-category?categoryIds=%s", categoryIds), nil)
func (c *Client) V3CustomFieldCountByCategory(categoryIds string) (resp *Response[Category], err error) {
resp, err = Get[Category](c, fmt.Sprintf("/v3/customfield/count-by-category?categoryIds=%s", categoryIds), nil)
if err != nil {
return nil, errors.WithStack(err)
}
return
}

Expand All @@ -85,8 +98,12 @@ func V3CustomFieldCountByCategory(categoryIds string) (data Category, err error)
// @param sfcIds 任务类型ID集合,逗号组合
// @param pageToken 分页标识
// @param pageSize 分页大小(默认50)
func V3ScenarioFieldConfigSearch(q, sfcIds string, pageToken string, pageSize int) (data Scenariofieldconfig, nextPageToken string, err error) {
data, resp, err := Get[Scenariofieldconfig](fmt.Sprintf("/v3/scenariofieldconfig/search?q=%s&sfcIds=%s&pageToken=%s&pageSize=%d", q, sfcIds, pageToken, pageSize), nil)
func (c *Client) V3ScenarioFieldConfigSearch(q, sfcIds string, pageToken string, pageSize int) (resp *Response[Scenariofieldconfig], err error) {
resp, err = Get[Scenariofieldconfig](c, fmt.Sprintf("/v3/scenariofieldconfig/search?q=%s&sfcIds=%s&pageToken=%s&pageSize=%d", q, sfcIds, pageToken, pageSize), nil)

return data, resp.NextPageToken, err
if err != nil {
return nil, errors.WithStack(err)
}

return
}
16 changes: 2 additions & 14 deletions teambition-api/api_org_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,13 @@ package teambitionapi_test

import (
"testing"

teambition "github.com/kexin8/teambition-sdk-go"
example "github.com/kexin8/teambition-sdk-go/example"
teambitionapi "github.com/kexin8/teambition-sdk-go/teambition-api"
)

func TestGetOrgInfo(t *testing.T) {

var (
orgId = example.OrgId
appId = example.AppId
appSecret = example.AppSecret
)

teambitionapi.NewClient(teambition.NewOptions(orgId, appId, appSecret))

orgInfo, err := teambitionapi.GetOrgInfo(orgId)
orgInfo, err := tbapi.GetOrgInfo(orgId)
if err != nil {
t.Error(err)
t.Errorf("%v", err)
}
t.Log(orgInfo)
}
Loading

0 comments on commit 84349f0

Please sign in to comment.