Skip to content

Commit b9385b4

Browse files
committed
Add: react-query
1 parent b598e08 commit b9385b4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

104 files changed

+32379
-962
lines changed

.idea/dataSources.xml

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/prettier.xml

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ch7/front/package-lock.json

Lines changed: 1241 additions & 947 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ch7/front/package.json

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,37 +11,37 @@
1111
"author": "ZeroCho",
1212
"license": "ISC",
1313
"dependencies": {
14-
"@ant-design/icons": "^4.2.1",
15-
"@next/bundle-analyzer": "^9.4.4",
16-
"antd": "^4.3.1",
14+
"@ant-design/icons": "^4.3.0",
15+
"@next/bundle-analyzer": "^9.5.5",
16+
"antd": "^4.8.6",
1717
"axios": "^0.21.0",
18-
"babel-plugin-styled-components": "^1.10.7",
18+
"babel-plugin-styled-components": "^1.12.0",
1919
"cross-env": "^7.0.2",
2020
"faker": "^4.1.0",
2121
"immer": "^9.0.6",
22-
"moment": "^2.27.0",
22+
"moment": "^2.29.1",
2323
"next": "^9.5.5",
2424
"next-redux-wrapper": "^6.0.2",
25-
"pm2": "^4.4.0",
25+
"pm2": "^4.5.0",
2626
"prop-types": "^15.7.2",
2727
"react": "^17.0.1",
2828
"react-dom": "^17.0.1",
29-
"react-redux": "^7.2.0",
29+
"react-redux": "^7.2.2",
3030
"react-slick": "^0.26.1",
3131
"redux": "^4.0.5",
3232
"redux-devtools-extension": "^2.13.8",
3333
"redux-saga": "^1.1.3",
34-
"shortid": "^2.2.15",
35-
"styled-components": "^5.1.1",
34+
"shortid": "^2.2.16",
35+
"styled-components": "^5.2.1",
3636
"swr": "^0.3.9"
3737
},
3838
"devDependencies": {
3939
"babel-eslint": "^10.1.0",
40-
"eslint": "^7.1.0",
41-
"eslint-config-airbnb": "^18.1.0",
42-
"eslint-plugin-import": "^2.21.2",
43-
"eslint-plugin-jsx-a11y": "^6.2.3",
44-
"eslint-plugin-react": "^7.20.0",
45-
"eslint-plugin-react-hooks": "^4.0.4"
40+
"eslint": "^7.14.0",
41+
"eslint-config-airbnb": "^18.2.1",
42+
"eslint-plugin-import": "^2.22.1",
43+
"eslint-plugin-jsx-a11y": "^6.4.1",
44+
"eslint-plugin-react": "^7.21.5",
45+
"eslint-plugin-react-hooks": "^4.2.0"
4646
}
4747
}

react-query/back/app.js

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
const express = require('express');
2+
const cors = require('cors');
3+
const session = require('express-session');
4+
const cookieParser = require('cookie-parser');
5+
const passport = require('passport');
6+
const dotenv = require('dotenv');
7+
const morgan = require('morgan');
8+
const path = require('path');
9+
const hpp = require('hpp');
10+
const helmet = require('helmet');
11+
12+
const postRouter = require('./routes/post');
13+
const postsRouter = require('./routes/posts');
14+
const userRouter = require('./routes/user');
15+
const hashtagRouter = require('./routes/hashtag');
16+
const db = require('./models');
17+
const passportConfig = require('./passport');
18+
19+
dotenv.config();
20+
const app = express();
21+
db.sequelize.sync()
22+
.then(() => {
23+
console.log('db 연결 성공');
24+
})
25+
.catch(console.error);
26+
passportConfig();
27+
28+
if (process.env.NODE_ENV === 'production') {
29+
app.use(morgan('combined'));
30+
app.use(hpp());
31+
app.use(helmet({ contentSecurityPolicy: false }));
32+
app.use(cors({
33+
origin: 'http://nodebird.com',
34+
credentials: true,
35+
}));
36+
} else {
37+
app.use(morgan('dev'));
38+
app.use(cors({
39+
origin: true,
40+
credentials: true,
41+
}));
42+
}
43+
app.use('/', express.static(path.join(__dirname, 'uploads')));
44+
app.use(express.json());
45+
app.use(express.urlencoded({ extended: true }));
46+
app.use(cookieParser(process.env.COOKIE_SECRET));
47+
app.use(session({
48+
saveUninitialized: false,
49+
resave: false,
50+
secret: process.env.COOKIE_SECRET,
51+
cookie: {
52+
httpOnly: true,
53+
secure: false,
54+
domain: process.env.NODE_ENV === 'production' && '.nodebird.com'
55+
},
56+
}));
57+
app.use(passport.initialize());
58+
app.use(passport.session());
59+
60+
app.get('/', (req, res) => {
61+
res.send('hello express');
62+
});
63+
64+
app.use('/posts', postsRouter);
65+
app.use('/post', postRouter);
66+
app.use('/user', userRouter);
67+
app.use('/hashtag', hashtagRouter);
68+
69+
app.listen(3065, () => {
70+
console.log('서버 실행 중!');
71+
});

