Skip to content

Commit

Permalink
fix: api params
Browse files Browse the repository at this point in the history
  • Loading branch information
MarleneJiang committed Jan 28, 2023
1 parent 57cd86c commit b5f462a
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"name": "Apache 2.0",
"url": "https://www.apache.org/licenses/LICENSE-2.0.html"
},
"x-generation-date": "2023-01-27T08:40:22.000Z"
"x-generation-date": "2023-01-28T14:10:48.649Z"
},
"x-strapi-config": {
"path": "/documentation",
Expand Down
2 changes: 1 addition & 1 deletion frontend/components/ArticlesContent/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<script setup lang="ts">
import { Viewer } from '@bytemd/vue-next'
import 'highlight.js/styles/atom-one-dark.css'
import type { IArticle } from '@/server/api/articles/[id]'
import type { IArticle } from '~~/types/IArticle'
const props = defineProps({
article: {
type: Object as () => IArticle,
Expand Down
45 changes: 9 additions & 36 deletions frontend/server/api/articles/[id].ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,5 @@
import { useGraphql } from '~~/composables/useGraphql'
interface IAuthor {
name: string
motto: string
avatar: string
rank: Number
liked: Number
viewed: Number
}

interface ITagItem {
tag: string
}

interface IType {
type: string
}

interface IColumn {
column: string
}
export interface IArticle {
id: string
title: string
viewed: number
liked: number
shared: number
commented: number
content: string
cover: string
createdAt: string
updatedAt: string
authorId: IAuthor
tagIds: { data: ITagItem[] }
typeId: IType
columId: IColumn
}
import type { IArticle } from '~~/types/IArticle'
export default defineEventHandler(async (event): Promise<IArticle> => {
const id = event.context.params.id
const reqQuery = `query{
Expand Down Expand Up @@ -80,6 +45,14 @@ export default defineEventHandler(async (event): Promise<IArticle> => {
data{
attributes{
column
articles{
data{
id
attributes{
title
}
}
}
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion frontend/server/api/articles/tags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,17 @@ export default defineEventHandler(async (event): Promise<ITagItem[] | IArticleIt
}
}
}`
if (JSON.stringify(query) !== '{}' && !!query.tags) {
if (JSON.stringify(query) !== '{}' && !!query.tags && !!query.authorId) {
const tags = JSON.parse(query.tags as string)
const authorId = query.authorId
let tagQuery = ''
for (let i = 0; i < tags.length; i++)
tagQuery += `{ tagIds: { tag: { eq: "${tags[i]}" } } },`
reqQuery = `query {
articles(
filters:{
or: [${tagQuery}]
authorId: {id:{eq:"${authorId}"}}
}
){
data{
Expand Down
41 changes: 41 additions & 0 deletions frontend/types/IArticle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
interface IAuthor {
name: string
motto: string
avatar: string
rank: Number
liked: Number
viewed: Number
}

interface ITagItem {
tag: string
}

interface IType {
type: string
}

interface IColumnArticleItem {
id: string
title: string
}
interface IColumn {
column: string
articles: { data: IColumnArticleItem[] }
}
export interface IArticle {
id: string
title: string
viewed: number
liked: number
shared: number
commented: number
content: string
cover: string
createdAt: string
updatedAt: string
authorId: IAuthor
tagIds: { data: ITagItem[] }
typeId: IType
columId: IColumn
}

0 comments on commit b5f462a

Please sign in to comment.