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 #141

Open
wants to merge 36 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
29fb7af
add my folder with git ignoring rules #7
AdrianGonzalo Mar 20, 2024
bce891c
añadido gitignore
AdrianGonzalo Mar 20, 2024
4abe054
edit .DS_Store #7
AdrianGonzalo Mar 21, 2024
1a3e9fd
add initial code for social code app #140
AdrianGonzalo May 4, 2024
eb1142f
edit the apps and create my_app #140
AdrianGonzalo May 4, 2024
9419391
refactor app to list posts by means of logic #140
AdrianGonzalo May 5, 2024
8972c04
add create post logic #140
AdrianGonzalo May 6, 2024
daaef02
create cancel button and refresh the page #140
AdrianGonzalo May 8, 2024
23d779a
clear the code #140
AdrianGonzalo May 8, 2024
71d84d6
complete the socialcode #140
AdrianGonzalo May 10, 2024
a07713f
start to upgrade the socialcode #140
AdrianGonzalo May 23, 2024
530ec89
upgrade the api #140
AdrianGonzalo May 24, 2024
ef78ab3
complete the layer data and logic #140
AdrianGonzalo May 24, 2024
c6b224d
complete the insert user #140
AdrianGonzalo May 25, 2024
45dd518
edit the code #140
AdrianGonzalo May 27, 2024
2d72636
add logic the post in index api #140
AdrianGonzalo May 27, 2024
0d9e391
implement authenticate and tests in api; integrate register and authe…
AdrianGonzalo May 28, 2024
b1cd0c6
edit the code #140
AdrianGonzalo May 28, 2024
e7e20e5
implement get all post and create posts logic #140
AdrianGonzalo May 29, 2024
ec82307
implement delete post and get user name logics in api #140
AdrianGonzalo May 30, 2024
5523e59
edit the folders #140
AdrianGonzalo Jun 2, 2024
3137551
add app to react #140
AdrianGonzalo Jun 5, 2024
7644357
extract atomic, molecular and container core components
AdrianGonzalo Jun 6, 2024
a6668da
separate the components login, register, home the app file #140
AdrianGonzalo Jun 7, 2024
635f665
fix the title, the type button and access to home #140
AdrianGonzalo Jun 10, 2024
f39b691
add postList and styles #140
AdrianGonzalo Jun 11, 2024
1408e1f
add mongo in api #140
AdrianGonzalo Jun 27, 2024
7114488
create like and fix errors #140
AdrianGonzalo Jul 1, 2024
a1905b5
download mongoose and update the app to mongoose and fix errors #140
AdrianGonzalo Jul 3, 2024
8b03127
change logic to promise and testing #140
AdrianGonzalo Jul 10, 2024
76d3b73
fix the home #140
AdrianGonzalo Jul 10, 2024
772b01b
fix errors #140
AdrianGonzalo Jul 15, 2024
c4830d6
split api server handlers; add error handler; wip test with mocha cha…
AdrianGonzalo Jul 16, 2024
3dbfcae
add happy path test case in create post spec #140
AdrianGonzalo Jul 17, 2024
3b6693a
continue with the test and fix them #140
AdrianGonzalo Jul 20, 2024
d00e56b
add testing in registerUser, createPost, getAllPost, getUserName, del…
AdrianGonzalo Jul 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions staff/adrian-martin/.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/adrian-martin/socialcode/api/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
PORT = 9010
JWT_SECRET = wendy and peter have a rollete
MONGODB_URL = mongodb://localhost:27017/socialcode
MONGODB_URL_TEST = mongodb://localhost:27017/socialcode-test
2 changes: 2 additions & 0 deletions staff/adrian-martin/socialcode/api/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
!.env
40 changes: 40 additions & 0 deletions staff/adrian-martin/socialcode/api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
- list users

```sh
🐖 curl http://localhost:8080/users -v
```

- register user

