Toggle navigation
Toggle navigation
This project
Loading...
Sign in
오인제
/
Tunnel
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
고병후
2021-12-09 02:57:03 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
13df9ad273739381c0a41087d9e0b0ba84ddbaae
13df9ad2
1 parent
4bff8cee
Create user information router
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
104 additions
and
18 deletions
DB.txt
tunnel_BE/server/models/comment.js
tunnel_BE/server/models/post.js
tunnel_BE/server/models/user.js
tunnel_BE/server/routes/login.js
tunnel_BE/server/routes/logout.js
tunnel_BE/server/routes/main.js
tunnel_BE/server/routes/post.js
tunnel_BE/server/routes/user.js
tunnel_BE/server/server.js
DB.txt
View file @
13df9ad
...
...
@@ -29,9 +29,6 @@ COMMENT = 'post information'
DEFAULT CHARACTER SET = utf8
ENGINE = InnoDB;
<후 처리>
ALTER TABLE tunnel.posts MODIFY post TEXT CHARACTER SET utf8mb4;
:게시물에 이모지 사용가능하게 칼럼 수정.
<댓글>
CREATE TABLE tunnel.comments(
...
...
@@ -44,8 +41,6 @@ PRIMARY KEY(id),
INDEX postid_idx (postid ASC),
CONSTRAINT post_id FOREIGN KEY (postid) REFERENCES tunnel.posts (id)
ON DELETE CASCADE
ON UPDATE CASCADE,
CONSTRAINT user_id FOREIGN KEY (userid) REFERENCES tunnel.users (name)
ON UPDATE CASCADE
)
...
...
@@ -53,6 +48,11 @@ COMMENT = 'post information'
DEFAULT CHARACTER SET = utf8
ENGINE = InnoDB;
[후처리 보류]
<후 처리>
ALTER TABLE tunnel.posts MODIFY post TEXT CHARACTER SET utf8mb4;
:게시물에 이모지 사용가능하게 칼럼 수정.
<후 처리>
ALTER TABLE tunnel.comments MODIFY comment TEXT CHARACTER SET utf8mb4;
: 댓글에 이모지 사용가능하게 칼럼 수정.
...
...
@@ -60,6 +60,8 @@ ALTER TABLE tunnel.comments MODIFY comment TEXT CHARACTER SET utf8mb4;
<명령어>
SELECT * FROM tunnel.users
mysql -h localhost -u root -p
show databases;
use tunnel;
show tables;
...
...
tunnel_BE/server/models/comment.js
View file @
13df9ad
...
...
@@ -3,6 +3,11 @@ const Sequelize = require('sequelize');
module
.
exports
=
class
Comment
extends
Sequelize
.
Model
{
static
init
(
sequelize
)
{
return
super
.
init
({
userid
:{
type
:
Sequelize
.
STRING
(
30
),
allowNull
:
false
,
unique
:
true
,
},
comment
:{
type
:
Sequelize
.
TEXT
,
allowNull
:
false
,
...
...
@@ -25,5 +30,7 @@ module.exports = class Comment extends Sequelize.Model {
}
static
associate
(
db
)
{}
static
associate
(
db
)
{
db
.
Comment
.
belongsTo
(
db
.
Post
,{
foreignKey
:
'postid'
,
targetKey
:
'id'
});
}
};
\ No newline at end of file
...
...
tunnel_BE/server/models/post.js
View file @
13df9ad
...
...
@@ -33,5 +33,7 @@ module.exports = class Post extends Sequelize.Model {
}
static
associate
(
db
)
{}
static
associate
(
db
)
{
db
.
Post
.
belongsTo
(
db
.
User
,{
foreignKey
:
'userid'
,
targetKey
:
'name'
});
}
};
\ No newline at end of file
...
...
tunnel_BE/server/models/user.js
View file @
13df9ad
...
...
@@ -33,5 +33,7 @@ module.exports = class User extends Sequelize.Model {
}
static
associate
(
db
)
{}
static
associate
(
db
)
{
db
.
User
.
hasMany
(
db
.
Post
,{
foreignKey
:
'userid'
,
sourceKey
:
'name'
});
}
};
\ No newline at end of file
...
...
tunnel_BE/server/routes/login.js
View file @
13df9ad
...
...
@@ -25,7 +25,7 @@ router.post('/',(req,res)=>{
res
.
status
(
401
).
send
(
"pwError"
);
}
else
if
(
result
.
dataValues
.
pw
==
req
.
body
.
Password
){
req
.
session
.
id
=
result
.
dataValues
.
id
;
req
.
session
.
user
id
=
result
.
dataValues
.
id
;
req
.
session
.
name
=
result
.
dataValues
.
name
;
req
.
session
.
personality
=
result
.
dataValues
.
personality
;
req
.
session
.
status
=
result
.
dataValues
.
status
;
...
...
tunnel_BE/server/routes/logout.js
View file @
13df9ad
const
express
=
require
(
"express"
);
const
bodyParser
=
require
(
"body-parser"
);
const
router
=
express
.
Router
();
const
auth
=
require
(
"../obj/authorize"
);
const
{
User
}
=
require
(
'../models'
);
router
.
get
(
'/'
,(
req
,
res
)
=>
{
});
//로그아웃
router
.
post
(
'/'
,(
req
,
res
)
=>
{
if
(
result
.
dataValues
.
pw
==
req
.
body
.
Password
){
req
.
session
.
id
=
null
;
router
.
get
(
'/'
,
auth
,(
req
,
res
)
=>
{
req
.
session
.
userid
=
null
;
req
.
session
.
name
=
null
;
req
.
session
.
personality
=
null
;
req
.
session
.
status
=
null
;
req
.
session
.
isAuthorized
=
null
;
console
.
log
(
"Logout"
);
res
.
sendStatus
(
200
);
}
})
module
.
exports
=
router
;
\ No newline at end of file
...
...
tunnel_BE/server/routes/main.js
View file @
13df9ad
...
...
@@ -9,7 +9,7 @@ router.get('/',auth,(req,res)=>{
//메인페이지
//테스트 코드
console
.
log
(
req
.
session
.
id
);
console
.
log
(
req
.
session
.
user
id
);
res
.
send
(
req
.
session
.
name
);
});
...
...
tunnel_BE/server/routes/post.js
0 → 100644
View file @
13df9ad
const
express
=
require
(
"express"
);
const
bodyParser
=
require
(
"body-parser"
);
const
router
=
express
.
Router
();
const
auth
=
require
(
"../obj/authorize"
);
const
{
User
}
=
require
(
'../models'
);
//유저정보 db연결
const
{
Post
}
=
require
(
'../models'
);
//게시물정보 db연결
//현재 로그인된 사용자의 게시물 배열 응답
router
.
get
(
'/'
,
auth
,(
req
,
res
)
=>
{
Post
.
findAll
({
where
:{
userid
:
req
.
session
.
name
}
})
.
then
((
result
)
=>
{
//게시물이 0개인 경우
if
(
result
===
null
||
result
===
undefined
){
console
.
log
(
"해당유저의 게시물이 없습니다."
)
res
.
status
(
401
).
send
(
"null"
);
}
else
{
console
.
log
(
result
.
length
);
res
.
sendStatus
(
200
);
}
})
});
//게시물 작성
router
.
post
(
'/'
,
auth
,(
req
,
res
)
=>
{
try
{
Post
.
create
({
userid
:
req
.
session
.
name
,
title
:
"프로트랑 맞추기"
,
post
:
"프론트랑 맞추기"
,
status
:
false
})
console
.
log
(
"게시"
);
res
.
sendStatus
(
200
);
}
catch
(
err
){
console
.
log
(
"실패"
);
res
.
send
(
err
);
}
/*
User.create({
name: req.body.Id,
pw:req.body.Password,
personality:req.body.Personality,
status:false
*/
});
module
.
exports
=
router
;
\ No newline at end of file
tunnel_BE/server/routes/user.js
0 → 100644
View file @
13df9ad
const
express
=
require
(
"express"
);
const
bodyParser
=
require
(
"body-parser"
);
const
router
=
express
.
Router
();
const
auth
=
require
(
"../obj/authorize"
);
//로그인 된 회원정보 반환
router
.
get
(
'/'
,
auth
,(
req
,
res
)
=>
{
res
.
status
(
200
).
json
({
Id
:
req
.
session
.
userid
,
Password
:
req
.
session
.
name
,
Personality
:
req
.
session
.
personality
,
Status
:
req
.
session
.
status
})
});
module
.
exports
=
router
;
\ No newline at end of file
tunnel_BE/server/server.js
View file @
13df9ad
...
...
@@ -16,6 +16,8 @@ const registerRouter = require('./routes/register.js');
const
mainRouter
=
require
(
'./routes/main.js'
);
const
logoutRouter
=
require
(
'./routes/logout.js'
);
const
authRouter
=
require
(
'./routes/auth.js'
);
const
userRouter
=
require
(
'./routes/user.js'
);
const
postRouter
=
require
(
'./routes/post.js'
);
const
app
=
express
();
app
.
set
(
'port'
,
process
.
env
.
PORT
||
3001
);
...
...
@@ -53,6 +55,8 @@ app.use('/api/login',loginRouter); //로그인 페이지
app
.
use
(
'/api/main'
,
mainRouter
);
//메인페이지
app
.
use
(
'/api/auth'
,
authRouter
);
//가입여부 확인
app
.
use
(
'/api/logout'
,
logoutRouter
);
//로그아웃
app
.
use
(
'/api/user'
,
userRouter
);
//유저정보 응답
app
.
use
(
'/api/post'
,
postRouter
);
//유저정보 응답
...
...
Please
register
or
login
to post a comment