plane_sticky.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. package plane_v2
  2. import (
  3. "fmt"
  4. "go.uber.org/zap"
  5. )
  6. // ==================== Sticky (便签) API ====================
  7. // ListStickies 列出便签
  8. func ListStickies(slug string) ([]byte, error) {
  9. url := fmt.Sprintf("/api/workspaces/%s/stickies/", slug)
  10. resp, err := planeWebGet(url)
  11. if err != nil {
  12. zap.L().Error("[PlaneWeb] ListStickies 请求失败", zap.Error(err))
  13. return nil, err
  14. }
  15. if !isWebSuccess(resp.StatusCode) {
  16. zap.L().Error("[PlaneWeb] ListStickies 返回错误", zap.String("status", resp.Status))
  17. return nil, fmt.Errorf("ListStickies 失败: %s", resp.Status)
  18. }
  19. return resp.Body, nil
  20. }
  21. // CreateSticky 创建便签
  22. func CreateSticky(slug string, data map[string]interface{}) ([]byte, error) {
  23. url := fmt.Sprintf("/api/workspaces/%s/stickies/", slug)
  24. resp, err := planeWebPost(url, data)
  25. if err != nil {
  26. zap.L().Error("[PlaneWeb] CreateSticky 请求失败", zap.Error(err))
  27. return nil, err
  28. }
  29. if resp.StatusCode != 201 {
  30. zap.L().Error("[PlaneWeb] CreateSticky 返回错误",
  31. zap.String("status", resp.Status),
  32. zap.String("body", string(resp.Body)),
  33. )
  34. return nil, fmt.Errorf("CreateSticky 失败: %s", resp.Status)
  35. }
  36. return resp.Body, nil
  37. }
  38. // GetSticky 获取便签详情
  39. func GetSticky(slug, stickyID string) ([]byte, error) {
  40. url := fmt.Sprintf("/api/workspaces/%s/stickies/%s/", slug, stickyID)
  41. resp, err := planeWebGet(url)
  42. if err != nil {
  43. zap.L().Error("[PlaneWeb] GetSticky 请求失败", zap.Error(err))
  44. return nil, err
  45. }
  46. if !isWebSuccess(resp.StatusCode) {
  47. zap.L().Error("[PlaneWeb] GetSticky 返回错误", zap.String("status", resp.Status))
  48. return nil, fmt.Errorf("GetSticky 失败: %s", resp.Status)
  49. }
  50. return resp.Body, nil
  51. }
  52. // UpdateSticky 更新便签
  53. func UpdateSticky(slug, stickyID string, data map[string]interface{}) ([]byte, error) {
  54. url := fmt.Sprintf("/api/workspaces/%s/stickies/%s/", slug, stickyID)
  55. resp, err := planeWebPatch(url, data)
  56. if err != nil {
  57. zap.L().Error("[PlaneWeb] UpdateSticky 请求失败", zap.Error(err))
  58. return nil, err
  59. }
  60. if !isWebSuccess(resp.StatusCode) {
  61. zap.L().Error("[PlaneWeb] UpdateSticky 返回错误",
  62. zap.String("status", resp.Status),
  63. zap.String("body", string(resp.Body)),
  64. )
  65. return nil, fmt.Errorf("UpdateSticky 失败: %s", resp.Status)
  66. }
  67. return resp.Body, nil
  68. }
  69. // DeleteSticky 删除便签
  70. func DeleteSticky(slug, stickyID string) error {
  71. url := fmt.Sprintf("/api/workspaces/%s/stickies/%s/", slug, stickyID)
  72. resp, err := planeWebDelete(url)
  73. if err != nil {
  74. zap.L().Error("[PlaneWeb] DeleteSticky 请求失败", zap.Error(err))
  75. return err
  76. }
  77. if resp.StatusCode != 204 {
  78. zap.L().Error("[PlaneWeb] DeleteSticky 返回错误", zap.String("status", resp.Status))
  79. return fmt.Errorf("DeleteSticky 失败: %s", resp.Status)
  80. }
  81. return nil
  82. }
  83. // ListCurrentStickies 列出当前工作空间的便签
  84. func ListCurrentStickies() ([]byte, error) {
  85. return ListStickies(webWorkspaceSlug)
  86. }