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.
change url of logic in app b00tc4mp#68
- Loading branch information
1 parent
e5cca42
commit cd273f0
Showing
37 changed files
with
381 additions
and
706 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
VITE_API_URL = http://localhost:8080 |
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,2 @@ | ||
!.env | ||
node_modules |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,33 +1,31 @@ | ||
import validate from "../../cor/validate.js" | ||
import { validate } from 'com' | ||
|
||
const createPost = (image, caption, callback) => { | ||
export default (image, caption, callback) => { | ||
validate.image(image, 'image') | ||
validate.string(caption, 'caption') | ||
validate.callback(callback) | ||
|
||
const xhr = new XMLHttpRequest | ||
|
||
xhr.onload = () => { | ||
if (xhr.status === 201) { | ||
callback(null) | ||
if (xhr.status === 201) { | ||
callback(null) | ||
|
||
return | ||
} | ||
return | ||
} | ||
|
||
const { error, message } = JSON.parse(xhr.response) | ||
const { error, message } = JSON.parse(xhr.response) | ||
|
||
const constructor = window[error] | ||
const constructor = window[error] | ||
|
||
callback(new constructor(message)) | ||
callback(new constructor(message)) | ||
} | ||
|
||
xhr.onerror = () => callback(new Error('network error')) | ||
|
||
xhr.open('POST', 'http://localhost:8080/posts') | ||
xhr.open('POST', `${import.meta.env.VITE_API_URL}/posts`) | ||
xhr.setRequestHeader('Authorization', `Basic ${sessionStorage.username}`) | ||
xhr.setRequestHeader('Content-Type', 'application/json') | ||
|
||
xhr.send(JSON.stringify({ image, caption })) | ||
|
||
}; | ||
|
||
export default createPost; | ||
} |
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
11 changes: 0 additions & 11 deletions
11
staff/nerina-castillo/ponies/app/logic/getAllFavPosts.test.js
This file was deleted.
Oops, something went wrong.
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,27 +1,29 @@ | ||
const getAllPosts = callback => { | ||
import { validate } from 'com' | ||
|
||
export default callback => { | ||
validate.callback(callback) | ||
|
||
const xhr = new XMLHttpRequest | ||
|
||
xhr.onload = () => { | ||
if (xhr.status === 200) { | ||
const posts = JSON.parse(xhr.response) | ||
if (xhr.status === 200) { | ||
const posts = JSON.parse(xhr.response) | ||
|
||
callback(null, posts) | ||
callback(null, posts) | ||
|
||
return | ||
} | ||
return | ||
} | ||
|
||
const { error, message } = JSON.parse(xhr.response) | ||
const { error, message } = JSON.parse(xhr.response) | ||
|
||
const constructor = window[error] | ||
const constructor = window[error] | ||
|
||
callback(new constructor(message)) | ||
callback(new constructor(message)) | ||
} | ||
|
||
xhr.onerror = () => callback(new Error('network error')) | ||
|
||
xhr.open('GET', 'http://localhost:8080/posts') | ||
xhr.open('GET', `${import.meta.env.VITE_API_URL}/posts`) | ||
xhr.setRequestHeader('Authorization', `Basic ${sessionStorage.username}`) | ||
xhr.send() | ||
} | ||
|
||
export default getAllPosts | ||
} |
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
Oops, something went wrong.