Skip to content

Commit

Permalink
add folder com to unsocial b00tc4mp#177
Browse files Browse the repository at this point in the history
  • Loading branch information
juanpabloarias1 committed Nov 5, 2024
1 parent c72f36f commit a96f7af
Show file tree
Hide file tree
Showing 32 changed files with 99 additions and 99 deletions.
7 changes: 4 additions & 3 deletions staff/juanp-arias/unsocial/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,12 @@ server.post('/register', jsonBodyParser, (req, res) => {
}
})

server.get('/users/:userId/name', (req, res) => {
const { userId } = req.params
server.get('/users/:targetUserId/name', (req, res) => {
const userId = req.headers.authorization.slice(6)
const { targetUserId } = req.params

try {
const name = logic.getUserName(userId)
const name = logic.getUserName(userId, targetUserId)

res.json(name)
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion staff/juanp-arias/unsocial/api/logic/addComments.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { storage, uuid } from '../data/index.js'
import validate from './helpers/validate.js'
import { validate } from 'com'


export default (userId, postId, text) => {
Expand Down
2 changes: 1 addition & 1 deletion staff/juanp-arias/unsocial/api/logic/authenticateUser.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { storage } from '../data/index.js'
import validate from './helpers/validate.js'
import { validate } from 'com'

export default (username, password) => {
validate.username(username)
Expand Down
2 changes: 1 addition & 1 deletion staff/juanp-arias/unsocial/api/logic/createPost.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import validate from './helpers/validate.js'
import { validate } from 'com'

import { storage, uuid } from '../data/index.js'

Expand Down
2 changes: 1 addition & 1 deletion staff/juanp-arias/unsocial/api/logic/deletePost.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { storage } from '../data/index.js'
import validate from './helpers/validate.js'
import { validate } from 'com'

export default (userId, postId) => {
validate.id(userId, 'userId')
Expand Down
2 changes: 1 addition & 1 deletion staff/juanp-arias/unsocial/api/logic/getComments.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import validate from './helpers/validate.js'
import { validate } from 'com'
import { storage } from '../data/index.js'

export default (userId, postId) => {
Expand Down
2 changes: 1 addition & 1 deletion staff/juanp-arias/unsocial/api/logic/getPosts.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { storage } from '../data/index.js'
import validate from './helpers/validate.js'
import { validate } from 'com'

export default userId => {
validate.id(userId, 'userId')
Expand Down
2 changes: 1 addition & 1 deletion staff/juanp-arias/unsocial/api/logic/getUserId.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { storage } from '../data/index.js'
import validate from './helpers/validate.js'
import { validate } from 'com'

export default userId => {
validate.id(userId, 'userId')
Expand Down
11 changes: 7 additions & 4 deletions staff/juanp-arias/unsocial/api/logic/getUserName.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { storage } from '../data/index.js'
import validate from './helpers/validate.js'
import { validate } from 'com'

export default userId => {
export default (userId, targetUserId) => {
validate.id(userId, 'userId')
validate.id(targetUserId, 'targetUserId')

const { users } = storage

const user = users.find(user => user.id === userId)
const found = users.some(({ id }) => id === userId)
if (!found) throw new Error('user not found')

if (!user) throw new Error('user not found')
const user = users.find(({ id }) => id === targetUserId)
if (!user) throw new Error('target user not found')

return user.name
}
3 changes: 1 addition & 2 deletions staff/juanp-arias/unsocial/api/logic/registerUser.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { storage, uuid } from '../data/index.js'

import validate from './helpers/validate.js'
import { validate } from 'com'

export default (name, email, username, password, passwordRepeat) => {
validate.name(name)
Expand Down
2 changes: 1 addition & 1 deletion staff/juanp-arias/unsocial/api/logic/removeComment.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import validate from './helpers/validate.js'
import { validate } from 'com'
import { storage } from '../data/index.js'

export default (userId, postId, commentId) => {
Expand Down
2 changes: 1 addition & 1 deletion staff/juanp-arias/unsocial/api/logic/toggleLikePosts.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import validate from './helpers/validate.js'
import { validate } from 'com'
import { storage } from '../data/index.js'

export default (userId, postId) => {
Expand Down
13 changes: 11 additions & 2 deletions staff/juanp-arias/unsocial/api/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion staff/juanp-arias/unsocial/api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "api",
"version": "1.0.0",
"version": "0.0.0",
"main": "index.js",
"type": "module",
"scripts": {
Expand All @@ -13,6 +13,7 @@
"license": "ISC",
"description": "",
"dependencies": {
"com": "file:../com",
"cors": "^2.8.5",
"express": "^4.21.1"
}
Expand Down
1 change: 1 addition & 0 deletions staff/juanp-arias/unsocial/api/test/get-user-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ xhr.addEventListener('load', () => {
})

xhr.open('GET', 'http://localhost:7070/users/m2x63gb7wns/name')
xhr.setRequestHeader('Authorization', 'Basic m2x63gb7wns')
xhr.send()
2 changes: 1 addition & 1 deletion staff/juanp-arias/unsocial/api/test/get-user-name.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
curl http://localhost:7070/users/m2x63gb7wns/name -v
curl -H 'Authorization: Basic m2x63gb7wns' http://localhost:7070/users/m2x63gb7wns/name -v
9 changes: 9 additions & 0 deletions staff/juanp-arias/unsocial/app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion staff/juanp-arias/unsocial/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"preview": "vite preview"
},
"dependencies": {
"com": "file:../com",
"react": "^18.3.1",
"react-dom": "^18.3.1"
},
Expand All @@ -26,4 +27,4 @@
"globals": "^15.9.0",
"vite": "^5.4.8"
}
}
}
35 changes: 28 additions & 7 deletions staff/juanp-arias/unsocial/app/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,43 @@ export default class extends Component {
this.state = { view: logic.isUserLoggedIn() ? 'home' : 'login' }
}

handlePostCreated = () => this.setState({ view: 'home' })

handleUserLoggedOut = () => this.setState({ view: 'login' })

handleUserLoggedIn = () => this.setState({ view: 'home' })

handleRegisterClick = () => this.setState({ view: 'register' })

handleLoginClick = () => this.setState({ view: 'login' })

handleUserRegistered = () => this.setState({ view: 'login' })

handleNewPostClick = () => this.setState({ view: 'new-post' })

handleHomeClick = () => this.setState({ view: 'home' })

render() {
return <div>

<Header view={this.state.view} onHomeClick={() => this.setState({ view: 'home' })} onLoggedOut={() => this.setState({ view: 'login' })} />
<Header view={this.state.view}
onHomeClick={this.handleHomeClick}
onLoggedOut={this.handleUserLoggedOut} />

{this.state.view === 'login' && <Login
onLoggedIn={() => this.setState({ view: 'home' })}
onRegisterClick={() => this.setState({ view: 'register' })}
onLoggedIn={this.handleUserLoggedIn}
onRegisterClick={this.handleRegisterClick}
/>}
{this.state.view === 'register' && <Register
onLoginClick={() => this.setState({ view: 'login' })}
onRegistered={() => this.setState({ view: 'login' })}
onLoginClick={this.handleLoginClick}
onRegistered={this.handleUserRegistered}
/>}
{this.state.view === 'home' && <Home />}

{this.state.view === 'new-post' && <CreatePost onCreated={() => this.setState({ view: 'home' })} />}
<Footer onNewPostClick={() => this.setState({ view: 'new-post' })} view={this.state.view} />
{this.state.view === 'new-post' && <CreatePost onCreated={this.handlePostCreated} />}

<Footer
onNewPostClick={this.handleNewPostClick} view={this.state.view} />
</div>
}
}
Expand Down
2 changes: 1 addition & 1 deletion staff/juanp-arias/unsocial/app/src/logic/addComments.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { validate } from './helpers'
import { validate } from 'com'
import uuid from '../data/uuid'

export default (postId, text) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import validate from './helpers/validate'
import { validate } from 'com'
import uuid from '../data/uuid'

export default (image, text) => {
Expand Down
3 changes: 3 additions & 0 deletions staff/juanp-arias/unsocial/app/src/logic/deletePost.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { validate } from 'com'

export default postId => {
validate.id(postId, 'postId')
const posts = JSON.parse(localStorage.posts)

const index = posts.findIndex(({ id }) => id === postId)
Expand Down
2 changes: 1 addition & 1 deletion staff/juanp-arias/unsocial/app/src/logic/getComments.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { validate } from './helpers'
import { validate } from 'com'

export default postId => {
validate.id(postId, 'PostID')
Expand Down
5 changes: 0 additions & 5 deletions staff/juanp-arias/unsocial/app/src/logic/helpers/index.js

This file was deleted.

56 changes: 0 additions & 56 deletions staff/juanp-arias/unsocial/app/src/logic/helpers/validate.js

This file was deleted.

2 changes: 1 addition & 1 deletion staff/juanp-arias/unsocial/app/src/logic/loginUser.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { validate } from './helpers'
import { validate } from 'com'

export default (username, password) => {
validate.username(username)
Expand Down
2 changes: 1 addition & 1 deletion staff/juanp-arias/unsocial/app/src/logic/registerUser.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { validate } from './helpers'
import { validate } from 'com'

export default (name, email, username, password, repeatpassword, callback) => {
validate.name(name)
Expand Down
2 changes: 1 addition & 1 deletion staff/juanp-arias/unsocial/app/src/logic/removeComment.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { validate } from './helpers'
import { validate } from 'com'

export default (postId, commentId) => {
validate.id(postId, 'Post ID')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import validate from './helpers/validate'
import { validate } from 'com'

export default (postId) => {
validate.id(postId, 'PostID')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import validate from './validate.js'

export default {
export {
validate
}
Loading

0 comments on commit a96f7af

Please sign in to comment.