forked from yinMrsir/chunyu-cms
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
252 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
Nest-server/src/modules/web/user-collect/dto/create-user-collect.dto.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { UserCollect } from '../entities/user-collect.entity'; | ||
|
||
export class CreateUserCollectDto extends UserCollect {} |
4 changes: 4 additions & 0 deletions
4
Nest-server/src/modules/web/user-collect/dto/update-user-collect.dto.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { PartialType } from '@nestjs/mapped-types'; | ||
import { CreateUserCollectDto } from './create-user-collect.dto'; | ||
|
||
export class UpdateUserCollectDto extends PartialType(CreateUserCollectDto) {} |
16 changes: 16 additions & 0 deletions
16
Nest-server/src/modules/web/user-collect/entities/user-collect.entity.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Entity, PrimaryColumn } from 'typeorm'; | ||
|
||
@Entity({ name: 'user-collect' }) | ||
export class UserCollect { | ||
@PrimaryColumn({ | ||
name: 'user_id', | ||
comment: '用户id', | ||
}) | ||
userId: number; | ||
|
||
@PrimaryColumn({ | ||
name: 'movie_id', | ||
comment: '影视id', | ||
}) | ||
movieId: number; | ||
} |
53 changes: 53 additions & 0 deletions
53
Nest-server/src/modules/web/user-collect/user-collect.controller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { | ||
Controller, | ||
Get, | ||
Post, | ||
Body, | ||
Param, | ||
Delete, | ||
Query, | ||
UseGuards, | ||
} from '@nestjs/common'; | ||
import { UserCollectService } from './user-collect.service'; | ||
import { CreateUserCollectDto } from './dto/create-user-collect.dto'; | ||
import { JwtWebAuthGuard } from '../../../common/guards/jwt-web-auth.guard'; | ||
import { User, UserEnum } from '../../../common/decorators/user.decorator'; | ||
import { Public } from '../../../common/decorators/public.decorator'; | ||
import { DataObj } from '../../../common/class/data-obj.class'; | ||
|
||
@Controller('user-collect') | ||
export class UserCollectController { | ||
constructor(private readonly userCollectService: UserCollectService) {} | ||
|
||
@Post() | ||
create(@Body() createUserCollectDto: CreateUserCollectDto) { | ||
return this.userCollectService.create(createUserCollectDto); | ||
} | ||
|
||
@Public() | ||
@Get('findByPage') | ||
@UseGuards(JwtWebAuthGuard) | ||
findByPage(@User(UserEnum.userId) userId: number) { | ||
return this.userCollectService.findByPage(userId); | ||
} | ||
|
||
@Get('findByMovieIdPage') | ||
findByMovieIdPage(movieId: number) { | ||
return this.userCollectService.findByMovieIdPage(movieId); | ||
} | ||
|
||
@Public() | ||
@Get('find') | ||
@UseGuards(JwtWebAuthGuard) | ||
finOne( | ||
@User(UserEnum.userId) userId: number, | ||
@Query() query: CreateUserCollectDto, | ||
) { | ||
return this.userCollectService.findOne(userId, query.movieId); | ||
} | ||
|
||
@Delete() | ||
remove(@Query() query: CreateUserCollectDto) { | ||
return this.userCollectService.remove(query.userId, query.movieId); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
Nest-server/src/modules/web/user-collect/user-collect.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { TypeOrmModule } from '@nestjs/typeorm'; | ||
import { UserCollectService } from './user-collect.service'; | ||
import { UserCollectController } from './user-collect.controller'; | ||
import { UserCollect } from './entities/user-collect.entity'; | ||
|
||
@Module({ | ||
imports: [TypeOrmModule.forFeature([UserCollect])], | ||
controllers: [UserCollectController], | ||
providers: [UserCollectService], | ||
}) | ||
export class UserCollectModule {} |
47 changes: 47 additions & 0 deletions
47
Nest-server/src/modules/web/user-collect/user-collect.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { InjectRepository } from '@nestjs/typeorm'; | ||
import { Repository } from 'typeorm'; | ||
import { CreateUserCollectDto } from './dto/create-user-collect.dto'; | ||
import { UpdateUserCollectDto } from './dto/update-user-collect.dto'; | ||
import { UserCollect } from './entities/user-collect.entity'; | ||
|
||
@Injectable() | ||
export class UserCollectService { | ||
constructor( | ||
@InjectRepository(UserCollect) | ||
private readonly userCollectRepository: Repository<UserCollect>, | ||
) {} | ||
|
||
create(createUserCollectDto: CreateUserCollectDto) { | ||
return this.userCollectRepository.create(createUserCollectDto); | ||
} | ||
|
||
async findByPage(userId) { | ||
const [rows, total] = await this.userCollectRepository.findAndCountBy({ | ||
userId, | ||
}); | ||
return { | ||
rows, | ||
total, | ||
}; | ||
} | ||
|
||
findByMovieIdPage(movieId) { | ||
return `This action returns all userCollect`; | ||
} | ||
|
||
findOne(userId: number, movieId: number) { | ||
return this.userCollectRepository.findOneBy({ | ||
userId, | ||
movieId, | ||
}); | ||
} | ||
|
||
update(id: number, updateUserCollectDto: UpdateUserCollectDto) { | ||
return `This action updates a #${id} userCollect`; | ||
} | ||
|
||
remove(userId: number, movieId: number) { | ||
return `This action removes a #${userId} userCollect`; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<template> | ||
<div> | ||
<ClientOnly> | ||
<el-empty description="您还未收藏视频噢~" v-if="movieList.length === 0" /> | ||
<div class="video-list" v-else> | ||
<el-row :gutter="20"> | ||
<el-col :sm="4" :xs="8" v-for="item in movieList"> | ||
<div class="video-list__block"> | ||
<nuxt-link :to="`/${item.columnValue}/movie/${item.id}`"> | ||
<el-image class="video-list__block__img" :src="item.poster || runtimeConfig.public.apiBase + '/default.jpg'" fit="cover" /> | ||
</nuxt-link> | ||
<div class="video-list__detail"> | ||
<h4 class="title text-overflow">{{ item.title }}</h4> | ||
<p class="text-overflow"> | ||
<template v-for="actor in item.casts"> | ||
{{ actor.actor.name }} | ||
</template> | ||
</p> | ||
</div> | ||
</div> | ||
</el-col> | ||
</el-row> | ||
<div class="pagination"> | ||
<el-pagination | ||
background | ||
layout="prev, pager, next" | ||
:current-page="currentPage" | ||
:page-size="30" | ||
:pager-count="5" | ||
:total="total" | ||
@current-change="handleCurrentChange" | ||
/> | ||
</div> | ||
</div> | ||
</ClientOnly> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
const movieList = ref<any[]>([]) | ||
const currentPage = ref<number>(1) | ||
const total = ref(0) | ||
async function getList() { | ||
const userInfo = useCookie<{token: string}>('userInfo') | ||
const { data } = await useFetch<{ rows:any[]; total: number }>('/api/user/collect/list', { | ||
query: { | ||
page: currentPage.value, | ||
size: 12 | ||
}, | ||
headers: { | ||
Authorization: userInfo.value ? 'Bearer ' + userInfo.value.token : '' | ||
} | ||
}) | ||
console.log(data) | ||
if (data.value) { | ||
movieList.value = data.value.rows | ||
total.value = data.value.total | ||
} | ||
} | ||
getList() | ||
function handleCurrentChange(page: number) { | ||
currentPage.value = page | ||
getList() | ||
} | ||
</script> | ||
|
||
<style scoped> | ||
.pagination { | ||
padding: 20px; | ||
display: flex; | ||
justify-content: center; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { useGet} from "~/composables/useHttp"; | ||
import { getHeaders } from "h3"; | ||
import { createRouter, defineEventHandler, useBase } from 'h3' | ||
|
||
const router = createRouter() | ||
|
||
router.get('/list', defineEventHandler(async (event) => { | ||
let headers = getHeaders(event) | ||
return useGet<{data: any}>('/user-collect/findByPage', {}, headers) | ||
})) | ||
|
||
router.get('/find', defineEventHandler(async (event) => { | ||
const headers = getHeaders(event) | ||
const query = getQuery(event) | ||
return useGet<{data: any}>('/user-collect/find', { movieId: query.id }, headers) | ||
})) | ||
|
||
export default useBase('/api/user/collect', router.handler) |