Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Olive
olive-recipes-api
Commits
c9c6a0f4
Commit
c9c6a0f4
authored
3 years ago
by
Daniela Amaral Da Rosa
Browse files
Options
Download
Plain Diff
Merge branch 'dev' into 'feat/continuous-delivery'
# Conflicts: # src/__tests__/endpoints/recipeEndpoints.ts
parents
dff8c977
f8b4e466
Pipeline
#1188
passed with stage
in 1 minute and 6 seconds
Changes
6
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
src/__tests__/endpoints/recipeEndpoints.ts
+1
-1
src/__tests__/endpoints/recipeEndpoints.ts
src/repositories/recipeRepository.ts
+15
-0
src/repositories/recipeRepository.ts
src/routes.ts
+3
-6
src/routes.ts
src/server.ts
+3
-3
src/server.ts
src/services/recipeService.ts
+7
-2
src/services/recipeService.ts
swagger.yaml
+8
-0
swagger.yaml
with
37 additions
and
12 deletions
+37
-12
src/__tests__/endpoints/recipeEndpoints.ts
View file @
c9c6a0f4
...
...
@@ -133,7 +133,7 @@ describe('Getting recipes - Endpoint', () => {
it
(
'
should not return a recipe with an id that doesnt exists
'
,
async
()
=>
{
const
response
=
await
request
.
get
(
'
/recipes/9999
'
);
expect
(
response
.
status
).
toBe
(
404
);
//expect(response.body).toBe(null);
});
});
...
...
This diff is collapsed.
Click to expand it.
src/repositories/recipeRepository.ts
View file @
c9c6a0f4
...
...
@@ -106,6 +106,21 @@ export async function findRecipeById(
return
populateRecipesWithTagsAndSteps
(
recipe
);
}
/**
* Receives a list of recipe_id
* @param recipes_id
* @returns Promise<Recipe[]>
*/
export
async
function
findRecipesByListOfId
(
recipesId
:
number
[],
):
Promise
<
Recipe
[]
>
{
const
recipe
=
await
db
.
select
(
'
*
'
)
.
from
<
Recipe
>
(
'
recipes
'
)
.
whereIn
(
'
recipe_id
'
,
recipesId
)
.
andWhere
(
'
active
'
,
1
);
return
populateRecipesWithTagsAndSteps
(
recipe
);
}
/**
* Receives an array of recipes and adds its tags
* @param recipes
...
...
This diff is collapsed.
Click to expand it.
src/routes.ts
View file @
c9c6a0f4
import
{
celebrate
,
Joi
,
Segments
}
from
'
celebrate
'
;
import
{
celebrate
,
Joi
,
Segments
}
from
'
celebrate
'
;
import
express
from
'
express
'
;
import
healthCheck
from
'
./controllers/healthController
'
;
import
{
indexRecipes
,
postRecipe
,
searchRecipeById
,
searchRecipesByUser
}
from
'
./controllers/recipeController
'
;
import
{
indexRecipes
,
postRecipe
,
searchRecipeById
,
searchRecipesByUser
}
from
'
./controllers/recipeController
'
;
import
indexTags
from
'
./controllers/tagController
'
;
const
routes
=
express
.
Router
();
...
...
@@ -28,6 +26,7 @@ routes.get('/recipes',
[
Segments
.
QUERY
]:
{
tag
:
Joi
.
alternatives
().
try
(
Joi
.
number
(),
Joi
.
array
().
items
(
Joi
.
number
())),
title
:
Joi
.
string
(),
recipeId
:
Joi
.
alternatives
().
try
(
Joi
.
number
(),
Joi
.
array
().
items
(
Joi
.
number
())),
},
}),
indexRecipes
);
routes
.
get
(
'
/tags
'
,
indexTags
);
...
...
@@ -44,6 +43,4 @@ routes.get('/recipes/:recipe_id', celebrate({
},
}),
searchRecipeById
);
routes
.
get
(
'
/tags
'
,
indexTags
);
export
default
routes
;
This diff is collapsed.
Click to expand it.
src/server.ts
View file @
c9c6a0f4
import
{
errors
}
from
'
celebrate
'
;
import
{
errors
}
from
'
celebrate
'
;
import
cors
from
'
cors
'
;
import
express
from
'
express
'
;
import
path
from
'
path
'
;
...
...
@@ -12,9 +12,9 @@ app.use(express.json());
app
.
use
(
routes
);
app
.
use
(
errors
());
if
(
process
.
env
.
NODE_ENV
===
'
development
'
)
{
//
if (process.env.NODE_ENV === 'development') {
const
swaggerDocument
=
YAML
.
load
(
path
.
resolve
(
__dirname
,
'
..
'
,
'
swagger.yaml
'
));
app
.
use
(
'
/api-docs
'
,
swagger
.
serve
,
swagger
.
setup
(
swaggerDocument
,
{
explorer
:
true
}));
}
//
}
export
default
app
;
This diff is collapsed.
Click to expand it.
src/services/recipeService.ts
View file @
c9c6a0f4
...
...
@@ -2,6 +2,7 @@ import Recipe from '../models/recipe';
import
{
findAllRecipes
,
findRecipeById
,
findRecipesByListOfId
,
findRecipesByQueryParams
,
findRecipesByUser
,
saveRecipe
...
...
@@ -23,10 +24,14 @@ function mountRecipe(recipes: Recipe[]) {
}
export
async
function
getAllRecipes
(
query
:
any
):
Promise
<
Recipe
[]
>
{
const
{
tag
,
title
}
=
query
;
const
{
tag
,
title
,
recipeId
}
=
query
;
let
tags
:
number
[]
=
[];
let
recipes
:
Recipe
[];
if
(
tag
||
title
)
{
if
(
recipeId
)
{
let
ids
:
number
[]
=
[];
ids
=
ids
.
concat
(
recipeId
);
recipes
=
await
findRecipesByListOfId
(
ids
);
}
else
if
(
tag
||
title
)
{
tags
=
typeof
tag
!==
'
undefined
'
?
tags
.
concat
(
tag
)
:
[];
recipes
=
await
findRecipesByQueryParams
(
title
,
tags
);
}
else
{
...
...
This diff is collapsed.
Click to expand it.
swagger.yaml
View file @
c9c6a0f4
...
...
@@ -49,6 +49,14 @@ paths:
items
:
type
:
"
number"
collectionFormat
:
"
multi"
-
name
:
"
recipeId"
in
:
"
query"
description
:
"
Id
da
receita"
required
:
false
type
:
"
array"
items
:
type
:
"
number"
collectionFormat
:
"
multi"
-
name
:
"
title"
in
:
"
query"
description
:
"
Título
da
receita"
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help