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
5d59e60d
Commit
5d59e60d
authored
Jul 25, 2022
by
Lee Soobeom
Browse files
Merge remote-tracking branch 'origin/sm14' into develop
parents
7a94cbcc
d17da917
Changes
12
Hide whitespace changes
Inline
Side-by-side
frontend/src/App.tsx
View file @
5d59e60d
...
@@ -37,7 +37,7 @@ export const App = () => {
...
@@ -37,7 +37,7 @@ export const App = () => {
</
RequireAuth
>
</
RequireAuth
>
}
}
/>
/>
<
Route
path
=
"admin"
element
=
{
<
Admin
/
>
}
/>
<
Route
path
=
"admin"
element
=
{
<
RequireAuth
><
Admin
/></
RequireAuth
>
}
/>
<
Route
path
=
"admin/:imgId"
element
=
{
<
ImgRewrite
/>
}
/>
<
Route
path
=
"admin/:imgId"
element
=
{
<
ImgRewrite
/>
}
/>
<
Route
path
=
"rewrite"
element
=
{
<
ImgRewrite
/>
}
/>
<
Route
path
=
"rewrite"
element
=
{
<
ImgRewrite
/>
}
/>
</
Route
>
</
Route
>
...
...
frontend/src/auth/admin.tsx
View file @
5d59e60d
import
{
get
}
from
"
mongoose
"
;
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
"
;
...
@@ -11,200 +12,214 @@ import { MySlide } from "./adminslide";
...
@@ -11,200 +12,214 @@ import { MySlide } from "./adminslide";
// }
// }
export
default
function
Admin
()
{
export
default
function
Admin
()
{
// 이미지 전체 불러오기
// 이미지 전체 불러오기
const
[
getimgs
,
setGetimgs
]
=
useState
<
MainimgType
[]
>
([]);
const
[
getimgs
,
setGetimgs
]
=
useState
<
MainimgType
[]
>
([]);
async
function
imgsData
()
{
async
function
imgsData
()
{
const
imgs
=
await
mainimgApi
.
getmainimg
();
const
imgs
=
await
mainimgApi
.
getmainimg
();
setGetimgs
(
imgs
);
setGetimgs
(
imgs
);
}
}
useEffect
(()
=>
{
useEffect
(()
=>
{
imgsData
();
imgsData
();
},
[]);
},
[]);
// 이미지 추가하기
const
[
addimg
,
setAddimg
]
=
useState
<
MainimgType
>
({
_id
:
""
,
theme
:
""
,
city
:
""
,
title
:
""
,
fileInfo
:
{
originalfilename
:
""
,
newfilename
:
""
},
});
// 이미지 추가하기
const
[
loading
,
setLoading
]
=
useState
(
false
);
const
[
addimg
,
setAddimg
]
=
useState
<
MainimgType
>
({
const
[
error
,
setError
]
=
useState
(
""
);
_id
:
""
,
const
[
addSuccess
,
setAddSuccess
]
=
useState
(
false
);
theme
:
""
,
const
[
delSuccess
,
setDelSuccess
]
=
useState
(
false
);
city
:
""
,
const
[
file
,
setFile
]
=
useState
<
File
>
();
title
:
""
,
pic
:
{
originalfilename
:
""
,
newfilename
:
""
},
});
const
[
loading
,
setLoading
]
=
useState
(
false
);
const
[
error
,
setError
]
=
useState
(
""
);
const
[
addSuccess
,
setAddSuccess
]
=
useState
(
false
);
const
[
delSuccess
,
setDelSuccess
]
=
useState
(
false
);
const
[
file
,
setFile
]
=
useState
<
File
>
();
function
handleSelectChange
(
event
:
React
.
ChangeEvent
<
HTMLSelectElement
>
)
{
function
handleSelectChange
(
event
:
React
.
ChangeEvent
<
HTMLSelectElement
>
)
{
const
{
name
,
value
}
=
event
.
currentTarget
;
const
{
name
,
value
}
=
event
.
currentTarget
;
console
.
log
(
value
);
console
.
log
(
value
);
setAddimg
({
...
addimg
,
[
name
]:
value
});
setAddimg
({
...
addimg
,
[
name
]:
value
});
}
}
function
handleInputeChange
(
event
:
React
.
ChangeEvent
<
HTMLInputElement
>
)
{
function
handleInputeChange
(
event
:
React
.
ChangeEvent
<
HTMLInputElement
>
)
{
const
{
name
,
value
}
=
event
.
currentTarget
;
const
{
name
,
value
}
=
event
.
currentTarget
;
setAddimg
({
...
addimg
,
[
name
]:
value
});
setAddimg
({
...
addimg
,
[
name
]:
value
});
}
}
function
handleFileChange
(
e
:
React
.
ChangeEvent
<
HTMLInputElement
>
)
{
function
handleFileChange
(
e
:
React
.
ChangeEvent
<
HTMLInputElement
>
)
{
const
file
=
e
.
target
.
files
?.[
0
];
const
file
=
e
.
target
.
files
?.[
0
];
if
(
!
(
file
===
undefined
))
{
if
(
!
(
file
===
undefined
))
{
setFile
(
file
);
setFile
(
file
);
}
}
}
}
async
function
handleSubmit
(
event
:
FormEvent
)
{
async
function
handleSubmit
(
event
:
FormEvent
)
{
event
.
preventDefault
();
event
.
preventDefault
();
const
formdata
=
new
FormData
();
const
formdata
=
new
FormData
();
console
.
log
(
addimg
);
console
.
log
(
addimg
);
formdata
.
append
(
"
city
"
,
addimg
.
city
);
formdata
.
append
(
"
city
"
,
addimg
.
city
);
formdata
.
append
(
"
theme
"
,
addimg
.
theme
);
formdata
.
append
(
"
theme
"
,
addimg
.
theme
);
formdata
.
append
(
"
title
"
,
addimg
.
title
);
formdata
.
append
(
"
title
"
,
addimg
.
title
);
if
(
!
(
file
===
undefined
))
{
try
{
formdata
.
append
(
"
mainimg
"
,
file
);
if
(
!
(
file
===
undefined
))
{
console
.
log
(
formdata
);
formdata
.
append
(
"
mainimg
"
,
file
);
const
res
=
await
mainimgApi
.
mainimg
(
formdata
);
console
.
log
(
"
fordata
"
,
formdata
);
console
.
log
(
"
확인 중
"
,
res
);
const
res
=
await
mainimgApi
.
mainimg
(
formdata
);
alert
(
"
img 추가되었습니다
"
);
console
.
log
(
"
확인 중
"
,
res
);
alert
(
"
img 추가되었습니다
"
);
setGetimgs
([...
getimgs
,
res
])
}
else
(
console
.
log
(
"
file === undefined
"
)
)
}
catch
(
error
)
{
console
.
log
(
"
에러발생
"
);
catchErrors
(
error
,
setError
);
}
finally
{
setLoading
(
false
);
}
}
}
}
// 이미지 삭제하기
async
function
handleDeleteClick
(
event
:
MouseEvent
<
HTMLButtonElement
>
)
{
// 이미지 삭제하기
try
{
async
function
handleDeleteClick
(
event
:
MouseEvent
<
HTMLButtonElement
>
)
{
if
(
confirm
(
"
삭제하시겠습니까?
"
)
==
true
)
{
try
{
const
picId
=
event
.
currentTarget
.
id
;
if
(
confirm
(
"
삭제하시겠습니까?
"
)
==
true
)
{
console
.
log
(
"
picId :
"
,
picId
);
const
picId
=
event
.
currentTarget
.
id
;
const
res
=
await
mainimgApi
.
delmainimg
(
picId
);
console
.
log
(
"
picId :
"
,
picId
);
console
.
log
(
"
delete img
"
,
res
);
const
res
=
await
mainimgApi
.
delmainimg
(
picId
);
// setGetimgs(getimgs)
console
.
log
(
"
delete img
"
,
res
);
setDelSuccess
(
true
);
// setGetimgs(getimgs)
setError
(
""
);
setDelSuccess
(
true
);
alert
(
"
img 삭제되었습니다
"
);
setError
(
""
);
}
else
{
alert
(
"
img 삭제되었습니다
"
);
return
false
;
const
deleteimg
=
getimgs
.
filter
(
pic
=>
picId
!==
pic
.
_id
)
}
setGetimgs
(
deleteimg
)
}
catch
(
error
)
{
}
else
{
console
.
log
(
"
에러발생
"
);
return
false
;
catchErrors
(
error
,
setError
);
}
}
finally
{
}
catch
(
error
)
{
setLoading
(
false
);
console
.
log
(
"
에러발생
"
);
catchErrors
(
error
,
setError
);
}
finally
{
setLoading
(
false
);
}
}
}
}
let
limit
=
15
;
let
limit
=
15
;
const
numPages
=
Math
.
ceil
(
getimgs
.
length
/
15
);
const
numPages
=
Math
.
ceil
(
getimgs
.
length
/
15
);
// const location = useLocation() as ImgState;
// const location = useLocation() as ImgState;
// const img = location.state;
// const img = location.state;
const
slides
=
[];
const
slides
=
[];
for
(
let
i
=
0
;
i
<
numPages
;
i
++
)
{
for
(
let
i
=
0
;
i
<
numPages
;
i
++
)
{
const
k
=
[
const
k
=
[
getimgs
getimgs
.
slice
(
i
*
limit
,
i
*
limit
+
limit
)
.
slice
(
i
*
limit
,
i
*
limit
+
limit
)
.
map
((
picture
,
index
:
number
)
=>
(
.
map
((
picture
,
index
:
number
)
=>
(
<
div
key
=
{
index
}
>
<
div
key
=
{
index
}
>
<
div
className
=
{
`m-1 shrink-0 bg-gray-200 rounded shadow-md `
}
>
<
div
className
=
{
`m-1 shrink-0 bg-gray-200 rounded shadow-md `
}
>
<
img
<
img
src
=
{
"
http://localhost:3000/images/
"
+
picture
.
pic
.
newfilename
}
src
=
{
"
http://localhost:3000/images/
"
+
picture
.
fileInfo
.
newfilename
}
className
=
"w-full h-10 md:h-20 object-center"
className
=
"w-full h-10 md:h-20 object-center"
/>
/>
<
p
className
=
"text-center text-xs"
>
{
picture
.
title
}
</
p
>
<
p
className
=
"text-center text-xs"
>
{
picture
.
title
}
</
p
>
</
div
>
</
div
>
<
div
className
=
"text-end"
>
<
div
className
=
"text-end"
>
<
button
className
=
"border-r-2 border-r-indigo-500 text-xs"
>
<
button
className
=
"border-r-2 border-r-indigo-500 text-xs"
>
<
Link
to
=
{
`/admin/
${
picture
.
_id
}
`
}
state
=
{
picture
}
>
<
Link
to
=
{
`/admin/
${
picture
.
_id
}
`
}
state
=
{
picture
}
>
수정
수정
</
Link
>
</
Link
>
</
button
>
</
button
>
<
button
<
button
id
=
{
picture
.
_id
}
id
=
{
picture
.
_id
}
onClick
=
{
handleDeleteClick
}
onClick
=
{
handleDeleteClick
}
className
=
"text-xs"
className
=
"text-xs"
>
>
삭제
삭제
</
button
>
</
button
>
</
div
>
</
div
>
</
div
>
</
div
>
)),
)),
];
];
slides
.
push
(
k
);
slides
.
push
(
k
);
}
}
return
(
return
(
<
div
>
<
div
>
<
form
onSubmit
=
{
handleSubmit
}
>
<
form
onSubmit
=
{
handleSubmit
}
>
<
div
className
=
"flex flex-wrap justify-center gap-3"
>
<
div
className
=
"flex flex-wrap justify-center gap-3"
>
<
div
className
=
"gap-3 md:flex "
>
<
div
className
=
"gap-3 md:flex "
>
<
select
<
select
name
=
"city"
name
=
"city"
id
=
"Questions"
id
=
"Questions"
className
=
"border border-3 border-black w-20 my-5"
className
=
"border border-3 border-black w-20 my-5"
defaultValue
=
"질문종류"
defaultValue
=
"질문종류"
onChange
=
{
handleSelectChange
}
onChange
=
{
handleSelectChange
}
>
>
<
option
value
=
"질문종류"
>
도시
</
option
>
<
option
value
=
"질문종류"
>
도시
</
option
>
<
option
value
=
"서울"
>
서울
</
option
>
<
option
value
=
"Seoul"
>
서울
</
option
>
<
option
value
=
"부산"
>
부산
</
option
>
<
option
value
=
"Busan"
>
부산
</
option
>
<
option
value
=
"인천"
>
인천
</
option
>
<
option
value
=
"Incheon"
>
인천
</
option
>
<
option
value
=
"대구"
>
대구
</
option
>
<
option
value
=
"Daegoo"
>
대구
</
option
>
<
option
value
=
"광주"
>
광주
</
option
>
<
option
value
=
"Gwangjoo"
>
광주
</
option
>
<
option
value
=
"대전"
>
대전
</
option
>
<
option
value
=
"Daejeon"
>
대전
</
option
>
<
option
value
=
"울산"
>
울산
</
option
>
<
option
value
=
"Woolsan"
>
울산
</
option
>
<
option
value
=
"세종"
>
세종
</
option
>
<
option
value
=
"Sejong"
>
세종
</
option
>
<
option
value
=
"독도"
>
독도
</
option
>
<
option
value
=
"Dokdo"
>
독도
</
option
>
<
option
value
=
"제주"
>
제주
</
option
>
<
option
value
=
"Jeju"
>
제주
</
option
>
</
select
>
</
select
>
<
select
<
select
name
=
"theme"
name
=
"theme"
id
=
"Questions"
id
=
"Questions"
className
=
"border border-3 border-black w-20 my-5"
className
=
"border border-3 border-black w-20 my-5"
defaultValue
=
"질문종류"
defaultValue
=
"질문종류"
onChange
=
{
handleSelectChange
}
onChange
=
{
handleSelectChange
}
>
>
<
option
value
=
"질문종류"
>
테마
</
option
>
<
option
value
=
"질문종류"
>
테마
</
option
>
<
option
value
=
"사이클링"
>
사이클링
</
option
>
<
option
value
=
"cycling"
>
사이클링
</
option
>
<
option
value
=
"서핑"
>
서핑
</
option
>
<
option
value
=
"surfing"
>
서핑
</
option
>
<
option
value
=
"액티비티"
>
액티비티
</
option
>
<
option
value
=
"activity"
>
액티비티
</
option
>
<
option
value
=
"캠핑"
>
캠핑
</
option
>
<
option
value
=
"camping"
>
캠핑
</
option
>
<
option
value
=
"스키"
>
스키
</
option
>
<
option
value
=
"skiing"
>
스키
</
option
>
<
option
value
=
"보트"
>
보트
</
option
>
<
option
value
=
"boat"
>
보트
</
option
>
<
option
value
=
"사막"
>
사막
</
option
>
<
option
value
=
"desert"
>
사막
</
option
>
<
option
value
=
"골프"
>
골프
</
option
>
<
option
value
=
"golf"
>
골프
</
option
>
<
option
value
=
"동굴"
>
동굴
</
option
>
<
option
value
=
"cave"
>
동굴
</
option
>
<
option
value
=
"문화재"
>
문화재
</
option
>
<
option
value
=
"history"
>
문화재
</
option
>
<
option
value
=
"동물원"
>
동물원
</
option
>
<
option
value
=
"zoo"
>
동물원
</
option
>
<
option
value
=
"사이클링"
>
사이클링
</
option
>
<
option
value
=
"cycling"
>
사이클링
</
option
>
</
select
>
</
select
>
<
div
className
=
"flex items-center justify-end gap-3"
>
<
div
className
=
"flex items-center justify-end gap-3"
>
<
input
<
input
type
=
"file"
type
=
"file"
id
=
"files"
id
=
"files"
className
=
"hidden"
className
=
"hidden"
onChange
=
{
handleFileChange
}
onChange
=
{
handleFileChange
}
></
input
>
></
input
>
<
label
htmlFor
=
"files"
className
=
"border-2 m-5"
>
<
label
htmlFor
=
"files"
className
=
"border-2 m-5"
>
이미지 선택
이미지 선택
</
label
>
</
label
>
</
div
>
</
div
>
<
div
className
=
"flex items-center justify-end gap-3 mt-2 md:mt-0"
>
<
div
className
=
"flex items-center justify-end gap-3 mt-2 md:mt-0"
>
<
p
>
title :
</
p
>
<
p
>
title :
</
p
>
<
input
<
input
name
=
"title"
name
=
"title"
className
=
"border-2 border-sky-500"
className
=
"border-2 border-sky-500"
onChange
=
{
handleInputeChange
}
onChange
=
{
handleInputeChange
}
/>
/>
</
div
>
</
div
>
<
div
className
=
"my-5 flex items-center"
>
<
button
className
=
"border-2 border-gray-500 rounded "
>
추가
</
button
>
</
div
>
</
div
>
</
form
>
<
div
className
=
"flex justify-center"
>
<
MySlide
key
=
{
Math
.
random
()
}
slides
=
{
slides
}
/>
</
div
>
</
div
>
</
div
>
<
div
className
=
"my-5 flex items-center"
>
<
button
className
=
"border-2 border-gray-500 rounded "
>
추가
</
button
>
</
div
>
</
div
>
</
div
>
</
form
>
);
<
div
className
=
"flex justify-center"
>
<
MySlide
key
=
{
Math
.
random
()
}
slides
=
{
slides
}
/>
</
div
>
</
div
>
);
}
}
frontend/src/auth/imgrewrite.tsx
View file @
5d59e60d
import
React
,
{
FormEvent
,
useState
}
from
"
react
"
;
import
React
,
{
FormEvent
,
useState
,
useEffect
}
from
"
react
"
;
import
{
Link
,
Outlet
,
useNavigate
,
useLocation
}
from
"
react-router-dom
"
;
import
{
Link
,
Outlet
,
useNavigate
,
useLocation
}
from
"
react-router-dom
"
;
import
{
mainimgApi
}
from
"
../apis
"
;
import
{
mainimgApi
}
from
"
../apis
"
;
import
isLength
from
"
validator/lib/isLength
"
;
import
isLength
from
"
validator/lib/isLength
"
;
...
@@ -27,9 +27,11 @@ export default function ImgRewrite() {
...
@@ -27,9 +27,11 @@ export default function ImgRewrite() {
theme
:
img
.
theme
,
theme
:
img
.
theme
,
city
:
img
.
city
,
city
:
img
.
city
,
title
:
img
.
title
,
title
:
img
.
title
,
pic
:
{
originalfilename
:
""
,
newfilename
:
""
},
fileInfo
:
{
originalfilename
:
""
,
newfilename
:
""
},
});
});
useEffect
(()
=>
{
console
.
log
(
"
수정 전 :
"
,
imgdata
);
},
[]);
const
[
loading
,
setLoading
]
=
useState
(
false
);
const
[
loading
,
setLoading
]
=
useState
(
false
);
const
[
error
,
setError
]
=
useState
(
""
);
const
[
error
,
setError
]
=
useState
(
""
);
...
@@ -86,7 +88,6 @@ export default function ImgRewrite() {
...
@@ -86,7 +88,6 @@ export default function ImgRewrite() {
console
.
log
(
"
확인 중
"
,
res
);
console
.
log
(
"
확인 중
"
,
res
);
}
}
else
{
else
{
console
.
log
(
"
ㅇ에러
"
)
formdata
.
append
(
"
updatemainimg
"
,
""
);
formdata
.
append
(
"
updatemainimg
"
,
""
);
console
.
log
(
"
formdata
"
,
formdata
);
console
.
log
(
"
formdata
"
,
formdata
);
const
res
=
await
mainimgApi
.
updateimg
(
formdata
,
imgdata
.
_id
);
const
res
=
await
mainimgApi
.
updateimg
(
formdata
,
imgdata
.
_id
);
...
@@ -109,7 +110,7 @@ export default function ImgRewrite() {
...
@@ -109,7 +110,7 @@ export default function ImgRewrite() {
if
(
!
isLength
(
pic
.
title
??
""
,
{
min
:
1
}))
{
if
(
!
isLength
(
pic
.
title
??
""
,
{
min
:
1
}))
{
setError
(
"
제목을 입력해 주세요.
"
);
setError
(
"
제목을 입력해 주세요.
"
);
return
false
;
return
false
;
}
else
if
(
!
isLength
(
pic
.
pic
.
newfilename
??
""
,
{
min
:
1
}))
{
}
else
if
(
!
isLength
(
pic
.
fileInfo
.
newfilename
??
""
,
{
min
:
1
}))
{
setError
(
"
파일을 선택해 주세요.
"
);
setError
(
"
파일을 선택해 주세요.
"
);
return
false
;
return
false
;
}
else
if
(
equals
(
pic
.
city
,
"
city
"
))
{
}
else
if
(
equals
(
pic
.
city
,
"
city
"
))
{
...
@@ -232,7 +233,7 @@ export default function ImgRewrite() {
...
@@ -232,7 +233,7 @@ export default function ImgRewrite() {
/>
/>
)
:
(
)
:
(
<
img
<
img
src
=
{
"
http://localhost:3000/images/
"
+
img
.
pic
.
newfilename
}
src
=
{
"
http://localhost:3000/images/
"
+
img
.
fileInfo
.
newfilename
}
className
=
"object-cover object-center h-full"
className
=
"object-cover object-center h-full"
/>
/>
)
}
)
}
...
...
frontend/src/board/board.tsx
View file @
5d59e60d
...
@@ -13,7 +13,8 @@ export default function BoardPage() {
...
@@ -13,7 +13,8 @@ export default function BoardPage() {
useEffect
(()
=>
{
useEffect
(()
=>
{
getDataList
();
getDataList
();
},
[
posts
]);
},
[]);
// posts
// posts
const
getDataList
=
async
()
=>
{
const
getDataList
=
async
()
=>
{
const
res
=
await
postApi
.
getData
();
const
res
=
await
postApi
.
getData
();
...
...
frontend/src/home/body.tsx
View file @
5d59e60d
...
@@ -69,7 +69,9 @@ export default function Body() {
...
@@ -69,7 +69,9 @@ export default function Body() {
key
=
{
index
}
key
=
{
index
}
>
>
<
img
<
img
src
=
{
"
http://localhost:3000/images/
"
+
picture
.
pic
.
newfilename
}
src
=
{
"
http://localhost:3000/images/
"
+
picture
.
fileInfo
.
newfilename
}
className
=
"w-full h-40 object-cover hover:scale-110 transition duration-0 hover:duration-500"
className
=
"w-full h-40 object-cover hover:scale-110 transition duration-0 hover:duration-500"
/>
/>
<
div
className
=
"bg-transparent text-neutral-50 text-xs rounded-full absolute bottom-0 ml-1 mb-1 hover:scale-110 transition duration-0 hover:duration-500"
>
<
div
className
=
"bg-transparent text-neutral-50 text-xs rounded-full absolute bottom-0 ml-1 mb-1 hover:scale-110 transition duration-0 hover:duration-500"
>
...
...
frontend/src/home/theme.tsx
View file @
5d59e60d
...
@@ -29,7 +29,7 @@ export default function Theme({ handleClick }: ThemeProps) {
...
@@ -29,7 +29,7 @@ export default function Theme({ handleClick }: ThemeProps) {
캠핑
캠핑
</
button
>
</
button
>
<
button
<
button
id
=
{
"
sking
"
}
id
=
{
"
ski
i
ng
"
}
onClick
=
{
handleClick
}
onClick
=
{
handleClick
}
className
=
"shrink-0 px-5 hover:text-sky-300"
className
=
"shrink-0 px-5 hover:text-sky-300"
>
>
...
...
frontend/src/pages/citylist.tsx
View file @
5d59e60d
...
@@ -11,70 +11,70 @@ export default function Citylist({ handleClick }: CityProps) {
...
@@ -11,70 +11,70 @@ export default function Citylist({ handleClick }: CityProps) {
도시
도시
</
div
>
</
div
>
<
button
<
button
id
=
{
"
서울
"
}
id
=
{
"
Seoul
"
}
onClick
=
{
handleClick
}
onClick
=
{
handleClick
}
className
=
"text-start px-5 py-2 hover:underline whitespace-nowrap"
className
=
"text-start px-5 py-2 hover:underline whitespace-nowrap"
>
>
서울
서울
</
button
>
</
button
>
<
button
<
button
id
=
{
"
부산
"
}
id
=
{
"
Busan
"
}
onClick
=
{
handleClick
}
onClick
=
{
handleClick
}
className
=
"text-start px-5 py-2 hover:underline whitespace-nowrap"
className
=
"text-start px-5 py-2 hover:underline whitespace-nowrap"
>
>
부산
부산
</
button
>
</
button
>
<
button
<
button
id
=
{
"
인천
"
}
id
=
{
"
Incheon
"
}
onClick
=
{
handleClick
}
onClick
=
{
handleClick
}
className
=
"text-start px-5 py-2 hover:underline whitespace-nowrap"
className
=
"text-start px-5 py-2 hover:underline whitespace-nowrap"
>
>
인천
인천
</
button
>
</
button
>
<
button
<
button
id
=
{
"
대구
"
}
id
=
{
"
Daegoo
"
}
onClick
=
{
handleClick
}
onClick
=
{
handleClick
}
className
=
"text-start px-5 py-2 hover:underline whitespace-nowrap"
className
=
"text-start px-5 py-2 hover:underline whitespace-nowrap"
>
>
대구
대구
</
button
>
</
button
>
<
button
<
button
id
=
{
"
광주
"
}
id
=
{
"
Gwangjoo
"
}
onClick
=
{
handleClick
}
onClick
=
{
handleClick
}
className
=
"text-start px-5 py-2 hover:underline whitespace-nowrap"
className
=
"text-start px-5 py-2 hover:underline whitespace-nowrap"
>
>
광주
광주
</
button
>
</
button
>
<
button
<
button
id
=
{
"
대전
"
}
id
=
{
"
Daejeon
"
}
onClick
=
{
handleClick
}
onClick
=
{
handleClick
}
className
=
"text-start px-5 py-2 hover:underline whitespace-nowrap"
className
=
"text-start px-5 py-2 hover:underline whitespace-nowrap"
>
>
대전
대전
</
button
>
</
button
>
<
button
<
button
id
=
{
"
울산
"
}
id
=
{
"
Woolsan
"
}
onClick
=
{
handleClick
}
onClick
=
{
handleClick
}
className
=
"text-start px-5 py-2 hover:underline whitespace-nowrap"
className
=
"text-start px-5 py-2 hover:underline whitespace-nowrap"
>
>
울산
울산
</
button
>
</
button
>
<
button
<
button
id
=
{
"
세종
"
}
id
=
{
"
Sejong
"
}
onClick
=
{
handleClick
}
onClick
=
{
handleClick
}
className
=
"text-start px-5 py-2 hover:underline whitespace-nowrap"
className
=
"text-start px-5 py-2 hover:underline whitespace-nowrap"
>
>
세종
세종
</
button
>
</
button
>
<
button
<
button
id
=
{
"
독도
"
}
id
=
{
"
Dokdo
"
}
onClick
=
{
handleClick
}
onClick
=
{
handleClick
}
className
=
"text-start px-5 py-2 hover:underline whitespace-nowrap"
className
=
"text-start px-5 py-2 hover:underline whitespace-nowrap"
>
>
독도
독도
</
button
>
</
button
>
<
button
<
button
id
=
{
"
제주
"
}
id
=
{
"
Jeju
"
}
onClick
=
{
handleClick
}
onClick
=
{
handleClick
}
className
=
"text-start px-5 py-2 hover:underline whitespace-nowrap"
className
=
"text-start px-5 py-2 hover:underline whitespace-nowrap"
>
>
...
...
frontend/src/types/index.tsx
View file @
5d59e60d
...
@@ -44,7 +44,7 @@ export interface MainimgType {
...
@@ -44,7 +44,7 @@ export interface MainimgType {
theme
:
string
;
theme
:
string
;
city
:
string
;
city
:
string
;
title
:
string
;
title
:
string
;
pic
:
{
fileInfo
:
{
originalfilename
:
string
;
originalfilename
:
string
;
newfilename
:
string
;
newfilename
:
string
;
};
};
...
...
src/controllers/mainimg.controller.ts
View file @
5d59e60d
...
@@ -17,7 +17,7 @@ export const createMainimg = asyncWrap(async (reqExp, res) => {
...
@@ -17,7 +17,7 @@ export const createMainimg = asyncWrap(async (reqExp, res) => {
multiples
:
false
,
multiples
:
false
,
});
});
form
.
parse
(
req
,
(
err
,
fields
,
files
)
=>
{
form
.
parse
(
req
,
async
(
err
,
fields
,
files
)
=>
{
if
(
!
Array
.
isArray
(
files
.
mainimg
))
{
if
(
!
Array
.
isArray
(
files
.
mainimg
))
{
//파일 좁히기 중
//파일 좁히기 중
if
(
if
(
...
@@ -33,37 +33,24 @@ export const createMainimg = asyncWrap(async (reqExp, res) => {
...
@@ -33,37 +33,24 @@ export const createMainimg = asyncWrap(async (reqExp, res) => {
const
originalfilename
=
files
.
mainimg
?.
originalFilename
;
const
originalfilename
=
files
.
mainimg
?.
originalFilename
;
const
newfilename
=
files
.
mainimg
.
newFilename
;
const
newfilename
=
files
.
mainimg
.
newFilename
;
if
(
!
(
originalfilename
===
null
||
newfilename
===
undefined
))
{
if
(
!
(
originalfilename
===
null
||
newfilename
===
undefined
))
{
mainimgDb
.
createMainimg
(
const
imgRes
=
await
mainimgDb
.
createMainimg
(
{
city
,
title
,
theme
},
{
city
,
title
,
theme
},
{
{
originalfilename
,
originalfilename
,
newfilename
,
newfilename
,
}
}
);
);
console
.
log
(
imgRes
)
return
res
.
json
(
imgRes
);
}
else
{
return
res
.
send
(
"
에러
"
)
}
}
}
}
}
}
});
});
res
.
json
();
});
});
// if (!isLength(url ?? "", { min: 1 })) {
// return res.status(422).send("이미지 url을 입력해주세요");
// }
// if (!isLength(title ?? "", { min: 1 })) {
// return res.status(422).send("이미지 제목을 입력해주세요");
// }
// const newMainimg = await mainimgDb.createMainimg({
// theme,
// city,
// url,
// title,
// });
// return res.json(newMainimg);
// });
export
const
getMainimg
=
asyncWrap
(
async
(
req
,
res
)
=>
{
export
const
getMainimg
=
asyncWrap
(
async
(
req
,
res
)
=>
{
const
mainimgs
=
await
mainimgDb
.
getMainimg
();
const
mainimgs
=
await
mainimgDb
.
getMainimg
();
...
@@ -72,8 +59,8 @@ export const getMainimg = asyncWrap(async (req, res) => {
...
@@ -72,8 +59,8 @@ export const getMainimg = asyncWrap(async (req, res) => {
export
const
deleteMainimg
=
asyncWrap
(
async
(
req
,
res
)
=>
{
export
const
deleteMainimg
=
asyncWrap
(
async
(
req
,
res
)
=>
{
const
{
imgId
}
=
req
.
params
;
const
{
imgId
}
=
req
.
params
;
console
.
log
(
imgId
);
const
deleteCount
=
await
mainimgDb
.
deleteOneMainimg
(
imgId
);
const
deleteCount
=
await
mainimgDb
.
deleteOneMainimg
(
imgId
);
console
.
log
(
deleteCount
);
return
res
.
json
(
deleteCount
);
return
res
.
json
(
deleteCount
);
});
});
...
@@ -107,7 +94,7 @@ export const updateMainimg = asyncWrap(async (reqExp, res) => {
...
@@ -107,7 +94,7 @@ export const updateMainimg = asyncWrap(async (reqExp, res) => {
const
originalfilename
=
files
.
updatemainimg
?.
originalFilename
;
const
originalfilename
=
files
.
updatemainimg
?.
originalFilename
;
const
newfilename
=
files
.
updatemainimg
.
newFilename
;
const
newfilename
=
files
.
updatemainimg
.
newFilename
;
if
(
!
(
originalfilename
===
null
||
newfilename
===
undefined
))
{
if
(
!
(
originalfilename
===
null
||
newfilename
===
undefined
))
{
mainimgDb
.
updateOneMainimg
(
const
imgRes
=
mainimgDb
.
updateOneMainimg
(
id
,
id
,
theme
,
theme
,
city
,
city
,
...
@@ -115,12 +102,13 @@ export const updateMainimg = asyncWrap(async (reqExp, res) => {
...
@@ -115,12 +102,13 @@ export const updateMainimg = asyncWrap(async (reqExp, res) => {
originalfilename
,
originalfilename
,
newfilename
newfilename
);
);
return
res
.
json
(
imgRes
);
}
}
}
else
{
}
else
{
mainimgDb
.
updateOneMainimg
(
id
,
theme
,
city
,
title
);
const
imgRes
=
mainimgDb
.
updateOneMainimg
(
id
,
theme
,
city
,
title
);
return
res
.
json
(
imgRes
);
}
}
}
}
}
}
});
});
res
.
json
();
});
});
src/db/mainimg.db.ts
View file @
5d59e60d
import
{
ObjectId
}
from
"
mongoose
"
;
import
{
ObjectId
}
from
"
mongoose
"
;
import
{
FileInfo
,
IFileInfo
,
Mainimg
,
MainimgType
}
from
"
../models
"
;
import
{
FileInfo
,
IFileInfo
,
Mainimg
,
MainimgType
}
from
"
../models
"
;
import
fs
from
"
fs/promises
"
;
import
{
fileInfoCtrl
}
from
"
../controllers
"
;
export
const
createMainimg
=
async
(
mainimg
:
MainimgType
,
pic
:
IFileInfo
)
=>
{
export
const
createMainimg
=
async
(
mainimg
:
MainimgType
,
pic
:
IFileInfo
)
=>
{
const
newPic
=
await
FileInfo
.
create
({
const
newPic
=
await
FileInfo
.
create
({
...
@@ -11,10 +13,10 @@ export const createMainimg = async (mainimg: MainimgType, pic: IFileInfo) => {
...
@@ -11,10 +13,10 @@ export const createMainimg = async (mainimg: MainimgType, pic: IFileInfo) => {
const
newMainimg
=
await
Mainimg
.
create
({
const
newMainimg
=
await
Mainimg
.
create
({
theme
:
mainimg
.
theme
,
theme
:
mainimg
.
theme
,
city
:
mainimg
.
city
,
city
:
mainimg
.
city
,
pic
:
newPic
.
_id
,
fileInfo
:
newPic
.
_id
,
title
:
mainimg
.
title
,
title
:
mainimg
.
title
,
});
});
return
newMainimg
;
return
newMainimg
.
populate
(
"
fileInfo
"
)
;
};
};
export
const
getMainimg
=
async
()
=>
{
export
const
getMainimg
=
async
()
=>
{
...
@@ -24,8 +26,16 @@ export const getMainimg = async () => {
...
@@ -24,8 +26,16 @@ export const getMainimg = async () => {
};
};
export
const
deleteOneMainimg
=
async
(
_id
:
string
)
=>
{
export
const
deleteOneMainimg
=
async
(
_id
:
string
)
=>
{
const
res
=
await
Mainimg
.
deleteOne
({
_id
:
_id
});
const
main
=
await
Mainimg
.
findById
(
_id
);
return
res
;
if
(
!
(
main
?.
fileInfo
===
undefined
))
{
const
ref
=
await
FileInfo
.
findById
(
main
.
fileInfo
.
_id
);
if
(
!
(
ref
?.
newfilename
===
undefined
))
{
await
fs
.
unlink
(
"
../travel/uploads/
"
+
ref
?.
newfilename
);
}
await
FileInfo
.
deleteOne
({
_id
:
main
.
fileInfo
.
_id
});
const
res
=
await
Mainimg
.
deleteOne
({
_id
:
_id
});
return
res
;
}
};
};
export
const
updateOneMainimg
=
async
(
export
const
updateOneMainimg
=
async
(
...
...
src/models/mainimg.model.ts
View file @
5d59e60d
...
@@ -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
,
},
},
fileInfo
:
{
type
:
Schema
.
Types
.
ObjectId
,
ref
:
"
File
i
nfo
"
},
fileInfo
:
{
type
:
Schema
.
Types
.
ObjectId
,
ref
:
"
File
I
nfo
"
},
});
});
export
default
model
<
MainimgType
>
(
"
Mainimg
"
,
MainimgSchema
);
export
default
model
<
MainimgType
>
(
"
Mainimg
"
,
MainimgSchema
);
src/routes/mainimg.route.ts
View file @
5d59e60d
...
@@ -5,13 +5,13 @@ const router = express.Router();
...
@@ -5,13 +5,13 @@ const router = express.Router();
router
router
.
route
(
"
/
"
)
.
route
(
"
/
"
)
.
get
(
authCtrl
.
requireLogin
,
mainimgCtrl
.
getMainimg
)
.
get
(
mainimgCtrl
.
getMainimg
)
.
post
(
authCtrl
.
requireLogin
,
mainimgCtrl
.
createMainimg
)
.
post
(
authCtrl
.
requireLogin
,
authCtrl
.
hasRole
(
"
admin
"
),
mainimgCtrl
.
createMainimg
)
router
router
.
route
(
"
/:imgId
"
)
.
route
(
"
/:imgId
"
)
.
delete
(
authCtrl
.
requireLogin
,
mainimgCtrl
.
deleteMainimg
)
.
delete
(
authCtrl
.
requireLogin
,
authCtrl
.
hasRole
(
"
admin
"
),
mainimgCtrl
.
deleteMainimg
)
.
put
(
authCtrl
.
requireLogin
,
authCtrl
.
hasRole
(
"
admin
"
),
mainimgCtrl
.
updateMainimg
);
.
put
(
authCtrl
.
requireLogin
,
authCtrl
.
hasRole
(
"
admin
"
),
mainimgCtrl
.
updateMainimg
);
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