Add API endpoint for updating pin status (#1449)

This commit is contained in:
yonathan suarez 2024-05-19 19:47:47 +02:00 committed by GitHub
parent bea36d65a0
commit ecd5d3cb8a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 134 additions and 0 deletions

View File

@ -447,6 +447,73 @@ function apiWorkspaceEndpoints(app) {
}
);
app.post(
"/v1/workspace/:slug/update-pin",
[validApiKey],
async (request, response) => {
/*
#swagger.tags = ['Workspaces']
#swagger.description = 'Add or remove pin from a document in a workspace by its unique slug.'
#swagger.path = '/workspace/{slug}/update-pin'
#swagger.parameters['slug'] = {
in: 'path',
description: 'Unique slug of workspace to find',
required: true,
type: 'string'
}
#swagger.requestBody = {
description: 'JSON object with the document path and pin status to update.',
required: true,
type: 'object',
content: {
"application/json": {
example: {
docPath: "custom-documents/my-pdf.pdf-hash.json",
pinStatus: true
}
}
}
}
#swagger.responses[200] = {
description: 'OK',
content: {
"application/json": {
schema: {
type: 'object',
example: {
message: 'Pin status updated successfully'
}
}
}
}
}
#swagger.responses[404] = {
description: 'Document not found'
}
#swagger.responses[500] = {
description: 'Internal Server Error'
}
*/
try {
const { slug = null } = request.params;
const { docPath, pinStatus = false } = reqBody(request);
const workspace = await Workspace.get({ slug });
const document = await Document.get({
workspaceId: workspace.id,
docpath: docPath,
});
if (!document) return response.sendStatus(404).end();
await Document.update(document.id, { pinned: pinStatus });
return response.status(200).json({ message: 'Pin status updated successfully' }).end();
} catch (error) {
console.error("Error processing the pin status update:", error);
return response.status(500).end();
}
}
);
app.post(
"/v1/workspace/:slug/chat",
[validApiKey],

View File

@ -1999,6 +1999,73 @@
}
}
}
},"/v1/workspace/{slug}/update-pin": {
"post": {
"tags": [
"Workspaces"
],
"description": "Add or remove pin from a document in a workspace by its unique slug.",
"parameters": [
{
"name": "slug",
"in": "path",
"required": true,
"schema": {
"type": "string"
},
"description": "Unique slug of workspace to find"
},
{
"name": "Authorization",
"in": "header",
"schema": {
"type": "string"
}
}
],
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"type": "object",
"example": {
"message": "Pin status updated successfully"
}
}
}
}
},
"404": {
"description": "Document not found"
},
"500": {
"description": "Internal Server Error"
}
},
"requestBody": {
"description": "JSON object with the document path and pin status to update.",
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"docPath": {
"type": "string",
"example": "custom-documents/my-pdf.pdf-hash.json"
},
"pinStatus": {
"type": "boolean",
"example": true
}
}
}
}
}
}
}
},
"/v1/workspace/{slug}/chat": {
"post": {