Skip to content

Commit

Permalink
change url of logic in app b00tc4mp#68
Browse files Browse the repository at this point in the history
  • Loading branch information
NerinaHctz committed Jul 27, 2024
1 parent e5cca42 commit cd273f0
Show file tree
Hide file tree
Showing 37 changed files with 381 additions and 706 deletions.
1 change: 1 addition & 0 deletions staff/nerina-castillo/ponies/app/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VITE_API_URL = http://localhost:8080
2 changes: 2 additions & 0 deletions staff/nerina-castillo/ponies/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
!.env
node_modules
14 changes: 0 additions & 14 deletions staff/nerina-castillo/ponies/app/data/deletePost.js

This file was deleted.

10 changes: 0 additions & 10 deletions staff/nerina-castillo/ponies/app/data/findPost.js

This file was deleted.

10 changes: 0 additions & 10 deletions staff/nerina-castillo/ponies/app/data/findPosts.js

This file was deleted.

10 changes: 0 additions & 10 deletions staff/nerina-castillo/ponies/app/data/findUser.js

This file was deleted.

23 changes: 0 additions & 23 deletions staff/nerina-castillo/ponies/app/data/index.js

This file was deleted.

9 changes: 0 additions & 9 deletions staff/nerina-castillo/ponies/app/data/insertAvatar.js

This file was deleted.

10 changes: 0 additions & 10 deletions staff/nerina-castillo/ponies/app/data/insertPost.js

This file was deleted.

10 changes: 0 additions & 10 deletions staff/nerina-castillo/ponies/app/data/insertUser.js

This file was deleted.

14 changes: 0 additions & 14 deletions staff/nerina-castillo/ponies/app/data/updatePost.js

This file was deleted.

14 changes: 0 additions & 14 deletions staff/nerina-castillo/ponies/app/data/updateUser.js

This file was deleted.

26 changes: 12 additions & 14 deletions staff/nerina-castillo/ponies/app/logic/createPost.js
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;
}
18 changes: 7 additions & 11 deletions staff/nerina-castillo/ponies/app/logic/deletePost.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import validate from "../../cor/validate.js"
import { validate } from "com"

const deletePost = (postId, callback) => {
validate.callback(callback)
validate.string(postId)
export default (postId, callback) => {
validate.string(postId, 'postId')
validate.callback(callback)


const xhr = new XMLHttpRequest
const xhr = new XMLHttpRequest

xhr.onload = () => {
if (xhr.status === 204) {
Expand All @@ -23,11 +22,8 @@ const deletePost = (postId, callback) => {

xhr.onerror = () => callback(new Error('network error'))

xhr.open('DELETE', `http://localhost:8080/posts/${postId}`)
xhr.open('DELETE', `${import.meta.env.VITE_API_URL}/posts/${postId}`)
xhr.setRequestHeader('Authorization', `Basic ${sessionStorage.username}`)

xhr.send()

};

export default deletePost;
}
14 changes: 8 additions & 6 deletions staff/nerina-castillo/ponies/app/logic/getAllFavPosts.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
const getAllFavPosts = callback => {
const xhr = new XMLHttpRequest
import { validate } from 'com'

export default callback => {
validate.callback(callback)

const xhr = new XMLHttpRequest

xhr.onload = () => {
if (xhr.status === 200) {
Expand All @@ -19,9 +23,7 @@ const getAllFavPosts = callback => {

xhr.onerror = () => callback(new Error('network error'))

xhr.open('GET', 'http://localhost:8080/posts/favs')
xhr.open('GET', `${import.meta.env.VITE_API_URL}/posts/favs`)
xhr.setRequestHeader('Authorization', `Basic ${sessionStorage.username}`)
xhr.send()
}

export default getAllFavPosts
}
11 changes: 0 additions & 11 deletions staff/nerina-castillo/ponies/app/logic/getAllFavPosts.test.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
const getAllFollowingUserPosts = callback => {
import { validate } from 'com'

export default callback => {
validate.callback(callback)

const xhr = new XMLHttpRequest

xhr.onload = () => {
Expand All @@ -17,10 +21,9 @@ const getAllFollowingUserPosts = callback => {
callback(new constructor(message))
}

xhr.onerror = () => callback(new Error('network error'))

xhr.open('GET', 'http://localhost:8080/posts/following')
xhr.open('GET', `${import.meta.env.VITE_API_URL}/posts/following`)
xhr.setRequestHeader('Authorization', `Basic ${sessionStorage.username}`)
xhr.send()
};

export default getAllFollowingUserPosts;
}
28 changes: 15 additions & 13 deletions staff/nerina-castillo/ponies/app/logic/getAllPosts.js
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
}
12 changes: 7 additions & 5 deletions staff/nerina-castillo/ponies/app/logic/getUserName.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
const getUserName = callback => {
import { validate } from 'com'

export default callback => {
validate.callback(callback)

const xhr = new XMLHttpRequest

xhr.onload = () => {
Expand All @@ -19,9 +23,7 @@ const getUserName = callback => {

xhr.onerror = () => callback(new Error('network error'))

xhr.open('GET', `http://localhost:8080/users/${sessionStorage.username}/name`)
xhr.open('GET', `${import.meta.env.VITE_API_URL}/users/${sessionStorage.username}/name`)
xhr.setRequestHeader('Authorization', `Basic ${sessionStorage.username}`)
xhr.send()
}

export default getUserName
}
22 changes: 9 additions & 13 deletions staff/nerina-castillo/ponies/app/logic/loginUser.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import validate from "../../cor/validate.js"
import { validate } from 'com'

const loginUser = (username, password, callback) => {
validate.username(username)
validate.password(password)

const xhr = new XMLHttpRequest
export default (username, password, callback) => {
validate.username(username)
validate.password(password)
validate.callback(callback)

const xhr = new XMLHttpRequest

xhr.onload = () => {
if (xhr.status === 200) {
Expand All @@ -25,12 +25,8 @@ const loginUser = (username, password, callback) => {

xhr.onerror = () => callback(new Error('network error'))

xhr.open('POST', 'http://localhost:8080/users/auth')
xhr.open('POST', `${import.meta.env.VITE_API_URL}/users/auth`)
xhr.setRequestHeader('Content-Type', 'application/json')

xhr.send(JSON.stringify({ username, password }))
}


export default loginUser;

}
Loading

0 comments on commit cd273f0

Please sign in to comment.