```sh
🐖 curl -X POST http://localhost:8080/users -H "Content-Type: application/json" -d '{"name":"Pepito","surname":"Grillo","email":"[email protected]","username":"pepitogrillo","password":"123123123","passwordRepeat":"123123123"}' -v
```
- authenticate user

```sh
🐖 curl -X POST http://localhost:8080/users/auth -H "Content-Type: application/json" -d '{"username":"AdrianGon","password":"321321321"}' -v
```

- get user name

```sh
🐖 curl http://localhost:8080/users/AdrianGon -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJBZHJpYW5Hb24iLCJpYXQiOjE3MTg3MzY3NTgsImV4cCI6MTcxODc0MDM1OH0.abhG3rqw9V6XdNZ4Qzs09Xs2ysbMHa5OprRJtm5VyjI" -v
```

- get all posts

```sh
🐖 curl -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJBZHJpYW5Hb24iLCJpYXQiOjE3MTg3ODk5NDEsImV4cCI6MTcxODc5MzU0MX0.nKzPApr26Fr15DMWxBNe7k0QbBDE21E1yllUNJBgozQ" http://localhost:8080/posts -v
```

- create post

```sh
🐖 $ curl -X POST http://localhost:8080/posts -H "Authorization: Basic AdrianGon" -H "Content-Type: application/json" -d '{"title":"Buenos Dias","image":"https://imgs.search.brave.com/J8imP8bduv7lIhsfCsnGwaeKNgdHqp2g5dCpK8aVkYA/rs:fit:860:0:0/g:ce/aHR0cHM6Ly90My5m/dGNkbi5uZXQvanBn/LzAxLzAzLzM2LzA0/LzM2MF9GXzEwMzM2/MDQyNV9IekJxZEkx/d1dOTjBWU3Z2ZXkw/R3RRTlRvaDJLenhy/Ny5qcGc","description":"blah blah"}' -v
```

- delete post

```sh
🐖 $ curl -X DELETE http://localhost:8080/posts/7956804321626201-1716989998980 -H "Authorization: Basic AdrianGon" -v
```
35 changes: 35 additions & 0 deletions staff/adrian-martin/socialcode/api/data/Post.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
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
29 changes: 29 additions & 0 deletions staff/adrian-martin/socialcode/api/data/User.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
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
49 changes: 49 additions & 0 deletions staff/adrian-martin/socialcode/api/data/demo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import mongoose from 'mongoose'
import { User, Post } from './index.js'


mongoose.connect('mongodb://localhost:27017/test')
.then(() => {
// User.create({ name: 'Super', surname: 'Woman', email: '[email protected]', username: 'superwoman', password: '123123123' })
// .then(() => console.log('created'))
// .catch(error => console.error(error))

// Post.create({ author: 'pepitogrillo', title: 'console.log', image: 'https://whatever.com', description: '...' })
// .then(() => console.log('created'))
// .catch(error => console.error(error))

Post.find({}).populate('author', 'username')
.then(posts => console.log('retrieved', posts))
.catch(error => console.error(error))
})
.catch(error => console.error(error))




// import mongodb, { ObjectId } from 'mongodb'

// const { MongoClient } = mongodb

// const client = new MongoClient('mongodb://localhost:27017')

// client.connect()
// .then(connection => {
// const db = connection.db('test')

// const users = db.collection('users')

// users.insertOne({ name:'Adrian', surname:'Gon', email:'[email protected]', username: 'AdrianGon',password: '123456789' })
// .then(result => console.log(result))
// .catch(error => console.error(error))

// users.deleteOne({ _id: new ObjectId('667d3a8fea21f86e28cc8988') })
// .then(result => console.log(result))
// .catch(error => console.error(error))

// users.find({}).toArray()
// .then(result => console.log(result))
// .catch(error => console.error(error))

// })
// .catch(error => console.error(error))
163 changes: 163 additions & 0 deletions staff/adrian-martin/socialcode/api/data/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
import User from './User.js';
import Post from './Post.js';

