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
992699ae
Commit
992699ae
authored
Aug 02, 2021
by
Jiwon Yoon
Browse files
Merge branch 'kimpen'
parents
1abc13d9
ced462de
Changes
11
Hide whitespace changes
Inline
Side-by-side
client/src/apis/timetable.api.js
0 → 100644
View file @
992699ae
import
axios
from
"
axios
"
;
import
{
baseUrl
}
from
"
../utils/baseUrl.js
"
;
const
submit
=
async
(
sendData
)
=>
{
const
{
data
}
=
await
axios
.
post
(
`
${
baseUrl
}
/api/timetable`
,
sendData
)
return
data
}
const
timetableApi
=
{
submit
}
export
default
timetableApi
\ No newline at end of file
client/src/components/Admin/TheaterEditForm.js
View file @
992699ae
...
...
@@ -48,6 +48,7 @@ const TheaterEditForm = ({ edit, formRef }) => {
window
.
location
.
reload
()
}
catch
(
error
)
{
catchErrors
(
error
,
setError
)
setTheater
({
...
theater
,
...
INIT_THEATER
})
}
}
...
...
client/src/components/Admin/TimeTable.js
View file @
992699ae
const
TimeTable
=
()
=>
{
return
(
<>
<
/
>
<
div
className
=
"
col-6
"
>
<
/
div
>
)
}
...
...
client/src/components/Admin/TimeTableEdit.js
View file @
992699ae
...
...
@@ -4,11 +4,11 @@ import TimeTable from "./TimeTable";
const
TimeTableEdit
=
()
=>
{
return
(
<>
<
h2
className
=
"
border-bottom border-2 text-center pb-2 me-2
"
>
현재
상영시간표
정보
<
/h2
>
<
div
>
<
TimeTableEditForm
/>
<
TimeTable
/>
<
/div
>
<
h2
className
=
"
border-bottom border-2 text-center pb-2 me-2
"
>
현재
상영시간표
정보
<
/h2
>
<
div
className
=
"
d-flex
"
>
<
TimeTableEditForm
/>
<
TimeTable
/>
<
/div
>
<
/
>
)
}
...
...
client/src/components/Admin/TimeTableEditForm.js
View file @
992699ae
import
{
useState
,
useEffect
}
from
"
react
"
;
import
movieApi
from
"
../../apis/movie.api.js
"
;
import
theaterApi
from
"
../../apis/theater.api.js
"
;
import
timetableApi
from
"
../../apis/timetable.api.js
"
;
import
catchErrors
from
"
../../utils/catchErrors.js
"
;
import
styles
from
"
./admin.module.scss
"
;
const
INIT_MOVIE
=
{
movieId
:
0
,
title
:
""
,
release_date
:
""
,
end_date
:
""
,
theater
:
[],
times
:
[]
const
INIT_INFO
=
{
theater
:
0
,
start
:
""
,
end
:
""
}
const
TimeTableEditForm
=
()
=>
{
...
...
@@ -18,9 +16,9 @@ const TimeTableEditForm = () => {
const
[
theaterList
,
setTheaterList
]
=
useState
([])
const
[
selectId
,
setSelectId
]
=
useState
(
0
)
const
[
selectMovie
,
setSelectMovie
]
=
useState
({})
const
[
selectInfo
,
setSelectInfo
]
=
useState
({
theater
:
0
,
start
:
""
,
end
:
""
})
const
[
info
,
setInfo
]
=
useState
({
end_date
:
""
})
const
[
selectInfo
,
setSelectInfo
]
=
useState
(
INIT_INFO
)
const
[
showTimes
,
setShowTimes
]
=
useState
({
list
:
[]
})
const
[
sendInfo
,
setSendInfo
]
=
useState
(
INIT_MOVIE
)
const
[
error
,
setError
]
=
useState
(
""
)
useEffect
(()
=>
{
...
...
@@ -28,6 +26,11 @@ const TimeTableEditForm = () => {
getTheater
()
},
[])
useEffect
(()
=>
{
setSelectInfo
({
...
selectInfo
,
...
INIT_INFO
})
setShowTimes
({
list
:
[]
})
},
[
selectId
])
async
function
getMoviesfromDB
()
{
try
{
setError
(
""
)
...
...
@@ -48,17 +51,23 @@ const TimeTableEditForm = () => {
}
}
function
getDate
(
string
)
{
const
arr
=
string
.
split
(
'
:
'
)
const
date
=
new
Date
(
0
,
0
,
0
,
Number
(
arr
[
0
]),
Number
(
arr
[
1
]))
return
date
}
function
addRunTime
(
start
,
runTime
)
{
const
startArr
=
start
.
split
(
'
:
'
)
const
add
=
Number
(
startArr
[
1
])
+
runTime
let
hours
=
Number
(
startArr
[
0
])
+
Math
.
floor
(
add
/
60
)
if
(
hours
<=
9
)
hours
=
'
0
'
+
hours
if
(
hours
/
24
>
0
)
hours
=
'
0
'
+
hours
%
24
if
(
Math
.
floor
(
hours
/
24
)
>
0
)
hours
=
'
0
'
+
hours
%
24
else
if
(
hours
<=
9
)
hours
=
'
0
'
+
hours
let
mins
=
add
%
60
if
(
mins
<=
9
)
mins
=
'
0
'
+
mins
setSelectInfo
({
...
selectInfo
,
"
start
"
:
start
,
"
end
"
:
hours
+
'
:
'
+
mins
})
}
...
...
@@ -66,23 +75,27 @@ const TimeTableEditForm = () => {
const
{
list
}
=
showTimes
const
isSelect
=
Object
.
values
(
selectInfo
).
every
((
el
)
=>
Boolean
(
el
))
if
(
isSelect
)
{
const
theater
=
theaterList
.
find
(
theater
=>
theater
.
theatertypeId
===
selectInfo
.
theater
)
if
(
theater
)
{
const
myTime
=
{
theaterTypeId
:
selectInfo
.
theater
,
theaterName
:
theater
.
theaterName
+
'
관 /
'
+
theater
.
theatertype
.
theaterTypeName
,
start
:
selectInfo
.
start
,
end
:
selectInfo
.
end
}
setShowTimes
({
list
:
list
.
concat
(
myTime
)
})
}
else
alert
(
'
선택한 상영관을 찾지 못했습니다. 다시 시도하길 바랍니다.
'
)
const
isTime
=
list
.
find
(
el
=>
el
.
theaterTypeId
===
selectInfo
.
theater
&&
(
getDate
(
el
.
start
)
<=
getDate
(
selectInfo
.
end
)
&&
getDate
(
el
.
end
)
>=
getDate
(
selectInfo
.
start
)))
if
(
isTime
)
alert
(
'
이미 추가한 상영시간대입니다. 다른 시간대를 골라주시기 바랍니다.
'
)
else
{
const
theater
=
theaterList
.
find
(
theater
=>
theater
.
theatertypeId
===
selectInfo
.
theater
)
if
(
theater
)
{
const
myTime
=
{
theaterTypeId
:
selectInfo
.
theater
,
theaterName
:
theater
.
theaterName
+
'
관 /
'
+
theater
.
theatertype
.
theaterTypeName
,
start
:
selectInfo
.
start
,
end
:
selectInfo
.
end
}
setShowTimes
({
list
:
list
.
concat
(
myTime
)
})
}
else
alert
(
'
선택한 상영관을 찾지 못했습니다. 다시 시도하길 바랍니다.
'
)
}
}
else
alert
(
'
추가할 데이터의 갯수가 부족합니다. 모든 항목을 입력해주시길 바랍니다.
'
)
setSelectInfo
({
...
selectInfo
,
theater
:
0
,
start
:
""
,
end
:
""
})
setSelectInfo
({
...
selectInfo
,
...
INIT_INFO
})
}
function
delData
(
index
)
{
let
{
list
}
=
showTimes
list
=
list
.
splice
(
index
,
1
)
list
.
splice
(
index
,
1
)
setShowTimes
({
list
:
list
})
}
...
...
@@ -94,9 +107,9 @@ const TimeTableEditForm = () => {
setSelectId
(
value
)
const
res
=
await
movieApi
.
getMovieInfofromTM
(
value
)
setSelectMovie
({
...
res
})
set
Send
Info
({
...
sendInfo
,
movieId
:
value
,
title
:
res
.
title
,
release_date
:
res
.
release_date
,
end_date
:
""
})
setInfo
({
...
info
,
end_date
:
""
})
}
else
if
(
name
===
"
end_date
"
)
{
set
Send
Info
({
...
sendI
nfo
,
[
name
]:
value
})
setInfo
({
...
i
nfo
,
[
name
]:
value
})
}
else
if
(
name
===
"
theater
"
)
{
setSelectInfo
({
...
selectInfo
,
[
name
]:
Number
(
value
)
})
}
else
if
(
name
===
"
start
"
)
{
...
...
@@ -105,13 +118,25 @@ const TimeTableEditForm = () => {
}
catch
(
error
)
{
catchErrors
(
error
,
setError
)
}
}
async
function
handleSubmit
(
e
)
{
e
.
preventDefault
()
const
timeArr
=
[]
try
{
setError
(
""
)
showTimes
.
list
.
map
(
time
=>
{
timeArr
.
push
({
theater
:
time
.
theaterTypeId
,
start
:
time
.
start
,
end
:
time
.
end
})
})
const
sendData
=
{
movieId
:
selectMovie
.
id
,
title
:
selectMovie
.
title
,
release_date
:
selectMovie
.
release_date
,
runtime
:
selectMovie
.
runtime
,
theater
:
timeArr
,
date
:
info
.
end_date
}
await
timetableApi
.
submit
(
sendData
)
alert
(
"
해당 상영시간표 정보 등록이 성공적으로 완료되었습니다.
"
)
window
.
location
.
reload
()
}
catch
(
error
)
{
...
...
@@ -120,8 +145,7 @@ const TimeTableEditForm = () => {
}
return
(
<
form
onSubmit
=
{
handleSubmit
}
>
{
console
.
log
(
"
select==
"
,
showTimes
)}
<
form
className
=
"
col-6
"
onSubmit
=
{
handleSubmit
}
>
<
select
className
=
{
`form-select mb-3
${
styles
.
shadowNone
}
${
styles
.
selectInput
}
`
}
id
=
"
movieId
"
name
=
"
movieId
"
value
=
{
selectId
}
onChange
=
{
handleChange
}
aria
-
label
=
"
select movie
"
defaultValue
=
"
0
"
>
{
movieList
.
length
!==
0
?
movieList
.
map
((
movie
,
index
)
=>
{
...
...
@@ -139,7 +163,7 @@ const TimeTableEditForm = () => {
<
/div
>
<
div
className
=
"
col-md-6 mb-3
"
>
<
label
htmlFor
=
"
end_date
"
className
=
"
form-label
"
>
상영종료일
<
/label
>
<
input
type
=
"
date
"
className
=
{
`form-control
${
styles
.
shadowNone
}
`
}
id
=
"
end_date
"
name
=
"
end_date
"
value
=
{
sendI
nfo
.
end_date
}
min
=
{
se
ndInfo
.
release_date
}
onChange
=
{
handleChange
}
/
>
<
input
type
=
"
date
"
className
=
{
`form-control
${
styles
.
shadowNone
}
`
}
id
=
"
end_date
"
name
=
"
end_date
"
value
=
{
i
nfo
.
end_date
}
min
=
{
se
lectMovie
.
release_date
}
onChange
=
{
handleChange
}
/
>
<
/div
>
<
p
>
시간대
설정
<
/p
>
<
ul
className
=
"
list-group list-group-flush
"
>
...
...
server/controllers/theater.controller.js
View file @
992699ae
...
...
@@ -15,7 +15,7 @@ const getTheaterInfo = async (req, res) => {
}
const
getAll
=
async
(
req
,
res
)
=>
{
try
{
const
findList
=
await
Theater
.
findAll
({
attributes
:
{
exclude
:
[
'
createdAt
'
,
'
updatedAt
'
]
},
include
:
[
TheaterType
],
order
:
[[
'
theaterName
'
]]
})
const
findList
=
await
Theater
.
findAll
({
attributes
:
{
exclude
:
[
'
createdAt
'
,
'
updatedAt
'
]
},
include
:
[
TheaterType
],
order
:
[[
'
theaterName
'
]]
})
return
res
.
json
(
findList
)
}
catch
(
error
)
{
return
res
.
status
(
500
).
send
(
error
.
message
||
"
상영관 정보 가져오는 중 에러 발생
"
)
...
...
@@ -25,7 +25,7 @@ const getAll = async (req, res) => {
const
getOne
=
async
(
req
,
res
)
=>
{
try
{
const
{
theaterId
}
=
req
.
params
const
find
=
await
Theater
.
findOne
({
where
:
{
id
:
theaterId
}
,
attributes
:
{
exclude
:
[
'
createdAt
'
,
'
updatedAt
'
]
}
})
const
find
=
await
Theater
.
findOne
({
where
:
{
id
:
theaterId
},
attributes
:
{
exclude
:
[
'
createdAt
'
,
'
updatedAt
'
]
}
})
if
(
!
find
)
throw
new
Error
(
"
해당 정보를 찾지 못했습니다.
"
);
return
res
.
json
(
find
)
}
catch
(
error
)
{
...
...
@@ -47,7 +47,14 @@ const submit = async (req, res) => {
const
{
id
,
theatertypeId
,
theaterName
,
rows
,
columns
}
=
req
.
body
let
response
=
null
if
(
id
)
response
=
await
Theater
.
update
({
theatertypeId
,
theaterName
,
rows
,
columns
},
{
where
:
{
id
:
id
}
})
else
response
=
await
Theater
.
create
({
theatertypeId
,
theaterName
,
rows
,
columns
})
else
{
const
result
=
await
Theater
.
findOrCreate
({
where
:
{
theaterName
:
theaterName
},
defaults
:
{
theatertypeId
,
theaterName
,
rows
,
columns
}
})
if
(
!
result
[
1
])
throw
new
Error
(
"
이미 존재하는 이름의 상영관입니다. 다시 등록해주세요.
"
);
else
response
=
result
[
0
]
}
return
res
.
json
(
response
)
}
catch
(
error
)
{
return
res
.
status
(
500
).
send
(
error
.
message
||
"
상영관 정보 저장 중 에러 발생
"
)
...
...
server/controllers/timetable.controller.js
0 → 100644
View file @
992699ae
import
{
TimeTable
}
from
"
../db/index.js
"
;
import
sequelize
from
'
sequelize
'
const
{
Op
}
=
sequelize
const
submit
=
async
(
req
,
res
)
=>
{
try
{
console
.
log
(
"
req.body==
"
,
req
.
body
)
const
{
theater
,
runtime
}
=
req
.
body
const
result
=
theater
.
filter
(
async
(
theater
)
=>
{
const
startDate
=
getDate
(
theater
.
start
)
const
endDate
=
getDate
(
theater
.
start
,
runtime
)
// const isTimeTable = await TimeTable.findAll({
// where: {
// [Op.and]: [
// { theater: theater.theater },
// {
// [Op.and]: [
// { start_date: { [Op.lte]: endDate } },
// { end_date: { [Op.gte]: startDate } }
// ]
// }
// ]
// }
// })
// [Op.or]: [{ [Op.and]: [{ start_date: { [Op.gt]: startDate } }, { start_date: { [Op.gt]: endDate } }] },
// { [Op.and]: [{ end_date: { [Op.lt]: startDate } }, { end_date: { [Op.lt]: endDate } }] }]
console
.
log
(
"
isTimeTable==
"
,
isTimeTable
)
return
isTimeTable
})
console
.
log
(
"
result==
"
,
result
)
}
catch
(
error
)
{
return
res
.
status
(
500
).
send
(
error
.
message
||
"
상영시간표 저장 중 에러 발생
"
)
}
}
const
getDate
=
(
string
,
runtime
=
0
)
=>
{
const
arr
=
string
.
split
(
'
:
'
)
const
date
=
new
Date
(
0
,
0
,
0
,
Number
(
arr
[
0
]),
Number
(
arr
[
1
])
+
runtime
)
// console.log("custom==", date.toString())
return
date
}
export
default
{
submit
}
\ No newline at end of file
server/db/index.js
View file @
992699ae
...
...
@@ -41,7 +41,7 @@ const Guest = GuestModel(sequelize)
User
.
belongsTo
(
Role
);
Role
.
hasOne
(
User
);
Theater
.
belongsTo
(
TheaterType
);
Theater
.
belongsTo
(
TheaterType
,
{
onDelete
:
'
CASCADE
'
}
);
TicketFee
.
belongsTo
(
TheaterType
,
{
onDelete
:
'
CASCADE
'
});
...
...
server/models/timetable.model.js
View file @
992699ae
...
...
@@ -20,11 +20,19 @@ const TimeTableModel = (sequelize) => {
title
:
{
type
:
DataTypes
.
STRING
,
},
runtime
:
{
type
:
DataTypes
.
INTEGER
,
},
release_date
:
{
type
:
DataTypes
.
STRING
},
date
:
{
type
:
DataTypes
.
STRING
,
start_date
:
{
type
:
DataTypes
.
DATE
,
defaultValue
:
new
Date
(
0
)
},
end_date
:
{
type
:
DataTypes
.
DATE
,
defaultValue
:
new
Date
(
0
)
},
time
:
{
type
:
DataTypes
.
TIME
,
...
...
server/routes/index.js
View file @
992699ae
import
express
from
"
express
"
;
import
userRouter
from
'
./user.route.js
'
import
movieRouter
from
'
./movie.route.js
'
import
theaterRouter
from
"
./theater.route.js
"
;
import
timetableRouter
from
"
./timetable.route.js
"
;
import
cinemaRouter
from
"
./cinema.route.js
"
;
import
kakaopayRouter
from
"
./kakaopay.route.js
"
;
import
emailRouter
from
'
./email.route.js
'
...
...
@@ -16,5 +18,6 @@ router.use('/email',emailRouter)
router
.
use
(
'
/info
'
,
cinemaRouter
)
router
.
use
(
'
/theater
'
,
theaterRouter
)
router
.
use
(
'
/reservation
'
,
reservationRouter
)
router
.
use
(
'
/timetable
'
,
timetableRouter
)
export
default
router
;
\ No newline at end of file
server/routes/timetable.route.js
0 → 100644
View file @
992699ae
import
express
from
"
express
"
;
import
timetableCtrl
from
"
../controllers/timetable.controller.js
"
;
const
router
=
express
.
Router
();
router
.
route
(
"
/
"
)
.
post
(
timetableCtrl
.
submit
)
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