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
8fb026f5
Commit
8fb026f5
authored
Jul 23, 2022
by
Kim, MinGyu
Browse files
Avatar -> fileInfo
parent
0be923a8
Changes
16
Show whitespace changes
Inline
Side-by-side
frontend/src/App.tsx
View file @
8fb026f5
...
@@ -2,15 +2,7 @@ import React from "react";
...
@@ -2,15 +2,7 @@ import React from "react";
import
{
BrowserRouter
,
Route
,
Routes
}
from
"
react-router-dom
"
;
import
{
BrowserRouter
,
Route
,
Routes
}
from
"
react-router-dom
"
;
import
"
tailwindcss/tailwind.css
"
;
import
"
tailwindcss/tailwind.css
"
;
import
{
IntoPost
}
from
"
./post/intopost
"
;
import
{
IntoPost
}
from
"
./post/intopost
"
;
import
{
import
{
Login
,
Profile
,
RequireAuth
,
Signup
,
Admin
,
ImgRewrite
}
from
"
./auth
"
;
Login
,
Profile
,
RequireAuth
,
Signup
,
Admin
,
ImgRewrite
,
Search
,
}
from
"
./auth
"
;
import
{
Header
,
Body
}
from
"
./home
"
;
import
{
Header
,
Body
}
from
"
./home
"
;
import
{
Board
}
from
"
./board
"
;
import
{
Board
}
from
"
./board
"
;
import
Posting
from
"
./post/posting
"
;
import
Posting
from
"
./post/posting
"
;
...
@@ -37,7 +29,6 @@ export const App = () => {
...
@@ -37,7 +29,6 @@ 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
path
=
"profile"
path
=
"profile"
element
=
{
element
=
{
...
@@ -48,7 +39,6 @@ export const App = () => {
...
@@ -48,7 +39,6 @@ export const App = () => {
/>
/>
<
Route
path
=
"admin"
element
=
{
<
Admin
/>
}
/>
<
Route
path
=
"admin"
element
=
{
<
Admin
/>
}
/>
<
Route
path
=
"rewrite"
element
=
{
<
ImgRewrite
/>
}
/>
<
Route
path
=
"rewrite"
element
=
{
<
ImgRewrite
/>
}
/>
<
Route
path
=
"search"
element
=
{
<
Search
/>
}
/>
</
Route
>
</
Route
>
</
Route
>
</
Route
>
</
Routes
>
</
Routes
>
...
...
frontend/src/auth/RequireAuth.tsx
View file @
8fb026f5
...
@@ -7,9 +7,7 @@ export const RequireAuth: FC<{ children: JSX.Element }> = ({ children }) => {
...
@@ -7,9 +7,7 @@ export const RequireAuth: FC<{ children: JSX.Element }> = ({ children }) => {
const
location
=
useLocation
();
const
location
=
useLocation
();
if
(
!
user
.
isLoggedIn
)
{
if
(
!
user
.
isLoggedIn
)
{
return
(
return
<
Navigate
to
=
{
"
/
"
}
state
=
{
{
from
:
location
.
pathname
}
}
replace
/>;
<
Navigate
to
=
{
"
/login
"
}
state
=
{
{
from
:
location
.
pathname
}
}
replace
/>
);
}
}
return
children
;
return
children
;
};
};
frontend/src/auth/admin.tsx
View file @
8fb026f5
import
React
,
{
FormEvent
,
useEffect
,
useState
,
MouseEvent
}
from
"
react
"
;
import
React
,
{
FormEvent
,
useEffect
,
useState
,
MouseEvent
}
from
"
react
"
;
import
{
Link
}
from
"
react-router-dom
"
;
import
{
Link
}
from
"
react-router-dom
"
;
import
{
mainimgApi
}
from
"
../apis
"
;
import
{
mainimgApi
}
from
"
../apis
"
;
import
{
p
icture
}
from
"
../apis/profile.api
"
;
import
{
p
rofileUpload
}
from
"
../apis/profile.api
"
;
import
{
catchErrors
}
from
"
../helpers
"
;
import
{
catchErrors
}
from
"
../helpers
"
;
import
{
MainimgType
}
from
"
../types
"
;
import
{
MainimgType
}
from
"
../types
"
;
import
{
MySlide
}
from
"
./adminslide
"
;
import
{
MySlide
}
from
"
./adminslide
"
;
...
...
frontend/src/auth/index.tsx
View file @
8fb026f5
...
@@ -4,4 +4,3 @@ export { default as Profile } from "./profile";
...
@@ -4,4 +4,3 @@ export { default as Profile } from "./profile";
export
{
RequireAuth
}
from
"
./RequireAuth
"
;
export
{
RequireAuth
}
from
"
./RequireAuth
"
;
export
{
default
as
Admin
}
from
"
./admin
"
;
export
{
default
as
Admin
}
from
"
./admin
"
;
export
{
default
as
ImgRewrite
}
from
"
./imgrewrite
"
;
export
{
default
as
ImgRewrite
}
from
"
./imgrewrite
"
;
export
{
default
as
Search
}
from
"
./search
"
;
frontend/src/auth/search.tsx
deleted
100644 → 0
View file @
0be923a8
import
React
from
"
react
"
;
import
{
useLocation
}
from
"
react-router-dom
"
;
export
default
function
Search
()
{
const
a
=
useLocation
().
state
;
return
(
<
div
>
<
div
></
div
>
</
div
>
);
}
frontend/src/types/index.tsx
View file @
8fb026f5
...
@@ -31,7 +31,7 @@ export interface SignupUser {
...
@@ -31,7 +31,7 @@ export interface SignupUser {
export
interface
Profile
{
export
interface
Profile
{
_id
:
string
;
_id
:
string
;
email
:
string
;
email
:
string
;
avatar
:
{
fileInfo
:
{
originalfilename
:
string
;
originalfilename
:
string
;
newfilename
:
string
;
newfilename
:
string
;
picturepath
:
string
;
picturepath
:
string
;
...
...
src/app.ts
View file @
8fb026f5
...
@@ -12,7 +12,6 @@ app.use(cookieParser());
...
@@ -12,7 +12,6 @@ app.use(cookieParser());
app
.
use
(
"
/api
"
,
router
);
app
.
use
(
"
/api
"
,
router
);
app
.
use
(
"
/images
"
,
express
.
static
(
path
.
join
(
__dirname
,
"
..
"
,
"
/uploads
"
)));
app
.
use
(
"
/images
"
,
express
.
static
(
path
.
join
(
__dirname
,
"
..
"
,
"
/uploads
"
)));
app
.
use
(
"
/images
"
,
express
.
static
(
path
.
join
(
__dirname
,
"
..
"
,
"
/adminpics
"
)));
app
.
use
((
err
:
any
,
req
:
Request
,
res
:
Response
,
next
:
NextFunction
)
=>
{
app
.
use
((
err
:
any
,
req
:
Request
,
res
:
Response
,
next
:
NextFunction
)
=>
{
console
.
log
(
"
익스프레스 에러:
"
,
err
);
console
.
log
(
"
익스프레스 에러:
"
,
err
);
...
...
src/controllers/fileinfo.controller.ts
0 → 100644
View file @
8fb026f5
import
formidable
from
"
formidable
"
;
import
{
asyncWrap
}
from
"
../helpers/asyncWrap
"
;
import
{
TypedRequest
}
from
"
../types
"
;
export
const
uploadFile
=
asyncWrap
(
async
(
reqExp
,
res
,
next
)
=>
{
const
req
=
reqExp
as
TypedRequest
;
const
form
=
formidable
({
multiples
:
false
,
uploadDir
:
"
uploads
"
});
await
new
Promise
((
resolve
,
reject
)
=>
{
form
.
parse
(
req
,
(
err
,
fields
,
files
)
=>
{
if
(
err
)
{
reject
(
err
);
return
;
}
console
.
log
(
"
fields
"
,
fields
);
console
.
log
(
"
files
"
,
files
);
req
.
body
=
fields
;
req
.
files
=
files
;
resolve
(
files
);
});
});
next
();
return
;
});
export
const
uploadFiles
=
asyncWrap
(
async
(
reqExp
,
res
,
next
)
=>
{
const
req
=
reqExp
as
TypedRequest
;
const
form
=
formidable
({
multiples
:
true
,
uploadDir
:
"
uploads
"
});
await
new
Promise
((
resolve
,
reject
)
=>
{
form
.
parse
(
req
,
(
err
,
fields
,
files
)
=>
{
if
(
err
)
{
reject
(
err
);
return
;
}
console
.
log
(
"
fields
"
,
fields
);
console
.
log
(
"
files
"
,
files
);
req
.
body
=
fields
;
req
.
files
=
files
;
resolve
(
files
);
});
});
next
();
return
;
});
src/controllers/index.ts
View file @
8fb026f5
...
@@ -3,3 +3,4 @@ export * as postCtrl from "./post.controller";
...
@@ -3,3 +3,4 @@ export * as postCtrl from "./post.controller";
export
*
as
roleCtrl
from
"
./role.controller
"
;
export
*
as
roleCtrl
from
"
./role.controller
"
;
export
*
as
userCtrl
from
"
./user.controller
"
;
export
*
as
userCtrl
from
"
./user.controller
"
;
export
*
as
mainimgCtrl
from
"
./mainimg.controller
"
;
export
*
as
mainimgCtrl
from
"
./mainimg.controller
"
;
export
*
as
fileInfoCtrl
from
"
./fileinfo.controller
"
;
src/controllers/mainimg.controller.ts
View file @
8fb026f5
...
@@ -12,7 +12,7 @@ export const createMainimg = asyncWrap(async (reqExp, res) => {
...
@@ -12,7 +12,7 @@ export const createMainimg = asyncWrap(async (reqExp, res) => {
const
{
userId
}
=
req
.
auth
;
const
{
userId
}
=
req
.
auth
;
const
form
=
formidable
({
const
form
=
formidable
({
uploadDir
:
"
adminpic
s
"
,
uploadDir
:
"
upload
s
"
,
keepExtensions
:
true
,
keepExtensions
:
true
,
multiples
:
false
,
multiples
:
false
,
});
});
...
...
src/db/mainimg.db.ts
View file @
8fb026f5
import
{
ObjectId
}
from
"
mongoose
"
;
import
{
ObjectId
}
from
"
mongoose
"
;
import
{
Avatar
,
IAvatar
,
Mainimg
,
MainimgType
}
from
"
../models
"
;
import
{
FileInfo
,
IFileInfo
,
Mainimg
,
MainimgType
}
from
"
../models
"
;
export
const
createMainimg
=
async
(
mainimg
:
MainimgType
,
pic
:
I
Avatar
)
=>
{
export
const
createMainimg
=
async
(
mainimg
:
MainimgType
,
pic
:
I
FileInfo
)
=>
{
const
newPic
=
await
Avatar
.
create
({
const
newPic
=
await
FileInfo
.
create
({
originalfilename
:
pic
.
originalfilename
,
originalfilename
:
pic
.
originalfilename
,
newfilename
:
pic
.
newfilename
,
newfilename
:
pic
.
newfilename
,
pictureauth
:
pic
.
picturepath
,
pictureauth
:
pic
.
picturepath
,
...
...
src/models/fileinfo.model.ts
View file @
8fb026f5
import
{
model
,
Schema
}
from
"
mongoose
"
;
import
{
model
,
Schema
}
from
"
mongoose
"
;
export
interface
I
Avatar
{
export
interface
I
FileInfo
{
originalfilename
?:
string
;
originalfilename
?:
string
;
newfilename
?:
string
;
newfilename
?:
string
;
picturepath
?:
string
;
picturepath
?:
string
;
nickname
?:
string
;
nickname
?:
string
;
}
}
const
Avatar
schema
=
new
Schema
<
I
Avatar
>
({
const
schema
=
new
Schema
<
I
FileInfo
>
({
originalfilename
:
{
type
:
String
,
unique
:
true
},
originalfilename
:
{
type
:
String
,
unique
:
true
},
newfilename
:
{
type
:
String
},
newfilename
:
{
type
:
String
},
nickname
:
{
type
:
String
},
nickname
:
{
type
:
String
},
picturepath
:
{
type
:
String
},
picturepath
:
{
type
:
String
},
});
});
export
default
model
<
I
Avatar
>
(
"
Avatar
"
,
Avatar
schema
);
export
default
model
<
I
FileInfo
>
(
"
FileInfo
"
,
schema
);
src/models/index.ts
View file @
8fb026f5
export
{
default
as
User
,
IUser
}
from
"
./user.model
"
;
export
{
default
as
User
,
IUser
}
from
"
./user.model
"
;
export
{
default
as
Post
,
PostType
}
from
"
./post.model
"
;
export
{
default
as
Post
,
PostType
}
from
"
./post.model
"
;
export
{
default
as
Role
}
from
"
./role.model
"
;
export
{
default
as
Role
}
from
"
./role.model
"
;
export
{
default
as
Avatar
,
IAvatar
}
from
"
./fileinfo.model
"
;
export
{
default
as
FileInfo
,
IFileInfo
}
from
"
./fileinfo.model
"
;
export
{
default
as
Mainimg
,
MainimgType
}
from
"
./mainimg.model
"
;
export
{
default
as
Mainimg
,
MainimgType
}
from
"
./mainimg.model
"
;
src/models/mainimg.model.ts
View file @
8fb026f5
...
@@ -4,7 +4,7 @@ export interface MainimgType {
...
@@ -4,7 +4,7 @@ export interface MainimgType {
theme
:
string
;
theme
:
string
;
city
:
string
;
city
:
string
;
title
:
string
;
title
:
string
;
pic
?:
Types
.
ObjectId
;
fileInfo
?:
Types
.
ObjectId
;
}
}
const
MainimgSchema
=
new
Schema
<
MainimgType
>
({
const
MainimgSchema
=
new
Schema
<
MainimgType
>
({
...
@@ -18,7 +18,7 @@ const MainimgSchema = new Schema<MainimgType>({
...
@@ -18,7 +18,7 @@ const MainimgSchema = new Schema<MainimgType>({
type
:
String
,
type
:
String
,
required
:
true
,
required
:
true
,
},
},
pic
:
{
type
:
Schema
.
Types
.
ObjectId
,
ref
:
"
Avatar
"
},
fileInfo
:
{
type
:
Schema
.
Types
.
ObjectId
,
ref
:
"
Fileinfo
"
},
});
});
export
default
model
<
MainimgType
>
(
"
Mainimg
"
,
MainimgSchema
);
export
default
model
<
MainimgType
>
(
"
Mainimg
"
,
MainimgSchema
);
src/models/user.model.ts
View file @
8fb026f5
...
@@ -5,7 +5,7 @@ export interface IUser {
...
@@ -5,7 +5,7 @@ export interface IUser {
name
?:
string
;
name
?:
string
;
password
:
string
;
password
:
string
;
role
?:
Types
.
ObjectId
;
role
?:
Types
.
ObjectId
;
avatar
?:
Types
.
ObjectId
;
fileInfo
?:
Types
.
ObjectId
;
}
}
const
validateEmail
=
(
email
:
string
)
=>
{
const
validateEmail
=
(
email
:
string
)
=>
{
...
@@ -22,7 +22,7 @@ const schema = new Schema<IUser>(
...
@@ -22,7 +22,7 @@ const schema = new Schema<IUser>(
validate
:
[
validateEmail
,
"
이메일을 입력해주세요
"
],
validate
:
[
validateEmail
,
"
이메일을 입력해주세요
"
],
},
},
name
:
{
type
:
String
},
name
:
{
type
:
String
},
avatar
:
{
type
:
Schema
.
Types
.
ObjectId
,
ref
:
"
Avatar
"
},
fileInfo
:
{
type
:
Schema
.
Types
.
ObjectId
,
ref
:
"
FileInfo
"
},
password
:
{
type
:
String
,
required
:
true
,
select
:
false
},
password
:
{
type
:
String
,
required
:
true
,
select
:
false
},
role
:
{
type
:
Schema
.
Types
.
ObjectId
,
ref
:
"
Role
"
},
role
:
{
type
:
Schema
.
Types
.
ObjectId
,
ref
:
"
Role
"
},
},
},
...
...
src/routes/user.route.ts
View file @
8fb026f5
import
express
from
"
express
"
;
import
express
from
"
express
"
;
import
{
userCtrl
,
authCtrl
}
from
"
../controllers
"
;
import
{
userCtrl
,
authCtrl
,
fileInfoCtrl
}
from
"
../controllers
"
;
const
router
=
express
.
Router
();
const
router
=
express
.
Router
();
router
router
.
route
(
"
/
"
)
.
route
(
"
/
"
)
.
get
(
authCtrl
.
requireLogin
,
userCtrl
.
getUsers
)
.
get
(
authCtrl
.
requireLogin
,
userCtrl
.
getUsers
)
.
post
(
authCtrl
.
requireLogin
,
authCtrl
.
hasRole
(
"
admin
"
),
userCtrl
.
createUser
);
.
post
(
authCtrl
.
requireLogin
,
authCtrl
.
hasRole
(
"
admin
"
),
fileInfoCtrl
.
uploadFile
,
userCtrl
.
createUser
);
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