Skip to content

Commit

Permalink
获取需求分类
Browse files Browse the repository at this point in the history
  • Loading branch information
flc1125 committed Aug 26, 2024
1 parent b0a505f commit b1aab62
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 34 deletions.
53 changes: 50 additions & 3 deletions api_story.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`

Check failure on line 382 in api_story.go

View workflow job for this annotation

GitHub Actions / lint

var-naming: struct field ParentId should be ParentID (revive)
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

Check failure on line 403 in api_story.go

View workflow job for this annotation

GitHub Actions / lint

Consider pre-allocating `categories` (prealloc)
for _, item := range items {
categories = append(categories, item.Category)
}

return categories, resp, nil
}

// 获取需求分类数量
// 获取指定分类需求数量

Expand All @@ -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
Expand All @@ -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"`
}
Expand Down
1 change: 0 additions & 1 deletion api_types.go

This file was deleted.

62 changes: 62 additions & 0 deletions api_types_order.go
Original file line number Diff line number Diff line change
@@ -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
}
3 changes: 2 additions & 1 deletion features.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
1、所有字段均为指针类型,不限于请求和响应
2、尽可能以最精简的请求参数或结构体、响应参数或结构体
3、所有的WorkSpaceID和StoryID等均为string类型
```

## 研发协作API
Expand All @@ -19,7 +20,7 @@
- [ ] 获取需求数量:请求参数未优化
- [ ] 获取保密需求
- [ ] 获取保密需求数量
- [ ] 获取需求分类
- [x] 获取需求分类
- [ ] 获取需求分类数量
- [ ] 获取指定分类需求数量
- [ ] 获取需求变更历史
Expand Down
29 changes: 0 additions & 29 deletions helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit b1aab62

Please sign in to comment.