| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- package plane_v2
- import (
- "fmt"
- "go.uber.org/zap"
- )
- // ==================== Sticky (便签) API ====================
- // ListStickies 列出便签
- func ListStickies(slug string) ([]byte, error) {
- url := fmt.Sprintf("/api/workspaces/%s/stickies/", slug)
- resp, err := planeWebGet(url)
- if err != nil {
- zap.L().Error("[PlaneWeb] ListStickies 请求失败", zap.Error(err))
- return nil, err
- }
- if !isWebSuccess(resp.StatusCode) {
- zap.L().Error("[PlaneWeb] ListStickies 返回错误", zap.String("status", resp.Status))
- return nil, fmt.Errorf("ListStickies 失败: %s", resp.Status)
- }
- return resp.Body, nil
- }
- // CreateSticky 创建便签
- func CreateSticky(slug string, data map[string]interface{}) ([]byte, error) {
- url := fmt.Sprintf("/api/workspaces/%s/stickies/", slug)
- resp, err := planeWebPost(url, data)
- if err != nil {
- zap.L().Error("[PlaneWeb] CreateSticky 请求失败", zap.Error(err))
- return nil, err
- }
- if resp.StatusCode != 201 {
- zap.L().Error("[PlaneWeb] 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(slug, stickyID string) ([]byte, error) {
- url := fmt.Sprintf("/api/workspaces/%s/stickies/%s/", slug, stickyID)
- resp, err := planeWebGet(url)
- if err != nil {
- zap.L().Error("[PlaneWeb] GetSticky 请求失败", zap.Error(err))
- return nil, err
- }
- if !isWebSuccess(resp.StatusCode) {
- zap.L().Error("[PlaneWeb] GetSticky 返回错误", zap.String("status", resp.Status))
- return nil, fmt.Errorf("GetSticky 失败: %s", resp.Status)
- }
- return resp.Body, nil
- }
- // UpdateSticky 更新便签
- func UpdateSticky(slug, stickyID string, data map[string]interface{}) ([]byte, error) {
- url := fmt.Sprintf("/api/workspaces/%s/stickies/%s/", slug, stickyID)
- resp, err := planeWebPatch(url, data)
- if err != nil {
- zap.L().Error("[PlaneWeb] UpdateSticky 请求失败", zap.Error(err))
- return nil, err
- }
- if !isWebSuccess(resp.StatusCode) {
- zap.L().Error("[PlaneWeb] 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(slug, stickyID string) error {
- url := fmt.Sprintf("/api/workspaces/%s/stickies/%s/", slug, stickyID)
- resp, err := planeWebDelete(url)
- if err != nil {
- zap.L().Error("[PlaneWeb] DeleteSticky 请求失败", zap.Error(err))
- return err
- }
- if resp.StatusCode != 204 {
- zap.L().Error("[PlaneWeb] DeleteSticky 返回错误", zap.String("status", resp.Status))
- return fmt.Errorf("DeleteSticky 失败: %s", resp.Status)
- }
- return nil
- }
- // ListCurrentStickies 列出当前工作空间的便签
- func ListCurrentStickies() ([]byte, error) {
- return ListStickies(webWorkspaceSlug)
- }
|