react-query/back/config/config.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
const dotenv = require('dotenv');
2+
3+
dotenv.config();
4+
5+
module.exports = {
6+
development: {
7+
username: 'root',
8+
password: process.env.DB_PASSWORD,
9+
database: 'react-nodebird',
10+
host: '127.0.0.1',
11+
dialect: 'mysql',
12+
},
13+
test: {
14+
username: 'root',
15+
password: process.env.DB_PASSWORD,
16+
database: 'react-nodebird',
17+
host: '127.0.0.1',
18+
dialect: 'mysql',
19+
},
20+
production: {
21+
username: 'root',
22+
password: process.env.DB_PASSWORD,
23+
database: 'react-nodebird',
24+
host: '127.0.0.1',
25+
dialect: 'mysql',
26+
},
27+
};

react-query/back/models/comment.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
const DataTypes = require('sequelize');
2+
const { Model } = DataTypes;
3+
4+
module.exports = class Comment extends Model {
5+
static init(sequelize) {
6+
return super.init({
7+
// id가 기본적으로 들어있다.
8+
content: {
9+
type: DataTypes.TEXT,
10+
allowNull: false,
11+
},
12+
// UserId: 1
13+
// PostId: 3
14+
}, {
15+
modelName: 'Comment',
16+
tableName: 'comments',
17+
charset: 'utf8mb4',
18+
collate: 'utf8mb4_general_ci', // 이모티콘 저장
19+
sequelize,
20+
});
21+
}
22+
23+
static associate(db) {
24+
db.Comment.belongsTo(db.User);
25+
db.Comment.belongsTo(db.Post);
26+
}
27+
};

react-query/back/models/hashtag.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const DataTypes = require('sequelize');
2+
const { Model } = DataTypes;
3+
4+
module.exports = class Hashtag extends Model {
5+
static init(sequelize) {
6+
return super.init({
7+
// id가 기본적으로 들어있다.
8+
name: {
9+
type: DataTypes.STRING(20),
10+
allowNull: false,
11+
},
12+
}, {
13+
modelName: 'Hashtag',
14+
tableName: 'hashtags',
15+
charset: 'utf8mb4',
16+
collate: 'utf8mb4_general_ci', // 이모티콘 저장
17+
sequelize,
18+
});
19+
}
20+
static associate(db) {
21+
db.Hashtag.belongsToMany(db.Post, { through: 'PostHashtag' });
22+
}
23+
};

react-query/back/models/image.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const DataTypes = require('sequelize');
2+
const { Model } = DataTypes;
3+
4+
module.exports = class Image extends Model {
5+
static init(sequelize) {
6+
return super.init({
7+
// id가 기본적으로 들어있다.
8+
src: {
9+
type: DataTypes.STRING(200),
10+
allowNull: false,
11+
},
12+
}, {
13+
modelName: 'Image',
14+
tableName: 'images',
15+
charset: 'utf8',
16+
collate: 'utf8_general_ci',
17+
sequelize,
18+
});
19+
}
20+
static associate(db) {
21+
db.Image.belongsTo(db.Post);
22+
}
23+
};

