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/socialcode #147

Open
wants to merge 70 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
a85100e
add my folder git ignore rules #5
DanielGuillen88 Mar 20, 2024
f331eaf
add .Ds_Store in gitignore #5
DanielGuillen88 Mar 21, 2024
8f5e0c5
renamed folder danielguillen88 to daniel guillen #5
DanielGuillen88 Mar 23, 2024
a3c3e2e
add initial code for socialcode app #145
DanielGuillen88 May 5, 2024
0212bb0
created in the order daniel-guillen/staff/socialcode in the absence o…
DanielGuillen88 May 5, 2024
0fdd020
backup of app 1 with error in Form to be discovered #147
DanielGuillen88 May 6, 2024
3687545
error found in logic change 28 const->let user #147
DanielGuillen88 May 6, 2024
a69f3a3
register, login, create and delete functional post #147
DanielGuillen88 May 7, 2024
6b3eff1
delete folder daniel-guillen/staff/socialcode/app #147
DanielGuillen88 May 8, 2024
39b0328
new order for form and new functions to cancel button #147
DanielGuillen88 May 8, 2024
b5d2507
add new style #147
DanielGuillen88 May 8, 2024
cfd9677
backup saved: app 2 #147
DanielGuillen88 May 12, 2024
02e7d8f
new order of responsibilities and added confirmation step for deletio…
DanielGuillen88 May 12, 2024
4ebcb71
add initial code for api #147
DanielGuillen88 May 22, 2024
bb7a954
added new functions to the api #147
DanielGuillen88 May 23, 2024
89a6e84
backup api-1 #147
DanielGuillen88 May 23, 2024
42b0fcc
the separation of responsibilities by layers begins #147
DanielGuillen88 May 23, 2024
c960b19
added logic and tests #147
DanielGuillen88 May 27, 2024
c60b0be
add new register and authenticate #147
DanielGuillen88 May 28, 2024
a3ed643
we connect the api and app #147
DanielGuillen88 May 28, 2024
d3ed3ae
Fixed some bugs before taking the big leap #147
DanielGuillen88 May 28, 2024
93434ad
app functions are implemented in the api #147
DanielGuillen88 May 29, 2024
62eb904
socialcode backup #147
DanielGuillen88 May 29, 2024
5f78408
fixed name error in header, implemented delete #147
DanielGuillen88 May 30, 2024
b31433b
backup socialcode2
DanielGuillen88 May 30, 2024
477974d
fixed css errors #147
DanielGuillen88 May 30, 2024
80b65aa
change css backup socialcode2 #147
DanielGuillen88 Jun 3, 2024
0e91c39
the new era begins with vite and react #147
DanielGuillen88 Jun 4, 2024
95c01be
add register, home, link separate view #147
DanielGuillen88 Jun 5, 2024
e03084c
add register, home, link separate view #147
DanielGuillen88 Jun 5, 2024
93dc60a
extraction of containers and components #147
DanielGuillen88 Jun 6, 2024
ccbb455
The main components of the app are divided #147
DanielGuillen88 Jun 10, 2024
abf1cc7
new alert register, login and home, backup socialcode #147
DanielGuillen88 Jun 10, 2024
8e3a982
add heading and image core components; update title and css #147
DanielGuillen88 Jun 11, 2024
6d7e14a
separate post & add delete button #147
DanielGuillen88 Jun 12, 2024
e3998e5
add createpostform component add refresh auto list & auto top post #147
DanielGuillen88 Jun 13, 2024
67219d2
backup socialcode-react2 #147
DanielGuillen88 Jun 13, 2024
ee32d7d
change in alert messages and two steps to delete post #147
DanielGuillen88 Jun 17, 2024
ffb4daf
protecting user data with jwt #147
DanielGuillen88 Jun 19, 2024
1294f46
add jwt security in get-all-posts and delete-posts logic #147
DanielGuillen88 Jun 23, 2024
a290a69
backup socialcode #147
DanielGuillen88 Jun 23, 2024
19278ae
backup socialcode react jwt #147
DanielGuillen88 Jun 23, 2024
ce7c821
complete API logic division and responsibility for errors and validat…
DanielGuillen88 Jun 23, 2024
5c18681
add new style css #147
DanielGuillen88 Jun 24, 2024
f9b11eb
split in com, more security with hashing and added .env in api #147
DanielGuillen88 Jun 24, 2024
f76cf6e
change style css use jwt async on api #147
DanielGuillen88 Jun 27, 2024
a644679
add on api mongodb; start whit user data #147
DanielGuillen88 Jun 30, 2024
b4bc3f4
migrated databases to mongodb update logic #147
DanielGuillen88 Jun 30, 2024
4933505
tests and fixed some bugs #147
DanielGuillen88 Jul 1, 2024
7910d89
change style css #147
DanielGuillen88 Jul 1, 2024
4856291
backup socialcode7-react-jwt-hashing-env-mongodb 147
DanielGuillen88 Jul 1, 2024
8fc0d60
new data model mongoose and move api to mongoose #147
DanielGuillen88 Jul 2, 2024
dd1b348
use ids instead of usernames in api and app (with mistakes) #147
DanielGuillen88 Jul 4, 2024
a0c46ec
use ids instead of usernames in api and app (with bugs fixed) #147
DanielGuillen88 Jul 4, 2024
0396160
backup socialcode9 #147
DanielGuillen88 Jul 4, 2024
f0227b5
change xht to fetch on app logic #147
DanielGuillen88 Jul 7, 2024
a521b34
chnaged register user client logic app to primised #147
DanielGuillen88 Jul 9, 2024
4e6c7e4
migrate api to promised #147
DanielGuillen88 Jul 9, 2024
1881766
add button scrolltop on footer and slight changes in css styles #147
DanielGuillen88 Jul 10, 2024
50bc5cc
add error handler in api, backup socialcode with promised #147
DanielGuillen88 Jul 11, 2024
be6c613
fixed logout header and add error handler in api #147
DanielGuillen88 Jul 11, 2024
683995c
create all route handlers in api #147
DanielGuillen88 Jul 13, 2024
0d63e87
split api server handlers, error handler, install mocha & chai #147
DanielGuillen88 Jul 16, 2024
1e3709d
bug fixed #147
DanielGuillen88 Jul 16, 2024
0a2b6e0
change app css style to tailwind #147
DanielGuillen88 Jul 20, 2024
78e5f81
fixed error css style #147
DanielGuillen88 Jul 22, 2024
d90ee45
add react router to app #147
DanielGuillen88 Jul 23, 2024
8a11668
backup socialcode12 #147
DanielGuillen88 Jul 23, 2024
d85bedf
add comfirm and alert component and integrate only in home #147
DanielGuillen88 Jul 24, 2024
cdea10a
backup 13, create custom hook use-context global centric alert in app…
DanielGuillen88 Jul 25, 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
  •  
  •  
  •  
