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
butter-studio
Commits
302514b3
Commit
302514b3
authored
Jul 31, 2021
by
Kim, Subin
Browse files
theaterEdit 기능 완성
parent
bedd74ec
Changes
6
Show whitespace changes
Inline
Side-by-side
client/src/apis/theater.api.js
View file @
302514b3
...
@@ -6,8 +6,8 @@ const getAll = async () => {
...
@@ -6,8 +6,8 @@ const getAll = async () => {
return
data
return
data
}
}
const
getOne
=
async
()
=>
{
const
getOne
=
async
(
theaterId
)
=>
{
const
{
data
}
=
await
axios
.
get
(
`
${
baseUrl
}
/api/theater`
)
const
{
data
}
=
await
axios
.
get
(
`
${
baseUrl
}
/api/theater
/
${
theaterId
}
`
)
return
data
return
data
}
}
...
@@ -17,12 +17,12 @@ const getTheaterType = async () => {
...
@@ -17,12 +17,12 @@ const getTheaterType = async () => {
}
}
const
sendData
=
async
(
theater
)
=>
{
const
sendData
=
async
(
theater
)
=>
{
const
{
data
}
=
await
axios
.
put
(
`
${
baseUrl
}
/api/theater
/type
`
,
theater
)
const
{
data
}
=
await
axios
.
put
(
`
${
baseUrl
}
/api/theater`
,
theater
)
return
data
return
data
}
}
const
remove
=
async
()
=>
{
const
remove
=
async
(
theaterId
)
=>
{
const
{
data
}
=
await
axios
.
delete
(
`
${
baseUrl
}
/api/theater`
)
const
{
data
}
=
await
axios
.
delete
(
`
${
baseUrl
}
/api/theater
/
${
theaterId
}
`
)
return
data
return
data
}
}
...
...
client/src/components/Admin/TheaterEditForm.js
View file @
302514b3
...
@@ -4,8 +4,9 @@ import catchErrors from "../../utils/catchErrors.js";
...
@@ -4,8 +4,9 @@ import catchErrors from "../../utils/catchErrors.js";
import
styles
from
"
./admin.module.scss
"
;
import
styles
from
"
./admin.module.scss
"
;
const
INIT_THEATER
=
{
const
INIT_THEATER
=
{
id
:
0
,
theaterName
:
""
,
theaterName
:
""
,
theater
T
ype
:
0
,
theater
t
ype
Id
:
0
,
rows
:
1
,
rows
:
1
,
columns
:
1
columns
:
1
}
}
...
@@ -51,22 +52,23 @@ const TheaterEditForm = ({ edit, formRef }) => {
...
@@ -51,22 +52,23 @@ const TheaterEditForm = ({ edit, formRef }) => {
}
}
return
(
return
(
<
form
ref
=
{
formRef
}
onSubmit
=
{
handleSubmit
}
>
<
form
ref
=
{
formRef
}
className
=
"
mb-5
"
onSubmit
=
{
handleSubmit
}
>
<
div
className
=
"
d-flex justify-content-lg-between row row-cols-2 row-cols-lg-
4
gx-0 gy-2 gy-lg-0 mb-2 mb-lg-3
"
>
<
div
className
=
"
d-flex justify-content-lg-between row row-cols-2 row-cols-lg-
5
gx-0 gy-2 gy-lg-0 mb-2 mb-lg-3
"
>
<
label
htmlfor
=
"
theaterName
"
className
=
"
col-3 col-lg-auto col-form-label
"
>
상영관
이름
<
/label
>
<
label
htmlfor
=
"
theaterName
"
className
=
"
col-3 col-lg-auto col-form-label
"
>
상영관
이름
<
/label
>
<
div
className
=
"
col-
9
col-lg-4
"
>
<
div
className
=
"
col-
8
col-lg-4
"
>
<
input
className
=
{
`form-control
${
styles
.
shadowNone
}
`
}
id
=
"
theaterName
"
name
=
"
theaterName
"
type
=
"
text
"
value
=
{
theater
.
theaterName
}
onChange
=
{
handleChange
}
/
>
<
input
className
=
{
`form-control
${
styles
.
shadowNone
}
`
}
id
=
"
theaterName
"
name
=
"
theaterName
"
type
=
"
text
"
value
=
{
theater
.
theaterName
}
onChange
=
{
handleChange
}
/
>
<
/div
>
<
/div
>
<
lebel
htmlfor
=
"
theaterName
"
className
=
"
col-auto col-form-label mx-2 mx-lg-0
"
>
관
<
/lebel
>
<
label
htmlfor
=
"
theaterType
"
className
=
"
col-3 col-lg-auto col-form-label text-lg-center
"
>
상영관
종류
<
/label
>
<
label
htmlfor
=
"
theaterType
"
className
=
"
col-3 col-lg-auto col-form-label text-lg-center
"
>
상영관
종류
<
/label
>
<
div
className
=
"
col-9 col-lg-5
"
>
<
div
className
=
"
col-9 col-lg-5
"
>
<
select
className
=
{
`form-select
${
styles
.
shadowNone
}
${
styles
.
selectInput
}
`
}
id
=
"
theater
T
ype
"
name
=
"
theater
T
ype
"
onChange
=
{
handleChange
}
aria
-
label
=
"
select theaterType
"
defaultValue
=
{
theater
.
theaterType
}
>
<
select
className
=
{
`form-select
${
styles
.
shadowNone
}
${
styles
.
selectInput
}
`
}
id
=
"
theater
t
ype
Id
"
name
=
"
theater
t
ype
Id
"
value
=
{
theater
.
theatertypeId
}
onChange
=
{
handleChange
}
aria
-
label
=
"
select theaterType
"
defaultValue
=
"
0
"
>
{
types
.
length
!==
0
?
{
types
.
length
!==
0
?
types
.
map
((
type
,
index
)
=>
{
types
.
map
((
type
,
index
)
=>
{
if
(
index
===
0
)
return
<>
if
(
index
===
0
)
return
<>
<
option
value
=
"
0
"
disabled
>
상영관
종류를
선택해주십시오
.
<
/option
>
<
option
value
=
"
0
"
disabled
>
상영관
종류를
선택해주십시오
.
<
/option
>
<
option
value
=
{
type
.
id
}
>
{
type
.
theaterType
}
<
/option
>
<
option
value
=
{
type
.
id
}
>
{
type
.
theaterType
Name
}
<
/option
>
<
/
>
<
/
>
else
return
<
option
value
=
{
type
.
id
}
>
{
type
.
theaterType
}
<
/option
>
else
return
<
option
value
=
{
type
.
id
}
>
{
type
.
theaterType
Name
}
<
/option
>
})
})
:
<
option
value
=
"
0
"
disabled
>
서버에
등록된
상영관
종류가
없습니다
.
<
/option>
}
:
<
option
value
=
"
0
"
disabled
>
서버에
등록된
상영관
종류가
없습니다
.
<
/option>
}
<
/select
>
<
/select
>
...
...
client/src/components/Admin/TheaterTable.js
View file @
302514b3
...
@@ -21,10 +21,10 @@ const TheaterTable = ({ setEdit, formRef }) => {
...
@@ -21,10 +21,10 @@ const TheaterTable = ({ setEdit, formRef }) => {
}
}
}
}
async
function
editTheater
()
{
async
function
editTheater
(
theaterId
)
{
try
{
try
{
setError
(
""
)
setError
(
""
)
const
res
=
await
theaterApi
.
getOne
()
const
res
=
await
theaterApi
.
getOne
(
theaterId
)
setEdit
({
...
res
})
setEdit
({
...
res
})
formRef
?.
current
.
scrollIntoView
({
behavior
:
"
smooth
"
,
block
:
"
center
"
})
formRef
?.
current
.
scrollIntoView
({
behavior
:
"
smooth
"
,
block
:
"
center
"
})
}
catch
(
error
)
{
}
catch
(
error
)
{
...
@@ -32,10 +32,10 @@ const TheaterTable = ({ setEdit, formRef }) => {
...
@@ -32,10 +32,10 @@ const TheaterTable = ({ setEdit, formRef }) => {
}
}
}
}
async
function
deleteTheater
()
{
async
function
deleteTheater
(
theaterId
)
{
try
{
try
{
setError
(
""
)
setError
(
""
)
await
theaterApi
.
remove
()
await
theaterApi
.
remove
(
theaterId
)
alert
(
"
해당 상영관 정보를 성공적으로 삭제했습니다.
"
)
alert
(
"
해당 상영관 정보를 성공적으로 삭제했습니다.
"
)
getTheaterList
()
getTheaterList
()
}
catch
(
error
)
{
}
catch
(
error
)
{
...
@@ -45,6 +45,7 @@ const TheaterTable = ({ setEdit, formRef }) => {
...
@@ -45,6 +45,7 @@ const TheaterTable = ({ setEdit, formRef }) => {
return
(
return
(
<
table
className
=
{
`table text-center align-middle
${
styles
.
tableForm
}
`
}
>
<
table
className
=
{
`table text-center align-middle
${
styles
.
tableForm
}
`
}
>
{
console
.
log
(
"
asd==
"
,
theaterList
)}
<
thead
className
=
{
`table-dark align-middle
${
styles
.
dNone
}
`
}
>
<
thead
className
=
{
`table-dark align-middle
${
styles
.
dNone
}
`
}
>
<
tr
>
<
tr
>
<
th
>
상영관
이름
<
/th
>
<
th
>
상영관
이름
<
/th
>
...
@@ -56,13 +57,13 @@ const TheaterTable = ({ setEdit, formRef }) => {
...
@@ -56,13 +57,13 @@ const TheaterTable = ({ setEdit, formRef }) => {
<
tbody
>
<
tbody
>
{
theaterList
.
length
!==
0
?
theaterList
.
map
(
info
=>
{
theaterList
.
length
!==
0
?
theaterList
.
map
(
info
=>
<
tr
>
<
tr
>
<
td
>
ads
<
/td
>
<
td
>
{
info
.
theaterName
}
관
<
/td
>
<
td
>
ads
<
/td
>
<
td
>
{
info
.
theatertype
.
theaterTypeName
}
<
/td
>
<
td
>
ads
<
/td
>
<
td
>
{
info
.
rows
}
행
{
info
.
columns
}
열
<
br
/>
총
{
info
.
rows
*
info
.
columns
}
석
<
/td
>
<
td
>
<
td
>
<
div
className
=
"
d-flex flex-column
"
>
<
div
className
=
"
d-flex flex-column
"
>
<
button
type
=
"
button
"
className
=
"
btn btn-primary my-1
"
onClick
=
{()
=>
editTheater
()}
>
수정
<
/button
>
<
button
type
=
"
button
"
className
=
"
btn btn-primary my-1
"
onClick
=
{()
=>
editTheater
(
info
.
id
)}
>
수정
<
/button
>
<
button
type
=
"
button
"
className
=
"
btn btn-danger my-1
"
onClick
=
{()
=>
deleteTheater
()}
>
삭제
<
/button
>
<
button
type
=
"
button
"
className
=
"
btn btn-danger my-1
"
onClick
=
{()
=>
deleteTheater
(
info
.
id
)}
>
삭제
<
/button
>
<
/div
>
<
/div
>
<
/td
>
<
/td
>
<
/tr>
)
<
/tr>
)
...
...
server/controllers/theater.controller.js
View file @
302514b3
import
{
Theater
,
T
icketFe
e
}
from
"
../db/index.js
"
;
import
{
Theater
,
T
heaterTyp
e
}
from
"
../db/index.js
"
;
const
getAll
=
async
(
req
,
res
)
=>
{
const
getAll
=
async
(
req
,
res
)
=>
{
try
{
try
{
const
findList
=
await
Theater
.
findAll
({
include
:
[{
model
:
TicketFee
,
attributes
:
[
"
theaterType
"
]
}]
})
const
findList
=
await
Theater
.
findAll
({
attributes
:
{
exclude
:
[
'
createdAt
'
,
'
updatedAt
'
]
},
include
:
[
TheaterType
],
order
:
[[
'
theaterName
'
]]
})
console
.
log
(
"
Ads==
"
,
findList
)
return
res
.
json
(
findList
)
return
res
.
json
(
findList
)
}
catch
(
error
)
{
}
catch
(
error
)
{
return
res
.
status
(
500
).
send
(
error
.
message
||
"
상영관 정보 가져오는 중 에러 발생
"
)
return
res
.
status
(
500
).
send
(
error
.
message
||
"
상영관 정보 가져오는 중 에러 발생
"
)
}
}
}
}
const
getOne
=
async
(
req
,
res
)
=>
{
try
{
const
{
theaterId
}
=
req
.
params
const
find
=
await
Theater
.
findOne
({
where
:
{
id
:
theaterId
}
,
attributes
:
{
exclude
:
[
'
createdAt
'
,
'
updatedAt
'
]
}
})
if
(
!
find
)
throw
new
Error
(
"
해당 정보를 찾지 못했습니다.
"
);
return
res
.
json
(
find
)
}
catch
(
error
)
{
return
res
.
status
(
500
).
send
(
error
.
message
||
"
상영관 정보 가져오는 중 에러 발생
"
)
}
}
const
getTypes
=
async
(
req
,
res
)
=>
{
const
getTypes
=
async
(
req
,
res
)
=>
{
try
{
try
{
const
findTypes
=
await
T
icketFe
e
.
findAll
({
attributes
:
[
'
id
'
,
'
theaterType
'
]
})
const
findTypes
=
await
T
heaterTyp
e
.
findAll
({
attributes
:
{
exclude
:
[
'
createdAt
'
,
'
updatedAt
'
]
}
})
return
res
.
json
(
findTypes
)
return
res
.
json
(
findTypes
)
}
catch
(
error
)
{
}
catch
(
error
)
{
return
res
.
status
(
500
).
send
(
error
.
message
||
"
상영관 정보 가져오는 중 에러 발생
"
)
return
res
.
status
(
500
).
send
(
error
.
message
||
"
상영관 정보 가져오는 중 에러 발생
"
)
...
@@ -21,10 +31,10 @@ const getTypes = async (req, res) => {
...
@@ -21,10 +31,10 @@ const getTypes = async (req, res) => {
const
submit
=
async
(
req
,
res
)
=>
{
const
submit
=
async
(
req
,
res
)
=>
{
try
{
try
{
const
{
id
}
=
req
.
body
const
{
id
,
theatertypeId
,
theaterName
,
rows
,
columns
}
=
req
.
body
let
response
=
null
let
response
=
null
if
(
id
)
response
=
await
Theater
.
update
({
...
req
.
body
},
{
where
:
{
id
:
id
}
})
if
(
id
)
response
=
await
Theater
.
update
({
theatertypeId
,
theaterName
,
rows
,
columns
},
{
where
:
{
id
:
id
}
})
else
response
=
await
Theater
.
create
({
...
req
.
body
})
else
response
=
await
Theater
.
create
({
theatertypeId
,
theaterName
,
rows
,
columns
})
return
res
.
json
(
response
)
return
res
.
json
(
response
)
}
catch
(
error
)
{
}
catch
(
error
)
{
return
res
.
status
(
500
).
send
(
error
.
message
||
"
상영관 정보 저장 중 에러 발생
"
)
return
res
.
status
(
500
).
send
(
error
.
message
||
"
상영관 정보 저장 중 에러 발생
"
)
...
@@ -33,7 +43,10 @@ const submit = async (req, res) => {
...
@@ -33,7 +43,10 @@ const submit = async (req, res) => {
const
remove
=
async
(
req
,
res
)
=>
{
const
remove
=
async
(
req
,
res
)
=>
{
try
{
try
{
const
{
theaterId
}
=
req
.
params
const
delNum
=
await
Theater
.
destroy
({
where
:
{
id
:
theaterId
}
})
if
(
delNum
)
res
.
json
(
delNum
)
else
throw
new
Error
(
"
해당 정보를 서버에서 삭제하는데 실패했습니다.
"
);
}
catch
(
error
)
{
}
catch
(
error
)
{
return
res
.
status
(
500
).
send
(
error
.
message
||
"
상영관 정보 삭제 중 에러 발생
"
)
return
res
.
status
(
500
).
send
(
error
.
message
||
"
상영관 정보 삭제 중 에러 발생
"
)
}
}
...
@@ -41,6 +54,7 @@ const remove = async (req, res) => {
...
@@ -41,6 +54,7 @@ const remove = async (req, res) => {
export
default
{
export
default
{
getAll
,
getAll
,
getOne
,
getTypes
,
getTypes
,
submit
,
submit
,
remove
remove
...
...
server/index.js
View file @
302514b3
...
@@ -10,7 +10,7 @@ dotenv.config({
...
@@ -10,7 +10,7 @@ dotenv.config({
});
});
sequelize
sequelize
.
sync
({
force
:
tru
e
})
.
sync
({
force
:
fals
e
})
.
then
(
async
()
=>
{
.
then
(
async
()
=>
{
await
Promise
.
all
(
await
Promise
.
all
(
Object
.
keys
(
ROLE_NAME
).
map
((
name
)
=>
{
Object
.
keys
(
ROLE_NAME
).
map
((
name
)
=>
{
...
...
server/routes/theater.route.js
View file @
302514b3
...
@@ -7,10 +7,14 @@ router
...
@@ -7,10 +7,14 @@ router
.
route
(
"
/
"
)
.
route
(
"
/
"
)
.
get
(
theaterCtrl
.
getAll
)
.
get
(
theaterCtrl
.
getAll
)
.
put
(
theaterCtrl
.
submit
)
.
put
(
theaterCtrl
.
submit
)
.
delete
(
theaterCtrl
.
remove
)
router
router
.
route
(
"
/type
"
)
.
route
(
"
/type
"
)
.
get
(
theaterCtrl
.
getTypes
)
.
get
(
theaterCtrl
.
getTypes
)
router
.
route
(
"
/:theaterId
"
)
.
get
(
theaterCtrl
.
getOne
)
.
delete
(
theaterCtrl
.
remove
)
export
default
router
;
export
default
router
;
\ No newline at end of file
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