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 { OrdersModule } from "./modules/orders/orders.module";
|
||||
import { PlayerModule } from "./modules/player/player.module";
|
||||
import { HistoryModule } from "./modules/history/history.module";
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
@@ -26,6 +27,7 @@ import { PlayerModule } from "./modules/player/player.module";
|
||||
AuthModule,
|
||||
OrdersModule,
|
||||
PlayerModule,
|
||||
HistoryModule,
|
||||
],
|
||||
})
|
||||
export class AppModule {}
|
||||
|
||||
@@ -14,6 +14,7 @@ import { Cover } from '../media/entities/cover.entity';
|
||||
import { MediaUploadJob } from '../media/entities/media-upload-job.entity';
|
||||
import { Order } from '../orders/entities/order.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';
|
||||
|
||||
const databaseImports = process.env.DB_HOST
|
||||
@@ -40,6 +41,7 @@ const databaseImports = process.env.DB_HOST
|
||||
MediaUploadJob,
|
||||
Order,
|
||||
UserEpisodeUnlock,
|
||||
UserPlaybackHistory,
|
||||
User,
|
||||
],
|
||||
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 { JwtAuthGuard } from '../auth/guards/jwt-auth.guard';
|
||||
import { UserRecord } from '../users/interfaces/user-record.interface';
|
||||
import { UpsertPlaybackHistoryDto } from './dto/upsert-playback-history.dto';
|
||||
import { PlaybackHistoryService } from './playback-history.service';
|
||||
import { UpsertPlaybackHistoryDto } from './dto/upsert-history.dto';
|
||||
import { HistoryService } from './history.service';
|
||||
|
||||
@ApiTags('PlaybackHistory')
|
||||
@Controller('/api/app/v1/playback-history')
|
||||
export class PlaybackHistoryController {
|
||||
constructor(private readonly playbackHistoryService: PlaybackHistoryService) {}
|
||||
@ApiTags('History')
|
||||
@Controller('/api/app/v1/history')
|
||||
export class HistoryController {
|
||||
constructor(private readonly historyService: HistoryService) {}
|
||||
|
||||
@Post()
|
||||
@ApiBearerAuth()
|
||||
@@ -18,7 +18,7 @@ export class PlaybackHistoryController {
|
||||
@CurrentUser() user: UserRecord,
|
||||
@Body() dto: UpsertPlaybackHistoryDto,
|
||||
) {
|
||||
return this.playbackHistoryService.upsertHistory(user, dto);
|
||||
return this.historyService.upsertHistory(user, dto);
|
||||
}
|
||||
|
||||
@Get()
|
||||
@@ -29,7 +29,7 @@ export class PlaybackHistoryController {
|
||||
@Query('page') page?: string,
|
||||
@Query('pageSize') pageSize?: string,
|
||||
) {
|
||||
return this.playbackHistoryService.listHistory(user, {
|
||||
return this.historyService.listHistory(user, {
|
||||
page: Number(page) || 1,
|
||||
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,
|
||||
} from '../dramas/interfaces/drama-records.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 {
|
||||
PlaybackHistoryListItem,
|
||||
PlaybackHistoryRecord,
|
||||
} from './interfaces/playback-history-record.interface';
|
||||
} from './interfaces/history-record.interface';
|
||||
|
||||
interface PaginationInput {
|
||||
page: number;
|
||||
@@ -21,7 +21,7 @@ interface PaginationInput {
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class PlaybackHistoryService {
|
||||
export class HistoryService {
|
||||
private historySequence = 1;
|
||||
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);
|
||||
|
||||
await request(app.getHttpServer())
|
||||
.post('/api/app/v1/playback-history')
|
||||
.post('/api/app/v1/history')
|
||||
.send({
|
||||
episodeId: episode.body.data.id,
|
||||
progressSeconds: 86,
|
||||
@@ -188,7 +188,7 @@ describe('Auth, orders, and playback', () => {
|
||||
.expect(401);
|
||||
|
||||
await request(app.getHttpServer())
|
||||
.post('/api/app/v1/playback-history')
|
||||
.post('/api/app/v1/history')
|
||||
.set('Authorization', `Bearer ${firstToken}`)
|
||||
.send({
|
||||
episodeId: episode.body.data.id,
|
||||
@@ -199,7 +199,7 @@ describe('Auth, orders, and playback', () => {
|
||||
.expect(201);
|
||||
|
||||
await request(app.getHttpServer())
|
||||
.post('/api/app/v1/playback-history')
|
||||
.post('/api/app/v1/history')
|
||||
.set('Authorization', `Bearer ${firstToken}`)
|
||||
.send({
|
||||
episodeId: episode.body.data.id,
|
||||
@@ -210,7 +210,7 @@ describe('Auth, orders, and playback', () => {
|
||||
.expect(201);
|
||||
|
||||
const firstHistory = await request(app.getHttpServer())
|
||||
.get('/api/app/v1/playback-history')
|
||||
.get('/api/app/v1/history')
|
||||
.set('Authorization', `Bearer ${firstToken}`)
|
||||
.expect(200);
|
||||
|
||||
@@ -234,7 +234,7 @@ describe('Auth, orders, and playback', () => {
|
||||
});
|
||||
|
||||
const secondHistory = await request(app.getHttpServer())
|
||||
.get('/api/app/v1/playback-history')
|
||||
.get('/api/app/v1/history')
|
||||
.set('Authorization', `Bearer ${secondToken}`)
|
||||
.expect(200);
|
||||
|
||||
@@ -280,7 +280,7 @@ describe('Auth, orders, and playback', () => {
|
||||
.expect(201);
|
||||
|
||||
await request(app.getHttpServer())
|
||||
.post('/api/app/v1/playback-history')
|
||||
.post('/api/app/v1/history')
|
||||
.set('Authorization', `Bearer ${login.body.data.accessToken}`)
|
||||
.send({
|
||||
episodeId: episode.body.data.id,
|
||||
|
||||
Reference in New Issue
Block a user