page.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. package plane_v2_api
  2. import (
  3. "fmt"
  4. plane "fwh-toolbox-server/repositories/api/plane_v2"
  5. )
  6. // ListPages 列出项目页面
  7. func ListPages(c *plane.PlaneClient, slug, projectID string) ([]byte, error) {
  8. url := fmt.Sprintf("/api/workspaces/%s/projects/%s/pages/", slug, projectID)
  9. resp, err := c.Get(url)
  10. if err != nil {
  11. return nil, err
  12. }
  13. if !plane.IsSuccess(resp.StatusCode) {
  14. return nil, fmt.Errorf("ListPages 失败: %s", resp.Status)
  15. }
  16. return resp.Body, nil
  17. }
  18. // CreatePage 创建页面
  19. func CreatePage(c *plane.PlaneClient, slug, projectID string, data map[string]interface{}) ([]byte, error) {
  20. url := fmt.Sprintf("/api/workspaces/%s/projects/%s/pages/", slug, projectID)
  21. resp, err := c.Post(url, data)
  22. if err != nil {
  23. return nil, err
  24. }
  25. if !plane.IsSuccess(resp.StatusCode) {
  26. return nil, fmt.Errorf("CreatePage 失败: %s, body=%s", resp.Status, string(resp.Body))
  27. }
  28. return resp.Body, nil
  29. }
  30. // GetPage 获取页面详情
  31. func GetPage(c *plane.PlaneClient, slug, projectID, pageID string) ([]byte, error) {
  32. url := fmt.Sprintf("/api/workspaces/%s/projects/%s/pages/%s/", slug, projectID, pageID)
  33. resp, err := c.Get(url)
  34. if err != nil {
  35. return nil, err
  36. }
  37. if !plane.IsSuccess(resp.StatusCode) {
  38. return nil, fmt.Errorf("GetPage 失败: %s", resp.Status)
  39. }
  40. return resp.Body, nil
  41. }
  42. // UpdatePage 更新页面
  43. func UpdatePage(c *plane.PlaneClient, slug, projectID, pageID string, data map[string]interface{}) ([]byte, error) {
  44. url := fmt.Sprintf("/api/workspaces/%s/projects/%s/pages/%s/", slug, projectID, pageID)
  45. resp, err := c.Patch(url, data)
  46. if err != nil {
  47. return nil, err
  48. }
  49. if !plane.IsSuccess(resp.StatusCode) {
  50. return nil, fmt.Errorf("UpdatePage 失败: %s, body=%s", resp.Status, string(resp.Body))
  51. }
  52. return resp.Body, nil
  53. }
  54. // DeletePage 删除页面
  55. func DeletePage(c *plane.PlaneClient, slug, projectID, pageID string) error {
  56. url := fmt.Sprintf("/api/workspaces/%s/projects/%s/pages/%s/", slug, projectID, pageID)
  57. resp, err := c.Delete(url)
  58. if err != nil {
  59. return err
  60. }
  61. if resp.StatusCode != 204 {
  62. return fmt.Errorf("DeletePage 失败: %s", resp.Status)
  63. }
  64. return nil
  65. }
  66. // ArchivePage 归档页面
  67. func ArchivePage(c *plane.PlaneClient, slug, projectID, pageID string) error {
  68. url := fmt.Sprintf("/api/workspaces/%s/projects/%s/pages/%s/archive/", slug, projectID, pageID)
  69. resp, err := c.Post(url, nil)
  70. if err != nil {
  71. return err
  72. }
  73. if !plane.IsSuccess(resp.StatusCode) {
  74. return fmt.Errorf("ArchivePage 失败: %s", resp.Status)
  75. }
  76. return nil
  77. }
  78. // UnarchivePage 取消归档页面
  79. func UnarchivePage(c *plane.PlaneClient, slug, projectID, pageID string) error {
  80. url := fmt.Sprintf("/api/workspaces/%s/projects/%s/pages/%s/archive/", slug, projectID, pageID)
  81. resp, err := c.Delete(url)
  82. if err != nil {
  83. return err
  84. }
  85. if !plane.IsSuccess(resp.StatusCode) {
  86. return fmt.Errorf("UnarchivePage 失败: %s", resp.Status)
  87. }
  88. return nil
  89. }
  90. // GetPageDescription 获取页面描述
  91. func GetPageDescription(c *plane.PlaneClient, slug, projectID, pageID string) ([]byte, error) {
  92. url := fmt.Sprintf("/api/workspaces/%s/projects/%s/pages/%s/description/", slug, projectID, pageID)
  93. resp, err := c.Get(url)
  94. if err != nil {
  95. return nil, err
  96. }
  97. if !plane.IsSuccess(resp.StatusCode) {
  98. return nil, fmt.Errorf("GetPageDescription 失败: %s", resp.Status)
  99. }
  100. return resp.Body, nil
  101. }