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
Show whitespace changes
Inline
Side-by-side
frontend/src/App.tsx
View file @
5d59e60d
...
...
@@ -37,7 +37,7 @@ export const App = () => {
</
RequireAuth
>
}
/>
<
Route
path
=
"admin"
element
=
{
<
Admin
/
>
}
/>
<
Route
path
=
"admin"
element
=
{
<
RequireAuth
><
Admin
/></
RequireAuth
>
}
/>
<
Route
path
=
"admin/:imgId"
element
=
{
<
ImgRewrite
/>
}
/>
<
Route
path
=
"rewrite"
element
=
{
<
ImgRewrite
/>
}
/>
</
Route
>
...
...
frontend/src/auth/admin.tsx
View file @
5d59e60d
import
{
get
}
from
"
mongoose
"
;
import
React
,
{
FormEvent
,
useEffect
,
useState
,
MouseEvent
}
from
"
react
"
;
import
{
Link
}
from
"
react-router-dom
"
;
import
{
mainimgApi
}
from
"
../apis
"
;
...
...
@@ -21,15 +22,15 @@ export default function Admin() {
useEffect
(()
=>
{
imgsData
();
},
[]);
// 이미지 추가하기
const
[
addimg
,
setAddimg
]
=
useState
<
MainimgType
>
({
_id
:
""
,
theme
:
""
,
city
:
""
,
title
:
""
,
pic
:
{
originalfilename
:
""
,
newfilename
:
""
},
fileInfo
:
{
originalfilename
:
""
,
newfilename
:
""
},
});
const
[
loading
,
setLoading
]
=
useState
(
false
);
const
[
error
,
setError
]
=
useState
(
""
);
const
[
addSuccess
,
setAddSuccess
]
=
useState
(
false
);
...
...
@@ -60,15 +61,27 @@ export default function Admin() {
formdata
.
append
(
"
city
"
,
addimg
.
city
);
formdata
.
append
(
"
theme
"
,
addimg
.
theme
);
formdata
.
append
(
"
title
"
,
addimg
.
title
);
try
{
if
(
!
(
file
===
undefined
))
{
formdata
.
append
(
"
mainimg
"
,
file
);
console
.
log
(
formdata
);
console
.
log
(
"
fordata
"
,
formdata
);
const
res
=
await
mainimgApi
.
mainimg
(
formdata
);
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
{
...
...
@@ -81,6 +94,8 @@ export default function Admin() {
setDelSuccess
(
true
);
setError
(
""
);
alert
(
"
img 삭제되었습니다
"
);
const
deleteimg
=
getimgs
.
filter
(
pic
=>
picId
!==
pic
.
_id
)
setGetimgs
(
deleteimg
)
}
else
{
return
false
;
}
...
...
@@ -107,7 +122,7 @@ export default function Admin() {
<
div
key
=
{
index
}
>
<
div
className
=
{
`m-1 shrink-0 bg-gray-200 rounded shadow-md `
}
>
<
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"
/>
<
p
className
=
"text-center text-xs"
>
{
picture
.
title
}
</
p
>
...
...
@@ -145,16 +160,16 @@ export default function Admin() {
onChange
=
{
handleSelectChange
}
>
<
option
value
=
"질문종류"
>
도시
</
option
>
<
option
value
=
"
서울
"
>
서울
</
option
>
<
option
value
=
"
부산
"
>
부산
</
option
>
<
option
value
=
"
인천
"
>
인천
</
option
>
<
option
value
=
"
대구
"
>
대구
</
option
>
<
option
value
=
"
광주
"
>
광주
</
option
>
<
option
value
=
"
대전
"
>
대전
</
option
>
<
option
value
=
"
울산
"
>
울산
</
option
>
<
option
value
=
"
세종
"
>
세종
</
option
>
<
option
value
=
"
독도
"
>
독도
</
option
>
<
option
value
=
"
제주
"
>
제주
</
option
>
<
option
value
=
"
Seoul
"
>
서울
</
option
>
<
option
value
=
"
Busan
"
>
부산
</
option
>
<
option
value
=
"
Incheon
"
>
인천
</
option
>
<
option
value
=
"
Daegoo
"
>
대구
</
option
>
<
option
value
=
"
Gwangjoo
"
>
광주
</
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"
...
...
@@ -164,18 +179,18 @@ export default function Admin() {
onChange
=
{
handleSelectChange
}
>
<
option
value
=
"질문종류"
>
테마
</
option
>
<
option
value
=
"
사이클링
"
>
사이클링
</
option
>
<
option
value
=
"
서핑
"
>
서핑
</
option
>
<
option
value
=
"
액티비티
"
>
액티비티
</
option
>
<
option
value
=
"
캠핑
"
>
캠핑
</
option
>
<
option
value
=
"
스키
"
>
스키
</
option
>
<
option
value
=
"
보트
"
>
보트
</
option
>
<
option
value
=
"
사막
"
>
사막
</
option
>
<
option
value
=
"
골프
"
>
골프
</
option
>
<
option
value
=
"
동굴
"
>
동굴
</
option
>
<
option
value
=
"
문화재
"
>
문화재
</
option
>
<
option
value
=
"
동물원
"
>
동물원
</
option
>
<
option
value
=
"
사이클링
"
>
사이클링
</
option
>
<
option
value
=
"
cycling
"
>
사이클링
</
option
>
<
option
value
=
"
surfing
"
>
서핑
</
option
>
<
option
value
=
"
activity
"
>
액티비티
</
option
>
<
option
value
=
"
camping
"
>
캠핑
</
option
>
<
option
value
=
"
skiing
"
>
스키
</
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
>
<
div
className
=
"flex items-center justify-end gap-3"
>
<
input
...
...
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
{
mainimgApi
}
from
"
../apis
"
;
import
isLength
from
"
validator/lib/isLength
"
;
...
...
@@ -27,9 +27,11 @@ export default function ImgRewrite() {
theme
:
img
.
theme
,
city
:
img
.
city
,
title
:
img
.
title
,
pic
:
{
originalfilename
:
""
,
newfilename
:
""
},
fileInfo
:
{
originalfilename
:
""
,
newfilename
:
""
},
});
useEffect
(()
=>
{
console
.
log
(
"
수정 전 :
"
,
imgdata
);
},
[]);
const
[
loading
,
setLoading
]
=
useState
(
false
);
const
[
error
,
setError
]
=
useState
(
""
);
...
...
@@ -86,7 +88,6 @@ export default function ImgRewrite() {
console
.
log
(
"
확인 중
"
,
res
);
}
else
{
console
.
log
(
"
ㅇ에러
"
)
formdata
.
append
(
"
updatemainimg
"
,
""
);
console
.
log
(
"
formdata
"
,
formdata
);
const
res
=
await
mainimgApi
.
updateimg
(
formdata
,
imgdata
.
_id
);
...
...
@@ -109,7 +110,7 @@ export default function ImgRewrite() {
if
(
!
isLength
(
pic
.
title
??
""
,
{
min
:
1
}))
{
setError
(
"
제목을 입력해 주세요.
"
);
return
false
;
}
else
if
(
!
isLength
(
pic
.
pic
.
newfilename
??
""
,
{
min
:
1
}))
{
}
else
if
(
!
isLength
(
pic
.
fileInfo
.
newfilename
??
""
,
{
min
:
1
}))
{
setError
(
"
파일을 선택해 주세요.
"
);
return
false
;
}
else
if
(
equals
(
pic
.
city
,
"
city
"
))
{
...
...
@@ -232,7 +233,7 @@ export default function ImgRewrite() {
/>
)
:
(
<
img
src
=
{
"
http://localhost:3000/images/
"
+
img
.
pic
.
newfilename
}
src
=
{
"
http://localhost:3000/images/
"
+
img
.
fileInfo
.
newfilename
}
className
=
"object-cover object-center h-full"
/>
)
}
...
...
frontend/src/board/board.tsx
View file @
5d59e60d
...
...
@@ -13,7 +13,8 @@ export default function BoardPage() {
useEffect
(()
=>
{
getDataList
();
},
[
posts
]);
},
[]);
// posts
const
getDataList
=
async
()
=>
{
const
res
=
await
postApi
.
getData
();
...
...
frontend/src/home/body.tsx
View file @
5d59e60d
...
...
@@ -69,7 +69,9 @@ export default function Body() {
key
=
{
index
}
>
<
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"
/>
<
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) {
캠핑
</
button
>
<
button
id
=
{
"
sking
"
}
id
=
{
"
ski
i
ng
"
}
onClick
=
{
handleClick
}
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) {
도시
</
div
>
<
button
id
=
{
"
서울
"
}
id
=
{
"
Seoul
"
}
onClick
=
{
handleClick
}
className
=
"text-start px-5 py-2 hover:underline whitespace-nowrap"
>
서울
</
button
>
<
button
id
=
{
"
부산
"
}
id
=
{
"
Busan
"
}
onClick
=
{
handleClick
}
className
=
"text-start px-5 py-2 hover:underline whitespace-nowrap"
>
부산
</
button
>
<
button
id
=
{
"
인천
"
}
id
=
{
"
Incheon
"
}
onClick
=
{
handleClick
}
className
=
"text-start px-5 py-2 hover:underline whitespace-nowrap"
>
인천
</
button
>
<
button
id
=
{
"
대구
"
}
id
=
{
"
Daegoo
"
}
onClick
=
{
handleClick
}
className
=
"text-start px-5 py-2 hover:underline whitespace-nowrap"
>
대구
</
button
>
<
button
id
=
{
"
광주
"
}
id
=
{
"
Gwangjoo
"
}
onClick
=
{
handleClick
}
className
=
"text-start px-5 py-2 hover:underline whitespace-nowrap"
>
광주
</
button
>
<
button
id
=
{
"
대전
"
}
id
=
{
"
Daejeon
"
}
onClick
=
{
handleClick
}
className
=
"text-start px-5 py-2 hover:underline whitespace-nowrap"
>
대전
</
button
>
<
button
id
=
{
"
울산
"
}
id
=
{
"
Woolsan
"
}
onClick
=
{
handleClick
}
className
=
"text-start px-5 py-2 hover:underline whitespace-nowrap"
>
울산
</
button
>
<
button
id
=
{
"
세종
"
}
id
=
{
"
Sejong
"
}
onClick
=
{
handleClick
}
className
=
"text-start px-5 py-2 hover:underline whitespace-nowrap"
>
세종
</
button
>
<
button
id
=
{
"
독도
"
}
id
=
{
"
Dokdo
"
}
onClick
=
{
handleClick
}
className
=
"text-start px-5 py-2 hover:underline whitespace-nowrap"
>
독도
</
button
>
<
button
id
=
{
"
제주
"
}
id
=
{
"
Jeju
"
}
onClick
=
{
handleClick
}
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 {
theme
:
string
;
city
:
string
;
title
:
string
;
pic
:
{
fileInfo
:
{
originalfilename
:
string
;
newfilename
:
string
;
};
...
...
src/controllers/mainimg.controller.ts
View file @
5d59e60d
...
...
@@ -17,7 +17,7 @@ export const createMainimg = asyncWrap(async (reqExp, res) => {
multiples
:
false
,
});
form
.
parse
(
req
,
(
err
,
fields
,
files
)
=>
{
form
.
parse
(
req
,
async
(
err
,
fields
,
files
)
=>
{
if
(
!
Array
.
isArray
(
files
.
mainimg
))
{
//파일 좁히기 중
if
(
...
...
@@ -33,37 +33,24 @@ export const createMainimg = asyncWrap(async (reqExp, res) => {
const
originalfilename
=
files
.
mainimg
?.
originalFilename
;
const
newfilename
=
files
.
mainimg
.
newFilename
;
if
(
!
(
originalfilename
===
null
||
newfilename
===
undefined
))
{
mainimgDb
.
createMainimg
(
const
imgRes
=
await
mainimgDb
.
createMainimg
(
{
city
,
title
,
theme
},
{
originalfilename
,
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
)
=>
{
const
mainimgs
=
await
mainimgDb
.
getMainimg
();
...
...
@@ -72,8 +59,8 @@ export const getMainimg = asyncWrap(async (req, res) => {
export
const
deleteMainimg
=
asyncWrap
(
async
(
req
,
res
)
=>
{
const
{
imgId
}
=
req
.
params
;
console
.
log
(
imgId
);
const
deleteCount
=
await
mainimgDb
.
deleteOneMainimg
(
imgId
);
console
.
log
(
deleteCount
);
return
res
.
json
(
deleteCount
);
});
...
...
@@ -107,7 +94,7 @@ export const updateMainimg = asyncWrap(async (reqExp, res) => {
const
originalfilename
=
files
.
updatemainimg
?.
originalFilename
;
const
newfilename
=
files
.
updatemainimg
.
newFilename
;
if
(
!
(
originalfilename
===
null
||
newfilename
===
undefined
))
{
mainimgDb
.
updateOneMainimg
(
const
imgRes
=
mainimgDb
.
updateOneMainimg
(
id
,
theme
,
city
,
...
...
@@ -115,12 +102,13 @@ export const updateMainimg = asyncWrap(async (reqExp, res) => {
originalfilename
,
newfilename
);
return
res
.
json
(
imgRes
);
}
}
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
{
FileInfo
,
IFileInfo
,
Mainimg
,
MainimgType
}
from
"
../models
"
;
import
fs
from
"
fs/promises
"
;
import
{
fileInfoCtrl
}
from
"
../controllers
"
;
export
const
createMainimg
=
async
(
mainimg
:
MainimgType
,
pic
:
IFileInfo
)
=>
{
const
newPic
=
await
FileInfo
.
create
({
...
...
@@ -11,10 +13,10 @@ export const createMainimg = async (mainimg: MainimgType, pic: IFileInfo) => {
const
newMainimg
=
await
Mainimg
.
create
({
theme
:
mainimg
.
theme
,
city
:
mainimg
.
city
,
pic
:
newPic
.
_id
,
fileInfo
:
newPic
.
_id
,
title
:
mainimg
.
title
,
});
return
newMainimg
;
return
newMainimg
.
populate
(
"
fileInfo
"
)
;
};
export
const
getMainimg
=
async
()
=>
{
...
...
@@ -24,8 +26,16 @@ export const getMainimg = async () => {
};
export
const
deleteOneMainimg
=
async
(
_id
:
string
)
=>
{
const
main
=
await
Mainimg
.
findById
(
_id
);
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
(
...
...
src/models/mainimg.model.ts
View file @
5d59e60d
...
...
@@ -18,7 +18,7 @@ const MainimgSchema = new Schema<MainimgType>({
type
:
String
,
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
);
src/routes/mainimg.route.ts
View file @
5d59e60d
...
...
@@ -5,13 +5,13 @@ const router = express.Router();
router
.
route
(
"
/
"
)
.
get
(
authCtrl
.
requireLogin
,
mainimgCtrl
.
getMainimg
)
.
post
(
authCtrl
.
requireLogin
,
mainimgCtrl
.
createMainimg
)
.
get
(
mainimgCtrl
.
getMainimg
)
.
post
(
authCtrl
.
requireLogin
,
authCtrl
.
hasRole
(
"
admin
"
),
mainimgCtrl
.
createMainimg
)
router
.
route
(
"
/:imgId
"
)
.
delete
(
authCtrl
.
requireLogin
,
mainimgCtrl
.
deleteMainimg
)
.
put
(
authCtrl
.
requireLogin
,
authCtrl
.
hasRole
(
"
admin
"
),
mainimgCtrl
.
updateMainimg
);
.
delete
(
authCtrl
.
requireLogin
,
authCtrl
.
hasRole
(
"
admin
"
),
mainimgCtrl
.
deleteMainimg
)
.
put
(
authCtrl
.
requireLogin
,
authCtrl
.
hasRole
(
"
admin
"
),
mainimgCtrl
.
updateMainimg
);
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