3 changes: 3 additions & 0 deletions staff/daniel-guillen/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.DS_Store
thumbs.db
node_modules
4 changes: 4 additions & 0 deletions staff/daniel-guillen/socialcode/api/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
PORT = 9010
JWT_SECRET = peter and wendy have a rollete
MONGODB_URL = mongodb://localhost:27017/socialcode
MONGODB_URL_TEST = mongodb://localhost:27017/socialcode-test
2 changes: 2 additions & 0 deletions staff/daniel-guillen/socialcode/api/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
!.env
36 changes: 36 additions & 0 deletions staff/daniel-guillen/socialcode/api/data/Post.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { Schema, model, Types } from 'mongoose'

const { ObjectId } = Types

const post = new Schema({
author: {
type: ObjectId,
required: true,
ref: 'User'
},
title: {
type: String,
required: true
},
image: {
type: String,
required: true
},
description: {
type: String,
required: true
},
date: {
type: Date,
required: true,
default: Date.now
},
likes: [{
type: ObjectId,
ref: 'User'
}]
})

const Post = model('Post', post)

export default Post
30 changes: 30 additions & 0 deletions staff/daniel-guillen/socialcode/api/data/User.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Schema, model } from 'mongoose'

const user = new Schema({
name: {
type: String,
required: true
},
surname: {
type: String,
required: true
},
email: {
type: String,
required: true,
unique: true
},
username: {
type: String,
required: true,
unique: true
},
password: {
type: String,
required: true
}
})

