Toggle navigation
Toggle navigation
This project
Loading...
Sign in
정성훈
/
MEALKHU
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
1
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
swa07016
2020-06-21 04:26:26 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
62f2df2e7906faaef6e5f8673938bc280ebda1db
62f2df2e
1 parent
1db9d8aa
'/api/mypicks' 유저 picks get api 구현
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
46 additions
and
75 deletions
client/src/components/MealCard.js
client/src/components/UserCards.js
client/src/pages/LandingPage.js
client/src/pages/MenuPage.js
server.js
client/src/components/MealCard.js
View file @
62f2df2
...
...
@@ -26,7 +26,6 @@ const MealCard = (props) => {
.
then
(
result
=>
{
if
(
result
.
message
===
'valid token'
)
{
return
fetch
(
'/api/pick'
,
{
method
:
'POST'
,
headers
:
{
...
...
@@ -39,9 +38,9 @@ const MealCard = (props) => {
}).
then
(
response
=>
response
.
json
())
.
then
(
result
=>
{
if
(
result
.
message
===
'insertion success'
)
{
alert
(
'
pick success
'
);
alert
(
'
MyPick에 담겼습니다.
'
);
}
else
if
(
result
.
message
===
'card exist'
)
{
alert
(
'이미
myp
ick에 존재합니다.'
);
alert
(
'이미
MyP
ick에 존재합니다.'
);
}
else
{
alert
(
'error'
);
}
...
...
client/src/components/UserCards.js
View file @
62f2df2
...
...
@@ -5,81 +5,35 @@ import axios from 'axios';
import
PickedCard
from
'../components/PickedCard'
;
const
UserCards
=
(
props
)
=>
{
const
[
datas
,
setDatas
]
=
useState
([]);
const
[
username
,
setUsername
]
=
useState
(
'User'
);
const
[
picks
,
setPicks
]
=
useState
([{
"id"
:
"1"
,
"name"
:
"#신슨즈(#Shinsons)"
,
"address"
:
"경기도 용인시 기흥구 서그내로15번길 34 (서천동)"
,
"latitude"
:
"37.2464876"
,
"longitude"
:
"127.0768072"
,
"type"
:
"호프"
,
"menu"
:
"칵테일, 술"
,
"img"
:
"/images/1_img.jpg"
,
"img_source"
:
"https://www.picuki.com/profile/shinsons"
},
{
"id"
:
"2"
,
"name"
:
"감쟈"
,
"address"
:
"경기도 용인시 기흥구 서그내로15번길 29, 102호 (서천동)"
,
"latitude"
:
"37.2464608"
,
"longitude"
:
"127.0764465"
,
"type"
:
"술집"
,
"menu"
:
"안주, 술"
,
"img"
:
"/images/2_img.jpg"
,
"img_source"
:
"https://www.facebook.com/gamjua/posts/1408798555882739/"
},
{
"id"
:
"3"
,
"name"
:
"깜냥"
,
"address"
:
"경기도 용인시 기흥구 서그내로15번길 29 (서천동,1층)"
,
"latitude"
:
"37.2464608"
,
"longitude"
:
"127.0764465"
,
"type"
:
"술집"
,
"menu"
:
"안주, 술"
,
"img"
:
"/images/3_img.jpg"
,
"img_source"
:
"https://www.facebook.com/ggamnyang316/"
},
{
"id"
:
"4"
,
"name"
:
"꼬꼬리아통닭"
,
"address"
:
"경기도 용인시 기흥구 서그내로15번길 39 (서천동)"
,
"latitude"
:
"37.2465772"
,
"longitude"
:
"127.0775286"
,
"type"
:
"호프"
,
"menu"
:
"치킨, 술"
,
"img"
:
"/images/4_img.jpg"
,
"img_source"
:
"https://bigsta.net/tag/%EA%BC%AC%EA%BC%AC%EB%A6%AC%EC%95%84/"
},
{
"id"
:
"5"
,
"name"
:
"도스마스수원경희대점"
,
"address"
:
"경기도 용인시 기흥구 서그내로15번길 33 (서천동, 서윤빌딩1층)"
,
"latitude"
:
"37.2467668"
,
"longitude"
:
"127.0768863"
,
"type"
:
"기타"
,
"menu"
:
"부리또, 타코"
,
"img"
:
"/images/5_img.jpg"
,
"img_source"
:
"https://blog.naver.com/alttium/221443978130"
}]);
const
[
picks
,
setPicks
]
=
useState
([]);
const
authApi
=
()
=>
{
const
user
=
JSON
.
parse
(
localStorage
.
getItem
(
'user'
));
return
fetch
(
'/api/mypicks'
,
{
method
:
'GET'
,
headers
:
{
'Content-Type'
:
'application/json'
,
'authorization'
:
user
}
}).
then
(
response
=>
response
.
json
())
.
then
(
result
=>
{
setPicks
(
result
.
datas
);
console
.
log
(
result
.
datas
);
}
);
}
useEffect
(()
=>
{
const
fetchData
=
async
()
=>
{
const
result
=
await
axios
(
'http://localhost:5000/api/datas'
,
// localhost로 바꾸기
);
setDatas
(
result
.
data
);
};
fetchData
();
setUsername
(
props
.
username
);
// setUsername(cookie.load('username'));
},
[
username
]);
setUsername
(
props
.
username
);
authApi
();
},
[
username
]);
const
LogoutHandler
=
(
e
)
=>
{
e
.
preventDefault
();
localStorage
.
removeItem
(
'user'
);
// cookie.remove('username');
props
.
isLogin
(
false
);
return
;
}
...
...
client/src/pages/LandingPage.js
View file @
62f2df2
...
...
@@ -27,7 +27,7 @@ const LandingPage = (props) => {
useEffect
(()
=>
{
const
fetchData
=
async
()
=>
{
const
result
=
await
axios
(
'
http://localhost:5000
/api/datas'
,
'/api/datas'
,
// localhost로 바꾸기
);
setDatas
(
result
.
data
);
...
...
client/src/pages/MenuPage.js
View file @
62f2df2
...
...
@@ -27,7 +27,7 @@ const MenuPage = (props) => {
useEffect
(()
=>
{
const
fetchData
=
async
()
=>
{
const
result
=
await
axios
(
'
http://localhost:5000
/api/datas'
,
'/api/datas'
,
// localhost로 바꾸기
);
setDatas
(
result
.
data
);
...
...
server.js
View file @
62f2df2
...
...
@@ -46,7 +46,6 @@ app.post("/api/signup", (req, res) => {
let
sql_usercheck
=
`SELECT * FROM USER WHERE name='
${
req
.
body
.
username
}
';`
;
connection
.
query
(
sql_usercheck
,
(
err
,
rows
,
fields
)
=>
{
console
.
log
(
rows
);
if
(
rows
.
length
!==
0
)
{
return
res
.
json
({
code
:
400
,
...
...
@@ -174,6 +173,26 @@ app.get('/api/auth', (req, res) => {
}
});
app
.
get
(
"/api/mypicks"
,
(
req
,
res
)
=>
{
let
result
=
[];
const
user
=
jwt_decode
(
req
.
headers
.
authorization
);
const
username
=
user
.
name
;
let
temp
=
iconv
.
decode
(
dataBuffer
,
"EUC-KR"
);
connection
.
query
(
`SELECT pick FROM USER WHERE NAME='
${
username
}
';`
,
(
err
,
rows
,
fileds
)
=>
{
let
user_picks
=
rows
[
0
].
pick
.
split
(
','
);
temp
=
JSON
.
parse
(
temp
);
user_picks
.
pop
();
for
(
let
i
=
0
;
i
<
user_picks
.
length
;
i
++
)
{
user_picks
[
i
]
=
parseInt
(
user_picks
[
i
]);
}
for
(
let
i
=
0
;
i
<
user_picks
.
length
;
i
++
)
{
result
.
push
(
temp
[
user_picks
[
i
]
-
1
]);
}
res
.
send
({
'datas'
:
result
});
})
});
app
.
post
(
'/api/pick'
,
(
req
,
res
)
=>
{
...
...
@@ -182,7 +201,6 @@ app.post('/api/pick', (req, res) => {
const
cardid
=
req
.
body
.
cardid
;
connection
.
query
(
`SELECT pick FROM USER WHERE NAME='
${
username
}
';`
,
(
err
,
rows
,
fileds
)
=>
{
console
.
log
(
rows
[
0
]);
if
(
rows
.
length
===
0
)
{
// ??
}
else
{
...
...
Please
register
or
login
to post a comment