Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
Lazzzer committed Jun 8, 2020
2 parents 4a2e749 + 836b448 commit eedaaa6
Show file tree
Hide file tree
Showing 14 changed files with 209 additions and 24 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
client/.env

docker-compose.prod.yml
docker-compose.prod.yml
redis.conf
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Moviepark is an open-source project using the TMDb API for its movie catalog.
- [Adonis.js 5](https://github.com/adonisjs)
- [TailwindCSS](https://github.com/tailwindcss/tailwindcss)
- [Traefik 2.2](https://github.com/containous/traefik/)
- [Redis](https://redis.io/)

## Requirements
- [Node.js >= 12.0.0](https://nodejs.org/en/)
Expand Down Expand Up @@ -41,7 +42,7 @@ To check how it would look like in production with docker (don't forget to add y
## Todo

- [x] Release version 1.0 Yay!
- [ ] Caching
- [x] Caching
- [ ] Get streaming services for each movie with [Utelly's API](https://rapidapi.com/utelly/api/utelly)
- [ ] More search filters (ex: search by company...)
- [ ] Watchlist
21 changes: 11 additions & 10 deletions client/components/movie/MobileMovieDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,17 @@
</svg>
</a>
</div>

<div class="px-6">
<a v-if="trailerId !== ''" :href="'https://youtube.com/watch?v='+ trailerId" target="_blank" rel="noopener" class="inline-flex items-center justify-center w-full px-4 py-3 mt-6 mb-6 text-base font-medium leading-4 text-gray-300 transition duration-150 ease-in-out border border-transparent rounded-md lg:px-3 lg:py-3 bg-m-burgundy-700 hover:bg-m-burgundy-600 focus:outline-none focus:border-m-burgundy-600 active:bg-m-burgundy-600">
<svg class="inline-block w-6 h-auto mr-2 stroke-current" viewBox="0 0 32 23" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M30.0533 4.56016C29.8949 3.92738 29.5723 3.34759 29.1182 2.87937C28.664 2.41115 28.0943 2.07108 27.4666 1.8935C25.1733 1.3335 15.9999 1.3335 15.9999 1.3335C15.9999 1.3335 6.82662 1.3335 4.53328 1.94683C3.90561 2.12441 3.33592 2.46448 2.88174 2.9327C2.42757 3.40093 2.105 3.98071 1.94662 4.6135C1.5269 6.9409 1.3216 9.30191 1.33328 11.6668C1.31832 14.0496 1.52364 16.4286 1.94662 18.7735C2.12123 19.3866 2.45102 19.9444 2.90414 20.3928C3.35726 20.8412 3.91838 21.1652 4.53328 21.3335C6.82662 21.9468 15.9999 21.9468 15.9999 21.9468C15.9999 21.9468 25.1733 21.9468 27.4666 21.3335C28.0943 21.1559 28.664 20.8158 29.1182 20.3476C29.5723 19.8794 29.8949 19.2996 30.0533 18.6668C30.4698 16.3569 30.6751 14.0139 30.6666 11.6668C30.6816 9.2841 30.4763 6.90509 30.0533 4.56016V4.56016Z" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" />
<path d="M13 16.0266L20.6667 11.6666L13 7.30664V16.0266Z" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" />
</svg>
<span class="font-bold ">Trailer</span>
</a>
</div>

<p class="mx-6 mt-2 text-lg italic text-m-blue-500">{{ movieInfos.tagline }}</p>
<p class="mx-6 my-4 leading-5 text-justify text-gray-300">{{ movieInfos.overview }}</p>

Expand All @@ -77,16 +88,6 @@
>{{ genre.name }}</span>
</div>

<div class="px-6">
<a v-if="trailerId !== ''" :href="'https://youtube.com/watch?v='+ trailerId" target="_blank" rel="noopener" class="inline-flex items-center justify-center w-full px-4 py-3 mt-6 mb-3 text-base font-medium leading-4 text-gray-300 transition duration-150 ease-in-out border border-transparent rounded-md lg:px-3 lg:py-3 bg-m-burgundy-700 hover:bg-m-burgundy-600 focus:outline-none focus:border-m-burgundy-600 active:bg-m-burgundy-600">
<svg class="inline-block w-6 h-auto mr-2 stroke-current" viewBox="0 0 32 23" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M30.0533 4.56016C29.8949 3.92738 29.5723 3.34759 29.1182 2.87937C28.664 2.41115 28.0943 2.07108 27.4666 1.8935C25.1733 1.3335 15.9999 1.3335 15.9999 1.3335C15.9999 1.3335 6.82662 1.3335 4.53328 1.94683C3.90561 2.12441 3.33592 2.46448 2.88174 2.9327C2.42757 3.40093 2.105 3.98071 1.94662 4.6135C1.5269 6.9409 1.3216 9.30191 1.33328 11.6668C1.31832 14.0496 1.52364 16.4286 1.94662 18.7735C2.12123 19.3866 2.45102 19.9444 2.90414 20.3928C3.35726 20.8412 3.91838 21.1652 4.53328 21.3335C6.82662 21.9468 15.9999 21.9468 15.9999 21.9468C15.9999 21.9468 25.1733 21.9468 27.4666 21.3335C28.0943 21.1559 28.664 20.8158 29.1182 20.3476C29.5723 19.8794 29.8949 19.2996 30.0533 18.6668C30.4698 16.3569 30.6751 14.0139 30.6666 11.6668C30.6816 9.2841 30.4763 6.90509 30.0533 4.56016V4.56016Z" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" />
<path d="M13 16.0266L20.6667 11.6666L13 7.30664V16.0266Z" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" />
</svg>
<span class="font-bold ">Trailer</span>
</a>
</div>

</div>

</template>
Expand Down
2 changes: 1 addition & 1 deletion client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "moviepark-client",
"version": "1.0.3",
"version": "1.0.4",
"description": "A webapp made with Nuxt using the TMDB API",
"author": "Lazar Pavicevic",
"private": true,
Expand Down
17 changes: 16 additions & 1 deletion docker-compose.staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,30 @@ services:
- TMDB_API_KEY=
- CLIENT_URL=
- CLIENT_BROWSER_URL=
- REDIS_CONNECTION=
- REDIS_HOST=
- REDIS_PORT=
- REDIS_PASSWORD=
labels:
- "traefik.enable=true"
- "traefik.http.routers.moviepark-server.rule=Host(`api.localhost`)"
- "traefik.http.routers.moviepark-server.entrypoints=web"
restart: always
depends_on:
- moviepark-traefik
- moviepark-redis
networks:
- moviepark-network
moviepark-redis:
image: redis:6-alpine
container_name: moviepark-redis
volumes:
- moviepark-redisData:/data
restart: always
networks:
- moviepark-network
networks:
moviepark-network:
driver: bridge
driver: bridge
volumes:
moviepark-redisData:
3 changes: 2 additions & 1 deletion server/.adonisrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
],
"providers": [
"./providers/AppProvider",
"@adonisjs/core"
"@adonisjs/core",
"@adonisjs/redis"
],
"metaFiles": [
".env",
Expand Down
6 changes: 5 additions & 1 deletion server/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@ APP_KEY=
TMDB_API_KEY=
CLIENT_URL=
CLIENT_BROWSER_URL=
CLIENT_WWW_BROWSER_URL=
CLIENT_WWW_BROWSER_URL=
REDIS_CONNECTION=
REDIS_HOST=
REDIS_PORT=
REDIS_PASSWORD=
30 changes: 27 additions & 3 deletions server/app/Controllers/Http/TmdbsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
import tmdbApi from '../../Services/TmdbService'
import {promises as fs } from 'fs'
import path from 'path'
import Redis from '@ioc:Adonis/Addons/Redis'

async function handleRequest (context: HttpContextContract, axiosPromise: Promise<any>) {
try {
Expand All @@ -12,13 +13,33 @@ async function handleRequest (context: HttpContextContract, axiosPromise: Promis
context.response.status(err.response.status).json({ status: err.response.status, error: err.response.statusText })
}
}

async function handleRequestWithCache (context: HttpContextContract, axiosPromise: Promise<any>, key: string, expiration: number) {
try {
const redisData = await Redis.connection().get(key)
if (redisData === null){
try {
const { data } = await axiosPromise
await Redis.connection().setex(key, expiration, JSON.stringify(data))
return context.response.status(200).send(data)
} catch (err){
console.log(err.response)
return context.response.status(err.response.status).json({ status: err.response.status, error: err.response.statusText })
}
}
return context.response.status(200).send(redisData)
} catch (err) {
return context.response.status(500).json({status: 500, error: 'Server error'})
}
}

export default class TmdbsController {
public async getTrending (context: HttpContextContract) {
return handleRequest(context, tmdbApi.getTrending())
return handleRequestWithCache(context, tmdbApi.getTrending(), 'trending', 43200)
}

public async getNextInTheaters (context: HttpContextContract) {
return handleRequest(context, tmdbApi.getNextInTheaters())
return handleRequestWithCache(context, tmdbApi.getNextInTheaters(), 'nextInTheaters', 43200)
}

public async getGenresList ({ response }: HttpContextContract) {
Expand All @@ -31,7 +52,10 @@ export default class TmdbsController {
}

public async getMovieDetails (context: HttpContextContract) {
return handleRequest(context, tmdbApi.getMovieDetails(context.params.id))
if (!isNaN(context.params.id)) {
return handleRequestWithCache(context, tmdbApi.getMovieDetails(context.params.id), context.params.id, 10800)
}
return context.response.status(404).json({ status: 404, error: 'Not Found' })
}

//SEARCH
Expand Down
48 changes: 48 additions & 0 deletions server/config/redis.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* Config source: https://git.io/JemcF
*
* Feel free to let us know via PR, if you find something broken in this config
* file.
*/

import Env from '@ioc:Adonis/Core/Env'
import { RedisConfig } from '@ioc:Adonis/Addons/Redis'

/*
|--------------------------------------------------------------------------
| Redis configuration
|--------------------------------------------------------------------------
|
| Following is the configuration used by the Redis provider to connect to
| the redis server and execute redis commands.
|
| Do make sure to pre-define the connections type inside `contracts/redis.ts`
| file for AdonisJs to recognize connections.
|
| Make sure to check `contracts/redis.ts` file for defining extra connections
*/
const redisConfig: RedisConfig = {
connection: Env.get('REDIS_CONNECTION', 'local') as 'local',

connections: {
/*
|--------------------------------------------------------------------------
| The default connection
|--------------------------------------------------------------------------
|
| The main connection you want to use to execute redis commands. The same
| connection will be used by the session provider, if you rely on the
| redis driver.
|
*/
local: {
host: Env.get('REDIS_HOST', '127.0.0.1') as string,
port: Env.get('REDIS_PORT', '6379') as string,
password: Env.get('REDIS_PASSWORD', '') as string,
db: 0,
keyPrefix: '',
},
}
}

export default redisConfig
12 changes: 12 additions & 0 deletions server/contracts/redis.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* Contract source: https://git.io/JemcN
*
* Feel free to let us know via PR, if you find something broken in this config
* file.
*/

declare module '@ioc:Adonis/Addons/Redis' {
interface RedisConnectionsList {
local: RedisConnectionConfig,
}
}
79 changes: 78 additions & 1 deletion server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit eedaaa6

Please sign in to comment.