react-query/back/models/index.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
const Sequelize = require('sequelize');
2+
const comment = require('./comment');
3+
const hashtag = require('./hashtag');
4+
const image = require('./image');
5+
const post = require('./post');
6+
const user = require('./user');
7+
8+
const env = process.env.NODE_ENV || 'development';
9+
const config = require('../config/config')[env];
10+
const db = {};
11+
12+
const sequelize = new Sequelize(config.database, config.username, config.password, config);
13+
14+
db.Comment = comment;
15+
db.Hashtag = hashtag;
16+
db.Image = image;
17+
db.Post = post;
18+
db.User = user;
19+
20+
Object.keys(db).forEach(modelName => {
21+
db[modelName].init(sequelize);
22+
})
23+
24+
Object.keys(db).forEach(modelName => {
25+
if (db[modelName].associate) {
26+
db[modelName].associate(db);
27+
}
28+
});
29+
30+
db.sequelize = sequelize;
31+
db.Sequelize = Sequelize;
32+
33+
module.exports = db;

react-query/back/models/post.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
const DataTypes = require('sequelize');
2+
const { Model } = DataTypes;
3+
4+
module.exports = class Post extends Model {
5+
static init(sequelize) {
6+
return super.init({
7+
// id가 기본적으로 들어있다.
8+
content: {
9+
type: DataTypes.TEXT,
10+
allowNull: false,
11+
},
12+
// RetweetId
13+
}, {
14+
modelName: 'Post',
15+
tableName: 'posts',
16+
charset: 'utf8mb4',
17+
collate: 'utf8mb4_general_ci', // 이모티콘 저장
18+
sequelize,
19+
});
20+
}
21+
static associate(db) {
22+
db.Post.belongsTo(db.User); // post.addUser, post.getUser, post.setUser
23+
db.Post.belongsToMany(db.Hashtag, { through: 'PostHashtag' }); // post.addHashtags
24+
db.Post.hasMany(db.Comment); // post.addComments, post.getComments
25+
db.Post.hasMany(db.Image); // post.addImages, post.getImages
26+
db.Post.belongsToMany(db.User, { through: 'Like', as: 'Likers' }) // post.addLikers, post.removeLikers
27+
db.Post.belongsTo(db.Post, { as: 'Retweet' }); // post.addRetweet
28+
}
29+
};

react-query/back/models/user.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
const DataTypes = require('sequelize');
2+
const { Model } = DataTypes;
3+
4+
module.exports = class User extends Model {
5+
static init(sequelize) {
6+
return super.init({
7+
// id가 기본적으로 들어있다.
8+
email: {
9+
type: DataTypes.STRING(30), // STRING, TEXT, BOOLEAN, INTEGER, FLOAT, DATETIME
10+
allowNull: false, // 필수
11+
unique: true, // 고유한 값
12+
},
13+
nickname: {
14+
type: DataTypes.STRING(30),
15+
allowNull: false, // 필수
16+
},
17+
password: {
18+
type: DataTypes.STRING(100),
19+
allowNull: false, // 필수
20+
},
21+
}, {
22+
modelName: 'User',
23+
tableName: 'users',
24+
charset: 'utf8',
25+
collate: 'utf8_general_ci', // 한글 저장
26+
sequelize,
27+
});
28+
}
29+
static associate(db) {
30+
db.User.hasMany(db.Post);
31+
db.User.hasMany(db.Comment);
32+
db.User.belongsToMany(db.Post, { through: 'Like', as: 'Liked' })
33+
db.User.belongsToMany(db.User, { through: 'Follow', as: 'Followers', foreignKey: 'FollowingId' });
34+
db.User.belongsToMany(db.User, { through: 'Follow', as: 'Followings', foreignKey: 'FollowerId' });
35+
}
36+
};

0 commit comments

Comments
 (0)