Skip to content

Commit

Permalink
MV #41 #2 : Siguiendo KISS y DRY y limpiando codigo
Browse files Browse the repository at this point in the history
  • Loading branch information
LCinder committed Dec 6, 2021
1 parent b3ba33d commit 9755a61
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/routes.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

import {Movie} from "./movie" ;
import {Movies} from "./movies";
import fastify, {FastifyRequest} from "fastify";
import fastify from "fastify";
const optionsLogger = {
logger: {
prettyPrint: {
Expand All @@ -11,6 +11,9 @@ const optionsLogger = {
}
}};
export const server = fastify(optionsLogger);

const movies = new Movies();
let movie: Movie = new Movie();
/**********************************************************************************************************************/
/**********************************************************************************************************************/
server.get("/status", async (request, reply) => {
Expand All @@ -20,8 +23,6 @@ server.get("/status", async (request, reply) => {
/**********************************************************************************************************************/
server.get("/movies", async (request, reply) => {
try {
const movies = new Movies();

request.log.info("Movies sent");
reply.code(200).send(movies.movies);
} catch(err: any) {
Expand All @@ -33,9 +34,7 @@ server.get("/movies", async (request, reply) => {
/**********************************************************************************************************************/
server.get("/movies/:movie", async (request: any, reply) => {
try {
const movies = new Movies();
const movie: Movie = new Movie(movies.convertJSON2Movie(movies.find(request.params.movie)));

movie = movies.convertJSON2Movie(movies.find(request.params.movie))
request.log.info(`Movie ${movie.title} sent`);
reply.code(200).send(JSON.stringify(movie));
} catch(err: any) {
Expand All @@ -47,8 +46,7 @@ server.get("/movies/:movie", async (request: any, reply) => {
/**********************************************************************************************************************/
server.get("/movies/:movie/keywords", async (request: any, reply) => {
try {
const movies = new Movies();
const movie: Movie = new Movie(movies.convertJSON2Movie(movies.find(request.params.movie)));
movie = movies.convertJSON2Movie(movies.find(request.params.movie))
const keywords: string[] = movie.extractKeywords();
request.log.info(`Extracted and sent keywords from movie ${movie.title}`);
reply.code(200).send(JSON.stringify(keywords));
Expand All @@ -59,4 +57,4 @@ server.get("/movies/:movie/keywords", async (request: any, reply) => {
});
/**********************************************************************************************************************/
/**********************************************************************************************************************/
//server.listen(5001)
//server.listen(5002)

0 comments on commit 9755a61

Please sign in to comment.