From 4f6cad5aa63131d6ac5f9d9f03452a2495982a0d Mon Sep 17 00:00:00 2001 From: Zena0128 <0128ja@gmail.com> Date: Sat, 24 Feb 2024 01:25:24 +0900 Subject: [PATCH] =?UTF-8?q?:bug:Fix:=20=ED=98=84=EC=9E=AC=20=EC=A0=91?= =?UTF-8?q?=EC=86=8D=ED=95=9C=20=EC=9C=A0=EC=A0=80=20=EC=A0=95=EB=B3=B4=20?= =?UTF-8?q?=ED=99=95=EC=9D=B8=20=ED=9B=84=20PDS=20=EC=9E=91=EC=84=B1/?= =?UTF-8?q?=EC=88=98=EC=A0=95/=EC=82=AD=EC=A0=9C=20=EA=B0=80=EB=8A=A5?= =?UTF-8?q?=ED=95=98=EA=B2=8C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mainpage/service/CategoryServiceImpl.java | 7 +++++++ .../domain/mainpage/service/DoServiceImpl.java | 11 +++++++++++ .../domain/mainpage/service/PlanServiceImpl.java | 13 ++++++++++++- .../domain/mainpage/service/SeeServiceImpl.java | 11 +++++++++++ 4 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/trendithon/timetris/domain/mainpage/service/CategoryServiceImpl.java b/src/main/java/com/trendithon/timetris/domain/mainpage/service/CategoryServiceImpl.java index 7b85f93..12a7749 100644 --- a/src/main/java/com/trendithon/timetris/domain/mainpage/service/CategoryServiceImpl.java +++ b/src/main/java/com/trendithon/timetris/domain/mainpage/service/CategoryServiceImpl.java @@ -47,6 +47,7 @@ public Category createCategory(long userId, CategoryRequestDTO categoryRequestDT public void updateCategory(long userId, long categoryId, CategoryRequestDTO categoryRequestDTO) { Category category = categoryRepository.findById(categoryId) .orElseThrow(() -> new CustomException(ErrorStatus.CATEGORY_NOT_FOUND_ERROR)); + findUser(userId); if (category.getUser().getId() != userId){ throw new CustomException(ErrorStatus.NO_PERMISSION_ERROR); } @@ -58,9 +59,15 @@ public void updateCategory(long userId, long categoryId, CategoryRequestDTO cate public void deleteCategory(long userId, long categoryId) { Category category = categoryRepository.findById(categoryId) .orElseThrow(() -> new CustomException(ErrorStatus.CATEGORY_NOT_FOUND_ERROR)); + findUser(userId); if (category.getUser().getId() != userId){ throw new CustomException(ErrorStatus.NO_PERMISSION_ERROR); } categoryRepository.delete(category); } + + public void findUser(long userId){ + User user = userRepository.findById(userId) + .orElseThrow(() -> new CustomException(ErrorStatus.USER_NOT_FOUND_ERROR)); + } } diff --git a/src/main/java/com/trendithon/timetris/domain/mainpage/service/DoServiceImpl.java b/src/main/java/com/trendithon/timetris/domain/mainpage/service/DoServiceImpl.java index 7280f1a..0281cba 100644 --- a/src/main/java/com/trendithon/timetris/domain/mainpage/service/DoServiceImpl.java +++ b/src/main/java/com/trendithon/timetris/domain/mainpage/service/DoServiceImpl.java @@ -11,6 +11,8 @@ import com.trendithon.timetris.domain.mainpage.repository.DateRepository; import com.trendithon.timetris.domain.mainpage.repository.DoRepository; import com.trendithon.timetris.domain.mainpage.repository.UserDateRepository; +import com.trendithon.timetris.domain.member.domain.User; +import com.trendithon.timetris.domain.member.repository.UserRepository; import com.trendithon.timetris.global.exception.CustomException; import com.trendithon.timetris.global.exception.enums.ErrorStatus; import lombok.RequiredArgsConstructor; @@ -31,9 +33,11 @@ public class DoServiceImpl implements DoService{ private final DateRepository dateRepository; private final UserDateRepository userDateRepository; private final CategoryRepository categoryRepository; + private final UserRepository userRepository; @Override public Do createDo(long userId, DoRequestDTO doRequestDTO) { + findUser(userId); LocalDate localDate = LocalDate.now(); Date date = dateRepository.findByDate(localDate); UserDate userDate = userDateRepository.findByUser_IdAndDate_Id(userId, date.getId()); @@ -50,6 +54,7 @@ public Do createDo(long userId, DoRequestDTO doRequestDTO) { @Override public void updateDo(long userId, long doId, DoRequestDTO doRequestDTO) { + findUser(userId); Do done = doRepository.findById(doId) .orElseThrow(() -> new CustomException(ErrorStatus.DO_NOT_FOUND_ERROR)); if (done.getUserDate().getUser().getId() != userId){ @@ -67,6 +72,7 @@ public void updateDo(long userId, long doId, DoRequestDTO doRequestDTO) { @Override public void deleteDo(long userId, long doId) { + findUser(userId); Do done = doRepository.findById(doId) .orElseThrow(() -> new CustomException(ErrorStatus.DO_NOT_FOUND_ERROR)); if (done.getUserDate().getUser().getId() != userId){ @@ -74,4 +80,9 @@ public void deleteDo(long userId, long doId) { } doRepository.delete(done); } + + public void findUser(long userId){ + User user = userRepository.findById(userId) + .orElseThrow(() -> new CustomException(ErrorStatus.USER_NOT_FOUND_ERROR)); + } } diff --git a/src/main/java/com/trendithon/timetris/domain/mainpage/service/PlanServiceImpl.java b/src/main/java/com/trendithon/timetris/domain/mainpage/service/PlanServiceImpl.java index 4973ff7..9d2f895 100644 --- a/src/main/java/com/trendithon/timetris/domain/mainpage/service/PlanServiceImpl.java +++ b/src/main/java/com/trendithon/timetris/domain/mainpage/service/PlanServiceImpl.java @@ -3,6 +3,8 @@ import com.trendithon.timetris.domain.mainpage.domain.*; import com.trendithon.timetris.domain.mainpage.dto.*; import com.trendithon.timetris.domain.mainpage.repository.*; +import com.trendithon.timetris.domain.member.domain.User; +import com.trendithon.timetris.domain.member.repository.UserRepository; import com.trendithon.timetris.global.exception.CustomException; import com.trendithon.timetris.global.exception.enums.ErrorStatus; import lombok.RequiredArgsConstructor; @@ -24,12 +26,13 @@ public class PlanServiceImpl implements PlanService { private final DateRepository dateRepository; private final UserDateRepository userDateRepository; private final CategoryRepository categoryRepository; - private final CycleRepository cycleRepository; + private final UserRepository userRepository; @Override public Plan createPlan(long userId, PlanRequestDTO planRequestDTO) { LocalDate localDate = LocalDate.now(); Date date = dateRepository.findByDate(localDate); + findUser(userId); UserDate userDate = userDateRepository.findByUser_IdAndDate_Id(userId, date.getId()); Category category = categoryRepository.findById(planRequestDTO.getCategoryId()) .orElseThrow(() -> new CustomException(ErrorStatus.CATEGORY_NOT_FOUND_ERROR)); @@ -45,6 +48,7 @@ public Plan createPlan(long userId, PlanRequestDTO planRequestDTO) { @Override public void updatePlan(long userId, long planId, PlanRequestDTO planRequestDTO) { + findUser(userId); Plan plan = planRepository.findById(planId) .orElseThrow(() -> new CustomException(ErrorStatus.PLAN_NOT_FOUND_ERROR)); long categoryId = planRequestDTO.getCategoryId(); @@ -63,6 +67,7 @@ public void updatePlan(long userId, long planId, PlanRequestDTO planRequestDTO) @Override public void deletePlan(long userId, long planId) { + findUser(userId); Plan plan = planRepository.findById(planId) .orElseThrow(() -> new CustomException(ErrorStatus.PLAN_NOT_FOUND_ERROR)); if (plan.getUserDate().getUser().getId() != userId) { @@ -73,6 +78,7 @@ public void deletePlan(long userId, long planId) { @Override public void donePlan(long userId, long planId) { + findUser(userId); Plan plan = planRepository.findById(planId) .orElseThrow(() -> new CustomException(ErrorStatus.PLAN_NOT_FOUND_ERROR)); if (plan.getUserDate().getUser().getId() != userId) { @@ -81,4 +87,9 @@ public void donePlan(long userId, long planId) { plan.donePlan(); planRepository.save(plan); } + + public void findUser(long userId){ + User user = userRepository.findById(userId) + .orElseThrow(() -> new CustomException(ErrorStatus.USER_NOT_FOUND_ERROR)); + } } diff --git a/src/main/java/com/trendithon/timetris/domain/mainpage/service/SeeServiceImpl.java b/src/main/java/com/trendithon/timetris/domain/mainpage/service/SeeServiceImpl.java index 1c94ffe..ddf0aee 100644 --- a/src/main/java/com/trendithon/timetris/domain/mainpage/service/SeeServiceImpl.java +++ b/src/main/java/com/trendithon/timetris/domain/mainpage/service/SeeServiceImpl.java @@ -12,6 +12,8 @@ import com.trendithon.timetris.domain.mainpage.repository.DateRepository; import com.trendithon.timetris.domain.mainpage.repository.SeeRepository; import com.trendithon.timetris.domain.mainpage.repository.UserDateRepository; +import com.trendithon.timetris.domain.member.domain.User; +import com.trendithon.timetris.domain.member.repository.UserRepository; import com.trendithon.timetris.global.exception.CustomException; import com.trendithon.timetris.global.exception.enums.ErrorStatus; import lombok.RequiredArgsConstructor; @@ -29,9 +31,11 @@ public class SeeServiceImpl implements SeeService{ private final SeeRepository seeRepository; private final DateRepository dateRepository; private final UserDateRepository userDateRepository; + private final UserRepository userRepository; @Override public See createSee(long userId, SeeRequestDTO seeRequestDTO) { + findUser(userId); LocalDate localDate = LocalDate.now(); Date date = dateRepository.findByDate(localDate); UserDate userDate = userDateRepository.findByUser_IdAndDate_Id(userId, date.getId()); @@ -45,6 +49,7 @@ public See createSee(long userId, SeeRequestDTO seeRequestDTO) { @Override public void updateSee(long userId, long seeId, SeeRequestDTO seeRequestDTO) { + findUser(userId); See see = seeRepository.findById(seeId) .orElseThrow(() -> new CustomException(ErrorStatus.SEE_NOT_FOUND_ERROR)); if (see.getUserDate().getUser().getId() != userId){ @@ -56,6 +61,7 @@ public void updateSee(long userId, long seeId, SeeRequestDTO seeRequestDTO) { @Override public void deleteSee(long userId, long seeId) { + findUser(userId); See see = seeRepository.findById(seeId) .orElseThrow(() -> new CustomException(ErrorStatus.SEE_NOT_FOUND_ERROR)); if (see.getUserDate().getUser().getId() != userId){ @@ -63,4 +69,9 @@ public void deleteSee(long userId, long seeId) { } seeRepository.delete(see); } + + public void findUser(long userId){ + User user = userRepository.findById(userId) + .orElseThrow(() -> new CustomException(ErrorStatus.USER_NOT_FOUND_ERROR)); + } }