Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
students
travel
Commits
33e86a75
Commit
33e86a75
authored
Jul 21, 2022
by
Lee Soobeom
Browse files
update button
parent
deade4a1
Changes
6
Show whitespace changes
Inline
Side-by-side
frontend/src/App.tsx
View file @
33e86a75
...
@@ -27,9 +27,9 @@ export const App = () => {
...
@@ -27,9 +27,9 @@ export const App = () => {
}
}
/>
/>
<
Route
path
=
"board"
element
=
{
<
Board
/>
}
/>
<
Route
path
=
"board"
element
=
{
<
Board
/>
}
/>
<
Route
path
=
"post/:postId
/
"
element
=
{
<
IntoPost
/>
}
>
<
Route
path
=
"post/:postId"
element
=
{
<
IntoPost
/>
}
/
>
<
Route
path
=
"edit"
element
=
{
<
EditPost
/>
}
/>
<
Route
path
=
"edit"
element
=
{
<
EditPost
/>
}
/>
</
Route
>
{
/*
</Route>
*/
}
<
Route
<
Route
path
=
"profile"
path
=
"profile"
element
=
{
element
=
{
...
...
frontend/src/post/editpost.tsx
View file @
33e86a75
...
@@ -33,17 +33,18 @@ export function EditPost() {
...
@@ -33,17 +33,18 @@ export function EditPost() {
const
[
disabled
,
setDisabled
]
=
useState
(
false
);
const
[
disabled
,
setDisabled
]
=
useState
(
false
);
const
[
success
,
setSuccess
]
=
useState
(
false
);
const
[
success
,
setSuccess
]
=
useState
(
false
);
async
function
handlePost
Submit
(
event
:
FormEvent
)
{
async
function
reWrite
Submit
(
event
:
FormEvent
)
{
event
.
preventDefault
();
event
.
preventDefault
();
try
{
try
{
setError
(
""
);
setError
(
""
);
console
.
log
(
"
user data
"
,
user
);
console
.
log
(
"
user data
"
,
user
);
if
(
postingFormMatch
(
)
)
{
if
(
postingFormMatch
(
user
)
===
true
)
{
setLoading
(
true
);
setLoading
(
true
);
const
res
=
await
postApi
.
updating
(
user
);
const
res
=
await
postApi
.
updating
(
user
);
console
.
log
(
"
clear
"
,
res
);
navigate
(
"
/board
"
,
{
replace
:
true
});
navigate
(
"
/board
"
,
{
replace
:
true
});
setSuccess
(
true
);
setSuccess
(
true
);
setError
(
""
);
setError
(
""
);
...
@@ -56,17 +57,17 @@ export function EditPost() {
...
@@ -56,17 +57,17 @@ export function EditPost() {
}
}
}
}
function
postingFormMatch
()
{
function
postingFormMatch
(
user
:
PostType
)
{
if
(
!
isLength
(
user
.
title
??
""
,
{
min
:
1
}))
{
if
(
!
isLength
(
user
.
title
??
""
,
{
min
:
1
}))
{
setError
(
"
제목을 입력해 주세요.
"
);
setError
(
"
제목을 입력해 주세요.
"
);
return
false
;
return
false
;
}
else
if
(
!
isLength
(
user
.
text
??
""
,
{
min
:
1
}))
{
}
else
if
(
!
isLength
(
user
.
text
??
""
,
{
min
:
1
}))
{
setError
(
"
내용을 입력해 주세요.
"
);
setError
(
"
내용을 입력해 주세요.
"
);
return
false
;
return
false
;
}
else
if
(
equals
(
city
,
"
질문종류
"
))
{
}
else
if
(
equals
(
city
,
"
city
"
))
{
setError
(
"
테마를 선택해 주세요.
"
);
setError
(
"
테마를 선택해 주세요.
"
);
return
false
;
return
false
;
}
else
if
(
equals
(
theme
,
"
질문종류
"
))
{
}
else
if
(
equals
(
theme
,
"
theme
"
))
{
setError
(
"
도시를 선택해 주세요.
"
);
setError
(
"
도시를 선택해 주세요.
"
);
return
false
;
return
false
;
}
else
{
}
else
{
...
@@ -108,18 +109,17 @@ export function EditPost() {
...
@@ -108,18 +109,17 @@ export function EditPost() {
return
(
return
(
<
div
className
=
"flex flex-col border-3"
>
<
div
className
=
"flex flex-col border-3"
>
<
form
onSubmit
=
{
handlePost
Submit
}
className
=
"w-full items-center"
>
<
form
onSubmit
=
{
reWrite
Submit
}
className
=
"w-full items-center"
>
<
div
className
=
"flex flex-row relative"
>
<
div
className
=
"flex flex-row relative"
>
<
p
className
=
"basis-1/12 gap-x-8"
>
Id
</
p
>
<
p
className
=
"basis-1/12 gap-x-8"
>
Id
</
p
>
<
p
className
=
"basis-8/12 invisible"
>
empty
</
p
>
<
p
className
=
"basis-8/12 invisible"
>
empty
</
p
>
<
select
<
select
name
=
"city"
name
=
"city"
id
=
"Questions"
className
=
"border border-3 border-black w-1/12"
className
=
"border border-3 border-black w-1/12"
onChange
=
{
cityChange
}
onChange
=
{
cityChange
}
defaultValue
=
"질문종류"
defaultValue
=
{
post
.
city
}
>
>
<
option
value
=
"
질문종류
"
>
도시
</
option
>
<
option
value
=
"
city
"
>
도시
</
option
>
<
option
value
=
"Seoul"
>
서울
</
option
>
<
option
value
=
"Seoul"
>
서울
</
option
>
<
option
value
=
"Busan"
>
부산
</
option
>
<
option
value
=
"Busan"
>
부산
</
option
>
<
option
value
=
"Incheon"
>
인천
</
option
>
<
option
value
=
"Incheon"
>
인천
</
option
>
...
@@ -133,12 +133,11 @@ export function EditPost() {
...
@@ -133,12 +133,11 @@ export function EditPost() {
</
select
>
</
select
>
<
select
<
select
name
=
"theme"
name
=
"theme"
id
=
"Questions"
className
=
"border border-3 border-black w-1/12"
className
=
"border border-3 border-black w-1/12"
onChange
=
{
themeChange
}
onChange
=
{
themeChange
}
defaultValue
=
"질문종류"
defaultValue
=
{
post
.
theme
}
>
>
<
option
value
=
"
질문종류
"
>
테마
</
option
>
<
option
value
=
"
theme
"
>
테마
</
option
>
<
option
value
=
"cycling"
>
사이클링
</
option
>
<
option
value
=
"cycling"
>
사이클링
</
option
>
<
option
value
=
"surfing"
>
서핑
</
option
>
<
option
value
=
"surfing"
>
서핑
</
option
>
<
option
value
=
"activity"
>
액티비티
</
option
>
<
option
value
=
"activity"
>
액티비티
</
option
>
...
@@ -157,7 +156,7 @@ export function EditPost() {
...
@@ -157,7 +156,7 @@ export function EditPost() {
type
=
"submit"
type
=
"submit"
className
=
"border border-black basis-1/12 gap-x-8"
className
=
"border border-black basis-1/12 gap-x-8"
>
>
글쓰기
Rewrite
</
button
>
</
button
>
</
div
>
</
div
>
...
@@ -167,7 +166,9 @@ export function EditPost() {
...
@@ -167,7 +166,9 @@ export function EditPost() {
onChange
=
{
titleChange
}
onChange
=
{
titleChange
}
placeholder
=
"title"
placeholder
=
"title"
className
=
"w-full h-8"
className
=
"w-full h-8"
></
textarea
>
>
{
post
.
title
}
</
textarea
>
</
div
>
</
div
>
<
div
className
=
"flex border-2"
>
<
div
className
=
"flex border-2"
>
<
textarea
<
textarea
...
@@ -175,7 +176,9 @@ export function EditPost() {
...
@@ -175,7 +176,9 @@ export function EditPost() {
name
=
"text"
name
=
"text"
placeholder
=
"text"
placeholder
=
"text"
className
=
"w-full h-96"
className
=
"w-full h-96"
></
textarea
>
>
{
post
.
text
}
</
textarea
>
</
div
>
</
div
>
</
form
>
</
form
>
</
div
>
</
div
>
...
...
frontend/src/post/intopost.tsx
View file @
33e86a75
import
React
,
{
MouseEvent
}
from
"
react
"
;
import
React
,
{
MouseEvent
}
from
"
react
"
;
import
{
useLocation
,
useNavigate
,
Link
}
from
"
react-router-dom
"
;
import
{
useLocation
,
useNavigate
,
Link
,
Outlet
}
from
"
react-router-dom
"
;
import
{
postApi
}
from
"
../apis
"
;
import
{
postApi
}
from
"
../apis
"
;
import
{
PostType
}
from
"
../types
"
;
import
{
PostType
}
from
"
../types
"
;
...
@@ -21,6 +21,7 @@ export function IntoPost() {
...
@@ -21,6 +21,7 @@ export function IntoPost() {
};
};
return
(
return
(
<
div
>
<
div
>
<
div
>
<
div
>
<
div
>
<
div
className
=
"flex flex-row basis-8"
>
<
div
className
=
"flex flex-row basis-8"
>
...
@@ -30,7 +31,7 @@ export function IntoPost() {
...
@@ -30,7 +31,7 @@ export function IntoPost() {
</
button
>
</
button
>
</
div
>
</
div
>
<
div
className
=
"border-2 border-current rounded"
>
<
div
className
=
"border-2 border-current rounded"
>
<
Link
to
=
{
`/post/
${
post
.
_id
}
/edit
`
}
state
=
{
post
}
>
<
Link
to
=
"
/edit
"
state
=
{
post
}
>
<
button
>
update
</
button
>
<
button
>
update
</
button
>
</
Link
>
</
Link
>
</
div
>
</
div
>
...
@@ -58,7 +59,9 @@ export function IntoPost() {
...
@@ -58,7 +59,9 @@ export function IntoPost() {
</
div
>
</
div
>
</
div
>
</
div
>
</
div
>
</
div
>
<
div
className
=
"border-2 border-black rounded h-96"
>
{
post
.
text
}
</
div
>
<
div
className
=
"border-2 border-black rounded h-full"
>
{
post
.
text
}
</
div
>
</
div
>
{
/* <Outlet /> */
}
</
div
>
</
div
>
);
);
}
}
src/controllers/post.controller.ts
View file @
33e86a75
...
@@ -94,7 +94,7 @@ export const getOnePost = asyncWrap(async (req, res) => {
...
@@ -94,7 +94,7 @@ export const getOnePost = asyncWrap(async (req, res) => {
export
const
deleteOnePost
=
asyncWrap
(
async
(
req
,
res
)
=>
{
export
const
deleteOnePost
=
asyncWrap
(
async
(
req
,
res
)
=>
{
const
{
postId
}
=
req
.
params
;
const
{
postId
}
=
req
.
params
;
console
.
log
(
postId
);
//
console.log(postId);
const
deleteCount
=
await
postDb
.
deletePost
(
postId
);
const
deleteCount
=
await
postDb
.
deletePost
(
postId
);
return
res
.
json
(
deleteCount
);
return
res
.
json
(
deleteCount
);
...
...
src/db/post.db.ts
View file @
33e86a75
...
@@ -42,7 +42,15 @@ export const deletePost = async (_id: string) => {
...
@@ -42,7 +42,15 @@ export const deletePost = async (_id: string) => {
export
const
updateOnePost
=
async
(
post
:
PostType
,
_id
:
string
)
=>
{
export
const
updateOnePost
=
async
(
post
:
PostType
,
_id
:
string
)
=>
{
const
newPost
=
await
Post
.
findOneAndUpdate
(
const
newPost
=
await
Post
.
findOneAndUpdate
(
{
_id
:
_id
},
{
_id
:
_id
},
{
post
},
{
title
:
post
.
title
,
text
:
post
.
text
,
theme
:
post
.
theme
,
city
:
post
.
city
,
date
:
post
.
date
,
counts
:
post
.
counts
,
user
:
post
.
user
,
},
{
new
:
true
}
{
new
:
true
}
);
);
return
newPost
;
return
newPost
;
...
...
src/routes/post.route.ts
View file @
33e86a75
...
@@ -9,11 +9,9 @@ router.route("/").get(postCtrl.getAllPost);
...
@@ -9,11 +9,9 @@ router.route("/").get(postCtrl.getAllPost);
router
router
.
route
(
"
/:postId
"
)
.
route
(
"
/:postId
"
)
.
post
(
authCtrl
.
requireLogin
,
postCtrl
.
addCounts
)
.
post
(
authCtrl
.
requireLogin
,
postCtrl
.
addCounts
)
.
get
(
authCtrl
.
requireLogin
,
postCtrl
.
getOnePost
);
.
get
(
authCtrl
.
requireLogin
,
postCtrl
.
getOnePost
)
.
delete
(
authCtrl
.
requireLogin
,
postCtrl
.
deleteOnePost
)
// authenticate
router
.
route
(
"
/:postId
"
).
delete
(
authCtrl
.
requireLogin
,
postCtrl
.
deleteOnePost
);
// authenticate
.
put
(
authCtrl
.
requireLogin
,
postCtrl
.
updatePost
);
router
.
route
(
"
/:postId
"
).
put
(
authCtrl
.
requireLogin
,
postCtrl
.
updatePost
);
router
.
param
(
"
postId
"
,
postCtrl
.
userByPostId
);
router
.
param
(
"
postId
"
,
postCtrl
.
userByPostId
);
export
default
router
;
export
default
router
;
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