Skip to content

Commit 0d8938c

Browse files
committed
feat(rest-api): Added /shows /shows/:page calls
And partly the /show/:imdId
1 parent cde3a11 commit 0d8938c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+1181
-129
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Controller, Get, Inject, Param, Query } from '@nestjs/common'
2-
import { MoviesService, MoviesArgs } from '@pct-org/movies'
2+
import { MoviesService, MoviesArgs } from '@pct-org/api/movies'
33
import { Movie } from '../../shared/movie.interface'
44

55
@Controller('/movies')
@@ -24,53 +24,49 @@ export class MoviesController {
2424
): Promise<Movie[]> {
2525
args.offset = (page - 1) * args.limit
2626
args.query = args.keywords
27-
28-
const movies = await this.moviesService.findAll(args)
2927

30-
return movies.map((movie) => {
31-
const released = new Date(movie.released)
28+
const movies = await this.moviesService.findAll(args)
3229

33-
return {
34-
_id: movie._id,
35-
imdb_id: movie._id,
36-
title: movie.title,
37-
year: `${released.getFullYear()}`,
38-
synopsis: movie.synopsis,
39-
runtime: `${(movie.runtime.hours * 60) + movie.runtime.minutes}`,
40-
released: movie.released,
41-
trailer: movie.trailer,
42-
certification: '',
43-
torrents: {
44-
en: {
45-
...movie.torrents.reduce((newTorrents, torrent) => {
46-
newTorrents[torrent.quality] = {
47-
url: torrent.url,
48-
seed: torrent.seeds,
49-
peer: torrent.peers,
50-
size: torrent.size,
51-
fileSize: torrent.sizeString,
52-
provider: torrent.provider
53-
}
30+
return movies.map((movie) => ({
31+
_id: movie._id,
32+
imdb_id: movie._id,
33+
title: movie.title,
34+
year: `${(new Date(movie.released)).getFullYear()}`,
35+
synopsis: movie.synopsis,
36+
runtime: `${(movie.runtime.hours * 60) + movie.runtime.minutes}`,
37+
released: movie.released,
38+
trailer: movie.trailer,
39+
certification: '',
40+
torrents: {
41+
en: {
42+
...movie.torrents.reduce((newTorrents, torrent) => {
43+
newTorrents[torrent.quality] = {
44+
url: torrent.url,
45+
seed: torrent.seeds,
46+
peer: torrent.peers,
47+
size: torrent.size,
48+
fileSize: torrent.sizeString,
49+
provider: torrent.provider
50+
}
5451

55-
return newTorrents
56-
}, {})
57-
}
58-
},
59-
genres: movie.genres,
60-
images: {
61-
poster: movie.images.poster.medium,
62-
fanart: movie.images.backdrop.medium,
63-
banner: movie.images.poster.medium
64-
},
65-
rating: {
66-
percentage: movie.rating.percentage,
67-
watching: movie.rating.watching,
68-
votes: movie.rating.votes,
69-
loved: 100,
70-
hated: 100
52+
return newTorrents
53+
}, {})
7154
}
55+
},
56+
genres: movie.genres,
57+
images: {
58+
poster: movie.images.poster.medium,
59+
fanart: movie.images.backdrop.medium,
60+
banner: movie.images.poster.medium
61+
},
62+
rating: {
63+
percentage: movie.rating.percentage,
64+
watching: movie.rating.watching,
65+
votes: movie.rating.votes,
66+
loved: 100,
67+
hated: 100
7268
}
73-
})
69+
}))
7470
}
7571

7672
}

β€Žapps/rest-api/src/routes/movies/movies.module.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Module } from '@nestjs/common'
2-
import { MoviesService } from '@pct-org/movies'
2+
import { MoviesService } from '@pct-org/api/movies'
33

44
import { MoviesController } from './movies.controller'
55

Original file line numberDiff line numberDiff line change
@@ -1,11 +1,92 @@
1-
import { Controller, Get } from '@nestjs/common'
1+
import { Controller, Get, Inject, Param, Query } from '@nestjs/common'
2+
import { ShowsArgs, ShowsService } from '@pct-org/api/shows'
23

3-
@Controller('/shows')
4+
import { Show, ShowClean } from '../../shared/show.interface'
5+
6+
@Controller()
47
export class ShowsController {
58

6-
@Get('')
7-
public watch() {
8-
return 'ok'
9+
@Inject()
10+
private readonly showsService: ShowsService
11+
12+
@Get('/shows')
13+
public async getShows(): Promise<string[]> {
14+
const totalShows = await this.showsService.count()
15+
16+
return Array(Math.round(totalShows / 50)).fill(null).map((empty, index) => (
17+
`/shows/${index + 1}`
18+
))
919
}
1020

21+
@Get('/shows/:page')
22+
public async getShowsPage(
23+
@Param('page') page: number,
24+
@Query() args: ShowsArgs
25+
): Promise<ShowClean[]> {
26+
args.offset = (page - 1) * args.limit
27+
args.query = args.keywords
28+
29+
const shows = await this.showsService.findAll(args)
30+
31+
return shows.map((show) => ({
32+
_id: show._id,
33+
imdb_id: show._id,
34+
tvdb_id: `${show.tvdbId}`,
35+
title: show.title,
36+
year: `${(new Date(show.released)).getFullYear()}`,
37+
slug: show.slug,
38+
num_seasons: show.numSeasons,
39+
images: {
40+
poster: show.images.poster.medium,
41+
fanart: show.images.backdrop.medium,
42+
banner: show.images.poster.medium
43+
},
44+
rating: {
45+
percentage: show.rating.percentage,
46+
watching: show.rating.watching,
47+
votes: show.rating.votes,
48+
loved: 100,
49+
hated: 100
50+
}
51+
}))
52+
}
53+
54+
@Get('/show/:imdbId')
55+
public async getShow(
56+
@Param('imdbId') imdbId: string
57+
): Promise<Show> {
58+
const show = await this.showsService.findOne(imdbId)
59+
60+
return ({
61+
_id: show._id,
62+
imdb_id: show._id,
63+
tvdb_id: `${show.tvdbId}`,
64+
title: show.title,
65+
year: `${(new Date(show.released)).getFullYear()}`,
66+
slug: show.slug,
67+
runtime: `${(show.runtime.hours * 60) + show.runtime.minutes}`,
68+
synopsis: show.synopsis,
69+
num_seasons: show.numSeasons,
70+
country: show.airInfo.country,
71+
network: show.airInfo.network,
72+
air_day: show.airInfo.day,
73+
air_time: show.airInfo.time,
74+
status: show.airInfo.status,
75+
genres: show.genres,
76+
images: {
77+
poster: show.images.poster.medium,
78+
fanart: show.images.backdrop.medium,
79+
banner: show.images.poster.medium
80+
},
81+
rating: {
82+
percentage: show.rating.percentage,
83+
watching: show.rating.watching,
84+
votes: show.rating.votes,
85+
loved: 100,
86+
hated: 100
87+
},
88+
last_updated: show.updatedAt,
89+
episodes: []
90+
})
91+
}
1192
}

β€Žapps/rest-api/src/routes/shows/shows.module.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import { Module } from '@nestjs/common'
2+
import { ShowsService } from '@pct-org/api/shows'
23

34
import { ShowsController } from './shows.controller'
45

56
@Module({
6-
providers: [],
7+
providers: [
8+
ShowsService
9+
],
710
controllers: [
811
ShowsController
912
]

β€Žapps/rest-api/src/shared/models.module.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
import { Global, Module } from '@nestjs/common'
2-
import { MOVIES_MONGOOSE_FEATURE } from '@pct-org/movies'
3-
2+
import { MOVIES_MONGOOSE_FEATURE } from '@pct-org/api/movies'
3+
import { SHOWS_MONGOOSE_FEATURE } from '@pct-org/api/shows'
44

55
@Global()
66
@Module({
77
imports: [
8-
MOVIES_MONGOOSE_FEATURE
8+
MOVIES_MONGOOSE_FEATURE,
9+
SHOWS_MONGOOSE_FEATURE
910
],
1011
exports: [
11-
MOVIES_MONGOOSE_FEATURE
12+
MOVIES_MONGOOSE_FEATURE,
13+
SHOWS_MONGOOSE_FEATURE
1214
]
1315
})
1416
export class ModelsModule {

β€Žapps/rest-api/src/shared/movie.interface.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ export interface Movie {
1111
released: number
1212
trailer: string
1313
certification: string
14-
torrents: Torrents,
14+
torrents: {
15+
en: Torrents
16+
}
1517
genres: string[]
1618

1719
images: {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import { Torrents } from './torrents.interface'
2+
3+
export interface ShowClean {
4+
5+
_id: string
6+
imdb_id: string
7+
tvdb_id: string
8+
title: string
9+
year: string
10+
slug: string
11+
num_seasons: number
12+
13+
images: {
14+
poster: string
15+
fanart: string
16+
banner: string
17+
},
18+
19+
rating: {
20+
percentage: number
21+
watching: number
22+
votes: number
23+
loved: number
24+
hated: number
25+
}
26+
27+
}
28+
29+
export interface Show extends ShowClean {
30+
31+
synopsis: string
32+
runtime: string
33+
country: string
34+
network: string
35+
air_day: string
36+
air_time: string
37+
status: string
38+
last_updated: number
39+
genres: string[]
40+
41+
episodes: ShowEpisode[]
42+
}
43+
44+
export interface ShowEpisode {
45+
46+
torrents: Torrents
47+
48+
watched: {
49+
watched: boolean
50+
}
51+
52+
first_aired: number
53+
date_based: false
54+
overview: string
55+
title: string
56+
episode: number
57+
season: number
58+
tvdb_id: number
59+
60+
}
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
export interface Torrents {
22

3-
en: {
4-
[key: string]: {
5-
url: string
6-
seed: number
7-
peer: number
8-
size: number
9-
filesize: string
10-
provider: string
11-
},
12-
}
3+
[key: string]: {
4+
url: string
5+
seed: number
6+
peer: number
7+
size: number
8+
filesize: string
9+
provider: string
10+
},
1311

1412
}

β€Žjest.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ module.exports = {
66
resolver: '@nrwl/jest/plugins/resolver',
77
moduleFileExtensions: ['ts', 'js', 'html'],
88
coverageReporters: ['html'],
9-
projects: '<rootDir>/libs/movies',
9+
projects: '<rootDir>/libs/api/download',
1010
};

β€Žlibs/api/movies/.eslintrc.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"extends": "../../../.eslintrc.json",
3+
"ignorePatterns": ["!**/*"],
4+
"rules": {}
5+
}

β€Žlibs/api/movies/README.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# api-movies
2+
3+
This library was generated with [Nx](https://nx.dev).
4+
5+
## Running unit tests
6+
7+
Run `nx test api-movies` to execute the unit tests via [Jest](https://jestjs.io).

β€Žlibs/api/movies/jest.config.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module.exports = {
2+
displayName: 'api-movies',
3+
preset: '../../../jest.preset.js',
4+
globals: {
5+
'ts-jest': {
6+
tsConfig: '<rootDir>/tsconfig.spec.json',
7+
},
8+
},
9+
transform: {
10+
'^.+\\.[tj]sx?$': 'ts-jest',
11+
},
12+
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
13+
coverageDirectory: '../../../coverage/libs/api/movies',
14+
};

β€Žlibs/movies/src/dto/movies.args.ts β€Žlibs/api/movies/src/dto/movies.args.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { ArgsType, Field } from '@nestjs/graphql'
2-
3-
import { ContentsArgs } from '../content/dto/contents.args'
2+
import { ContentsArgs } from '@pct-org/api/shared'
43

54
@ArgsType()
65
export class MoviesArgs extends ContentsArgs {

β€Žlibs/movies/src/index.ts β€Žlibs/api/movies/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { MongooseModule } from '@nestjs/mongoose'
22

33
export { MoviesService } from './movies.service'
44
export { MoviesArgs } from './dto/movies.args'
5+
export { MovieArgs } from './dto/movie.args'
56

67
import { movieSchema } from './movie.schema'
78

File renamed without changes.

β€Žlibs/movies/src/movie.object-type.ts β€Žlibs/api/movies/src/movie.object-type.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
import { Field, ObjectType } from '@nestjs/graphql'
2-
3-
import { Content } from '../shared/content.object-type'
4-
import { Torrent } from '../shared/torrent.object-type'
5-
import { Watched } from '../shared/watched.object-type'
6-
import { DownloadInfo } from '../shared/download-info.object-type'
2+
import { Content, Torrent, Watched, DownloadInfo } from '@pct-org/api/shared'
73

84
@ObjectType()
95
export class Movie extends Content {
File renamed without changes.

0 commit comments

Comments
Β (0)