Skip to content

Commit

Permalink
* [stories] imp stories api
Browse files Browse the repository at this point in the history
  • Loading branch information
ysicing committed Sep 20, 2024
1 parent b96d97e commit 739d49f
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 9 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,11 @@ Zentao API client enabling Go programs to interact with Zentao in a simple and u
- [x] 激活需求
- [x] 关闭需求
- [x] 指派需求
- [ ] 预估工时
- [ ] 获取工时(开源版不支持)
- [ ] 预估工时(开源版不支持)
- [ ] 子需求
- [ ] 撤回评审
- [ ] 评审需求
- [x] 撤回评审
- [x] 评审需求
- [x] 项目(Projects)
- [x] 创建项目
- [x] 获取项目列表
Expand Down
28 changes: 28 additions & 0 deletions example/stories/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,32 @@ func main() {
panic(err)
}
log.Printf("assign story id: %v", p9.ID)
// p10, _, err := zt.Stories.GetEstimateByID(p9.ID)
// if err != nil {
// panic(err)
// }
// log.Printf("assign story id: %v", p10.ID)
// p10, _, err := zt.Stories.UpdateEstimateByID(p9.ID, zentao.StoriesEstimate{})
// if err != nil {
// panic(err)
// }
// log.Printf("assign story id: %v", p10.ID)
_, _, err = zt.Stories.RecallByID(p9.ID)
if err != nil {
panic(err)
}
log.Printf("recall story id: %v", p9.ID)
p11, _, err := zt.Stories.ReviewByID(p9.ID, zentao.StoriesReview{
Result: zentao.ReviewResultPass,
Estimate: 1.1,
Comment: "test review",
})
if err != nil {
panic(err)
}
log.Printf("review story id: %v", p11.ID)
_, _, err = zt.Stories.DeleteByID(p9.ID)
if err != nil {
panic(err)
}
}
37 changes: 31 additions & 6 deletions zentao/stories.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,18 @@ type StoriesActive struct {
Comment string `json:"comment,omitempty"`
}

type StoriesEstimate struct {
}

type StoriesReview struct {
ReviewedDate string `json:"reviewedDate,omitempty"`
Result StoriesReviewResult `json:"result,omitempty"`
ClosedReason StoriesCloseReason `json:"closedReason,omitempty"`
Pri int `json:"pri,omitempty"`
Estimate float64 `json:"estimate"`
Comment string `json:"comment,omitempty"`
}

// ProjectsList 获取项目需求列表
func (s *StoriesService) ProjectsList(id int) (*StoriesListMeta, *req.Response, error) {
var u StoriesListMeta
Expand Down Expand Up @@ -239,8 +251,18 @@ func (s *StoriesService) AssignByID(id int, story StoriesActive) (*StoriesMsg, *
return &u, resp, err
}

// EstimateByID 预估工时
func (s *StoriesService) EstimateByID(id int, story StoriesMeta) (*StoriesMsg, *req.Response, error) {
// GetEstimateByID 获取工时, 开源版不支持
func (s *StoriesService) GetEstimateByID(id int) (*StoriesMsg, *req.Response, error) {
var u StoriesMsg
resp, err := s.client.client.R().
SetHeader("Token", s.client.token).
SetSuccessResult(&u).
Get(s.client.RequestURL(fmt.Sprintf("/stories/%d/estimate", id)))
return &u, resp, err
}

// UpdateEstimateByID 更新工时
func (s *StoriesService) UpdateEstimateByID(id int, story StoriesEstimate) (*StoriesMsg, *req.Response, error) {
var u StoriesMsg
resp, err := s.client.client.R().
SetHeader("Token", s.client.token).
Expand All @@ -262,19 +284,22 @@ func (s *StoriesService) ChildByID(id int, story StoriesMeta) (*StoriesMsg, *req
}

// RecallByID 撤回评审
func (s *StoriesService) RecallByID(id int, story StoriesMeta) (*StoriesMsg, *req.Response, error) {
func (s *StoriesService) RecallByID(id int) (*StoriesMsg, *req.Response, error) {
var u StoriesMsg
resp, err := s.client.client.R().
SetHeader("Token", s.client.token).
SetBody(&story).
SetSuccessResult(&u).
Post(s.client.RequestURL(fmt.Sprintf("/stories/%d/recall", id)))
Delete(s.client.RequestURL(fmt.Sprintf("/stories/%d/recall", id)))
return &u, resp, err
}

// ReviewByID 审核需求
func (s *StoriesService) ReviewByID(id int, story StoriesMeta) (*StoriesMsg, *req.Response, error) {
func (s *StoriesService) ReviewByID(id int, story StoriesReview) (*StoriesMsg, *req.Response, error) {
var u StoriesMsg
story.ClosedReason = CloseReasonDone
if story.Estimate <= 0 {
story.Estimate = 1.0
}
resp, err := s.client.client.R().
SetHeader("Token", s.client.token).
SetBody(&story).
Expand Down
8 changes: 8 additions & 0 deletions zentao/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ var (
CloseReasonBydesign StoriesCloseReason = "bydesign" // 设计如此
)

type StoriesReviewResult string // 需求评审结果

var (
ReviewResultPass StoriesReviewResult = "pass" // 通过
ReviewResultRevert StoriesReviewResult = "revert" // 退回 撤销变更
ReviewResultClarify StoriesReviewResult = "clarify" // 有待明确
)

// CustomResp 通用Resp
type CustomResp struct {
Message string `json:"message,omitempty"`
Expand Down

0 comments on commit 739d49f

Please sign in to comment.