const User = model('User', user)

export default User
7 changes: 7 additions & 0 deletions staff/daniel-guillen/socialcode/api/data/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import User from './User.js'
import Post from './Post.js'

export {
User,
Post
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import jwt from '../util/jwt-promised.js'

import logic from '../logic/index.js'

import { SystemError } from 'com/errors.js'

const { JWT_SECRET } = process.env

export default (req, res, next) => {
const { username, password } = req.body

try {
logic.authenticateUser(username, password)
.then(userId =>
jwt.sign({ sub: userId }, JWT_SECRET, { expiresIn: '1h' })
.then(token => res.json(token))
.catch(error => next(new SystemError(error.message)))
)
.catch(error => next(error))
} catch (error) {
next(error)
}
}
31 changes: 31 additions & 0 deletions staff/daniel-guillen/socialcode/api/handlers/createPostHandler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import jwt from '../util/jwt-promised.js'

import logic from '../logic/index.js'

import { CredentialsError } from 'com/errors.js'

const { JWT_SECRET } = process.env

export default (req, res, next) => {
try {
const token = req.headers.authorization.slice(7)

jwt.verify(token, JWT_SECRET)
.then(payload => {
const { sub: userId } = payload

const { title, image, description } = req.body

try {
logic.createPost(userId, title, image, description)
.then(() => res.status(201).send())
.catch(error => next(error))
} catch (error) {
next(error)
}
})
.catch(error => next(new CredentialsError(error.message)))
} catch (error) {
next(error)
}
}
31 changes: 31 additions & 0 deletions staff/daniel-guillen/socialcode/api/handlers/deletePostHandler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import jwt from '../util/jwt-promised.js'

import logic from '../logic/index.js'

import { CredentialsError } from 'com/errors.js'

const { JWT_SECRET } = process.env

export default (req, res, next) => {
try {
const token = req.headers.authorization.slice(7)

jwt.verify(token, JWT_SECRET)
.then(payload => {
const { sub: userId } = payload

const { postId } = req.params

try {
logic.deletePost(userId, postId)
.then(() => res.status(204).send())
.catch(error => next(error))
} catch (error) {
next(error)
}
})
.catch(error => next(new CredentialsError(error.message)))
} catch (error) {
next(error)
}
}
18 changes: 18 additions & 0 deletions staff/daniel-guillen/socialcode/api/handlers/errorHandler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { ContentError, CredentialsError, DuplicityError, MatchError, NotFoundError } from 'com/errors.js'

export default (error, req, res, next) => {
let status = 500

if (error instanceof DuplicityError)
status = 409
else if (error instanceof ContentError)
status = 400
else if (error instanceof MatchError)
status = 412
else if (error instanceof CredentialsError)
status = 401
else if (error instanceof NotFoundError)
status = 404

res.status(status).json({ error: error.constructor.name, message: error.message })
}
29 changes: 29 additions & 0 deletions staff/daniel-guillen/socialcode/api/handlers/getAllPostshandler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import jwt from '../util/jwt-promised.js'

import logic from '../logic/index.js'

import { CredentialsError } from 'com/errors.js'

const { JWT_SECRET } = process.env

export default (req, res, next) => {
try {
const token = req.headers.authorization.slice(7)

jwt.verify(token, JWT_SECRET)
.then(payload => {
const { sub: userId } = payload

try {
logic.getAllPosts(userId)
.then(posts => res.json(posts))
.catch(error => next(error))
} catch (error) {
next(error)
}
})
.catch(error => next(new CredentialsError(error.message)))
} catch (error) {
next(error)
}
}
31 changes: 31 additions & 0 deletions staff/daniel-guillen/socialcode/api/handlers/getUserNameHandler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import jwt from '../util/jwt-promised.js'

import logic from '../logic/index.js'

import { CredentialsError } from 'com/errors.js'

const { JWT_SECRET } = process.env

export default (req, res, next) => {
try {
const token = req.headers.authorization.slice(7)

jwt.verify(token, JWT_SECRET)
.then(payload => {
const { sub: userId } = payload

const { targetUserId } = req.params

try {
logic.getUserName(userId, targetUserId)
.then(name => res.json(name))
.catch(error => next(error))
} catch (error) {
next(error)
}
})
.catch(error => next(new CredentialsError(error.message)))
} catch (error) {
next(error)
}
}
19 changes: 19 additions & 0 deletions staff/daniel-guillen/socialcode/api/handlers/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import registerUserHandler from './registerUserHandler.js'
import authenticateUserHandler from './authenticateUserHandler.js'
import getUserNameHandler from './getUserNameHandler.js'
import createPostHandler from './createPostHandler.js'
import getAllPostsHandler from './getAllPostsHandler.js'
import deletePostHandler from './deletePostHandler.js'
import toggleLikePostHandler from './toggleLikePostHandler.js'
import errorHandler from './errorHandler.js'

export {
registerUserHandler,
authenticateUserHandler,
getUserNameHandler,
createPostHandler,
getAllPostsHandler,
deletePostHandler,
toggleLikePostHandler,
errorHandler
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import logic from '../logic/index.js'

export default (req, res, next) => {
const { name, surname, email, username, password, passwordRepeat } = req.body

try {
logic.registerUser(name, surname, email, username, password, passwordRepeat)
.then(() => res.status(201).send())
.catch(error => next(error))
} catch (error) {
next(error)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import jwt from '../util/jwt-promised.js'

import logic from '../logic/index.js'

import { CredentialsError } from 'com/errors.js'

const { JWT_SECRET } = process.env

export default (req, res, next) => {
try {
const token = req.headers.authorization.slice(7)

jwt.verify(token, JWT_SECRET)
.then(payload => {
const { sub: userId } = payload

const { postId } = req.params

try {
logic.toggleLikePost(userId, postId)
.then(() => res.status(204).send())
.catch(error => next(error))
} catch (error) {
next(error)
}
})
.catch(error => next(new CredentialsError(error.message)))
} catch (error) {
next(error)
}
}
47 changes: 47 additions & 0 deletions staff/daniel-guillen/socialcode/api/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import 'dotenv/config'
import express from 'express'
import cors from 'cors'
import mongoose from 'mongoose'

import {
registerUserHandler,
authenticateUserHandler,
getUserNameHandler,
createPostHandler,
getAllPostsHandler,
deletePostHandler,
toggleLikePostHandler,
errorHandler
} from './handlers/index.js'

const { MONGODB_URL, PORT } = process.env

mongoose.connect(MONGODB_URL)
.then(() => {
const api = express()

api.use(cors())

api.get('/', (_, res) => res.send("It's Alive!!!"))

const jsonBodyParser = express.json({ strict: true, type: 'application/json' })

api.post('/users', jsonBodyParser, registerUserHandler)

api.post('/users/auth', jsonBodyParser, authenticateUserHandler)

api.get('/users/:targetUserId', getUserNameHandler)

api.get('/posts', getAllPostsHandler)

api.post('/posts', jsonBodyParser, createPostHandler)

api.delete('/posts/:postId', deletePostHandler)

api.patch('/posts/:postId/likes', toggleLikePostHandler)

api.use(errorHandler)

api.listen(PORT, () => console.log(`API running on PORT ${PORT}`))
})
.catch(error => console.error(error))
Loading