| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- package plane_v2_api
- import (
- "fmt"
- plane "fwh-toolbox-server/repositories/api/plane_v2"
- )
- // ListPages 列出项目页面
- func ListPages(c *plane.PlaneClient, slug, projectID string) ([]byte, error) {
- url := fmt.Sprintf("/api/workspaces/%s/projects/%s/pages/", slug, projectID)
- resp, err := c.Get(url)
- if err != nil {
- return nil, err
- }
- if !plane.IsSuccess(resp.StatusCode) {
- return nil, fmt.Errorf("ListPages 失败: %s", resp.Status)
- }
- return resp.Body, nil
- }
- // CreatePage 创建页面
- func CreatePage(c *plane.PlaneClient, slug, projectID string, data map[string]interface{}) ([]byte, error) {
- url := fmt.Sprintf("/api/workspaces/%s/projects/%s/pages/", slug, projectID)
- resp, err := c.Post(url, data)
- if err != nil {
- return nil, err
- }
- if !plane.IsSuccess(resp.StatusCode) {
- return nil, fmt.Errorf("CreatePage 失败: %s, body=%s", resp.Status, string(resp.Body))
- }
- return resp.Body, nil
- }
- // GetPage 获取页面详情
- func GetPage(c *plane.PlaneClient, slug, projectID, pageID string) ([]byte, error) {
- url := fmt.Sprintf("/api/workspaces/%s/projects/%s/pages/%s/", slug, projectID, pageID)
- resp, err := c.Get(url)
- if err != nil {
- return nil, err
- }
- if !plane.IsSuccess(resp.StatusCode) {
- return nil, fmt.Errorf("GetPage 失败: %s", resp.Status)
- }
- return resp.Body, nil
- }
- // UpdatePage 更新页面
- func UpdatePage(c *plane.PlaneClient, slug, projectID, pageID string, data map[string]interface{}) ([]byte, error) {
- url := fmt.Sprintf("/api/workspaces/%s/projects/%s/pages/%s/", slug, projectID, pageID)
- resp, err := c.Patch(url, data)
- if err != nil {
- return nil, err
- }
- if !plane.IsSuccess(resp.StatusCode) {
- return nil, fmt.Errorf("UpdatePage 失败: %s, body=%s", resp.Status, string(resp.Body))
- }
- return resp.Body, nil
- }
- // DeletePage 删除页面
- func DeletePage(c *plane.PlaneClient, slug, projectID, pageID string) error {
- url := fmt.Sprintf("/api/workspaces/%s/projects/%s/pages/%s/", slug, projectID, pageID)
- resp, err := c.Delete(url)
- if err != nil {
- return err
- }
- if resp.StatusCode != 204 {
- return fmt.Errorf("DeletePage 失败: %s", resp.Status)
- }
- return nil
- }
- // ArchivePage 归档页面
- func ArchivePage(c *plane.PlaneClient, slug, projectID, pageID string) error {
- url := fmt.Sprintf("/api/workspaces/%s/projects/%s/pages/%s/archive/", slug, projectID, pageID)
- resp, err := c.Post(url, nil)
- if err != nil {
- return err
- }
- if !plane.IsSuccess(resp.StatusCode) {
- return fmt.Errorf("ArchivePage 失败: %s", resp.Status)
- }
- return nil
- }
- // UnarchivePage 取消归档页面
- func UnarchivePage(c *plane.PlaneClient, slug, projectID, pageID string) error {
- url := fmt.Sprintf("/api/workspaces/%s/projects/%s/pages/%s/archive/", slug, projectID, pageID)
- resp, err := c.Delete(url)
- if err != nil {
- return err
- }
- if !plane.IsSuccess(resp.StatusCode) {
- return fmt.Errorf("UnarchivePage 失败: %s", resp.Status)
- }
- return nil
- }
- // GetPageDescription 获取页面描述
- func GetPageDescription(c *plane.PlaneClient, slug, projectID, pageID string) ([]byte, error) {
- url := fmt.Sprintf("/api/workspaces/%s/projects/%s/pages/%s/description/", slug, projectID, pageID)
- resp, err := c.Get(url)
- if err != nil {
- return nil, err
- }
- if !plane.IsSuccess(resp.StatusCode) {
- return nil, fmt.Errorf("GetPageDescription 失败: %s", resp.Status)
- }
- return resp.Body, nil
- }
|