Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
students
travel
Commits
5135892d
Commit
5135892d
authored
Jul 27, 2022
by
Lee Soobeom
Browse files
debugging
parent
35f8698d
Changes
9
Hide whitespace changes
Inline
Side-by-side
frontend/src/board/board.tsx
View file @
5135892d
...
...
@@ -17,7 +17,7 @@ export default function BoardPage() {
const
location
=
useLocation
()
as
Newpost
;
const
newPost
=
location
.
state
;
//
console.log("get newPost Info", newPost);
console
.
log
(
"
get newPost Info
"
,
newPost
);
const
setNewPosts
=
(
newpost
:
PostType
)
=>
{
const
postArr
=
posts
?.
splice
(
-
1
,
0
,
newPost
);
...
...
frontend/src/post/editpost.tsx
View file @
5135892d
import
React
,
{
FormEvent
,
useState
}
from
"
react
"
;
import
{
useNavigate
,
useLocation
}
from
"
react-router-dom
"
;
import
React
,
{
FormEvent
,
MouseEventHandler
,
useState
}
from
"
react
"
;
import
{
useNavigate
,
useLocation
,
Link
}
from
"
react-router-dom
"
;
import
isLength
from
"
validator/lib/isLength
"
;
import
equals
from
"
validator/lib/equals
"
;
import
{
catchErrors
}
from
"
../helpers
"
;
...
...
@@ -65,8 +65,8 @@ export function EditPost() {
if
(
postingFormMatch
(
user
)
===
true
)
{
setLoading
(
true
);
const
res
=
updateImg2Db
(
file
);
navigate
(
"
/board
"
,
{
replace
:
true
});
const
updateRes
=
await
updateImg2Db
(
file
);
navigate
(
"
/board
"
,
{
replace
:
true
,
state
:
updateRes
});
setSuccess
(
true
);
setError
(
""
);
...
...
@@ -164,6 +164,12 @@ export function EditPost() {
setUser
(
newUser
);
};
const
GoBack
=
()
=>
{
if
(
confirm
(
"
취소하시겠습니까?
"
)
==
true
)
{
navigate
(
-
1
);
}
};
const
oldFileShow
=
(
post
:
PostType
)
=>
{
const
res
=
post
.
file
?.
map
((
file
,
i
)
=>
(
<
img
...
...
@@ -185,90 +191,100 @@ export function EditPost() {
};
return
(
<
form
onSubmit
=
{
reWriteSubmit
}
className
=
"flex flex-col w-full"
>
<
div
className
=
"flex flex-row h-10 gap-x-1 justify-end"
>
<
div
className
=
"place-self-center w-16 h-6 border-2 border-sky-400 transition delay-150 bg-white-400 hover:-translate-y-1 hover:scale-110 hover:bg-gray-300 duration-300"
>
<
input
id
=
"files"
type
=
"file"
multiple
onChange
=
{
handleInputPic
}
className
=
"hidden"
/>
<
label
htmlFor
=
"files"
className
=
"text-xs grid place-items-center"
>
파일 선택
</
label
>
</
div
>
<
div
>
<
form
onSubmit
=
{
reWriteSubmit
}
className
=
"flex flex-col w-full"
>
<
div
className
=
"flex flex-row h-10 gap-x-1 justify-end"
>
<
div
className
=
"place-self-center w-16 h-6 border-2 border-sky-400 transition delay-150 bg-white-400 hover:-translate-y-1 hover:scale-110 hover:bg-gray-300 duration-300"
>
<
input
id
=
"files"
type
=
"file"
multiple
onChange
=
{
handleInputPic
}
className
=
"hidden"
/>
<
label
htmlFor
=
"files"
className
=
"text-xs grid place-items-center"
>
파일 선택
</
label
>
</
div
>
<
select
name
=
"city"
className
=
"border-2 border-sky-400 text-xs h-6 place-self-center"
onChange
=
{
cityChange
}
defaultValue
=
{
post
.
city
}
>
<
option
value
=
"city"
>
도시
</
option
>
<
option
value
=
"Seoul"
>
서울
</
option
>
<
option
value
=
"Busan"
>
부산
</
option
>
<
option
value
=
"Incheon"
>
인천
</
option
>
<
option
value
=
"Daegu"
>
대구
</
option
>
<
option
value
=
"Gwangju"
>
광주
</
option
>
<
option
value
=
"Daejeon"
>
대전
</
option
>
<
option
value
=
"Woolsan"
>
울산
</
option
>
<
option
value
=
"Sejong"
>
세종
</
option
>
<
option
value
=
"Dokdo"
>
독도
</
option
>
<
option
value
=
"Jeju"
>
제주
</
option
>
</
select
>
<
select
name
=
"city"
className
=
"border-2 border-sky-400 text-xs h-6 place-self-center"
onChange
=
{
cityChange
}
defaultValue
=
{
post
.
city
}
>
<
option
value
=
"city"
>
도시
</
option
>
<
option
value
=
"Seoul"
>
서울
</
option
>
<
option
value
=
"Busan"
>
부산
</
option
>
<
option
value
=
"Incheon"
>
인천
</
option
>
<
option
value
=
"Daegu"
>
대구
</
option
>
<
option
value
=
"Gwangju"
>
광주
</
option
>
<
option
value
=
"Daejeon"
>
대전
</
option
>
<
option
value
=
"Woolsan"
>
울산
</
option
>
<
option
value
=
"Sejong"
>
세종
</
option
>
<
option
value
=
"Dokdo"
>
독도
</
option
>
<
option
value
=
"Jeju"
>
제주
</
option
>
</
select
>
<
select
name
=
"theme"
className
=
"border-2 border-sky-400 text-xs h-6 place-self-center"
onChange
=
{
themeChange
}
defaultValue
=
{
post
.
theme
}
>
<
option
value
=
"theme"
>
테마
</
option
>
<
option
value
=
"cycling"
>
사이클링
</
option
>
<
option
value
=
"surfing"
>
서핑
</
option
>
<
option
value
=
"activity"
>
액티비티
</
option
>
<
option
value
=
"camping"
>
캠핑
</
option
>
<
option
value
=
"sking"
>
스키
</
option
>
<
option
value
=
"boat"
>
보트
</
option
>
<
option
value
=
"desert"
>
사막
</
option
>
<
option
value
=
"golf"
>
골프
</
option
>
<
option
value
=
"cave"
>
동굴
</
option
>
<
option
value
=
"history"
>
문화재
</
option
>
<
option
value
=
"zoo"
>
동물원
</
option
>
<
option
value
=
"cycling"
>
사이클링
</
option
>
</
select
>
<
select
name
=
"theme"
className
=
"border-2 border-sky-400 text-xs h-6 place-self-center"
onChange
=
{
themeChange
}
defaultValue
=
{
post
.
theme
}
>
<
option
value
=
"theme"
>
테마
</
option
>
<
option
value
=
"cycling"
>
사이클링
</
option
>
<
option
value
=
"surfing"
>
서핑
</
option
>
<
option
value
=
"activity"
>
액티비티
</
option
>
<
option
value
=
"camping"
>
캠핑
</
option
>
<
option
value
=
"sking"
>
스키
</
option
>
<
option
value
=
"boat"
>
보트
</
option
>
<
option
value
=
"desert"
>
사막
</
option
>
<
option
value
=
"golf"
>
골프
</
option
>
<
option
value
=
"cave"
>
동굴
</
option
>
<
option
value
=
"history"
>
문화재
</
option
>
<
option
value
=
"zoo"
>
동물원
</
option
>
<
option
value
=
"cycling"
>
사이클링
</
option
>
</
select
>
<
button
type
=
"submit"
className
=
"h-6 w-10 place-self-center place-self-center border-2 border-sky-400 text-xs text-center transition delay-150 bg-white-400 hover:-translate-y-1 hover:scale-110 hover:bg-sky-300 duration-300"
>
수정
</
button
>
</
div
>
<
button
type
=
"submit"
className
=
"h-6 w-10 place-self-center place-self-center border-2 border-sky-400 text-xs text-center transition delay-150 bg-white-400 hover:-translate-y-1 hover:scale-110 hover:bg-sky-300 duration-300"
>
수정
</
button
>
</
div
>
<
div
className
=
"flex flex-col w-full border-y-2 border-sky-500"
>
<
textarea
defaultValue
=
{
post
.
title
}
name
=
"title"
onChange
=
{
titleChange
}
placeholder
=
"제목을 입력해 주세요!"
className
=
"flex focus:outline-none"
/>
<
div
className
=
"flex flex-col mt-1 mb-1 border-t-2 border-sky-200"
>
<
div
className
=
"flex gap-x-2 h-44 overflow-x-auto "
>
{
change
?
newFileShow
(
imgSrc
)
:
oldFileShow
(
post
)
}
<
div
className
=
"flex flex-col w-full border-y-2 border-sky-500"
>
<
textarea
defaultValue
=
{
post
.
title
}
name
=
"title"
onChange
=
{
titleChange
}
placeholder
=
"제목을 입력해 주세요!"
className
=
"flex focus:outline-none"
/>
<
div
className
=
"flex flex-col mt-1 mb-1 border-t-2 border-sky-200"
>
<
div
className
=
"flex gap-x-2 h-44 overflow-x-auto "
>
{
change
?
newFileShow
(
imgSrc
)
:
oldFileShow
(
post
)
}
</
div
>
</
div
>
<
textarea
defaultValue
=
{
post
.
text
}
onChange
=
{
textChange
}
name
=
"text"
placeholder
=
"여행 후기를 알려주세요!"
className
=
"flex h-44 border-t-2 border-sky-200 focus:outline-none "
/>
</
div
>
<
textarea
defaultValue
=
{
post
.
text
}
onChange
=
{
textChange
}
name
=
"text"
placeholder
=
"여행 후기를 알려주세요!"
className
=
"flex h-44 border-t-2 border-sky-200 focus:outline-none "
/>
</
form
>
<
div
className
=
"flex md:mb-20 justify-center"
>
<
button
onClick
=
{
GoBack
}
className
=
" mt-5 h-12 w-40 text-lg border-2 border-sky-500 place-self-center"
>
취소
</
button
>
</
div
>
</
form
>
</
div
>
);
}
frontend/src/post/intopost.tsx
View file @
5135892d
...
...
@@ -13,6 +13,8 @@ export function IntoPost() {
const
post
=
location
.
state
;
const
navigate
=
useNavigate
();
console
.
log
(
"
user info
"
,
post
.
user
);
const
[
loading
,
setLoading
]
=
useState
(
false
);
const
[
error
,
setError
]
=
useState
(
""
);
const
[
addSuccess
,
setAddSuccess
]
=
useState
(
false
);
...
...
@@ -56,7 +58,7 @@ export function IntoPost() {
<
div
className
=
"flex h-10 items-center border-t-2 border-sky-200 md:flex-row justify-between bg-slate-50 text-sm"
>
<
div
className
=
"flex whitespace-nowrap pr-5 "
>
작성자:
{
post
.
user
.
slice
(
0
,
8
)
}
작성자:
{
post
.
user
.
name
}
</
div
>
<
div
className
=
"flex divide-x divide-slate-300 "
>
...
...
frontend/src/post/posting.tsx
View file @
5135892d
import
React
,
{
FormEvent
,
useEffect
,
useState
}
from
"
react
"
;
import
{
useNavigate
}
from
"
react-router-dom
"
;
import
{
useNavigate
,
Link
}
from
"
react-router-dom
"
;
import
isLength
from
"
validator/lib/isLength
"
;
import
equals
from
"
validator/lib/equals
"
;
import
{
catchErrors
}
from
"
../helpers
"
;
...
...
@@ -21,11 +21,15 @@ export default function Posting() {
theme
:
""
,
city
:
""
,
date
:
""
,
user
:
""
,
user
:
{
_id
:
""
,
name
:
""
,
},
counts
:
0
,
_id
:
""
,
file
:
[
{
_id
:
""
,
originalfilename
:
""
,
newfilename
:
""
,
picturepath
:
""
,
...
...
@@ -69,12 +73,10 @@ export default function Posting() {
try
{
if
(
confirm
(
"
게시물을 작성하시겠습니까?
"
)
==
true
)
{
setError
(
""
);
// console.log("user data", user);
if
(
postingFormMatch
(
user
,
file
))
{
setLoading
(
true
);
if
(
file
)
{
const
postRes
=
await
sendImg2Db
(
file
);
// console.log("Newpost Info", postRes);
navigate
(
"
/board
"
,
{
replace
:
true
,
state
:
postRes
});
}
setSuccess
(
true
);
...
...
@@ -174,91 +176,107 @@ export default function Posting() {
}
};
const
GoBack
=
()
=>
{
if
(
confirm
(
"
취소하시겠습니까?
"
)
==
true
)
{
navigate
(
-
1
);
}
};
return
(
<
form
onSubmit
=
{
handlePostSubmit
}
className
=
"flex flex-col w-full"
>
<
div
className
=
"flex flex-row gap-x-1 justify-end h-10 "
>
<
div
className
=
"place-self-center w-16 h-6 border-2 border-sky-400 transition delay-150 bg-white-400 hover:-translate-y-1 hover:scale-110 hover:bg-gray-300 duration-300"
>
<
input
id
=
"files"
type
=
"file"
multiple
onChange
=
{
handleInputPic
}
className
=
"hidden"
/>
<
label
htmlFor
=
"files"
className
=
"text-xs grid place-items-center"
>
파일 선택
</
label
>
</
div
>
<
div
>
<
form
onSubmit
=
{
handlePostSubmit
}
className
=
"flex flex-col w-full"
>
<
div
className
=
"flex flex-row gap-x-1 justify-end h-10 "
>
<
div
className
=
"place-self-center w-16 h-6 border-2 border-sky-400 transition delay-150 bg-white-400 hover:-translate-y-1 hover:scale-110 hover:bg-gray-300 duration-300"
>
<
input
id
=
"files"
type
=
"file"
multiple
onChange
=
{
handleInputPic
}
className
=
"hidden"
/>
<
label
htmlFor
=
"files"
className
=
"text-xs grid place-items-center"
>
파일 선택
</
label
>
</
div
>
<
select
name
=
"city"
className
=
"border-2 border-sky-400 text-xs h-6 place-self-center"
onChange
=
{
cityChange
}
defaultValue
=
"질문종류"
>
<
option
value
=
"질문종류"
>
도시
</
option
>
<
option
value
=
"Seoul"
>
서울
</
option
>
<
option
value
=
"Busan"
>
부산
</
option
>
<
option
value
=
"Incheon"
>
인천
</
option
>
<
option
value
=
"Daegu"
>
대구
</
option
>
<
option
value
=
"Gwangju"
>
광주
</
option
>
<
option
value
=
"Daejeon"
>
대전
</
option
>
<
option
value
=
"Woolsan"
>
울산
</
option
>
<
option
value
=
"Sejong"
>
세종
</
option
>
<
option
value
=
"Dokdo"
>
독도
</
option
>
<
option
value
=
"Jeju"
>
제주
</
option
>
</
select
>
<
select
name
=
"city"
className
=
"border-2 border-sky-400 text-xs h-6 place-self-center"
onChange
=
{
cityChange
}
defaultValue
=
"질문종류"
>
<
option
value
=
"질문종류"
>
도시
</
option
>
<
option
value
=
"Seoul"
>
서울
</
option
>
<
option
value
=
"Busan"
>
부산
</
option
>
<
option
value
=
"Incheon"
>
인천
</
option
>
<
option
value
=
"Daegu"
>
대구
</
option
>
<
option
value
=
"Gwangju"
>
광주
</
option
>
<
option
value
=
"Daejeon"
>
대전
</
option
>
<
option
value
=
"Woolsan"
>
울산
</
option
>
<
option
value
=
"Sejong"
>
세종
</
option
>
<
option
value
=
"Dokdo"
>
독도
</
option
>
<
option
value
=
"Jeju"
>
제주
</
option
>
</
select
>
<
select
name
=
"theme"
className
=
"border-2 border-sky-400 text-xs h-6 place-self-center"
onChange
=
{
themeChange
}
defaultValue
=
"질문종류"
>
<
option
value
=
"질문종류"
>
테마
</
option
>
<
option
value
=
"cycling"
>
사이클링
</
option
>
<
option
value
=
"surfing"
>
서핑
</
option
>
<
option
value
=
"activity"
>
액티비티
</
option
>
<
option
value
=
"camping"
>
캠핑
</
option
>
<
option
value
=
"sking"
>
스키
</
option
>
<
option
value
=
"boat"
>
보트
</
option
>
<
option
value
=
"desert"
>
사막
</
option
>
<
option
value
=
"golf"
>
골프
</
option
>
<
option
value
=
"cave"
>
동굴
</
option
>
<
option
value
=
"history"
>
문화재
</
option
>
<
option
value
=
"zoo"
>
동물원
</
option
>
<
option
value
=
"cycling"
>
사이클링
</
option
>
</
select
>
<
select
name
=
"theme"
className
=
"border-2 border-sky-400 text-xs h-6 place-self-center"
onChange
=
{
themeChange
}
defaultValue
=
"질문종류"
>
<
option
value
=
"질문종류"
>
테마
</
option
>
<
option
value
=
"cycling"
>
사이클링
</
option
>
<
option
value
=
"surfing"
>
서핑
</
option
>
<
option
value
=
"activity"
>
액티비티
</
option
>
<
option
value
=
"camping"
>
캠핑
</
option
>
<
option
value
=
"sking"
>
스키
</
option
>
<
option
value
=
"boat"
>
보트
</
option
>
<
option
value
=
"desert"
>
사막
</
option
>
<
option
value
=
"golf"
>
골프
</
option
>
<
option
value
=
"cave"
>
동굴
</
option
>
<
option
value
=
"history"
>
문화재
</
option
>
<
option
value
=
"zoo"
>
동물원
</
option
>
<
option
value
=
"cycling"
>
사이클링
</
option
>
</
select
>
<
button
type
=
"submit"
className
=
"h-6 place-self-center place-self-center border-2 border-sky-400 text-xs text-center transition ease-in-out delay-150 bg-white-400 hover:-translate-y-1 hover:scale-110 hover:bg-sky-300 duration-300"
>
글쓰기
</
button
>
</
div
>
<
button
type
=
"submit"
className
=
"h-6 place-self-center place-self-center border-2 border-sky-400 text-xs text-center transition ease-in-out delay-150 bg-white-400 hover:-translate-y-1 hover:scale-110 hover:bg-sky-300 duration-300"
>
글쓰기
</
button
>
</
div
>
<
div
className
=
"flex flex-col w-full border-y-2 border-sky-500"
>
<
textarea
name
=
"title"
onChange
=
{
titleChange
}
placeholder
=
"제목을 입력해 주세요!"
className
=
"flex focus:outline-none"
/>
<
div
className
=
"flex flex-col mt-1 mb-1 border-t-2 border-sky-200"
>
<
div
className
=
"flex gap-x-2 h-44 overflow-x-auto"
>
{
imgSrc
?.
map
((
img
,
i
)
=>
(
<
img
key
=
{
i
}
src
=
{
img
}
width
=
{
200
}
height
=
{
200
}
/>
))
}
<
div
className
=
"flex flex-col w-full border-y-2 border-sky-500"
>
<
textarea
name
=
"title"
onChange
=
{
titleChange
}
placeholder
=
"제목을 입력해 주세요!"
className
=
"flex focus:outline-none"
/>
<
div
className
=
"flex flex-col mt-1 mb-1 border-t-2 border-sky-200"
>
<
div
className
=
"flex gap-x-2 h-44 overflow-x-auto"
>
{
imgSrc
?.
map
((
img
,
i
)
=>
(
<
img
key
=
{
i
}
src
=
{
img
}
width
=
{
200
}
height
=
{
200
}
/>
))
}
</
div
>
</
div
>
<
textarea
onChange
=
{
textChange
}
name
=
"text"
placeholder
=
"여행 후기를 알려주세요!"
className
=
"flex h-44 border-t-2 border-sky-200 focus:outline-none "
/>
</
div
>
<
textarea
onChange
=
{
textChange
}
name
=
"text"
placeholder
=
"여행 후기를 알려주세요!"
className
=
"flex h-44 border-t-2 border-sky-200 focus:outline-none "
/>
</
form
>
<
div
className
=
"flex md:mb-20 justify-center"
>
<
button
onClick
=
{
GoBack
}
className
=
" mt-5 h-12 w-40 text-lg border-2 border-sky-500 place-self-center"
>
취소
</
button
>
</
div
>
</
form
>
</
div
>
);
}
frontend/src/types/index.tsx
View file @
5135892d
...
...
@@ -20,9 +20,13 @@ export interface PostType {
date
:
string
;
counts
:
number
;
_id
:
string
;
user
:
string
;
user
:
{
_id
:
string
;
name
:
string
;
};
file
:
[
{
_id
:
string
;
originalfilename
:
string
;
newfilename
:
string
;
picturepath
:
string
;
...
...
src/controllers/auth.controller.ts
View file @
5135892d
...
...
@@ -22,6 +22,7 @@ export const authenticate = asyncWrap(
if
(
req
.
auth
)
{
const
{
userId
}
=
req
.
auth
;
const
user
=
req
.
user
;
// const adminId =
if
(
user
&&
user
.
id
===
userId
)
{
return
next
();
}
else
{
...
...
src/controllers/post.controller.ts
View file @
5135892d
...
...
@@ -18,7 +18,7 @@ export const userByPostId = (
next
();
};
export
const
s
ubTract
=
(
oldSet
:
Set
<
string
>
,
newSet
:
Set
<
string
>
)
=>
{
export
const
S
ubTract
=
(
oldSet
:
Set
<
string
>
,
newSet
:
Set
<
string
>
)
=>
{
const
keep
=
new
Array
<
string
>
();
//유지
const
drop
=
new
Array
<
string
>
();
//삭제
const
add
=
new
Array
<
string
>
();
//추가
...
...
@@ -234,7 +234,7 @@ export const updateOnePost = asyncWrap(async (reqExp, res) => {
console
.
log
(
"
NewSet
"
,
newSet
);
//유지, 삭제, 추가 구분하기
const
trdPart
=
s
ubTract
(
oldSet
,
newSet
);
const
trdPart
=
S
ubTract
(
oldSet
,
newSet
);
console
.
log
(
"
keep
"
,
trdPart
.
keep
);
console
.
log
(
"
drop
"
,
trdPart
.
drop
);
...
...
@@ -294,7 +294,7 @@ export const updateOnePost = asyncWrap(async (reqExp, res) => {
console
.
log
(
"
NewSet
"
,
newSet
);
//유지, 삭제, 추가 구분하기
const
trdPart
=
s
ubTract
(
oldSet
,
newSet
);
const
trdPart
=
S
ubTract
(
oldSet
,
newSet
);
//삭제
for
(
var
i
=
0
;
i
<
trdPart
.
drop
.
length
;
i
++
)
{
...
...
src/db/post.db.ts
View file @
5135892d
...
...
@@ -34,8 +34,11 @@ export const createFilesRow = async (
//Read
export
const
getPosts
=
async
()
=>
{
const
posts
=
await
Post
.
find
().
populate
(
"
file
"
).
sort
({
date
:
-
1
});
console
.
log
(
posts
);
const
posts
=
await
Post
.
find
()
.
populate
(
"
file
"
)
.
populate
(
"
user
"
)
.
sort
({
date
:
-
1
});
console
.
log
(
"
file nickname
"
,
posts
);
return
posts
;
};
...
...
src/models/fileinfo.model.ts
View file @
5135892d
...
...
@@ -4,13 +4,11 @@ export interface IFileInfo {
originalfilename
:
string
;
newfilename
:
string
;
picturepath
:
string
;
nickname
?:
string
;
}
const
schema
=
new
Schema
<
IFileInfo
>
({
originalfilename
:
{
type
:
String
,
unique
:
true
},
newfilename
:
{
type
:
String
},
nickname
:
{
type
:
String
},
picturepath
:
{
type
:
String
},
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment