Skip to content

Commit

Permalink
feat: add 相关文章、专栏文章api
Browse files Browse the repository at this point in the history
  • Loading branch information
MarleneJiang committed Jan 27, 2023
1 parent 2bfba8d commit cb017d5
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
94 changes: 47 additions & 47 deletions frontend/server/api/articles/[id].ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,53 +39,53 @@ export default defineEventHandler(async (event): Promise<IArticle> => {
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)
})
20 changes: 20 additions & 0 deletions frontend/server/api/articles/columns/[id].ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { useGraphql } from '~~/composables/useGraphql'

interface IArticleItem {
id: string
title: string
}
export default defineEventHandler(async (event): Promise<IArticleItem[]> => {
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
})
2 changes: 1 addition & 1 deletion frontend/server/api/articles/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,5 @@ export default defineEventHandler(async (event): Promise<IArticleItem[]> => {
}
}
}`
return await useGraphql(reqQuery)
return (await useGraphql(reqQuery)).articles.data
})
29 changes: 27 additions & 2 deletions frontend/server/api/articles/tags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import { useGraphql } from '~~/composables/useGraphql'
interface ITagItem {
tag: string
}
export default defineEventHandler(async (): Promise<ITagItem[]> => {
const reqQuery = `query{
export default defineEventHandler(async (event): Promise<ITagItem[]> => {
const query = getQuery(event)
let reqQuery = `query{
tags{
data{
attributes{
Expand All @@ -12,5 +13,29 @@ export default defineEventHandler(async (): Promise<ITagItem[]> => {
}
}
}`
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
})

0 comments on commit cb017d5

Please sign in to comment.