Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/ponies #59

Open
wants to merge 103 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
103 commits
Select commit Hold shift + click to select a range
0e832fb
add my folder #1
manuelbarzi May 28, 2024
35b24e2
add ponies base code #58
manuelbarzi Jun 10, 2024
cce1f7a
implement register page #58
manuelbarzi Jun 11, 2024
f29bf8b
use local and session storages for users persistence and username in …
manuelbarzi Jun 11, 2024
e51afa6
separate concerns in app (presentation vs logic) #58
manuelbarzi Jun 12, 2024
c7055d9
implement logout; add create post base code; #58
manuelbarzi Jun 13, 2024
5e05835
implement create post section and logic; implement list posts and log…
manuelbarzi Jun 14, 2024
6b733af
adjust get user username logic name; #58
manuelbarzi Jun 14, 2024
4f12fb5
add ids generator for posts; implement delete post logic; #58
manuelbarzi Jun 17, 2024
a018cb0
add edit post caption functionality #58
manuelbarzi Jun 18, 2024
22d96e3
add layout styles to ponies; #58
manuelbarzi Jun 18, 2024
b7e3f3f
adjust layout and styles in header, footer and create-post-section; #58
manuelbarzi Jun 19, 2024
5325627
create initial abstractions of components in ponies #58
manuelbarzi Jun 21, 2024
f100196
add button compo; remove iffes and use scoped blocks; add doc with cl…
manuelbarzi Jun 25, 2024
50698dd
componetize post-list, post, heading, image; use other existing compo…
manuelbarzi Jun 25, 2024
75c77e6
componetize post; add input and label compos; update button compo; #58
manuelbarzi Jun 26, 2024
3116413
componetize footer; add context "logic" to logics; separate logics in…
manuelbarzi Jun 26, 2024
a106b21
add missing arrow function in footer; #58
manuelbarzi Jun 26, 2024
9098217
separate find user and insert user data layer functions to their own …
manuelbarzi Jun 27, 2024
3e19e75
implement toggle like post functionality; move all code to ecmascript…
manuelbarzi Jun 27, 2024
bf631b7
add toggle fav post functionality (button); fix edit post caption rep…
manuelbarzi Jun 28, 2024
5d1114b
add fav post functionality; add follow pony buttons; #58
manuelbarzi Jun 28, 2024
d6f7cc5
add following / unfollowing functionality; improve styles to minimali…
manuelbarzi Jul 1, 2024
dbbc180
use this in arrow functions (remove self var) #58
manuelbarzi Jul 2, 2024
8921b14
move ponies to react (first steps) with babel compiler #58
manuelbarzi Jul 2, 2024
86b8480
implement register and initial compos of home in react; #58
manuelbarzi Jul 3, 2024
7a53662
implement initial code of footer (make create form show and hide with…
manuelbarzi Jul 4, 2024
02e4bd2
implement create post, delete post, edit post caption, and refresh of…
manuelbarzi Jul 4, 2024
f2869c2
correct console debug for handle edit post submit in post compo; #58
manuelbarzi Jul 5, 2024
21206e3
correct html for and class names in post compo; #58
manuelbarzi Jul 5, 2024
9371907
implement fav post toggle, like post toggle, and follow user toggle; #58
manuelbarzi Jul 5, 2024
7a7c028
implement favs and ponies lists functionalities #58
manuelbarzi Jul 5, 2024
6e6b3d0
add Button styles in atomic components folder #58
manuelbarzi Jul 5, 2024
d195e20
create atomic and molecular components from existing jsx; #58
manuelbarzi Jul 8, 2024
664303d
use core components in login, register, and create post; #58
manuelbarzi Jul 9, 2024
79b7179
refactor app merging all views management into app main component; ma…
manuelbarzi Jul 9, 2024
d5a6538
add avatar component for post author; #58
manuelbarzi Jul 9, 2024
814be46
move app to vite bundler #58
manuelbarzi Jul 10, 2024
690a790
manage user session in app (keep home when user logged in); update fi…
manuelbarzi Jul 11, 2024
14ed973
add api base for ponies #58
manuelbarzi Jul 11, 2024
fc67bf5
implement data and logic in api; add input validation; add base code …
manuelbarzi Jul 12, 2024
3e674f9
move logic and data to core package (cor); install cor in web; use co…
manuelbarzi Jul 16, 2024
5cdb4a4
implement register in web #58
manuelbarzi Jul 17, 2024
cd6711c
implement register user api endpoint and its test sh #58
manuelbarzi Jul 17, 2024
4440576
implement all api route handlers #58
manuelbarzi Jul 18, 2024
9c87e49
update get user name #58
manuelbarzi Jul 18, 2024
1530a86
add cors support for api route /posts; update get-all-posts app logic…
manuelbarzi Jul 18, 2024
8ee7286
connect register-user login-user and get-user-name with api; add cors…
manuelbarzi Jul 19, 2024
7ff5fe8
use api in logics create-post, delete-post, toggle-like-post, toggle-…
manuelbarzi Jul 19, 2024
d90229f
make more api and cor asynchronous #58
manuelbarzi Jul 19, 2024
60712c2
move all api to asynchronous with callback #58
manuelbarzi Jul 22, 2024
fe8df40
add chats.json initial demo #58
manuelbarzi Jul 22, 2024
2535633
move app and home to function components #58
manuelbarzi Jul 23, 2024
efebd85
move all components to hooks #58
manuelbarzi Jul 23, 2024
8677dba
add mongodb in ponies api; create demo with mongodb; #58
manuelbarzi Jul 23, 2024
c62b876
move all cor to mongodb; connect mongodb in api server; #58
manuelbarzi Jul 24, 2024
87b95a0
add env vars in api, cor, and app; refactor logics (simplify exports)…
manuelbarzi Jul 25, 2024
6a79cc5
add com package and move validate inside; import com in cor and app a…
manuelbarzi Jul 25, 2024
089ad51
add doc #58
manuelbarzi Jul 25, 2024
529f06a
migrate to mongoose in cor and api #58
manuelbarzi Jul 25, 2024
1892159
move all remaining logic to mongoose #58
manuelbarzi Jul 26, 2024
05cd593
implement first logic tests #58
manuelbarzi Jul 26, 2024
de9c132
add custom errors for validations and logic #58
manuelbarzi Jul 29, 2024
e4118db
add custom errors in logic and manage them in api #58
manuelbarzi Jul 29, 2024
18079f0
update app to manage custom errors too in logic #58
manuelbarzi Jul 29, 2024
544e737
add json web token security protection in api #58
manuelbarzi Jul 30, 2024
e88993d
move app session to json web token #58
manuelbarzi Jul 30, 2024
7ad4f81
update get-user-username logic with username extraction from token #58
manuelbarzi Jul 30, 2024
c7d86e9
add missing import of errors in delete-post logic in app #58
manuelbarzi Jul 30, 2024
d0d2b6d
add password hashing #58
manuelbarzi Jul 30, 2024
c7edfbc
add json-body-parser middleware; move middlewares and handlers to fil…
manuelbarzi Jul 31, 2024
f8cbb56
move create error-handler middleware and apply it in all route handle…
manuelbarzi Jul 31, 2024
20fc0fb
move autenticate-user, register-user and toggle-like-post logics to p…
manuelbarzi Aug 1, 2024
dd0cf78
update api route handlers with promises in logic calls #58
manuelbarzi Aug 1, 2024
48c9fc6
move create-post to promises in app #58
manuelbarzi Aug 2, 2024
81433d1
use promises in get-all-posts logic in app #58
manuelbarzi Aug 2, 2024
8c70ef6
move toggle-like-post logic to promises #58
manuelbarzi Aug 2, 2024
3489387
move delete-post logic to promises #58
manuelbarzi Aug 2, 2024
b4eb106
staff/manuel-barzi/ponies/
manuelbarzi Aug 2, 2024
d7a30e1
use promises in toggle-follow-user #58
manuelbarzi Aug 2, 2024
73287ba
move get-all-fav-posts and get-all-ponies-posts logics to promises #58
manuelbarzi Aug 2, 2024
c85291f
move login-user, register-user, toggle-fav-post, toggle-follow-user, …
manuelbarzi Aug 2, 2024
73668be
add system-error import in update-post-caption #58
manuelbarzi Aug 2, 2024
5e58997
change authenticate-user and create-post logics in api to use user-id…
manuelbarzi Aug 2, 2024
b3c8ab6
use user-id instead of username in create-post and delete-post logics…
manuelbarzi Aug 2, 2024
93436ce
use user-id in get-all-*-posts logics and handlers #58
manuelbarzi Aug 2, 2024
924892c
use user-id instead of username in get-user-name logic and handler #58
manuelbarzi Aug 2, 2024
31a1ecc
use user-id instead username in toggle-fav-post logic and handler #58
manuelbarzi Aug 2, 2024
90113f9
add previous version of api #58
manuelbarzi Aug 2, 2024
d4b09ea
use user-id instead of username in toggle-follow-user logic and handl…
manuelbarzi Aug 2, 2024
5fa0d78
use user-id instead of username in api and app #58
manuelbarzi Aug 2, 2024
bfbb033
add react-router-dom to app for providing semantic and user-friendly …
manuelbarzi Aug 5, 2024
e98af04
add sub-routes for home views: posts-list, ponies-posts-list and favs…
manuelbarzi Aug 5, 2024
89509d0
add hello and search-results demos #58
manuelbarzi Aug 5, 2024
83fb41b
add search-posts logic and route handler in cor and api, respectively…
manuelbarzi Aug 5, 2024
b1048bb
add search posts functionality in app #58
manuelbarzi Aug 6, 2024
8e3c106
adjust compos behavior for search and results #58
manuelbarzi Aug 6, 2024
8233fa2
add tailwindcss to app #58
manuelbarzi Aug 6, 2024
b5ab0ff
move more components styles to tailwind #58
manuelbarzi Aug 7, 2024
f926d07
move remaining components to tailwind #58
manuelbarzi Aug 7, 2024
e218827
customize font families in tailwind and use them in app #58
manuelbarzi Aug 7, 2024
c09978c
add dark mode, alert, confirm components #58
manuelbarzi Aug 8, 2024
910a65b
add code coverage with c8 tool in cor package (for logic) #58
manuelbarzi Aug 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Empty file added staff/manuel-barzi/.gitkeep
Empty file.
Binary file added staff/manuel-barzi/ponies/.DS_Store
Binary file not shown.
Binary file added staff/manuel-barzi/ponies/app/.DS_Store
Binary file not shown.
13 changes: 13 additions & 0 deletions staff/manuel-barzi/ponies/app/data/deletePost.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function deletePost(condition) {
const posts = localStorage.posts !== undefined ? JSON.parse(localStorage.posts) : []

const postIndex = posts.findIndex(condition)

if (postIndex > -1) {
posts.splice(postIndex, 1)

localStorage.posts = JSON.stringify(posts)
}
}

export default deletePost
9 changes: 9 additions & 0 deletions staff/manuel-barzi/ponies/app/data/findPost.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
function findPost(condition) {
const posts = localStorage.posts !== undefined ? JSON.parse(localStorage.posts) : []

const post = posts.find(condition)

return post || null
}

export default findPost
9 changes: 9 additions & 0 deletions staff/manuel-barzi/ponies/app/data/findPosts.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
function findPosts(condition) {
const posts = localStorage.posts !== undefined ? JSON.parse(localStorage.posts) : []

const foundPosts = posts.filter(condition)

return foundPosts
}

export default findPosts
9 changes: 9 additions & 0 deletions staff/manuel-barzi/ponies/app/data/findUser.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
function findUser(condition) {
const users = localStorage.users !== undefined ? JSON.parse(localStorage.users) : []

const user = users.find(condition)

return user || null
}

export default findUser
21 changes: 21 additions & 0 deletions staff/manuel-barzi/ponies/app/data/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import deletePost from './deletePost.mjs'
import findPost from './findPost.mjs'
import findPosts from './findPosts.mjs'
import findUser from './findUser.mjs'
import insertPost from './insertPost.mjs'
import insertUser from './insertUser.mjs'
import updatePost from './updatePost.mjs'
import updateUser from './updateUser.mjs'

const data = {
deletePost,
findPost,
findPosts,
findUser,
insertPost,
insertUser,
updatePost,
updateUser
}

export default data
9 changes: 9 additions & 0 deletions staff/manuel-barzi/ponies/app/data/insertPost.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
function insertPost(post) {
const posts = localStorage.posts !== undefined ? JSON.parse(localStorage.posts) : []

posts.push(post)

localStorage.posts = JSON.stringify(posts)
}

export default insertPost
9 changes: 9 additions & 0 deletions staff/manuel-barzi/ponies/app/data/insertUser.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
function insertUser(user) {
const users = localStorage.users !== undefined ? JSON.parse(localStorage.users) : []

users.push(user)

localStorage.users = JSON.stringify(users)
}

export default insertUser
13 changes: 13 additions & 0 deletions staff/manuel-barzi/ponies/app/data/updatePost.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function updatePost(condition, post) {
const posts = localStorage.posts !== undefined ? JSON.parse(localStorage.posts) : []

const index = posts.findIndex(condition)

if (index > -1) {
posts.splice(index, 1, post)

localStorage.posts = JSON.stringify(posts)
}
}

export default updatePost
13 changes: 13 additions & 0 deletions staff/manuel-barzi/ponies/app/data/updateUser.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function updateUser(condition, user) {
const users = localStorage.users !== undefined ? JSON.parse(localStorage.users) : []

const index = users.findIndex(condition)

if (index > -1) {
users.splice(index, 1, user)

localStorage.users = JSON.stringify(users)
}
}

export default updateUser
21 changes: 21 additions & 0 deletions staff/manuel-barzi/ponies/app/logic/createPost.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import data from '../data/index.mjs'

import generateId from '../util/generateId.mjs'

const createPost = (image, caption) => {
if (!image.startsWith('http'))
throw new Error('invalid image')

const post = {
id: generateId(),
image: image,
caption: caption,
author: sessionStorage.username,
date: new Date().toISOString(),
likes: []
}

data.insertPost(post)
}

export default createPost
13 changes: 13 additions & 0 deletions staff/manuel-barzi/ponies/app/logic/deletePost.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import data from '../data/index.mjs'

const deletePost = postId => {
if (postId.trim().length === 0) throw new Error('invalid postId')

const post = data.findPost(post => post.id === postId)

if (post === null) throw new Error('post not found')

data.deletePost(post => post.id === postId)
}

export default deletePost
23 changes: 23 additions & 0 deletions staff/manuel-barzi/ponies/app/logic/getAllFavPosts.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import data from '../data/index.mjs'

const getAllFavPosts = () => {
const user = data.findUser(user => user.username === sessionStorage.username)

if (user === null)
throw new Error('user not found')

const posts = data.findPosts(post => user.favs.includes(post.id))

posts.forEach(post => {
post.fav = user.favs.includes(post.id)
post.like = post.likes.includes(sessionStorage.username)
post.author = {
username: post.author,
following: user.following.includes(post.author)
}
})

return posts.reverse()
}

export default getAllFavPosts
11 changes: 11 additions & 0 deletions staff/manuel-barzi/ponies/app/logic/getAllFavPosts.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import getAllFavPosts from './getAllFavPosts.mjs'

console.info('TEST getAllFavPosts')

console.info('CASE get all fav posts from mamoracho')

sessionStorage.username = 'mamoracho'

const favs = getAllFavPosts()

console.log(favs)
23 changes: 23 additions & 0 deletions staff/manuel-barzi/ponies/app/logic/getAllFollowingUserPosts.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import data from '../data/index.mjs'

const getAllFollowingUserPosts = () => {
const user = data.findUser(user => user.username === sessionStorage.username)

if (user === null)
throw new Error('user not found')

const posts = data.findPosts(post => user.following.includes(post.author))

posts.forEach(post => {
post.fav = user.favs.includes(post.id)
post.like = post.likes.includes(sessionStorage.username)
post.author = {
username: post.author,
following: user.following.includes(post.author)
}
})

return posts.reverse()
}

export default getAllFollowingUserPosts
23 changes: 23 additions & 0 deletions staff/manuel-barzi/ponies/app/logic/getAllPosts.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import data from '../data/index.mjs'

const getAllPosts = () => {
const user = data.findUser(user => user.username === sessionStorage.username)

if (user === null)
throw new Error('user not found')

const posts = data.findPosts(() => true)

posts.forEach(post => {
post.fav = user.favs.includes(post.id)
post.like = post.likes.includes(sessionStorage.username)
post.author = {
username: post.author,
following: user.following.includes(post.author)
}
})

return posts.reverse()
}

export default getAllPosts
12 changes: 12 additions & 0 deletions staff/manuel-barzi/ponies/app/logic/getUserName.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import data from '../data/index.mjs'

const getUserName = () => {
const user = data.findUser(user => user.username === sessionStorage.username)

if (user === null)
throw new Error('user not found')

return user.name
}

export default getUserName
3 changes: 3 additions & 0 deletions staff/manuel-barzi/ponies/app/logic/getUserUsername.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const getUserUsername = () => sessionStorage.username

export default getUserUsername
33 changes: 33 additions & 0 deletions staff/manuel-barzi/ponies/app/logic/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import getAllPosts from './getAllPosts.mjs'
import getUserName from './getUserName.mjs'
import getUserUsername from './getUserUsername.mjs'
import loginUser from './loginUser.mjs'
import logoutUser from './logoutUser.mjs'
import registerUser from './registerUser.mjs'
import toggleLikePost from './toggleLikePost.mjs'
import updatePostCaption from './updatePostCaption.mjs'
import createPost from './createPost.mjs'
import deletePost from './deletePost.mjs'
import toggleFavPost from './toggleFavPost.mjs'
import getAllFavPosts from './getAllFavPosts.mjs'
import toggleFollowUser from './toggleFollowUser.mjs'
import getAllFollowingUserPosts from './getAllFollowingUserPosts.mjs'

const logic = {
getAllPosts,
getUserName,
getUserUsername,
loginUser,
logoutUser,
registerUser,
toggleLikePost,
updatePostCaption,
createPost,
deletePost,
toggleFavPost,
getAllFavPosts,
toggleFollowUser,
getAllFollowingUserPosts
}

export default logic
21 changes: 21 additions & 0 deletions staff/manuel-barzi/ponies/app/logic/loginUser.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import data from '../data/index.mjs'

const loginUser = (username, password) => {
if (username.trim().length < 4)
throw new Error('invalid username')

if (password.trim().length < 8)
throw new Error('invalid password')

const user = data.findUser(user => user.username === username)

if (user === null)
throw new Error('username does not exist')

if (user.password !== password)
throw new Error('wrong password')

sessionStorage.username = username
}

export default loginUser
3 changes: 3 additions & 0 deletions staff/manuel-barzi/ponies/app/logic/logoutUser.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const logoutUser = () => delete sessionStorage.username

export default logoutUser
47 changes: 47 additions & 0 deletions staff/manuel-barzi/ponies/app/logic/registerUser.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import data from '../data/index.mjs'

const EMAIL_REGEX = /^[a-z0-9._]+@[a-z0-9.-]{3,63}\.[a-z]{2,10}$/

const registerUser = (name, surname, email, username, password, passwordRepeat) => {
if (name.trim() === '')
throw new Error('invalid name')

if (surname.trim().length < 2)
throw new Error('invalid surname')

if (!EMAIL_REGEX.test(email))
throw new Error('invalid email')

if (username.trim().length < 4)
throw new Error('invalid username')

if (password.trim().length < 8)
throw new Error('invalid password')

if (password !== passwordRepeat)
throw new Error('passwords do not match')

let user = data.findUser(user => user.email === email)

if (user !== null)
throw new Error('email already exists')

user = data.findUser(user => user.username === username)

if (user !== null)
throw new Error('username already exists')

user = {
name: name,
surname: surname,
email: email,
username: username,
password: password,
favs: [],
following: []
}

data.insertUser(user)
}

export default registerUser
16 changes: 16 additions & 0 deletions staff/manuel-barzi/ponies/app/logic/test.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>TEST logic</title>
</head>

<body>
<h1>TEST logic</h1>

<script src="getAllFavPosts.test.mjs" type="module"></script>
</body>

</html>
Loading