From cb017d502d9f61d5808b4f78695a22edd02e6dc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=91=E8=BD=BB=E7=8B=82?= <1677568218@qq.com> Date: Fri, 27 Jan 2023 14:31:23 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20add=20=E7=9B=B8=E5=85=B3=E6=96=87?= =?UTF-8?q?=E7=AB=A0=E3=80=81=E4=B8=93=E6=A0=8F=E6=96=87=E7=AB=A0api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../1.0.0/full_documentation.json | 6 +- frontend/server/api/articles/[id].ts | 94 +++++++++---------- frontend/server/api/articles/columns/[id].ts | 20 ++++ frontend/server/api/articles/list.ts | 2 +- frontend/server/api/articles/tags.ts | 29 +++++- 5 files changed, 96 insertions(+), 55 deletions(-) create mode 100644 frontend/server/api/articles/columns/[id].ts diff --git a/backend/src/extensions/documentation/documentation/1.0.0/full_documentation.json b/backend/src/extensions/documentation/documentation/1.0.0/full_documentation.json index 3c8a9e9..986564d 100644 --- a/backend/src/extensions/documentation/documentation/1.0.0/full_documentation.json +++ b/backend/src/extensions/documentation/documentation/1.0.0/full_documentation.json @@ -14,11 +14,7 @@ "name": "Apache 2.0", "url": "https://www.apache.org/licenses/LICENSE-2.0.html" }, -<<<<<<< Updated upstream - "x-generation-date": "2023-01-26T05:03:19.417Z" -======= - "x-generation-date": "2023-01-26T13:01:50.925Z" ->>>>>>> Stashed changes + "x-generation-date": "2023-01-27T04:58:57.064Z" }, "x-strapi-config": { "path": "/documentation", diff --git a/frontend/server/api/articles/[id].ts b/frontend/server/api/articles/[id].ts index 9e817fb..5ca1bc7 100644 --- a/frontend/server/api/articles/[id].ts +++ b/frontend/server/api/articles/[id].ts @@ -39,53 +39,53 @@ export default defineEventHandler(async (event): Promise => { const id = event.context.params.id const reqQuery = `query{ article(id : ${id}){ - data{ - attributes{ - title - viewed - liked - shared - commented - content - cover - createdAt - updatedAt - authorId{ - data{ - attributes{ - name - motto - avatar - rank - liked - viewed - } - } - } - tagIds{ - data{ - attributes{ - tag - } - } - } - typeId{ - data{ - attributes{ - type - } - } - } - columId{ - data{ - attributes{ - column - } - } - } - } - } - } + data{ + attributes{ + title + viewed + liked + shared + commented + content + cover + createdAt + updatedAt + authorId{ + data{ + attributes{ + name + motto + avatar + rank + liked + viewed + } + } + } + tagIds{ + data{ + attributes{ + tag + } + } + } + typeId{ + data{ + attributes{ + type + } + } + } + columId{ + data{ + attributes{ + column + } + } + } + } + } + } }` return await useGraphql(reqQuery) }) diff --git a/frontend/server/api/articles/columns/[id].ts b/frontend/server/api/articles/columns/[id].ts new file mode 100644 index 0000000..76f2232 --- /dev/null +++ b/frontend/server/api/articles/columns/[id].ts @@ -0,0 +1,20 @@ +import { useGraphql } from '~~/composables/useGraphql' + +interface IArticleItem { + id: string + title: string +} +export default defineEventHandler(async (event): Promise => { + const id = decodeURIComponent(event.context.params.id) + const reqQuery = `query { + articles(filters:{columId:{column:{eq:"${id}"}}}){ + data{ + id + attributes{ + title + } + } + } + }` + return (await useGraphql(reqQuery)).articles.data +}) diff --git a/frontend/server/api/articles/list.ts b/frontend/server/api/articles/list.ts index d72c981..80ac62f 100644 --- a/frontend/server/api/articles/list.ts +++ b/frontend/server/api/articles/list.ts @@ -88,5 +88,5 @@ export default defineEventHandler(async (event): Promise => { } } }` - return await useGraphql(reqQuery) + return (await useGraphql(reqQuery)).articles.data }) diff --git a/frontend/server/api/articles/tags.ts b/frontend/server/api/articles/tags.ts index 11d62e4..cff6774 100644 --- a/frontend/server/api/articles/tags.ts +++ b/frontend/server/api/articles/tags.ts @@ -2,8 +2,9 @@ import { useGraphql } from '~~/composables/useGraphql' interface ITagItem { tag: string } -export default defineEventHandler(async (): Promise => { - const reqQuery = `query{ +export default defineEventHandler(async (event): Promise => { + const query = getQuery(event) + let reqQuery = `query{ tags{ data{ attributes{ @@ -12,5 +13,29 @@ export default defineEventHandler(async (): Promise => { } } }` + if (JSON.stringify(query) !== '{}' && !!query.tags) { + const tags = JSON.parse(query.tags as string) + let tagQuery = '' + for (let i = 0; i < tags.length; i++) + tagQuery += `{ tagIds: { tag: { eq: "${tags[i]}" } } },` + reqQuery = `query { + articles( + filters:{ + or: [${tagQuery}] + } + ){ + data{ + id + attributes{ + title + liked + commented + } + } + } + }` + return (await useGraphql(reqQuery)).articles.data + } + return (await useGraphql(reqQuery)).tags.data })