diff --git a/src/app.module.ts b/src/app.module.ts index aa978ef..9cd363a 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -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 {} diff --git a/src/modules/database/database.module.ts b/src/modules/database/database.module.ts index b97e7cd..0985813 100644 --- a/src/modules/database/database.module.ts +++ b/src/modules/database/database.module.ts @@ -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', diff --git a/src/modules/playback-history/dto/upsert-playback-history.dto.ts b/src/modules/history/dto/upsert-history.dto.ts similarity index 100% rename from src/modules/playback-history/dto/upsert-playback-history.dto.ts rename to src/modules/history/dto/upsert-history.dto.ts diff --git a/src/modules/playback-history/entities/user-playback-history.entity.ts b/src/modules/history/entities/user-playback-history.entity.ts similarity index 100% rename from src/modules/playback-history/entities/user-playback-history.entity.ts rename to src/modules/history/entities/user-playback-history.entity.ts diff --git a/src/modules/playback-history/playback-history.controller.ts b/src/modules/history/history.controller.ts similarity index 62% rename from src/modules/playback-history/playback-history.controller.ts rename to src/modules/history/history.controller.ts index 73789bf..ff51028 100644 --- a/src/modules/playback-history/playback-history.controller.ts +++ b/src/modules/history/history.controller.ts @@ -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, }); diff --git a/src/modules/history/history.module.ts b/src/modules/history/history.module.ts new file mode 100644 index 0000000..25df03c --- /dev/null +++ b/src/modules/history/history.module.ts @@ -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 {} diff --git a/src/modules/playback-history/playback-history.service.ts b/src/modules/history/history.service.ts similarity index 97% rename from src/modules/playback-history/playback-history.service.ts rename to src/modules/history/history.service.ts index 50a543f..7554908 100644 --- a/src/modules/playback-history/playback-history.service.ts +++ b/src/modules/history/history.service.ts @@ -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[] = []; diff --git a/src/modules/playback-history/interfaces/playback-history-record.interface.ts b/src/modules/history/interfaces/history-record.interface.ts similarity index 100% rename from src/modules/playback-history/interfaces/playback-history-record.interface.ts rename to src/modules/history/interfaces/history-record.interface.ts diff --git a/src/modules/playback-history/playback-history.module.ts b/src/modules/playback-history/playback-history.module.ts deleted file mode 100644 index 766d817..0000000 --- a/src/modules/playback-history/playback-history.module.ts +++ /dev/null @@ -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 {} diff --git a/test/orders-playback.e2e-spec.ts b/test/orders-playback.e2e-spec.ts index dbb8ed5..8a91876 100644 --- a/test/orders-playback.e2e-spec.ts +++ b/test/orders-playback.e2e-spec.ts @@ -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,