export {
User,
Post
}

// import fs from 'fs'
// import { SystemError } from 'com/error.js'

// const data = {}

// data.findUser = (condition, callback) => {
// fs.readFile('./data/users.json', 'utf8', (error, json) => {
// if (error) {
// callback(new SystemError(error.message))

// return
// }

// if (!json) json = '[]'

// const users = JSON.parse(json)

// const user = users.find(condition)

// callback(null, user)
// })
// }

// data.insertUser = (user, callback) => {

// fs.readFile('./data/users.json', 'utf8', (error, json) => {
// if (error) {
// callback(new SystemError(error.message))

// return
// }

// if (!json) json = '[]'

// const users = JSON.parse(json)

// users.push(user)

// const newJson = JSON.stringify(users)

// fs.writeFile('./data/users.json', newJson, error => {
// if (error) {
// callback(new SystemError(error.message))

// return
// }

// callback(null)
// })
// })
// }




// data.findPosts = (condition, callback) => {
// fs.readFile('./data/posts.json', 'utf8', (error, json) => {
// if (error) {
// callback(new SystemError(error.message))

// return
// }

// if (!json) json = '[]'

// const posts = JSON.parse(json)

// const filtered = posts.filter(condition)

// callback(null, filtered)
// })
// }

// data.findPost = (condition, callback) => {
// fs.readFile('./data/posts.json', 'utf8', (error, json) => {
// if (error) {
// callback(new SystemError(error.message))

// return
// }

// if (!json) json = '[]'

// const posts = JSON.parse(json)

// const post = posts.find(condition)

// callback(null, post)
// })
// }


// data.insertPost = (post, callback) => {
// fs.readFile('./data/posts.json', 'utf8', (error, json) => {
// if (error) {
// callback(new SystemError(error.message))

// return
// }

// if (!json) json = '[]'

// const posts = JSON.parse(json)

// post.id = `${Math.random().toString().slice(2)}-${Date.now()}`

// posts.push(post)

// const newJson = JSON.stringify(posts)

// fs.writeFile('./data/posts.json', newJson, error => {
// if (error) {
// callback(new SystemError(error.message))

// return
// }

// callback(null)
// })
// })
// }

// data.deletePost = (condition, callback) => {
// fs.readFile('./data/posts.json', 'utf8', (error, json) => {
// if (error) {
// callback(new SystemError(error.message))

// return
// }

// if (!json) json = '[]'

// const posts = JSON.parse(json)

// const index = posts.findIndex(condition)

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

// const newJson = JSON.stringify(posts)

// fs.writeFile('./data/posts.json', newJson, error => {
// if (error) {
// callback(new SystemError(error.message))

// return
// }

// callback(null)
// })
// } else callback(null)
// })
// }

// export default data
56 changes: 56 additions & 0 deletions staff/adrian-martin/socialcode/api/data/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import data from './index.js'

// data.findUser(user => user.surname === 'Grillo', (error, user) => {
// if (error) {
// console.error(error)

// return
// }

// console.log(user)
// })

// data.insertUser({ name: 'James', surname: 'Hook', email: '[email protected]', username: 'jameshook', password: '123123123' }, error => {
// if (error) {
// console.error(error)

// return
// }

// console.log('user inserted')
// })

// data.findPosts(post => post.date.includes('T19'), (error, posts) => {
// if (error) {
// console.error(error)

// return
// }

// console.log(posts)
// })

// data.insertPost({
// author: 'jameshook',
// title: 'smile 2',
// image: 'https://m.media-amazon.com/images/I/41xsPjrM-pL._AC_UF350,350_QL50_.jpg', description: 'hi 2',
// date: new Date().toISOString()
// }, error => {
// if (error) {
// console.error(error)

// return
// }

// console.log('post inserted')
// })

// data.deletePost(post => post.title === 'smile 2', error => {
// if (error) {
// console.error(error)

// return
// }

// console.log('post deleted')
// })
Loading