| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- package plane_v2_api
- import (
- "fmt"
- plane "fwh-toolbox-server/repositories/api/plane_v2"
- )
- // ListProjects 列出工作空间下的所有项目
- func ListProjects(c *plane.PlaneClient, slug string) ([]byte, error) {
- url := fmt.Sprintf("/api/workspaces/%s/projects/", slug)
- resp, err := c.Get(url)
- if err != nil {
- return nil, err
- }
- if !plane.IsSuccess(resp.StatusCode) {
- return nil, fmt.Errorf("ListProjects 失败: %s", resp.Status)
- }
- return resp.Body, nil
- }
- // CreateProject 创建项目
- func CreateProject(c *plane.PlaneClient, slug string, data map[string]interface{}) ([]byte, error) {
- url := fmt.Sprintf("/api/workspaces/%s/projects/", slug)
- resp, err := c.Post(url, data)
- if err != nil {
- return nil, err
- }
- if !plane.IsSuccess(resp.StatusCode) {
- return nil, fmt.Errorf("CreateProject 失败: %s, body=%s", resp.Status, string(resp.Body))
- }
- return resp.Body, nil
- }
- // GetProject 获取项目详情
- func GetProject(c *plane.PlaneClient, slug, projectID string) ([]byte, error) {
- url := fmt.Sprintf("/api/workspaces/%s/projects/%s/", slug, projectID)
- resp, err := c.Get(url)
- if err != nil {
- return nil, err
- }
- if !plane.IsSuccess(resp.StatusCode) {
- return nil, fmt.Errorf("GetProject 失败: %s", resp.Status)
- }
- return resp.Body, nil
- }
- // UpdateProject 更新项目
- func UpdateProject(c *plane.PlaneClient, slug, projectID string, data map[string]interface{}) ([]byte, error) {
- url := fmt.Sprintf("/api/workspaces/%s/projects/%s/", slug, projectID)
- resp, err := c.Patch(url, data)
- if err != nil {
- return nil, err
- }
- if !plane.IsSuccess(resp.StatusCode) {
- return nil, fmt.Errorf("UpdateProject 失败: %s, body=%s", resp.Status, string(resp.Body))
- }
- return resp.Body, nil
- }
- // DeleteProject 删除项目
- func DeleteProject(c *plane.PlaneClient, slug, projectID string) error {
- url := fmt.Sprintf("/api/workspaces/%s/projects/%s/", slug, projectID)
- resp, err := c.Delete(url)
- if err != nil {
- return err
- }
- if resp.StatusCode != 204 {
- return fmt.Errorf("DeleteProject 失败: %s", resp.Status)
- }
- return nil
- }
- // ArchiveProject 归档项目
- func ArchiveProject(c *plane.PlaneClient, slug, projectID string) error {
- url := fmt.Sprintf("/api/workspaces/%s/projects/%s/archive/", slug, projectID)
- resp, err := c.Post(url, nil)
- if err != nil {
- return err
- }
- if !plane.IsSuccess(resp.StatusCode) {
- return fmt.Errorf("ArchiveProject 失败: %s", resp.Status)
- }
- return nil
- }
- // UnarchiveProject 取消归档项目
- func UnarchiveProject(c *plane.PlaneClient, slug, projectID string) error {
- url := fmt.Sprintf("/api/workspaces/%s/projects/%s/archive/", slug, projectID)
- resp, err := c.Delete(url)
- if err != nil {
- return err
- }
- if !plane.IsSuccess(resp.StatusCode) {
- return fmt.Errorf("UnarchiveProject 失败: %s", resp.Status)
- }
- return nil
- }
|