refactor(history): 重构播放历史模块,统一命名并迁移代码
将原playback-history模块重命名为history模块,统一所有相关文件的命名空间,移除冗余的重复代码,更新全局模块引用和测试用例接口路径
This commit is contained in:
@@ -10,6 +10,7 @@ import { LogsModule } from "./modules/logs/logs.module";
|
|||||||
import { MediaModule } from "./modules/media/media.module";
|
import { MediaModule } from "./modules/media/media.module";
|
||||||
import { OrdersModule } from "./modules/orders/orders.module";
|
import { OrdersModule } from "./modules/orders/orders.module";
|
||||||
import { PlayerModule } from "./modules/player/player.module";
|
import { PlayerModule } from "./modules/player/player.module";
|
||||||
|
import { HistoryModule } from "./modules/history/history.module";
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
@@ -26,6 +27,7 @@ import { PlayerModule } from "./modules/player/player.module";
|
|||||||
AuthModule,
|
AuthModule,
|
||||||
OrdersModule,
|
OrdersModule,
|
||||||
PlayerModule,
|
PlayerModule,
|
||||||
|
HistoryModule,
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
export class AppModule {}
|
export class AppModule {}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import { Cover } from '../media/entities/cover.entity';
|
|||||||
import { MediaUploadJob } from '../media/entities/media-upload-job.entity';
|
import { MediaUploadJob } from '../media/entities/media-upload-job.entity';
|
||||||
import { Order } from '../orders/entities/order.entity';
|
import { Order } from '../orders/entities/order.entity';
|
||||||
import { UserEpisodeUnlock } from '../orders/entities/user-episode-unlock.entity';
|
import { UserEpisodeUnlock } from '../orders/entities/user-episode-unlock.entity';
|
||||||
|
import { UserPlaybackHistory } from '../history/entities/user-playback-history.entity';
|
||||||
import { User } from '../users/entities/user.entity';
|
import { User } from '../users/entities/user.entity';
|
||||||
|
|
||||||
const databaseImports = process.env.DB_HOST
|
const databaseImports = process.env.DB_HOST
|
||||||
@@ -40,6 +41,7 @@ const databaseImports = process.env.DB_HOST
|
|||||||
MediaUploadJob,
|
MediaUploadJob,
|
||||||
Order,
|
Order,
|
||||||
UserEpisodeUnlock,
|
UserEpisodeUnlock,
|
||||||
|
UserPlaybackHistory,
|
||||||
User,
|
User,
|
||||||
],
|
],
|
||||||
synchronize: process.env.DB_SYNCHRONIZE === 'true',
|
synchronize: process.env.DB_SYNCHRONIZE === 'true',
|
||||||
|
|||||||
@@ -3,13 +3,13 @@ import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
|||||||
import { CurrentUser } from '../auth/decorators/current-user.decorator';
|
import { CurrentUser } from '../auth/decorators/current-user.decorator';
|
||||||
import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard';
|
import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard';
|
||||||
import { UserRecord } from '../users/interfaces/user-record.interface';
|
import { UserRecord } from '../users/interfaces/user-record.interface';
|
||||||
import { UpsertPlaybackHistoryDto } from './dto/upsert-playback-history.dto';
|
import { UpsertPlaybackHistoryDto } from './dto/upsert-history.dto';
|
||||||
import { PlaybackHistoryService } from './playback-history.service';
|
import { HistoryService } from './history.service';
|
||||||
|
|
||||||
@ApiTags('PlaybackHistory')
|
@ApiTags('History')
|
||||||
@Controller('/api/app/v1/playback-history')
|
@Controller('/api/app/v1/history')
|
||||||
export class PlaybackHistoryController {
|
export class HistoryController {
|
||||||
constructor(private readonly playbackHistoryService: PlaybackHistoryService) {}
|
constructor(private readonly historyService: HistoryService) {}
|
||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
@ApiBearerAuth()
|
@ApiBearerAuth()
|
||||||
@@ -18,7 +18,7 @@ export class PlaybackHistoryController {
|
|||||||
@CurrentUser() user: UserRecord,
|
@CurrentUser() user: UserRecord,
|
||||||
@Body() dto: UpsertPlaybackHistoryDto,
|
@Body() dto: UpsertPlaybackHistoryDto,
|
||||||
) {
|
) {
|
||||||
return this.playbackHistoryService.upsertHistory(user, dto);
|
return this.historyService.upsertHistory(user, dto);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
@@ -29,7 +29,7 @@ export class PlaybackHistoryController {
|
|||||||
@Query('page') page?: string,
|
@Query('page') page?: string,
|
||||||
@Query('pageSize') pageSize?: string,
|
@Query('pageSize') pageSize?: string,
|
||||||
) {
|
) {
|
||||||
return this.playbackHistoryService.listHistory(user, {
|
return this.historyService.listHistory(user, {
|
||||||
page: Number(page) || 1,
|
page: Number(page) || 1,
|
||||||
pageSize: Number(pageSize) || 20,
|
pageSize: Number(pageSize) || 20,
|
||||||
});
|
});
|
||||||
13
src/modules/history/history.module.ts
Normal file
13
src/modules/history/history.module.ts
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
import { Module } from '@nestjs/common';
|
||||||
|
import { AuthModule } from '../auth/auth.module';
|
||||||
|
import { DramasModule } from '../dramas/dramas.module';
|
||||||
|
import { UsersModule } from '../users/users.module';
|
||||||
|
import { HistoryController } from './history.controller';
|
||||||
|
import { HistoryService } from './history.service';
|
||||||
|
|
||||||
|
@Module({
|
||||||
|
imports: [AuthModule, DramasModule, UsersModule],
|
||||||
|
controllers: [HistoryController],
|
||||||
|
providers: [HistoryService],
|
||||||
|
})
|
||||||
|
export class HistoryModule {}
|
||||||
@@ -8,12 +8,12 @@ import {
|
|||||||
EpisodeRecord,
|
EpisodeRecord,
|
||||||
} from '../dramas/interfaces/drama-records.interface';
|
} from '../dramas/interfaces/drama-records.interface';
|
||||||
import { UserRecord } from '../users/interfaces/user-record.interface';
|
import { UserRecord } from '../users/interfaces/user-record.interface';
|
||||||
import { UpsertPlaybackHistoryDto } from './dto/upsert-playback-history.dto';
|
import { UpsertPlaybackHistoryDto } from './dto/upsert-history.dto';
|
||||||
import { UserPlaybackHistory } from './entities/user-playback-history.entity';
|
import { UserPlaybackHistory } from './entities/user-playback-history.entity';
|
||||||
import {
|
import {
|
||||||
PlaybackHistoryListItem,
|
PlaybackHistoryListItem,
|
||||||
PlaybackHistoryRecord,
|
PlaybackHistoryRecord,
|
||||||
} from './interfaces/playback-history-record.interface';
|
} from './interfaces/history-record.interface';
|
||||||
|
|
||||||
interface PaginationInput {
|
interface PaginationInput {
|
||||||
page: number;
|
page: number;
|
||||||
@@ -21,7 +21,7 @@ interface PaginationInput {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class PlaybackHistoryService {
|
export class HistoryService {
|
||||||
private historySequence = 1;
|
private historySequence = 1;
|
||||||
private readonly histories: PlaybackHistoryRecord[] = [];
|
private readonly histories: PlaybackHistoryRecord[] = [];
|
||||||
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
import { Module } from '@nestjs/common';
|
|
||||||
import { AuthModule } from '../auth/auth.module';
|
|
||||||
import { DramasModule } from '../dramas/dramas.module';
|
|
||||||
import { PlaybackHistoryController } from './playback-history.controller';
|
|
||||||
import { PlaybackHistoryService } from './playback-history.service';
|
|
||||||
|
|
||||||
@Module({
|
|
||||||
imports: [AuthModule, DramasModule],
|
|
||||||
controllers: [PlaybackHistoryController],
|
|
||||||
providers: [PlaybackHistoryService],
|
|
||||||
})
|
|
||||||
export class PlaybackHistoryModule {}
|
|
||||||
@@ -178,7 +178,7 @@ describe('Auth, orders, and playback', () => {
|
|||||||
.expect(201);
|
.expect(201);
|
||||||
|
|
||||||
await request(app.getHttpServer())
|
await request(app.getHttpServer())
|
||||||
.post('/api/app/v1/playback-history')
|
.post('/api/app/v1/history')
|
||||||
.send({
|
.send({
|
||||||
episodeId: episode.body.data.id,
|
episodeId: episode.body.data.id,
|
||||||
progressSeconds: 86,
|
progressSeconds: 86,
|
||||||
@@ -188,7 +188,7 @@ describe('Auth, orders, and playback', () => {
|
|||||||
.expect(401);
|
.expect(401);
|
||||||
|
|
||||||
await request(app.getHttpServer())
|
await request(app.getHttpServer())
|
||||||
.post('/api/app/v1/playback-history')
|
.post('/api/app/v1/history')
|
||||||
.set('Authorization', `Bearer ${firstToken}`)
|
.set('Authorization', `Bearer ${firstToken}`)
|
||||||
.send({
|
.send({
|
||||||
episodeId: episode.body.data.id,
|
episodeId: episode.body.data.id,
|
||||||
@@ -199,7 +199,7 @@ describe('Auth, orders, and playback', () => {
|
|||||||
.expect(201);
|
.expect(201);
|
||||||
|
|
||||||
await request(app.getHttpServer())
|
await request(app.getHttpServer())
|
||||||
.post('/api/app/v1/playback-history')
|
.post('/api/app/v1/history')
|
||||||
.set('Authorization', `Bearer ${firstToken}`)
|
.set('Authorization', `Bearer ${firstToken}`)
|
||||||
.send({
|
.send({
|
||||||
episodeId: episode.body.data.id,
|
episodeId: episode.body.data.id,
|
||||||
@@ -210,7 +210,7 @@ describe('Auth, orders, and playback', () => {
|
|||||||
.expect(201);
|
.expect(201);
|
||||||
|
|
||||||
const firstHistory = await request(app.getHttpServer())
|
const firstHistory = await request(app.getHttpServer())
|
||||||
.get('/api/app/v1/playback-history')
|
.get('/api/app/v1/history')
|
||||||
.set('Authorization', `Bearer ${firstToken}`)
|
.set('Authorization', `Bearer ${firstToken}`)
|
||||||
.expect(200);
|
.expect(200);
|
||||||
|
|
||||||
@@ -234,7 +234,7 @@ describe('Auth, orders, and playback', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const secondHistory = await request(app.getHttpServer())
|
const secondHistory = await request(app.getHttpServer())
|
||||||
.get('/api/app/v1/playback-history')
|
.get('/api/app/v1/history')
|
||||||
.set('Authorization', `Bearer ${secondToken}`)
|
.set('Authorization', `Bearer ${secondToken}`)
|
||||||
.expect(200);
|
.expect(200);
|
||||||
|
|
||||||
@@ -280,7 +280,7 @@ describe('Auth, orders, and playback', () => {
|
|||||||
.expect(201);
|
.expect(201);
|
||||||
|
|
||||||
await request(app.getHttpServer())
|
await request(app.getHttpServer())
|
||||||
.post('/api/app/v1/playback-history')
|
.post('/api/app/v1/history')
|
||||||
.set('Authorization', `Bearer ${login.body.data.accessToken}`)
|
.set('Authorization', `Bearer ${login.body.data.accessToken}`)
|
||||||
.send({
|
.send({
|
||||||
episodeId: episode.body.data.id,
|
episodeId: episode.body.data.id,
|
||||||
|
|||||||
Reference in New Issue
Block a user