Skip to content

Commit

Permalink
更新了
Browse files Browse the repository at this point in the history
  • Loading branch information
yinMrsir committed Apr 14, 2023
1 parent 51a9759 commit 0e4bd99
Show file tree
Hide file tree
Showing 14 changed files with 252 additions and 21 deletions.
2 changes: 2 additions & 0 deletions Nest-server/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import { ColumnModule } from './modules/column/column.module';
import { CollectModule } from './modules/collect/collect.module';
import { WebUserModule } from './modules/web/user/web-user.module';
import { WebAuthModule } from './modules/web/auth/web-auth.module';
import { UserCollectModule } from './modules/web/user-collect/user-collect.module';

/* 将 provider的类名作为别名,方便定时器调用 */
const providers = [JobService];
Expand Down Expand Up @@ -112,6 +113,7 @@ const aliasProviders = createAliasProviders();
IndexModule,
WebUserModule,
WebAuthModule,
UserCollectModule,
],
providers: [...aliasProviders],
})
Expand Down
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 {}
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) {}
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;
}
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 Nest-server/src/modules/web/user-collect/user-collect.module.ts
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 Nest-server/src/modules/web/user-collect/user-collect.service.ts
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`;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Type } from 'class-transformer';
import { IsNumber, IsOptional, IsString } from 'class-validator';
import { IsOptional, IsString } from 'class-validator';
import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';
import { BaseEntity } from '../../../../common/entities/base.entity';

Expand Down
5 changes: 3 additions & 2 deletions Nest-server/src/modules/web/user/web-user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { LoginWebUserDto, RegWebUserDto } from './dto/req-web-user.dto';
import { LocalWebAuthGuard } from 'src/common/guards/local-web-auth.guard';
import { JwtWebAuthGuard } from '../../../common/guards/jwt-web-auth.guard';
import { DataObj } from '../../../common/class/data-obj.class';
import { User, UserEnum } from '../../../common/decorators/user.decorator';

@Controller('web/user')
export class WebUserController {
Expand All @@ -27,8 +28,8 @@ export class WebUserController {
@Public()
@Get('info')
@UseGuards(JwtWebAuthGuard)
async info(@Req() req) {
const data = await this.webUserService.info(req.user.userId);
async info(@User(UserEnum.userId) userId: number) {
const data = await this.webUserService.info(userId);
return new DataObj(data);
}
}
75 changes: 75 additions & 0 deletions Nuxt-web/components/user/CollectData.vue
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>
8 changes: 8 additions & 0 deletions Nuxt-web/pages/[column]/movie/[id].vue
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,15 @@ import {ElMessage} from "element-plus";
const { globalTitle } = useRuntimeConfig()
const route = useRoute()
const userInfo = useCookie('userInfo')
const id = route.params.id
const qrcodeUrl = ref('')
const detail = ref({})
const roles = ref([])
const casts = ref([])
const weekList = ref([])
const monthList = ref([])
const isCoolect = ref(false)
onMounted(() => {
qrcodeUrl.value = window.location.href
Expand All @@ -194,6 +196,12 @@ if (!detail) {
})
}
const res = await useFetch('/api/user/collect/find', {
query: { id },
headers: {
Authorization: 'Bearer ' + userInfo.value.token
},
})
// 收藏
function handleCollect() {
const userInfo = useCookie('userInfo')
Expand Down
2 changes: 1 addition & 1 deletion Nuxt-web/pages/search/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
import {useFetch} from "nuxt/app";
const route = useRoute()
const runtimeConfig = useRuntimeConfig()
const activeName = ref('first')
const form = reactive({
keyword: undefined
Expand Down
26 changes: 9 additions & 17 deletions Nuxt-web/pages/user/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Style type="text/css" children="body { background-color: #f7f7f7; }" />
</Head>
<el-row :gutter="30" class="mt-20">
<el-col :span="6">
<el-col :md="6" :xs="24">
<div class="bg-fff user-index__head flex">
<img src="../../assets/images/toux.png" alt="">
<div>
Expand All @@ -15,43 +15,35 @@
</div>
</div>
</el-col>
<el-col :span="18" class="bg-fff">
<el-tabs
v-model="activeName"
class="demo-tabs"
@tab-click="handleClick"
>
<el-tab-pane label="我的收藏" name="first">我的收藏</el-tab-pane>
<el-tab-pane label="我的点赞" name="second">我的点赞</el-tab-pane>
<el-tab-pane label="我的评论" name="third">我的评论</el-tab-pane>
<el-col :md="18" :xs="24" class="bg-fff">
<el-tabs v-model="activeName">
<el-tab-pane label="我的收藏" name="collect">
<collect-data/>
</el-tab-pane>
</el-tabs>
</el-col>
</el-row>
</div>
</template>
<script setup lang="ts">
import type { TabsPaneContext } from 'element-plus'
import CollectData from '@/components/user/CollectData.vue'
definePageMeta({
middleware: ["auth"],
layout: false
})
const runtimeConfig = useRuntimeConfig()
const userInfo = useCookie('userInfo')
const activeName = ref('first')
const activeName = ref<string>('collect')
const { data: user } = await useFetch('/api/user/info', {
headers: {
Authorization: 'Bearer ' + userInfo.value.token
},
pick: ['email', 'userId']
})
const handleClick = (tab: TabsPaneContext, event: Event) => {
console.log(tab, event)
}
</script>
<style lang="scss" scoped>
Expand Down
18 changes: 18 additions & 0 deletions Nuxt-web/server/api/user/collect/[...slug].ts
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)

0 comments on commit 0e4bd99

Please sign in to comment.