# 评论

# 获取评论列表

# 接口调用说明:

GET https://lxapi.lexiangla.com/cgi-bin/v1/comments?target_type={target_type}&target_id={target_id}

# 参数说明:

支持分页参数和排序:(通用说明?

支持时间范围过滤

参数 是否必须 默认值 说明
target_type 评论对象类型,支持:answer,doc。
answer 表示乐问回答的评论
doc 表示文档的评论
target_id 评论对象的id

# SDK封装方法使用示例:

$Lxapi = new \Lexiangla\Openapi\Api(AppKey, AppSecret);
$response = $Lxapi->get('comments', [
    'target_type' => 'answer',
    'target_id' => 'answer_uuid'
]);

# 文档评论响应document

# 200 OK 状态码
{
  "data": [
    {
      "type": "comment", 
      "id": "808abd4e484411eca94d7e20e322797f", 
      "attributes": {
        "content": "评论", 
        "created_at": "2021-11-18 15:52:39"
      }, 
      "relationships": {
        "owner": {
          "data": {
            "type": "staff", 
            "id": "silee"
          }
        }
      }
    }
  ], 
  "links": {
    "first": "https://lxapi.lexiangla.com/cgi-bin/v1/comments?target_type=doc&target_id=7c6cca86484411ec922f960346af4b7a&page=1", 
    "last": "https://lxapi.lexiangla.com/cgi-bin/v1/comments?target_type=doc&target_id=7c6cca86484411ec922f960346af4b7a&page=1", 
    "prev": null, 
    "next": null
  }, 
  "meta": {
    "current_page": 1, 
    "from": 1, 
    "last_page": 1, 
    "path": "https://lxapi.lexiangla.com/cgi-bin/v1/comments", 
    "per_page": 20, 
    "to": 1, 
    "total": 1
  }, 
  "included": [
    {
      "type": "staff", 
      "id": "silee", 
      "attributes": {
        "name": "李四", 
        "english_name": null, 
        "organization": "测试部"
      }
    }
  ]
}

# 乐问回答评论响应document

# 200 OK 状态码
{
	"data": [{
			"type": "comment",
			"id": "311e2790477311ecb7822ac6d5b752b7",
			"attributes": {
				"content": "二级评论",
				"created_at": "2021-11-17 14:54:21"
			},
			"relationships": {
				"owner": {
					"data": {
						"type": "staff",
						"id": "threezhang"
					}
				}
			}
		},
		{
			"type": "comment",
			"id": "177ed6ae477311ecb0a742ed4b6c2348",
			"attributes": {
				"content": "一级评论",
				"created_at": "2021-11-17 14:53:38"
			},
			"relationships": {
				"owner": {
					"data": {
						"type": "staff",
						"id": "silee"
					}
				}
			}
		}
	],
	"links": {
		"first": "https://lxapi.lexiangla.com/cgi-bin/v1/comments?target_type=answer&target_id=5261ddb846bd11ecb0b3b22bd4419469&page=1",
		"last": "https://lxapi.lexiangla.com/cgi-bin/v1/comments?target_type=answer&target_id=5261ddb846bd11ecb0b3b22bd4419469&page=1",
		"prev": null,
		"next": null
	},
	"meta": {
		"current_page": 1,
		"from": 1,
		"last_page": 1,
		"path": "https://lxapi.lexiangla.com/cgi-bin/v1/comments",
		"per_page": 20,
		"to": 2,
		"total": 2
	},
	"included": [{
			"type": "staff",
			"id": "threezhang",
			"attributes": {
				"name": "张三",
				"english_name": null,
				"organization": "测试部"
			}
		},
		{
			"type": "staff",
			"id": "silee",
			"attributes": {
				"name": "李四",
				"english_name": null,
				"organization": "测试部"
			}
		}
	]
}

# 创建评论

# 接口调用说明:

POST https://lxapi.lexiangla.com/cgi-bin/v1/comments

# 请求document

{
    "data": {
        "type": "comment", 
        "attributes": {
            "content": "用API对文档评论"
        }, 
        "relationships": {
            "target": {
                "data": {
                    "type": "doc", 
                    "id": "cae375aae25a11e88d2c10e7c61c70fc"
                }
            }
        }
    }
}

# 参数说明:

参数 是否必须 默认值 说明
content 评论内容
target.type 评论对象类型,支持:doc、answer、comment
doc 表示对文档评论,answer 表示对乐问回答评论,comment 表示回复评论、回复评论的回复,仅支持文档和乐问
target.id 评论对象的id

# SDK封装方法使用示例:

$attributes = [
	'content' => '用API对文档评论',
	'target_type' => 'doc',
	'target_id'   => 'cae375aae25a11e88d2c10e7c61c70fc',
	//  回复评论,
	//	'target_type' => 'comment',
	//	'target_id'   => '8f2f0f5ae66b11e898c010e7c61c70fc',
];
$Lxapi = new \Lexiangla\Openapi\Api(AppKey, AppSecret);
$response = $Lxapi->postComment(StaffID, $attributes);

# 响应document

# 201 Created 状态码
{
    "data": {
        "type": "comment",
        "id": "8f2f0f5ae66b11e898c010e7c61c70fc",
        "attributes": {
            "content": "用API对文档评论",
            "updated_at": "2018-11-12 19:10:27",
            "created_at": "2018-11-12 19:10:27"
        },
        "relationships": {
            "owner": {
                "data": {
                    "type": "staff",
                    "id": "ThreeZhang"
                }
            }
        }
    },
    "included": [
        {
            "type": "staff",
            "id": "ThreeZhang",
            "attributes": {
                "name": "张三",
                "english_name": "ThreeZhang"
            }
        }
    ]
}

# 删除评论

# 接口调用说明:

DELETE https://lxapi.lexiangla.com/cgi-bin/v1/comments/{comment_id}

# 参数说明:

参数 是否必须 默认值 说明
comment_id 资源对象类型为 comment 的资源对象id,即评论id

# SDK封装方法使用示例:

$Lxapi = new \Lexiangla\Openapi\Api(AppKey, AppSecret);
$response = $Lxapi->forStaff(StaffID)->delete('comments/comment_id');

# 响应document

# 204 No Content 状态码