Skip to content

Commit

Permalink
fix: 루틴 완수 예외처리 (#66)
Browse files Browse the repository at this point in the history
* feat: 몇가지 소소한 수정

* refactor: ♻️ user 디렉토리 구조 수정 (#53)

* hotfix: conflict solve (#55)

* refactor: ♻️ user 디렉토리 구조 수정

* hotfix: conflict solve

* hotfix: 🚑 build error 해결 (#57)

* refactor: ♻️ user 디렉토리 구조 수정

* hotfix: conflict solve

* hotfix: 🚑 sever restart

* fix: 루틴 삭제 기능 수정

* fix: 루틴 삭제 기능 수정

* docs: 📝 auth api 문서 추가 (#61)

* hotfix: server restart

* docs: 📝 auth api 문서 추가

* fix: 루틴 완수 예외처리

* fix: 루틴 완수 예외처리

* fix: 루틴 완수 예외처리

---------

Co-authored-by: LEEJaeHyeok97 <[email protected]>
  • Loading branch information
gzhan0226 and LEEJaeHyeok97 authored Sep 28, 2024
1 parent a62f52b commit 91256f2
Showing 1 changed file with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.goormdari.domain.routine.application;

import com.amazonaws.services.kms.model.AlreadyExistsException;
import com.amazonaws.services.kms.model.NotFoundException;
import com.goormdari.domain.routine.domain.Routine;
import com.goormdari.domain.routine.dto.request.CompleteRoutineRequest;
Expand All @@ -22,10 +23,15 @@ public class RoutineService {
private final RoutineRepository routineRepository;
private final UserRepository userRepository;

private final S3Service s3Service;
@Transactional
public Message completeRoutine (Long userId, CompleteRoutineRequest completeRoutineRequest, String imgURL) {
User user = userRepository.findById(userId)
.orElseThrow(()->new NotFoundException("User Not Found"));

if(routineRepository.findByRoutineIndexAndUserId(userId, completeRoutineRequest.routineIndex())!= null) {
throw new IllegalStateException("Routine already completed for given index");
}
Routine routine = Routine.builder()
.user(user)
.routineImg(imgURL)
Expand All @@ -47,6 +53,7 @@ public Message deleteRoutineByUserIdAndRoutineIndex (Long userId, Long routineIn
.orElseThrow(()->new NotFoundException("User Not Found"));
Routine routine = routineRepository.findByRoutineIndexAndUserId(userId,routineIndex);
routineRepository.deleteById(routine.getId());
s3Service.deleteImageOnS3(routine.getRoutineImg());
user.updateCurrentStep(user.getCurrentStep()-1);
return Message.builder()
.message("루틴 삭제 성공")
Expand Down

0 comments on commit 91256f2

Please sign in to comment.