diff --git a/api_story.go b/api_story.go index 190e5a5..ed9f6be 100644 --- a/api_story.go +++ b/api_story.go @@ -359,7 +359,55 @@ func (s *StoryService) GetStoriesCount(ctx context.Context, request *GetStoriesC // 获取保密需求 // 获取保密需求数量 -// 获取需求分类 + +type GetStoryCategoriesRequest struct { + WorkspaceID *int `url:"workspace_id,omitempty"` // [必须]项目ID + ID *string `url:"id,omitempty"` // ID 支持多ID查询,多个ID用逗号分隔 + Name *string `url:"name,omitempty"` // 需求分类名称 支持模糊匹配 + Description *string `url:"description,omitempty"` // 需求分类描述 + ParentID *int `url:"parent_id,omitempty"` // 父分类ID + Created *string `url:"created,omitempty"` // 创建时间 支持时间查询 + Modified *string `url:"modified,omitempty"` // 最后修改时间 支持时间查询 + Limit *int `url:"limit,omitempty"` // 设置返回数量限制,默认为30 + Page *int `url:"page,omitempty"` // 返回当前数量限制下第N页的数据,默认为1(第一页) + Order *string `url:"order,omitempty"` // 排序规则,规则:字段名 ASC或者DESC,然后 urlencode 如按创建时间逆序:order=created%20desc + Fields *string `url:"fields,omitempty"` // 设置获取的字段,多个字段间以','逗号隔开 +} + +type StoryCategory struct { + ID *string `json:"id"` + WorkspaceID *string `json:"workspace_id"` + Name *string `json:"name"` + Description *string `json:"description"` + ParentId *string `json:"parent_id"` + Created *string `json:"created"` + Modified *string `json:"modified"` +} + +// GetStoryCategories 获取需求分类 +// https://open.tapd.cn/document/api-doc/API%E6%96%87%E6%A1%A3/api_reference/story/get_story_categories.html +func (s *StoryService) GetStoryCategories(ctx context.Context, request *GetStoryCategoriesRequest, opts ...RequestOption) ([]*StoryCategory, *Response, error) { + req, err := s.client.NewRequest(ctx, http.MethodGet, "story_categories", request, opts) + if err != nil { + return nil, nil, err + } + + var items []struct { + Category *StoryCategory + } + resp, err := s.client.Do(req, &items) + if err != nil { + return nil, resp, err + } + + var categories []*StoryCategory + for _, item := range items { + categories = append(categories, item.Category) + } + + return categories, resp, nil +} + // 获取需求分类数量 // 获取指定分类需求数量 @@ -379,7 +427,6 @@ type GetStoryChangesRequest struct { // page 否 integer 返回当前数量限制下第N页的数据,默认为1(第一页) // order 否 string 排序规则,规则:字段名 ASC或者DESC,然后 urlencode 如按创建时间逆序:order=created%20desc // fields 否 string 设置获取的字段,多个字段间以','逗号隔开 - // # ID *int `url:"id,omitempty"` // 变更历史id 支持多ID查询 StoryID *int `url:"story_id,omitempty"` // 需求id 支持多ID查询 WorkspaceID *int `url:"workspace_id,omitempty"` // [必须]项目ID @@ -398,7 +445,7 @@ type GetStoryChangesRequest struct { } type StoryChangeItem struct { - Field string `json:"field"` + Field string `json:"Field"` ValueBefore any `json:"value_before"` ValueAfter any `json:"value_after"` } diff --git a/api_types.go b/api_types.go deleted file mode 100644 index 318533c..0000000 --- a/api_types.go +++ /dev/null @@ -1 +0,0 @@ -package tapd diff --git a/api_types_order.go b/api_types_order.go new file mode 100644 index 0000000..e211a02 --- /dev/null +++ b/api_types_order.go @@ -0,0 +1,62 @@ +// Package tapd +// Dependence: api_types.go +package tapd + +import ( + "encoding/json" + "fmt" +) + +var ( + OrderAsc = WithOrderType(OrderTypeAsc) + OrderDesc = WithOrderType(OrderTypeDesc) +) + +type OrderType string + +const ( + OrderTypeAsc OrderType = "asc" + OrderTypeDesc OrderType = "desc" +) + +type Order struct { + Field string + OrderType OrderType +} + +var ( + _ json.Marshaler = (*Order)(nil) + _ json.Unmarshaler = (*Order)(nil) +) + +type OrderOption func(*Order) + +func WithOrderType(orderType OrderType) OrderOption { + return func(o *Order) { + o.OrderType = orderType + } +} + +func NewOrder(field string, opts ...OrderOption) *Order { + o := &Order{ + Field: field, + OrderType: OrderTypeAsc, + } + for _, opt := range opts { + opt(o) + } + return o +} + +func (o *Order) MarshalJSON() ([]byte, error) { + return json.Marshal(fmt.Sprintf("%s %s", o.Field, o.OrderType)) +} + +func (o *Order) UnmarshalJSON(bytes []byte) error { + var s string + if err := json.Unmarshal(bytes, &s); err != nil { + return err + } + _, err := fmt.Sscanf(s, "%s %s", &o.Field, &o.OrderType) + return err +} diff --git a/features.md b/features.md index 3dfd540..3fa426f 100644 --- a/features.md +++ b/features.md @@ -5,6 +5,7 @@ 1、所有字段均为指针类型,不限于请求和响应 2、尽可能以最精简的请求参数或结构体、响应参数或结构体 +3、所有的WorkSpaceID和StoryID等均为string类型 ``` ## 研发协作API @@ -19,7 +20,7 @@ - [ ] 获取需求数量:请求参数未优化 - [ ] 获取保密需求 - [ ] 获取保密需求数量 -- [ ] 获取需求分类 +- [x] 获取需求分类 - [ ] 获取需求分类数量 - [ ] 获取指定分类需求数量 - [ ] 获取需求变更历史 diff --git a/helpers.go b/helpers.go index 2581576..1690ea3 100644 --- a/helpers.go +++ b/helpers.go @@ -32,32 +32,3 @@ func ParseStoryID(id any) (string, error) { return "", ErrorInvalidStoryID } } - -type OrderType string - -const ( - OrderTypeAsc OrderType = "asc" - OrderTypeDesc OrderType = "desc" -) - -type Order struct { - field string - orderType OrderType -} - -type OrderOption func(*Order) - -func NewOrder(field string, opts ...OrderOption) *Order { - o := &Order{ - field: field, - orderType: OrderTypeAsc, - } - for _, opt := range opts { - opt(o) - } - return o -} - -func (o *Order) String() string { - return o.field + " " + string(o.orderType) -}