Skip to content

Commit 55decdd

Browse files
Merge pull request #19 from larksuite/master
add universe search sdk
2 parents 29c4737 + d61bb4d commit 55decdd

File tree

7 files changed

+224
-13
lines changed

7 files changed

+224
-13
lines changed

core/apiresp.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@ type CodeError struct {
4646
ErrCode int `json:"err_code"`
4747
ErrMsg string `json:"err_msg"`
4848
Err struct {
49-
Code int `json:"code,omitempty"`
50-
Msg string `json:"msg,omitempty"`
49+
Code int `json:"code,omitempty"`
50+
Msg string `json:"msg,omitempty"`
51+
LogID string `json:"log_id,omitempty"`
5152
} `json:"err"`
5253
}
5354

@@ -65,10 +66,18 @@ func (ce CodeError) Error() string {
6566

6667
func (ce CodeError) String() string {
6768
sb := strings.Builder{}
68-
sb.WriteString("msg:")
69-
sb.WriteString(ce.ErrMsg)
70-
sb.WriteString(",code:")
69+
sb.WriteString("resp err, code:")
7170
sb.WriteString(strconv.Itoa(ce.ErrCode))
71+
sb.WriteString(", msg:")
72+
sb.WriteString(ce.ErrMsg)
73+
sb.WriteString(", inner code:")
74+
sb.WriteString(strconv.Itoa(ce.Err.Code))
75+
sb.WriteString(", inner msg:")
76+
sb.WriteString(ce.Err.Msg)
77+
if len(ce.Err.LogID) > 0 {
78+
sb.WriteString(", log_id:")
79+
sb.WriteString(ce.Err.LogID)
80+
}
7281
return sb.String()
7382
}
7483

core/apiresp_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package core
2+
3+
import "testing"
4+
5+
func TestAPIResp_Error_String(t *testing.T) {
6+
err := CodeError{
7+
ErrCode: 10001,
8+
ErrMsg: "error message",
9+
Err: struct {
10+
Code int `json:"code,omitempty"`
11+
Msg string `json:"msg,omitempty"`
12+
LogID string `json:"log_id,omitempty"`
13+
}{
14+
Code: 10002,
15+
Msg: "inner error message",
16+
LogID: "20210101000001",
17+
},
18+
}
19+
t.Logf(err.String())
20+
}

go.mod

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
module github.com/larksuite/project-oapi-sdk-golang
22

3-
go 1.15
3+
go 1.22.0
4+
5+
toolchain go1.22.2

service/field/model.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,23 +71,25 @@ type QueryLink struct {
7171
type SimpleField struct {
7272
FieldKey string `json:"field_key"`
7373

74-
FieldTypeKey string `json:"field_type_key"`
75-
76-
Options []*Option `json:"options"`
77-
78-
CompoundFields []*SimpleField `json:"compound_fields"`
79-
8074
FieldAlias string `json:"field_alias"`
8175

76+
FieldTypeKey string `json:"field_type_key"`
77+
8278
FieldName string `json:"field_name"`
8379

8480
IsCustomField bool `json:"is_custom_field"`
8581

82+
Options []*Option `json:"options"`
83+
84+
CompoundFields []*SimpleField `json:"compound_fields"`
85+
8686
IsObsoleted bool `json:"is_obsoleted"`
8787

8888
WorkItemScopes []string `json:"work_item_scopes"`
8989

9090
ValueGenerateMode string `json:"value_generate_mode"`
91+
92+
RelationID string `json:"relation_id"`
9193
}
9294

9395
type TargetState struct {

service/workitem/api.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ const APIPathUpdateWorkingHourRecord = "/open_api/:project_key/work_item/:work_i
7777

7878
const APIPathWbsView = "/open_api/:project_key/work_item/:work_item_type_key/:work_item_id/wbs_view"
7979

80+
const APIPath_UniversalSearch = "/open_api/view_search/universal_search"
81+
8082
func NewService(config *core.Config) *WorkItemService {
8183
a := &WorkItemService{config: config}
8284
return a
@@ -598,3 +600,27 @@ func (a *WorkItemService) WbsView(ctx context.Context, req *WbsViewReq, options
598600
}
599601
return resp, err
600602
}
603+
604+
/*
605+
* @name: openapi获取指定的工作项列表(极简链路,替代原有的GeneralSearch系列)
606+
* @desc: openapi获取指定的工作项列表(极简链路,替代原有的GeneralSearch系列)
607+
*/
608+
func (a *WorkItemService) UniversalSearch(ctx context.Context, req *UniversalSearchReq, options ...core.RequestOptionFunc) (*UniversalSearchResp, error) {
609+
// 发起请求
610+
apiReq := req.apiReq
611+
apiReq.ApiPath = APIPath_UniversalSearch
612+
apiReq.HttpMethod = "POST"
613+
apiResp, err := core.Request(ctx, apiReq, a.config, options...)
614+
if err != nil {
615+
a.config.Logger.Error(ctx, fmt.Sprintf("[UniversalSearch] fail to invoke api, error: %v", err.Error()))
616+
return nil, err
617+
}
618+
// 反序列响应结果
619+
resp := &UniversalSearchResp{APIResp: apiResp}
620+
err = apiResp.JSONUnmarshalBody(resp, a.config)
621+
if err != nil {
622+
a.config.Logger.Error(ctx, fmt.Sprintf("[UniversalSearch] fail to unmarshal response body, error: %v", err.Error()))
623+
return nil, err
624+
}
625+
return resp, err
626+
}

service/workitem/builder.go

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ type AbortWorkItemReqBody struct {
3535
IsAborted bool `json:"is_aborted"`
3636

3737
Reason string `json:"reason"`
38+
39+
ReasonOption string `json:"reason_option"`
3840
}
3941

4042
type AbortWorkItemResp struct {
@@ -56,6 +58,7 @@ func NewAbortWorkItemReqBuilder() *AbortWorkItemReqBuilder {
5658
builder.body = &AbortWorkItemReqBody{}
5759
return builder
5860
}
61+
5962
func (builder *AbortWorkItemReqBuilder) ProjectKey(projectKey string) *AbortWorkItemReqBuilder {
6063
builder.apiReq.PathParams.Set("project_key", fmt.Sprint(projectKey))
6164
return builder
@@ -72,10 +75,17 @@ func (builder *AbortWorkItemReqBuilder) IsAborted(isAborted bool) *AbortWorkItem
7275
builder.body.IsAborted = isAborted
7376
return builder
7477
}
78+
7579
func (builder *AbortWorkItemReqBuilder) Reason(reason string) *AbortWorkItemReqBuilder {
7680
builder.body.Reason = reason
7781
return builder
7882
}
83+
84+
func (builder *AbortWorkItemReqBuilder) ReasonOption(reasonOption string) *AbortWorkItemReqBuilder {
85+
builder.body.ReasonOption = reasonOption
86+
return builder
87+
}
88+
7989
func (builder *AbortWorkItemReqBuilder) Build() *AbortWorkItemReq {
8090
req := &AbortWorkItemReq{}
8191
req.apiReq = builder.apiReq
@@ -1780,3 +1790,79 @@ func (builder *WbsViewReqBuilder) Build() *WbsViewReq {
17801790
req.apiReq.Body = builder.body
17811791
return req
17821792
}
1793+
1794+
type UniversalSearchReq struct {
1795+
apiReq *core.APIReq
1796+
}
1797+
type UniversalSearchReqBody struct {
1798+
DataSources []DataSource `json:"data_sources,omitempty"`
1799+
1800+
UserKey *string `json:"user_key,omitempty"`
1801+
1802+
SearchGroup *SearchGroup `json:"search_group,omitempty"`
1803+
1804+
Sort *Sort `json:"sort,omitempty"`
1805+
1806+
Pagination *Pagination `json:"pagination,omitempty"`
1807+
1808+
FieldSelected []string `json:"field_selected,omitempty"`
1809+
1810+
Features map[string]string `json:"features,omitempty"`
1811+
}
1812+
1813+
type UniversalSearchResp struct {
1814+
*core.APIResp `json:"-"`
1815+
core.CodeError
1816+
Data *string `json:"data,omitempty"`
1817+
1818+
Pagination *Pagination `json:"pagination,omitempty"`
1819+
1820+
ExtraInfo map[string]string `json:"extra_info,omitempty"`
1821+
}
1822+
1823+
type UniversalSearchReqBuilder struct {
1824+
apiReq *core.APIReq
1825+
}
1826+
1827+
func NewUniversalSearchReqBuilder() *UniversalSearchReqBuilder {
1828+
builder := &UniversalSearchReqBuilder{}
1829+
builder.apiReq = &core.APIReq{
1830+
PathParams: core.PathParams{},
1831+
QueryParams: core.QueryParams{},
1832+
Body: &UniversalSearchReqBody{},
1833+
}
1834+
return builder
1835+
}
1836+
func (builder *UniversalSearchReqBuilder) DataSources(dataSources []DataSource) *UniversalSearchReqBuilder {
1837+
builder.apiReq.Body.(*UniversalSearchReqBody).DataSources = dataSources
1838+
return builder
1839+
}
1840+
func (builder *UniversalSearchReqBuilder) UserKey(userKey *string) *UniversalSearchReqBuilder {
1841+
builder.apiReq.Body.(*UniversalSearchReqBody).UserKey = userKey
1842+
return builder
1843+
}
1844+
func (builder *UniversalSearchReqBuilder) SearchGroup(searchGroup *SearchGroup) *UniversalSearchReqBuilder {
1845+
builder.apiReq.Body.(*UniversalSearchReqBody).SearchGroup = searchGroup
1846+
return builder
1847+
}
1848+
func (builder *UniversalSearchReqBuilder) Sort(sort *Sort) *UniversalSearchReqBuilder {
1849+
builder.apiReq.Body.(*UniversalSearchReqBody).Sort = sort
1850+
return builder
1851+
}
1852+
func (builder *UniversalSearchReqBuilder) Pagination(pagination *Pagination) *UniversalSearchReqBuilder {
1853+
builder.apiReq.Body.(*UniversalSearchReqBody).Pagination = pagination
1854+
return builder
1855+
}
1856+
func (builder *UniversalSearchReqBuilder) FieldSelected(fieldSelected []string) *UniversalSearchReqBuilder {
1857+
builder.apiReq.Body.(*UniversalSearchReqBody).FieldSelected = fieldSelected
1858+
return builder
1859+
}
1860+
func (builder *UniversalSearchReqBuilder) Features(features map[string]string) *UniversalSearchReqBuilder {
1861+
builder.apiReq.Body.(*UniversalSearchReqBody).Features = features
1862+
return builder
1863+
}
1864+
func (builder *UniversalSearchReqBuilder) Build() *UniversalSearchReq {
1865+
req := &UniversalSearchReq{}
1866+
req.apiReq = builder.apiReq
1867+
return req
1868+
}

service/workitem/model.go

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ type Expand struct {
8989
NeedUserDetail bool `json:"need_user_detail"`
9090

9191
NeedSubTaskParent bool `json:"need_sub_task_parent"`
92+
93+
NeedUnionDeliverable bool `json:"need_union_deliverable"`
9294
}
9395

9496
type FieldConf struct {
@@ -237,7 +239,7 @@ type Schedule struct {
237239
EstimateEndDate *int64 `json:"estimate_end_date,omitempty"`
238240

239241
Owners []string `json:"owners"`
240-
242+
241243
ActualWorkTime *float64 `json:"actual_work_time,omitempty"`
242244

243245
IsAuto *bool `json:"is_auto,omitempty"`
@@ -399,6 +401,8 @@ type WBSWorkItem struct {
399401
WorkItemTypeKey string `json:"work_item_type_key"`
400402

401403
Milestone bool `json:"milestone"`
404+
405+
UnionDeliverable UnionDeliverable `json:"union_deliverable"`
402406
}
403407

404408
type WbsViewResponse struct {
@@ -491,6 +495,8 @@ type WorkItemRelation struct {
491495
WorkItemTypeName string `json:"work_item_type_name"`
492496

493497
RelationDetails []*RelationDetail `json:"relation_details"`
498+
499+
RelationType int64 `json:"relation_type"`
494500
}
495501

496502
type WorkItemStatus struct {
@@ -572,3 +578,63 @@ type WorkflowNode struct {
572578

573579
Participants []string `json:"participants"`
574580
}
581+
582+
type UnionDeliverable struct {
583+
FieldDeliverables []FieldDeliverableItem `json:"field_deliverables"`
584+
585+
InstanceDeliverables []InstanceDeliverableItem `json:"instance_deliverables"`
586+
}
587+
588+
type FieldDeliverableItem struct {
589+
FieldInfo field.FieldValuePair `json:"field_info"`
590+
591+
Placeholder string `json:"placeholder"`
592+
593+
Remark string `json:"remark"`
594+
595+
Status int64 `json:"status"`
596+
}
597+
598+
type InstanceDeliverableItem struct {
599+
Name string `json:"name"`
600+
601+
WorkItemID int64 `json:"work_item_id"`
602+
603+
Deletable bool `json:"deletable"`
604+
605+
MustComplete bool `json:"must_complete"`
606+
607+
StateKey string `json:"state_key"`
608+
609+
StateName string `json:"state_name"`
610+
611+
Owners []string `json:"owners"`
612+
613+
Remark string `json:"remark"`
614+
}
615+
616+
type DataSource struct {
617+
ProjectKey *string `json:"project_key,omitempty"`
618+
619+
WorkItemTypeKeys *string `json:"work_item_type_keys,omitempty"`
620+
}
621+
622+
type Sort struct {
623+
FieldKey *string `json:"field_key,omitempty"`
624+
625+
FieldType *string `json:"field_type,omitempty"`
626+
627+
WorkItemTypeKey *string `json:"work_item_type_key,omitempty"`
628+
629+
Order *string `json:"order,omitempty"`
630+
631+
Params map[string]string `json:"params,omitempty"`
632+
}
633+
634+
type Pagination struct {
635+
PageNum *int64 `json:"page_num,omitempty"`
636+
637+
PageSize *int64 `json:"page_size,omitempty"`
638+
639+
Total *int64 `json:"total,omitempty"`
640+
}

0 commit comments

Comments
 (0)