Skip to content

Commit bb7f5d0

Browse files
committed
feat: display all galgame ratings on user's homepage
1 parent 80c1c70 commit bb7f5d0

File tree

10 files changed

+164
-4
lines changed

10 files changed

+164
-4
lines changed

components/user/Rating.vue

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<script setup lang="ts">
2+
const props = defineProps<{
3+
uid: number
4+
}>()
5+
6+
const pageData = reactive({
7+
page: 1,
8+
limit: 24,
9+
userId: props.uid
10+
})
11+
12+
const { data, status } = await useFetch(`/api/user/${props.uid}/ratings`, {
13+
method: 'GET',
14+
query: pageData,
15+
...kungalgameResponseHandler
16+
})
17+
</script>
18+
19+
<template>
20+
<div class="space-y-3">
21+
<KunHeader
22+
name="Galgame 评分"
23+
description="这是您的 Galgame 评分列表, 您可以在这里查看您发布的所有 Galgame 评分"
24+
/>
25+
26+
<div v-if="data && data.ratingData.length" class="space-y-3">
27+
<GalgameRatingCard :ratings="data.ratingData" />
28+
29+
<KunPagination
30+
v-if="data.totalCount > pageData.limit"
31+
v-model:current-page="pageData.page"
32+
:total-page="Math.ceil(data.totalCount / pageData.limit)"
33+
:is-loading="status === 'pending'"
34+
/>
35+
</div>
36+
37+
<KunNull v-if="data && !data.ratingData.length" description="暂无评分" />
38+
</div>
39+
</template>

components/user/nav/Item.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const iconMap: Record<string, string> = {
2626
topic: 'lucide:square-gantt-chart',
2727
galgame: 'lucide:gamepad-2',
2828
resource: 'lucide:package',
29+
rating: 'lucide:star',
2930
reply: 'carbon:reply',
3031
comment: 'uil:comment-dots'
3132
}

