| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- package plane_v1
- import (
- "fmt"
- "go.uber.org/zap"
- )
- // ==================== Sticky (便签) API ====================
- // ListStickies 列出便签
- func ListStickies() ([]byte, error) {
- path := fmt.Sprintf("/api/v1/workspaces/%s/stickies/", planeWorkspaceSlug)
- resp, err := planeHttpGet(path)
- if err != nil {
- zap.L().Error("[Plane] ListStickies 请求失败", zap.Error(err))
- return nil, err
- }
- if !isSuccess(resp.StatusCode) {
- zap.L().Error("[Plane] ListStickies 返回错误", zap.String("status", resp.Status))
- return nil, fmt.Errorf("ListStickies 失败: %s", resp.Status)
- }
- return resp.Body, nil
- }
- // CreateSticky 创建便签
- func CreateSticky(data map[string]interface{}) ([]byte, error) {
- path := fmt.Sprintf("/api/v1/workspaces/%s/stickies/", planeWorkspaceSlug)
- resp, err := planeHttpPost(path, data)
- if err != nil {
- zap.L().Error("[Plane] CreateSticky 请求失败", zap.Error(err))
- return nil, err
- }
- if resp.StatusCode != 201 {
- zap.L().Error("[Plane] CreateSticky 返回错误", zap.String("status", resp.Status), zap.String("body", string(resp.Body)))
- return nil, fmt.Errorf("CreateSticky 失败: %s", resp.Status)
- }
- return resp.Body, nil
- }
- // GetSticky 获取便签详情
- func GetSticky(stickyID string) ([]byte, error) {
- path := fmt.Sprintf("/api/v1/workspaces/%s/stickies/%s/", planeWorkspaceSlug, stickyID)
- resp, err := planeHttpGet(path)
- if err != nil {
- zap.L().Error("[Plane] GetSticky 请求失败", zap.Error(err))
- return nil, err
- }
- if !isSuccess(resp.StatusCode) {
- zap.L().Error("[Plane] GetSticky 返回错误", zap.String("status", resp.Status))
- return nil, fmt.Errorf("GetSticky 失败: %s", resp.Status)
- }
- return resp.Body, nil
- }
- // UpdateSticky 更新便签
- func UpdateSticky(stickyID string, data map[string]interface{}) ([]byte, error) {
- path := fmt.Sprintf("/api/v1/workspaces/%s/stickies/%s/", planeWorkspaceSlug, stickyID)
- resp, err := planeHttpPatch(path, data)
- if err != nil {
- zap.L().Error("[Plane] UpdateSticky 请求失败", zap.Error(err))
- return nil, err
- }
- if !isSuccess(resp.StatusCode) {
- zap.L().Error("[Plane] UpdateSticky 返回错误", zap.String("status", resp.Status), zap.String("body", string(resp.Body)))
- return nil, fmt.Errorf("UpdateSticky 失败: %s", resp.Status)
- }
- return resp.Body, nil
- }
- // DeleteSticky 删除便签
- func DeleteSticky(stickyID string) error {
- path := fmt.Sprintf("/api/v1/workspaces/%s/stickies/%s/", planeWorkspaceSlug, stickyID)
- resp, err := planeHttpDelete(path)
- if err != nil {
- zap.L().Error("[Plane] DeleteSticky 请求失败", zap.Error(err))
- return err
- }
- if resp.StatusCode != 204 {
- zap.L().Error("[Plane] DeleteSticky 返回错误", zap.String("status", resp.Status))
- return fmt.Errorf("DeleteSticky 失败: %s", resp.Status)
- }
- return nil
- }
|