Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
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
71aa5b17
Commit
71aa5b17
authored
2 years ago
by
Lee Soobeom
Browse files
Options
Download
Email Patches
Plain Diff
token user.id ref
parent
9fe5e544
main
MK28
MK29
sb0815
No related merge requests found
Changes
10
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
frontend/src/apis/post.api.ts
+3
-2
frontend/src/apis/post.api.ts
frontend/src/post/post.tsx
+1
-1
frontend/src/post/post.tsx
frontend/src/post/posting.tsx
+11
-5
frontend/src/post/posting.tsx
frontend/src/types/index.tsx
+4
-8
frontend/src/types/index.tsx
src/controllers/post.controller.ts
+16
-10
src/controllers/post.controller.ts
src/db/post.db.ts
+8
-9
src/db/post.db.ts
src/models/index.ts
+0
-1
src/models/index.ts
src/models/post.model.ts
+37
-14
src/models/post.model.ts
src/models/posting.model.ts
+0
-46
src/models/posting.model.ts
src/routes/post.route.ts
+1
-1
src/routes/post.route.ts
with
81 additions
and
97 deletions
+81
-97
frontend/src/apis/post.api.ts
View file @
71aa5b17
import
axios
from
"
axios
"
;
import
baseUrl
from
"
./baseUrl
"
;
import
{
Post
ing
Type
}
from
"
../types
"
;
import
{
PostType
}
from
"
../types
"
;
export
const
posting
=
async
(
post
:
Post
ing
Type
)
=>
{
export
const
posting
=
async
(
post
:
PostType
)
=>
{
const
{
data
}
=
await
axios
.
post
(
`
${
baseUrl
}
/posts/`
,
post
);
return
data
;
};
This diff is collapsed.
Click to expand it.
frontend/src/post/post.tsx
View file @
71aa5b17
...
...
@@ -10,7 +10,7 @@ export default function Post({ handleClick, post }: Props) {
return
(
<
div
className
=
"flex flex-row h-16 divide-x-2 border-2 border-solid"
>
<
div
className
=
"basis-full"
>
<
button
id
=
{
post
.
i
d
}
onClick
=
{
handleClick
}
>
<
button
id
=
{
post
.
userI
d
}
onClick
=
{
handleClick
}
>
{
post
.
title
}
</
button
>
</
div
>
...
...
This diff is collapsed.
Click to expand it.
frontend/src/post/posting.tsx
View file @
71aa5b17
import
React
,
{
FormEvent
,
useState
}
from
"
react
"
;
import
{
useNavigate
}
from
"
react-router-dom
"
;
import
isLength
from
"
validator/lib/isLength
"
;
import
equals
from
"
validator/lib/equals
"
;
// import { addDataList } from "../board/board";
import
{
catchErrors
}
from
"
../helpers
"
;
import
{
Post
ing
Type
}
from
"
../types
"
;
import
{
PostType
}
from
"
../types
"
;
import
{
postApi
}
from
"
../apis
"
;
export
default
function
Posting
()
{
...
...
@@ -10,13 +12,15 @@ export default function Posting() {
const
[
theme
,
setTheme
]
=
useState
<
string
>
(
"
질문종류
"
);
const
[
title
,
setTitle
]
=
useState
<
string
>
(
""
);
const
[
text
,
setText
]
=
useState
<
string
>
(
""
);
const
navigate
=
useNavigate
();
const
[
user
,
setUser
]
=
useState
<
Post
ing
Type
>
({
const
[
user
,
setUser
]
=
useState
<
PostType
>
({
title
:
""
,
text
:
""
,
theme
:
""
,
city
:
""
,
username
:
""
,
userId
:
""
,
counts
:
0
,
});
const
[
loading
,
setLoading
]
=
useState
(
false
);
...
...
@@ -32,8 +36,10 @@ export default function Posting() {
if
(
postingFormMatch
())
{
setLoading
(
true
);
const
res
=
await
postApi
.
posting
(
user
);
console
.
log
(
"
서버연결됬나요
"
,
res
);
console
.
log
(
"
user save
"
);
// addDataList(res);
// console.log("서버연결됬나요", res);
// console.log("user save");
navigate
(
"
/board
"
,
{
replace
:
true
});
setSuccess
(
true
);
setError
(
""
);
}
...
...
This diff is collapsed.
Click to expand it.
frontend/src/types/index.tsx
View file @
71aa5b17
...
...
@@ -9,18 +9,14 @@ export interface LoginUser {
password
:
string
;
}
export
interface
PostType
extends
PostingType
{
date
?:
string
;
counts
:
number
;
id
?:
string
;
}
export
interface
PostingType
{
export
interface
PostType
{
title
:
string
;
text
?:
string
;
theme
:
string
;
city
:
string
;
username
:
string
;
date
?:
string
;
counts
:
number
;
userId
:
string
;
}
export
interface
SignupUser
{
...
...
This diff is collapsed.
Click to expand it.
src/controllers/post.controller.ts
View file @
71aa5b17
import
{
NextFunction
,
Request
,
Response
}
from
"
express
"
;
import
isLength
from
"
validator/lib/isLength
"
;
import
equals
from
"
validator/lib/equals
"
;
import
{
requireLogin
}
from
"
./auth.controller
"
;
import
{
TypedRequestAuth
}
from
"
./auth.controller
"
;
import
{
asyncWrap
}
from
"
../helpers
"
;
import
{
postDb
}
from
"
../db
"
;
export
const
post
ing
=
asyncWrap
(
async
(
req
,
res
)
=>
{
const
{
title
,
text
,
theme
,
city
,
username
,
date
,
counts
}
=
req
.
body
;
export
const
post
Create
=
asyncWrap
(
async
(
req
Exp
,
res
,
next
)
=>
{
const
req
=
reqExp
as
TypedRequestAuth
<
{
userId
:
string
}
>
;
console
.
log
(
"
body
"
,
req
.
body
);
const
{
title
,
text
,
theme
,
city
,
date
}
=
req
.
body
as
{
title
:
string
;
text
:
string
;
theme
:
string
;
city
:
string
;
date
:
Date
;
};
// 0) 로그인 했는지 확인 requireLogin
console
.
log
(
"
body
"
,
req
.
body
);
// 1) title 빈 문자열인지 확인
if
(
!
isLength
(
title
??
""
,
{
min
:
1
}))
{
...
...
@@ -32,16 +38,16 @@ export const posting = asyncWrap(async (req, res) => {
return
res
.
status
(
422
).
send
(
"
도시를 선택해 주세요
"
);
}
// 5) username ref: cookie.token._id -> collection users, "User"-> name
const
userId
=
req
.
auth
.
userId
;
const
newPost
ing
=
await
postDb
.
createPost
ing
({
const
newPost
=
await
postDb
.
createPost
({
title
,
text
,
theme
,
city
,
username
,
date
,
counts
,
user
:
userId
,
});
return
res
.
json
(
newPosting
);
return
res
.
json
(
newPost
);
});
This diff is collapsed.
Click to expand it.
src/db/post.db.ts
View file @
71aa5b17
import
{
Posting
,
PostingType
}
from
"
../models
"
;
import
{
Post
,
PostType
}
from
"
../models
"
;
export
const
createPost
ing
=
async
(
post
ing
:
Post
ing
Type
)
=>
{
const
newPosting
=
await
Post
ing
.
create
({
title
:
post
ing
.
title
,
text
:
post
ing
.
text
,
theme
:
post
ing
.
theme
,
city
:
post
ing
.
city
,
user
name
:
post
ing
.
user
name
,
date
:
post
ing
.
date
,
export
const
createPost
=
async
(
post
:
PostType
)
=>
{
const
newPosting
=
await
Post
.
create
({
title
:
post
.
title
,
text
:
post
.
text
,
theme
:
post
.
theme
,
city
:
post
.
city
,
user
:
post
.
user
,
date
:
post
.
date
,
counts
:
0
,
});
return
newPosting
;
...
...
This diff is collapsed.
Click to expand it.
src/models/index.ts
View file @
71aa5b17
export
{
default
as
User
,
IUser
}
from
"
./user.model
"
;
export
{
default
as
Posting
,
PostingType
}
from
"
./posting.model
"
;
export
{
default
as
Post
,
PostType
}
from
"
./post.model
"
;
This diff is collapsed.
Click to expand it.
src/models/post.model.ts
View file @
71aa5b17
import
{
model
,
Schema
,
Types
}
from
"
mongoose
"
;
import
{
Posting
Type
}
from
"
.
/posting.model
"
;
import
{
Document
,
model
,
Schema
,
Types
}
from
"
mongoose
"
;
import
{
Posting
}
from
"
.
"
;
export
interface
PostType
extends
PostingType
{
date
?:
string
;
counts
:
number
;
id
?:
string
;
export
interface
PostType
{
title
:
string
;
text
?:
string
;
theme
:
string
;
city
:
string
;
user
?:
Types
.
ObjectId
|
string
;
date
?:
Date
;
counts
?:
number
;
}
const
postSchema
=
new
Schema
<
PostType
>
({
title
:
{
type
:
String
},
theme
:
{
type
:
String
},
city
:
{
type
:
String
},
username
:
{
type
:
String
},
date
:
{
type
:
String
},
counts
:
{
type
:
Number
},
const
PostSchema
=
new
Schema
<
PostType
>
({
title
:
{
type
:
String
,
required
:
true
,
},
text
:
{
type
:
String
,
required
:
true
,
},
theme
:
{
type
:
String
,
},
city
:
{
type
:
String
,
},
user
:
{
type
:
Schema
.
Types
.
ObjectId
,
ref
:
"
User
"
,
},
date
:
{
type
:
Date
,
default
:
Date
.
now
,
},
counts
:
{
type
:
Number
,
},
});
export
default
model
<
PostType
>
(
"
Post
"
,
p
ostSchema
);
export
default
model
<
PostType
>
(
"
Post
"
,
P
ostSchema
);
This diff is collapsed.
Click to expand it.
src/models/posting.model.ts
deleted
100644 → 0
View file @
9fe5e544
import
{
model
,
Schema
}
from
"
mongoose
"
;
export
interface
PostingType
{
title
:
string
;
text
?:
string
;
theme
:
string
;
city
:
string
;
username
?:
string
;
date
?:
string
;
counts
?:
number
;
}
const
postingSchema
=
new
Schema
<
PostingType
>
({
title
:
{
type
:
String
,
required
:
true
,
},
text
:
{
type
:
String
,
required
:
true
,
},
theme
:
{
type
:
String
,
},
city
:
{
type
:
String
,
},
username
:
{
type
:
String
,
// username: travelreport.users.findOne({id: cookie.token._id(Schema.Tpyes.ObjectId)}).name,
},
date
:
{
type
:
Date
,
default
:
Date
.
now
,
},
counts
:
{
type
:
Number
,
},
date
:
{
type
:
Date
,
dafault
:
Date
.
now
,
},
counts
:
0
,
});
export
default
model
<
PostingType
>
(
"
Posting
"
,
postingSchema
);
This diff is collapsed.
Click to expand it.
src/routes/post.route.ts
View file @
71aa5b17
...
...
@@ -3,6 +3,6 @@ import { postCtrl, authCtrl } from "../controllers";
const
router
=
express
.
Router
();
router
.
route
(
"
/
"
).
post
(
authCtrl
.
requireLogin
,
postCtrl
.
post
ing
);
router
.
route
(
"
/
"
).
post
(
authCtrl
.
requireLogin
,
postCtrl
.
post
Create
);
export
default
router
;
This diff is collapsed.
Click to expand it.
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
Menu
Projects
Groups
Snippets
Help