components/user/utils/routeName.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ export const navBarRoute: Ref<Nav[]> = ref([
4040
redirect: 'galgame/galgame',
4141
router: 'galgame'
4242
},
43+
{
44+
name: 'rating',
45+
router: 'rating',
46+
permission: [1, 2, 3, 4]
47+
},
4348
{
4449
name: 'resource',
4550
permission: [1, 2, 3, 4],

constants/user.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ export const KUN_USER_PAGE_NAV_MAP: Record<string, string> = {
160160
password: '密码设置',
161161
topic: '话题',
162162
galgame: 'Galgame',
163+
rating: 'Gal 评分',
163164
resource: 'Gal 资源',
164165
publish: '已发布',
165166
like: '已点赞',

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "kun-galgame-nuxt3",
3-
"version": "4.4.84",
3+
"version": "4.4.85",
44
"packageManager": "[email protected]",
55
"private": true,
66
"scripts": {

pages/galgame-tag/[id].vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,15 @@ const handleUpdateTag = async (data: UpdateGalgameTagPayload) => {
6363
if (data.value) {
6464
if (data.value.category !== 'sexual') {
6565
useKunSeoMeta({
66-
title: data.value.name,
66+
title: `标签 ${data.value.name} 的 Galgame`,
6767
description: data.value
6868
? data.value.galgame
6969
.map((g) => getPreferredLanguageText(g.name))
7070
.toString()
7171
: ''
7272
})
7373
} else {
74-
useKunDisableSeo(data.value.name)
74+
useKunDisableSeo(`标签 ${data.value.name} 的 Galgame`)
7575
}
7676
}
7777
</script>

pages/user/[uid]/rating.vue

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<script setup lang="ts">
2+
import type { UserInfo } from '~/types/api/user'
3+
4+
const props = defineProps<{
5+
user: UserInfo
6+
}>()
7+
8+
useKunDisableSeo(`${props.user.name} 的评分`)
9+
10+
useHead({
11+
link: [
12+
{
13+
rel: 'canonical',
14+
href: `${kungal.domain.main}/user/${props.user.id}/rating`
15+
}
16+
]
17+
})
18+
</script>
19+
20+
<template>
21+
<UserRating :uid="user.id" />
22+
</template>

pages/user/[uid]/resource/[type].vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const resourceType = computed(() => {
1717
})
1818
1919
useKunDisableSeo(
20-
`${props.user.name}${GALGAME_RESOURCE_NAV_CONFIG[resourceType.value].text}`
20+
`${props.user.name}${GALGAME_RESOURCE_NAV_CONFIG[resourceType.value].text}`
2121
)
2222
</script>
2323

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import prisma from '~/prisma/prisma'
2+
import { getUserRatingSchema } from '~/validations/user'
3+
import type { GalgameRatingCard } from '~/types/api/galgame-rating'
4+
import type { Prisma } from '@prisma/client'
5+
6+
export default defineEventHandler(async (event) => {
7+
const input = kunParseGetQuery(event, getUserRatingSchema)
8+
if (typeof input === 'string') {
9+
return kunError(event, input)
10+
}
11+
12+
const nsfw = getNSFWCookie(event)
13+
const { userId, page, limit } = input
14+
const skip = (page - 1) * limit
15+
16+
const where: Prisma.galgame_ratingWhereInput = {
17+
user_id: userId,
18+
galgame: {
19+
content_limit: nsfw === 'sfw' ? 'sfw' : undefined
20+
}
21+
}
22+
23+
const [rows, totalCount] = await Promise.all([
24+
prisma.galgame_rating.findMany({
25+
take: limit,
26+
skip,
27+
where,
28+
orderBy: { created: 'desc' },
29+
include: {
30+
user: { select: { id: true, name: true, avatar: true } },
31+
galgame: {
32+
select: {
33+
id: true,
34+
banner: true,
35+
name_en_us: true,
36+
name_ja_jp: true,
37+
name_zh_cn: true,
38+
name_zh_tw: true,
39+
content_limit: true
40+
}
41+
},
42+
_count: {
43+
select: {
44+
like: true
45+
}
46+
}
47+
}
48+
}),
49+
prisma.galgame_rating.count({ where })
50+
])
51+
52+
const ratingData: GalgameRatingCard[] = rows.map((r) => ({
53+
id: r.id,
54+
user: r.user,
55+
recommend: r.recommend,
56+
overall: r.overall,
57+
view: r.view,
58+
galgameType: r.galgame_type,
59+
play_status: r.play_status,
60+
short_summary: r.short_summary,
61+
spoiler_level: r.spoiler_level,
62+
art: r.art,
63+
story: r.story,
64+
music: r.music,
65+
character: r.character,
66+
route: r.route,
67+
system: r.system,
68+
voice: r.voice,
69+
replay_value: r.replay_value,
70+
likeCount: r._count.like,
71+
created: r.created,
72+
updated: r.updated,
73+
galgame: {
74+
id: r.galgame.id,
75+
contentLimit: r.galgame.content_limit,
76+
name: {
77+
'en-us': r.galgame.name_en_us,
78+
'ja-jp': r.galgame.name_ja_jp,
79+
'zh-cn': r.galgame.name_zh_cn,
80+
'zh-tw': r.galgame.name_zh_tw
81+
}
82+
}
83+
}))
84+
85+
return { ratingData, totalCount }
86+
})

validations/user.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ export const getUserGalgameResourceSchema = z.object({
5151
type: z.enum(KUN_USER_PAGE_GALGAME_RESOURCE_TYPE)
5252
})
5353

54+
export const getUserRatingSchema = z.object({
55+
userId: z.coerce.number().min(1).max(9999999),
56+
page: z.coerce.number().min(1).max(9999999),
57+
limit: z.coerce.number().min(1).max(50)
58+
})
59+
5460
export const updateUserBioSchema = z.object({
5561
bio: z.string().max(107, { message: '签名最大长度为 107 个字符' })
5662
})

0 commit comments

Comments
 (0)