forked from b00tc4mp/isdi-bootcamp-202409
-
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.
added more logic from app adapted to api and logic tests b00tc4mp#173
- Loading branch information
Showing
12 changed files
with
175 additions
and
14 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
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import createPost from './createPost.js'; | ||
|
||
try { | ||
console.log(createPost("m2x5v0tqblo", "https://letsenhance.io/static/8f5e523ee6b2479e26ecc91b9c25261e/1015f/MainAfter.jpg", "This is a new post!")) | ||
|
||
} catch (error) { | ||
console.error(error); | ||
} |
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,23 @@ | ||
import { validate } from './helpers/index.js' | ||
import { storage } from '../data/index.js' | ||
|
||
|
||
export default (postId, userId) => { | ||
validate.id(postId, 'postId') | ||
validate.id(userId, 'userId') | ||
|
||
const { posts } = storage | ||
const index = posts.findIndex(({ id }) => id === postId) | ||
|
||
if (index < 0) throw new Error('post not fouind') | ||
|
||
const post = posts[index] | ||
|
||
const { author } = post | ||
|
||
if (author !== userId) throw new Error('user is not author of post') | ||
|
||
posts.splice(index, 1) | ||
|
||
storage.posts = posts | ||
} |
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,8 @@ | ||
import deletePost from './deletePost.js'; | ||
|
||
try { | ||
console.log(deletePost("m2xhyzvb5gi", "m2x5opwqqap")) | ||
|
||
} catch (error) { | ||
console.error(error) | ||
} |
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,24 @@ | ||
import { validate } from './helpers/index.js' | ||
import { storage } from '../data/index.js' | ||
|
||
export default postId => { | ||
validate.id(postId, 'postId') | ||
|
||
const { posts, users } = storage | ||
|
||
const post = posts.find(({ id }) => id === postId) | ||
|
||
if (!post) throw new Error('post not found') | ||
|
||
const { comments } = post | ||
|
||
comments.forEach(comment => { | ||
const { author: authorId } = comment | ||
|
||
const { username } = users.find(({ id }) => id === authorId) | ||
|
||
comment.author = { id: authorId, username } | ||
}); | ||
|
||
return comments | ||
} |
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,19 @@ | ||
import { storage } from '../data/index.js' | ||
|
||
export default userId => { | ||
const { posts, users } = storage | ||
|
||
posts.forEach(post => { | ||
const { author: authorId } = post | ||
|
||
const { username } = users.find(({ id }) => id === authorId) | ||
|
||
post.author = { id: authorId, username } | ||
|
||
post.liked = post.likedBy.includes(userId) | ||
|
||
post.comments = post.comments.length | ||
}); | ||
|
||
return posts.toReversed() | ||
} |
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 -H 'Authorization: Basic m2x5tcx927f' -H 'Content-Type: application/json' -d '{"text":"yo que se"}' http://localhost:8080/posts/m2x69ey2d79/comments -v | ||
curl -H 'Authorization: Basic m2x5tcx927f' -H 'Content-Type: application/json' -d '{"text":"esto funciona?"}' http://localhost:8080/posts/m2x69ey2d79/comments -v |
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 @@ | ||
curl -H 'Authorization: Basic m2x5v0tqblo' -X DELETE http://localhost:8080/posts/m322enfihy -v |
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,10 @@ | ||
const xhr = new XMLHttpRequest | ||
|
||
xhr.addEventListener('load', () => { | ||
console.log(xhr.status, xhr.response) | ||
}) | ||
|
||
xhr.open('DELETE', 'http://localhost:8080/posts/m2x69ey2d79/comments/m320io97u3') | ||
xhr.setRequestHeader('Authorization', 'Basic m2x5tcx927f') | ||
xhr.setRequestHeader('Content-Type', 'application/json') | ||
xhr.send() |
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 @@ | ||
curl -H 'Authorization: Basic m2x5opwqqap' -X DELETE http://localhost:8080/posts/m2x69ey2d79/comments/m2xeoohf3v -v |