Skip to content

Commit

Permalink
Merge pull request #32 from Timetris-Trendithon/mainpage
Browse files Browse the repository at this point in the history
πŸ›Fix: ν˜„μž¬ μ ‘μ†ν•œ μœ μ € 정보 확인 ν›„ PDS μž‘μ„±/μˆ˜μ •/μ‚­μ œ κ°€λŠ₯ν•˜κ²Œ μˆ˜μ •
  • Loading branch information
Zena0128 authored Feb 23, 2024
2 parents 2133d74 + 4f6cad5 commit 8f29cfc
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
Expand All @@ -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){
Expand All @@ -67,11 +72,17 @@ 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){
throw new CustomException(ErrorStatus.NO_PERMISSION_ERROR);
}
doRepository.delete(done);
}

public void findUser(long userId){
User user = userRepository.findById(userId)
.orElseThrow(() -> new CustomException(ErrorStatus.USER_NOT_FOUND_ERROR));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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));
Expand All @@ -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();
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
Expand All @@ -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){
Expand All @@ -56,11 +61,17 @@ 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){
throw new CustomException(ErrorStatus.NO_PERMISSION_ERROR);
}
seeRepository.delete(see);
}

public void findUser(long userId){
User user = userRepository.findById(userId)
.orElseThrow(() -> new CustomException(ErrorStatus.USER_NOT_FOUND_ERROR));
}
}

0 comments on commit 8f29cfc

Please sign in to comment.