forked from b00tc4mp/isdi-parttime-202309
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
193 additions
and
126 deletions.
There are no files selected for viewing
4 changes: 2 additions & 2 deletions
4
staff/belen-ivars/project/api/handlers/retrieveRecipesHandler.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
staff/belen-ivars/project/api/test/retrieve-recipes.test.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
source pepetest.sh | ||
|
||
TEST 'retrieve-recipes' | ||
|
||
CASE 'success on current user' | ||
|
||
curl 'http://localhost:9000/recipes/65f85ac7883fd3713c8bd3a3' \ | ||
-H 'Authorization: Bearer 65f85ac7883fd3713c8bd3a3' \ | ||
-v | ||
|
||
# > GET /recipes/65f85ac7883fd3713c8bd3a3 HTTP/1.1 | ||
# > Host: localhost:9000 | ||
# > User-Agent: curl/8.4.0 | ||
# > Accept: */* | ||
# > Authorization: Bearer 65f85ac7883fd3713c8bd3a3 | ||
# > | ||
# < HTTP/1.1 200 OK | ||
# < X-Powered-By: Express | ||
# < Access-Control-Allow-Origin: * | ||
# < Content-Type: application/json; charset=utf-8 | ||
# < Content-Length: 1125 | ||
# < ETag: W/"465-DMOd83RcJKRMoeR/PypUE8SJ5aU" | ||
# < Date: Tue, 09 Apr 2024 17:37:27 GMT | ||
# < Connection: keep-alive | ||
# < Keep-Alive: timeout=5 | ||
# < | ||
# * Connection #0 to host localhost left intact | ||
# [{"_id":"65f883f4fb135521e8161c93","title":"Colors","description":"Persona con pintura corporal","image":"https://www.pexels.com/es-es/foto/persona-con-pintura-corporal-1209843/","author":"65d655fac1dd88f9aee917d6","__v":0},{"_id":"65f97adbd699fa7945c5d178","title":"Colors","description":"Persona con pintura corporal","image":"https://www.pexels.com/es-es/foto/persona-con-pintura-corporal-1209843/","author":"65d655fac1dd88f9aee917d6","__v":0},{"_id":"65f97ae4ee6c8ad8251da2b0","title":"Colors","description":"Persona con pintura corporal","image":"https://www.pexels.com/es-es/foto/persona-con-pintura-corporal-1209843/","author":"65d655fac1dd88f9aee917d6","__v":0},{"_id":"65fc725721104edb3ca0821b","title":"Colors","description":"Persona con pintura corporal","image":"https://www.pexels.com/es-es/foto/persona-con-pintura-corporal-1209843/","author":"65d655fac1dd88f9aee917d6","__v":0},{"_id":"65fc7fbf9c9ec7ea25f03601","title":"sdfgs","description":"srfwerf","image":"https://sorprendele.es/storage/2022/11/tassa-de-la-terreta-menges-mes-que-el-tio-sangonera-600x600.jpg","author":"65f85ac7883fd3713c8bd3a3","__v":0}] | ||
|
||
CASE "fail on non existing user" | ||
|
||
curl 'http://localhost:9000/recipes/65d642e9695ce01b53585a84' \ | ||
-H 'Authorization: Bearer 65d642e9695ce01b53585a84' \ | ||
-v | ||
|
||
# > GET /recipes/65d642e9695ce01b53585a84 HTTP/1.1 | ||
# > Host: localhost:9000 | ||
# > User-Agent: curl/8.4.0 | ||
# > Accept: */* | ||
# > Authorization: Bearer 65d642e9695ce01b53585a84 | ||
# > | ||
# < HTTP/1.1 404 Not Found | ||
# < X-Powered-By: Express | ||
# < Access-Control-Allow-Origin: * | ||
# < Content-Type: application/json; charset=utf-8 | ||
# < Content-Length: 24 | ||
# < ETag: W/"18-dMQu7DCvMLzkIB4OfTQNazIjBKo" | ||
# < Date: Tue, 09 Apr 2024 17:37:27 GMT | ||
# < Connection: keep-alive | ||
# < Keep-Alive: timeout=5 | ||
# < | ||
# * Connection #0 to host localhost left intact | ||
# {"name":"NotFoundError"}% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { useState } from 'react' | ||
import { useNavigate } from 'react-router-dom' | ||
|
||
import logic from "../logic" | ||
|
||
import { Button, Field, Form, Link } from "../library" | ||
import { useContext } from '../hooks' | ||
|
||
import session from '../logic/session' | ||
|
||
function Recipe(props) { | ||
|
||
console.log('Recipe') | ||
const [view, setView] = useState(null) | ||
|
||
const context = useContext() | ||
const navigate = useNavigate() | ||
|
||
|
||
|
||
return <article className="recipe"> | ||
{/* <h2><Link onClick={handleUserClick}> {props.recipe.author.name}</Link></h2> */} | ||
|
||
<h2> {props.recipe.title}</h2> | ||
<img className="recipe-image" src={props.recipe.image} /> | ||
<p>{props.recipe.description}</p> | ||
|
||
{/* {view === null && <p>{props.recipe.text}</p>} */} | ||
|
||
{/* {view === 'edit' && <Form onSubmit={handleEditSubmit}> | ||
<Field id="text" value={props.recipe.text} /> | ||
<Button type="submit">Save</Button> | ||
<Button onClick={handleEditCancelClick}>Cancel</Button> | ||
</Form>} */} | ||
|
||
|
||
{/* <div className="recipe-actions"> | ||
<Button onClick={handleToggleLikeClick}>{props.recipe.liked ? '❤️' : '🤍'} {props.recipe.likes.length}</Button> | ||
<Button onClick={handleToggleFavClick}>{props.recipe.fav ? '⭐️' : '✩'}</Button> | ||
{session.sessionUserId === props.recipe.author.id && <Button onClick={handleDeleteRecipeClick}>🗑️</Button>} | ||
{session.sessionUserId === props.recipe.author.id && view === null && <Button onClick={handleEditclick}>✏️</Button>} | ||
</div> */} | ||
</article> | ||
} | ||
|
||
export default Recipe |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,38 @@ | ||
function Recipes(props) { } | ||
import { useEffect, useState } from "react" | ||
import Recipe from './Recipe' | ||
import { useContext } from "../hooks" | ||
import logic from "../logic" | ||
|
||
function Recipes(props) { | ||
console.log('Recipes') | ||
|
||
const [recipes, setRecipes] = useState([]) | ||
|
||
const context = useContext() | ||
|
||
const refreshRecipes = () => { | ||
(async () => { | ||
|
||
try { | ||
const content = await logic.retrieveRecipes() | ||
|
||
setRecipes(content) | ||
} catch (error) { | ||
context.handleError(error) | ||
} | ||
})() | ||
} | ||
|
||
useEffect(() => { | ||
console.log('Recipes effect') | ||
|
||
refreshRecipes() | ||
}, [props.stamp]) | ||
|
||
return <div className="recipes"> | ||
{recipes.map(recipe => <Recipe key={recipe.id} recipe={recipe} onError={props.onError} />)} | ||
</div> | ||
|
||
} | ||
|
||
export default Recipes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
staff/belen-ivars/project/app/src/logic/retrieveRecipes.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import session from "./session" | ||
import { API_URL } from "../utils/constants" | ||
import { errors } from "com" | ||
const { SystemError } = errors | ||
|
||
export default async function retrieveRecipes() { | ||
return (async () => { | ||
const req = { | ||
method: 'GET', | ||
headers: { | ||
Authorization: `Bearer ${session.token}` | ||
} | ||
} | ||
|
||
let res | ||
try { | ||
res = await fetch(`${API_URL}/recipes/${session.sessionUserId}`, req) | ||
} catch (error) { | ||
throw new SystemError(error.message) | ||
} | ||
|
||
if (!res.ok) { | ||
let body | ||
|
||
try { | ||
body = await res.json() | ||
} catch (error) { | ||
throw new SystemError(error.message) | ||
} | ||
|
||
throw new errors[body.error](body.message) | ||
} | ||
|
||
try { | ||
const recipes = await res.json() | ||
|
||
return recipes | ||
} catch (error) { | ||
throw new SystemError(error.message) | ||
} | ||
})() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.