Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
FitUrRing
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
wss9
FitUrRing
Commits
f7c604ff
Commit
f7c604ff
authored
7 months ago
by
문경호
Browse files
Options
Downloads
Patches
Plain Diff
Fix: Fix removal logic
parent
e0e95304
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
back/src/controllers/dietController.js
+5
-18
5 additions, 18 deletions
back/src/controllers/dietController.js
front/src/pages/diet/MealRecord.jsx
+9
-11
9 additions, 11 deletions
front/src/pages/diet/MealRecord.jsx
front/src/pages/diet/api.js
+5
-5
5 additions, 5 deletions
front/src/pages/diet/api.js
with
19 additions
and
34 deletions
back/src/controllers/dietController.js
+
5
−
18
View file @
f7c604ff
...
@@ -188,7 +188,7 @@ const dietController = {
...
@@ -188,7 +188,7 @@ const dietController = {
);
);
if
(
existingFoodIndex
!==
-
1
)
{
if
(
existingFoodIndex
!==
-
1
)
{
// 이
��
존재하는 음식이면 그램수 업데이트
// 이
미
존재하는 음식이면 그램수 업데이트
targetDiet
.
meals
[
mealtime
][
existingFoodIndex
].
grams
=
grams
;
targetDiet
.
meals
[
mealtime
][
existingFoodIndex
].
grams
=
grams
;
}
else
{
}
else
{
// 새로운 음식 추가
// 새로운 음식 추가
...
@@ -231,14 +231,6 @@ const dietController = {
...
@@ -231,14 +231,6 @@ const dietController = {
});
});
}
}
// mealtime 유효성 검사
if
(
!
[
'
breakfast
'
,
'
lunch
'
,
'
dinner
'
].
includes
(
mealtime
))
{
return
res
.
status
(
400
).
json
({
status
:
'
error
'
,
message
:
'
잘못된 식사 시간입니다.
'
});
}
// 해당 날짜의 사용자 식단 찾기
// 해당 날짜의 사용자 식단 찾기
const
userDiet
=
await
UserDiet
.
findOne
({
const
userDiet
=
await
UserDiet
.
findOne
({
user_id
,
user_id
,
...
@@ -254,7 +246,7 @@ const dietController = {
...
@@ -254,7 +246,7 @@ const dietController = {
// 해당 날짜의 diet 찾기
// 해당 날짜의 diet 찾기
const
dietIndex
=
userDiet
.
diets
.
findIndex
(
const
dietIndex
=
userDiet
.
diets
.
findIndex
(
diet
=>
diet
.
date
.
getTime
()
===
new
Date
(
date
).
getTime
()
diet
=>
diet
.
date
.
toISOString
().
split
(
'
T
'
)[
0
]
===
new
Date
(
date
).
toISOString
().
split
(
'
T
'
)[
0
]
);
);
if
(
dietIndex
===
-
1
)
{
if
(
dietIndex
===
-
1
)
{
...
@@ -267,7 +259,7 @@ const dietController = {
...
@@ -267,7 +259,7 @@ const dietController = {
// 해당 음식 찾기 및 삭제
// 해당 음식 찾기 및 삭제
const
targetDiet
=
userDiet
.
diets
[
dietIndex
];
const
targetDiet
=
userDiet
.
diets
[
dietIndex
];
const
foodIndex
=
targetDiet
.
meals
[
mealtime
].
findIndex
(
const
foodIndex
=
targetDiet
.
meals
[
mealtime
].
findIndex
(
meal
=>
meal
.
food_id
===
food_id
meal
=>
meal
.
food_id
.
toString
()
===
food_id
.
toString
()
);
);
if
(
foodIndex
===
-
1
)
{
if
(
foodIndex
===
-
1
)
{
...
@@ -280,7 +272,7 @@ const dietController = {
...
@@ -280,7 +272,7 @@ const dietController = {
// 음식 삭제
// 음식 삭제
targetDiet
.
meals
[
mealtime
].
splice
(
foodIndex
,
1
);
targetDiet
.
meals
[
mealtime
].
splice
(
foodIndex
,
1
);
// 해당 식사 시간 음식이 모두 비었고, 다른 식사 시간도 비어있다면 해당 날짜 전체 삭제
// 해당 식사 시간
의
음식이 모두 비었고, 다른 식사 시간도 비어있다면 해당 날짜 전체 삭제
if
(
targetDiet
.
meals
[
mealtime
].
length
===
0
&&
if
(
targetDiet
.
meals
[
mealtime
].
length
===
0
&&
targetDiet
.
meals
.
breakfast
.
length
===
0
&&
targetDiet
.
meals
.
breakfast
.
length
===
0
&&
targetDiet
.
meals
.
lunch
.
length
===
0
&&
targetDiet
.
meals
.
lunch
.
length
===
0
&&
...
@@ -297,12 +289,7 @@ const dietController = {
...
@@ -297,12 +289,7 @@ const dietController = {
res
.
json
({
res
.
json
({
status
:
'
success
'
,
status
:
'
success
'
,
message
:
'
식단이 삭제되었습니다.
'
,
message
:
'
식단이 삭제되었습니다.
'
data
:
{
date
,
mealtime
,
food_id
}
});
});
}
catch
(
error
)
{
}
catch
(
error
)
{
...
...
This diff is collapsed.
Click to expand it.
front/src/pages/diet/MealRecord.jsx
+
9
−
11
View file @
f7c604ff
...
@@ -160,13 +160,12 @@ function MealRecord({ diet }) {
...
@@ -160,13 +160,12 @@ function MealRecord({ diet }) {
try
{
try
{
const
foodToDelete
=
data
[
selectedDate
][
meal
][
index
];
const
foodToDelete
=
data
[
selectedDate
][
meal
][
index
];
const
response
=
await
deleteDiet
({
await
deleteDiet
({
date
:
selectedDate
,
date
:
selectedDate
,
mealtime
:
meal
,
mealtime
:
meal
,
food_id
:
foodToDelete
.
food_id
food_id
:
foodToDelete
.
food_id
});
});
if
(
response
.
status
===
'
success
'
)
{
setData
(
prevData
=>
({
setData
(
prevData
=>
({
...
prevData
,
...
prevData
,
[
selectedDate
]:
{
[
selectedDate
]:
{
...
@@ -174,10 +173,9 @@ function MealRecord({ diet }) {
...
@@ -174,10 +173,9 @@ function MealRecord({ diet }) {
[
meal
]:
prevData
[
selectedDate
][
meal
].
filter
((
_
,
i
)
=>
i
!==
index
)
[
meal
]:
prevData
[
selectedDate
][
meal
].
filter
((
_
,
i
)
=>
i
!==
index
)
}
}
}));
}));
}
}
catch
(
err
)
{
}
catch
(
err
)
{
console
.
error
(
'
Delete error:
'
,
err
);
console
.
error
(
'
Delete error:
'
,
err
);
alert
(
err
.
message
||
'
삭제 중 오류가 발생했습니다.
'
);
alert
(
'
삭제 중 오류가 발생했습니다.
'
);
}
}
};
};
...
...
This diff is collapsed.
Click to expand it.
front/src/pages/diet/api.js
+
5
−
5
View file @
f7c604ff
...
@@ -101,17 +101,17 @@ const createDiet = async ({ date, mealtime, food_id, grams }) => {
...
@@ -101,17 +101,17 @@ const createDiet = async ({ date, mealtime, food_id, grams }) => {
};
};
const
deleteDiet
=
async
({
date
,
mealtime
,
food_id
})
=>
{
const
deleteDiet
=
async
({
date
,
mealtime
,
food_id
})
=>
{
return
await
fetchWithOptions
(
URL
,
{
return
await
fetchWithOptions
(
`
${
URL
}
/`
,
{
method
:
'
DELETE
'
,
method
:
'
DELETE
'
,
headers
:
{
headers
:
{
'
Content-Type
'
:
'
application/json
'
,
'
Content-Type
'
:
'
application/json
'
,
'
Authorization
'
:
`Bearer
${
localStorage
.
getItem
(
'
accessToken
'
)}
`
'
Authorization
'
:
`Bearer
${
localStorage
.
getItem
(
'
accessToken
'
)}
`
},
},
body
:
JSON
.
stringify
({
body
:
JSON
.
stringify
({
date
:
date
,
date
,
mealtime
:
mealtime
,
mealtime
,
food_id
:
food_id
food_id
:
Number
(
food_id
)
})
,
})
});
});
};
};
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment