forked from b00tc4mp/isdi-bootcamp-202405
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use user-id instead of username in ponies b00tc4mp#68
- Loading branch information
1 parent
4684858
commit c01f64e
Showing
82 changed files
with
671 additions
and
1,034 deletions.
There are no files selected for viewing
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
4 changes: 2 additions & 2 deletions
4
staff/nerina-castillo/ponies/api/handlers/createPostHandler.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
4 changes: 2 additions & 2 deletions
4
staff/nerina-castillo/ponies/api/handlers/deletePostHandler.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
4 changes: 2 additions & 2 deletions
4
staff/nerina-castillo/ponies/api/handlers/getAllFavPostsHandler.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
24 changes: 12 additions & 12 deletions
24
.../api/handlers/getAllFollowingUserPosts.js → ...ndlers/getAllFollowingUserPostsHandler.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 |
---|---|---|
@@ -1,13 +1,13 @@ | ||
import { logic } from '../../cor/index.js' | ||
|
||
export default (req, res, next) => { | ||
const { username } = req | ||
|
||
try { | ||
logic.getAllFollowingUserPosts(username) | ||
.then(posts => res.json(posts)) | ||
.catch(error => next(error)) | ||
} catch (error) { | ||
next(error) | ||
} | ||
import { logic } from '../../cor/index.js' | ||
|
||
export default (req, res, next) => { | ||
const { userId } = req | ||
|
||
try { | ||
logic.getAllFollowingUserPosts(userId) | ||
.then(posts => res.json(posts)) | ||
.catch(error => next(error)) | ||
} catch (error) { | ||
next(error) | ||
} | ||
} |
8 changes: 4 additions & 4 deletions
8
staff/nerina-castillo/ponies/api/handlers/getAllPostsHandler.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 |
---|---|---|
@@ -1,13 +1,13 @@ | ||
import { logic } from '../../cor/index.js' | ||
|
||
export default (req, res) => { | ||
const { username } = req | ||
export default (req, res, next) => { | ||
const { userId } = req | ||
|
||
try { | ||
logic.getAllPosts(username) | ||
logic.getAllPosts(userId) | ||
.then(posts => res.json(posts)) | ||
.catch(error => next(error)) | ||
} catch (error) { | ||
nexct(error) | ||
next(error) | ||
} | ||
} |
6 changes: 3 additions & 3 deletions
6
staff/nerina-castillo/ponies/api/handlers/getUserNameHandler.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
4 changes: 2 additions & 2 deletions
4
staff/nerina-castillo/ponies/api/handlers/toggleFavPostHandler.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
6 changes: 3 additions & 3 deletions
6
staff/nerina-castillo/ponies/api/handlers/toggleFollowUserHandler.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
4 changes: 2 additions & 2 deletions
4
staff/nerina-castillo/ponies/api/handlers/toggleLikePostHandler.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
4 changes: 2 additions & 2 deletions
4
staff/nerina-castillo/ponies/api/handlers/updatePostCaptionHandler.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
curl -v -X POST http://localhost:8080/posts -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJqYW5mcnlUb3BlcmEiLCJpYXQiOjE3MjIzMzAzNzl9.psSpv8cj_SrZSNGn2alTkkJ8-Aq7FTTkCGDsl9VEI-I" -d '{"image": "https://media.giphy.com/media/Ty9Sg8oHghPWg/giphy.gif?cid=790b7611k1isspkgnlxqcvk07kqq26fe137qherkek4mavvf&ep=v1_gifs_trending&rid=giphy.gif&ct=g", "caption": "This is a caption"}' -H "Content-Type: application/json" | ||
curl -v -X POST http://localhost:8080/posts -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI2NmFjZDIyOWZiNGJiYzZjYjY1ODFiNTIiLCJpYXQiOjE3MjI2MDIwNTJ9.VkAHNtRaPniHxh4laXR50kGVxRlzzU3SylcgQerj8iQ" -d '{"image": "https://media.giphy.com/media/Ty9Sg8oHghPWg/giphy.gif?cid=790b7611k1isspkgnlxqcvk07kqq26fe137qherkek4mavvf&ep=v1_gifs_trending&rid=giphy.gif&ct=g", "caption": "This is a caption"}' -H "Content-Type: application/json" |
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 +1 @@ | ||
curl -v -X DELETE http://localhost:8080/posts/3bi1ryn98p00 -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJqYW5mcnlUb3BlcmEiLCJpYXQiOjE3MjIzMzAzNzl9.psSpv8cj_SrZSNGn2alTkkJ8-Aq7FTTkCGDsl9VEI-I" | ||
curl -v -X DELETE http://localhost:8080/posts/66acdecc4b37b603b718ebb6 -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI2NmFjZDIyOWZiNGJiYzZjYjY1ODFiNTIiLCJpYXQiOjE3MjI2MDIwNTJ9.VkAHNtRaPniHxh4laXR50kGVxRlzzU3SylcgQerj8iQ" |
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 +1 @@ | ||
curl -v http://localhost:8080/posts/favs -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJqYW5mcnlUb3BlcmEiLCJpYXQiOjE3MjIzMzAzNzl9.psSpv8cj_SrZSNGn2alTkkJ8-Aq7FTTkCGDsl9VEI-I" | ||
curl -v http://localhost:8080/posts/favs -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI2NmFjZDIyOWZiNGJiYzZjYjY1ODFiNTIiLCJpYXQiOjE3MjI2MDIwNTJ9.VkAHNtRaPniHxh4laXR50kGVxRlzzU3SylcgQerj8iQ" |
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 +1 @@ | ||
curl -v http://localhost:8080/posts/following -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJqYW5mcnlUb3BlcmEiLCJpYXQiOjE3MjIzMzAzNzl9.psSpv8cj_SrZSNGn2alTkkJ8-Aq7FTTkCGDsl9VEI-I" | ||
curl -v http://localhost:8080/posts/following -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI2NmFjZDIyOWZiNGJiYzZjYjY1ODFiNTIiLCJpYXQiOjE3MjI2MDIwNTJ9.VkAHNtRaPniHxh4laXR50kGVxRlzzU3SylcgQerj8iQ" |
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 +1 @@ | ||
curl -v http://localhost:8080/posts -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJqYW5mcnlUb3BlcmEiLCJpYXQiOjE3MjIzMzAzNzl9.psSpv8cj_SrZSNGn2alTkkJ8-Aq7FTTkCGDsl9VEI-I" | ||
curl -v http://localhost:8080/posts -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI2NmFjZDIyOWZiNGJiYzZjYjY1ODFiNTIiLCJpYXQiOjE3MjI2MDIwNTJ9.VkAHNtRaPniHxh4laXR50kGVxRlzzU3SylcgQerj8iQ" |
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 +1 @@ | ||
curl -v http://localhost:8080/users/janfryTopera/name -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJqYW5mcnlUb3BlcmEiLCJpYXQiOjE3MjIzMzAzNzl9.psSpv8cj_SrZSNGn2alTkkJ8-Aq7FTTkCGDsl9VEI-I" | ||
curl -v http://localhost:8080/users/66acc0c8863c3606c60ba912/name -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI2NmFjZDIyOWZiNGJiYzZjYjY1ODFiNTIiLCJpYXQiOjE3MjI2MDIwNTJ9.VkAHNtRaPniHxh4laXR50kGVxRlzzU3SylcgQerj8iQ" |
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 +1,3 @@ | ||
curl -v http://localhost:8080/users -X POST -d '{"name":"janfry","surname":"topera","email":"[email protected]","username":"janfryTopera","password":"janfry123","passwordRepeat":"janfry123"}' -H "Content-Type: application/json" | ||
|
||
# eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI2NmFjZDIyOWZiNGJiYzZjYjY1ODFiNTIiLCJpYXQiOjE3MjI2MDIwNTJ9.VkAHNtRaPniHxh4laXR50kGVxRlzzU3SylcgQerj8iQ |
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 +1 @@ | ||
curl -v http://localhost:8080/posts/66ab7e7385156518ecdcd558/favs -X PATCH -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJqYW5mcnlUb3BlcmEiLCJpYXQiOjE3MjIzMzAzNzl9.psSpv8cj_SrZSNGn2alTkkJ8-Aq7FTTkCGDsl9VEI-I" | ||
curl -v http://localhost:8080/posts/66acdf2c4b37b603b718ebb9/favs -X PATCH -H "Authorization: Bearer Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI2NmFjZDIyOWZiNGJiYzZjYjY1ODFiNTIiLCJpYXQiOjE3MjI2MDIwNTJ9.VkAHNtRaPniHxh4laXR50kGVxRlzzU3SylcgQerj8iQ" |
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 +1 @@ | ||
curl -v http://localhost:8080/users/janfryTopera/follows -X PATCH -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJqYW5mcnlUb3BlcmEiLCJpYXQiOjE3MjIzMzAzNzl9.psSpv8cj_SrZSNGn2alTkkJ8-Aq7FTTkCGDsl9VEI-I" | ||
curl -v http://localhost:8080/users/66adf6279f45573c51492c75/follows -X PATCH -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI2NmFkZjYyNzlmNDU1NzNjNTE0OTJjNzUiLCJpYXQiOjE3MjI2NzY5MDh9.WuRv_S4DJVszuQtqdijMaN4kj0L7fg_p6Gpp0_DrFwU" |
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 +1 @@ | ||
curl -v -X PATCH http://localhost:8080/posts/3fswobxum974/likes -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJqYW5mcnlUb3BlcmEiLCJpYXQiOjE3MjIzMzAzNzl9.psSpv8cj_SrZSNGn2alTkkJ8-Aq7FTTkCGDsl9VEI-I" | ||
curl -v -X PATCH http://localhost:8080/posts/66acd344fb4bbc6cb6581b57/likes -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI2NmFjZDIyOWZiNGJiYzZjYjY1ODFiNTIiLCJpYXQiOjE3MjI2MDIwNTJ9.VkAHNtRaPniHxh4laXR50kGVxRlzzU3SylcgQerj8iQ" |
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 +1 @@ | ||
curl -v http://localhost:8080/posts/lfhkbfbgers/caption -X PATCH -d '{"caption":"ta bien"}' -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJqYW5mcnlUb3BlcmEiLCJpYXQiOjE3MjIzMzAzNzl9.psSpv8cj_SrZSNGn2alTkkJ8-Aq7FTTkCGDsl9VEI-I" -H "Content-Type: application/json" | ||
curl -v http://localhost:8080/posts/66acd344fb4bbc6cb6581b57/caption -X PATCH -d '{"caption":"ta bien"}' -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI2NmFjZDIyOWZiNGJiYzZjYjY1ODFiNTIiLCJpYXQiOjE3MjI2MDIwNTJ9.VkAHNtRaPniHxh4laXR50kGVxRlzzU3SylcgQerj8iQ" -H "Content-Type: application/json" |
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,31 +1,32 @@ | ||
import { validate, errors } from 'com' | ||
|
||
export default (image, caption, callback) => { | ||
const { SystemError } = errors | ||
|
||
export default (image, caption) => { | ||
validate.url(image, 'image') | ||
validate.string(caption, 'caption') | ||
validate.callback(callback) | ||
|
||
const xhr = new XMLHttpRequest | ||
|
||
xhr.onload = () => { | ||
if (xhr.status === 201) { | ||
callback(null) | ||
|
||
return | ||
} | ||
|
||
const { error, message } = JSON.parse(xhr.response) | ||
|
||
const constructor = errors[error] | ||
|
||
callback(new constructor(message)) | ||
} | ||
|
||
xhr.onerror = () => callback(new Error('network error')) | ||
|
||
xhr.open('POST', `${import.meta.env.VITE_API_URL}/posts`) | ||
xhr.setRequestHeader('Authorization', `Bearer ${sessionStorage.token}`) | ||
xhr.setRequestHeader('Content-Type', 'application/json') | ||
|
||
xhr.send(JSON.stringify({ image, caption })) | ||
return fetch(`${import.meta.env.VITE_API_URL}/posts`, { | ||
method: 'POST', | ||
headers: { | ||
Authorization: `Bearer ${sessionStorage.token}`, | ||
'Content-Type': 'application/json' | ||
}, | ||
body: JSON.stringify({ image, caption }) | ||
}) | ||
.catch(error => { throw new SystemError(error.message) }) | ||
.then(response => { | ||
const { status } = response | ||
|
||
if (status === 201) return | ||
|
||
return response.json() | ||
.then(body => { | ||
const { error, message } = body | ||
|
||
const constructor = errors[error] | ||
|
||
throw new constructor(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,29 @@ | ||
import { validate, errors } from "com" | ||
|
||
export default (postId, callback) => { | ||
validate.string(postId, 'postId') | ||
validate.callback(callback) | ||
|
||
const xhr = new XMLHttpRequest | ||
const { SystemError } = errors | ||
|
||
xhr.onload = () => { | ||
if (xhr.status === 204) { | ||
callback(null) | ||
export default postId => { | ||
validate.string(postId, 'postId') | ||
|
||
return | ||
return fetch(`${import.meta.env.VITE_API_URL}/posts/${postId}`, { | ||
method: 'DELETE', | ||
headers: { | ||
Authorization: `Bearer ${sessionStorage.token}` | ||
} | ||
}) | ||
.catch(error => { throw new SystemError(error.message) }) | ||
.then(response => { | ||
const { status } = response | ||
|
||
const { error, message } = JSON.parse(xhr.response) | ||
|
||
const constructor = errors[error] | ||
|
||
callback(new constructor(message)) | ||
} | ||
if (status === 204) return | ||
|
||
xhr.onerror = () => callback(new Error('network error')) | ||
return response.json() | ||
.then(body => { | ||
const { error, message } = body | ||
|
||
xhr.open('DELETE', `${import.meta.env.VITE_API_URL}/posts/${postId}`) | ||
xhr.setRequestHeader('Authorization', `Bearer ${sessionStorage.token}`) | ||
const constructor = errors[error] | ||
|
||
xhr.send() | ||
throw new constructor(message) | ||
}) | ||
}) | ||
} |
Oops, something went wrong.