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 }