plane_sticky.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. package plane_v1
  2. import (
  3. "fmt"
  4. "go.uber.org/zap"
  5. )
  6. // ==================== Sticky (便签) API ====================
  7. // ListStickies 列出便签
  8. func ListStickies() ([]byte, error) {
  9. path := fmt.Sprintf("/api/v1/workspaces/%s/stickies/", planeWorkspaceSlug)
  10. resp, err := planeHttpGet(path)
  11. if err != nil {
  12. zap.L().Error("[Plane] ListStickies 请求失败", zap.Error(err))
  13. return nil, err
  14. }
  15. if !isSuccess(resp.StatusCode) {
  16. zap.L().Error("[Plane] 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(data map[string]interface{}) ([]byte, error) {
  23. path := fmt.Sprintf("/api/v1/workspaces/%s/stickies/", planeWorkspaceSlug)
  24. resp, err := planeHttpPost(path, data)
  25. if err != nil {
  26. zap.L().Error("[Plane] CreateSticky 请求失败", zap.Error(err))
  27. return nil, err
  28. }
  29. if resp.StatusCode != 201 {
  30. zap.L().Error("[Plane] CreateSticky 返回错误", zap.String("status", resp.Status), zap.String("body", string(resp.Body)))
  31. return nil, fmt.Errorf("CreateSticky 失败: %s", resp.Status)
  32. }
  33. return resp.Body, nil
  34. }
  35. // GetSticky 获取便签详情
  36. func GetSticky(stickyID string) ([]byte, error) {
  37. path := fmt.Sprintf("/api/v1/workspaces/%s/stickies/%s/", planeWorkspaceSlug, stickyID)
  38. resp, err := planeHttpGet(path)
  39. if err != nil {
  40. zap.L().Error("[Plane] GetSticky 请求失败", zap.Error(err))
  41. return nil, err
  42. }
  43. if !isSuccess(resp.StatusCode) {
  44. zap.L().Error("[Plane] GetSticky 返回错误", zap.String("status", resp.Status))
  45. return nil, fmt.Errorf("GetSticky 失败: %s", resp.Status)
  46. }
  47. return resp.Body, nil
  48. }
  49. // UpdateSticky 更新便签
  50. func UpdateSticky(stickyID string, data map[string]interface{}) ([]byte, error) {
  51. path := fmt.Sprintf("/api/v1/workspaces/%s/stickies/%s/", planeWorkspaceSlug, stickyID)
  52. resp, err := planeHttpPatch(path, data)
  53. if err != nil {
  54. zap.L().Error("[Plane] UpdateSticky 请求失败", zap.Error(err))
  55. return nil, err
  56. }
  57. if !isSuccess(resp.StatusCode) {
  58. zap.L().Error("[Plane] UpdateSticky 返回错误", zap.String("status", resp.Status), zap.String("body", string(resp.Body)))
  59. return nil, fmt.Errorf("UpdateSticky 失败: %s", resp.Status)
  60. }
  61. return resp.Body, nil
  62. }
  63. // DeleteSticky 删除便签
  64. func DeleteSticky(stickyID string) error {
  65. path := fmt.Sprintf("/api/v1/workspaces/%s/stickies/%s/", planeWorkspaceSlug, stickyID)
  66. resp, err := planeHttpDelete(path)
  67. if err != nil {
  68. zap.L().Error("[Plane] DeleteSticky 请求失败", zap.Error(err))
  69. return err
  70. }
  71. if resp.StatusCode != 204 {
  72. zap.L().Error("[Plane] DeleteSticky 返回错误", zap.String("status", resp.Status))
  73. return fmt.Errorf("DeleteSticky 失败: %s", resp.Status)
  74. }
  75. return nil
  76. }