Skip to content

Commit

Permalink
fix: 기도 취소시 null값으로 들어가 생기는 문제 해결
Browse files Browse the repository at this point in the history
+ 일부 최적화
  • Loading branch information
dong2ast committed Jan 25, 2024
1 parent c286fda commit 768010d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/uspray/uspray/domain/Pray.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public void complete() {
}

public void deleteLastPrayedAt() {
this.lastPrayedAt = null;
this.lastPrayedAt = LocalDate.now().minusDays(1);
this.count--;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.uspray.uspray.infrastructure.querydsl.pray.PrayRepositoryCustom;
import java.time.LocalDate;
import java.util.List;
import java.util.Objects;
import org.springframework.data.jpa.repository.EntityGraph;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
Expand Down Expand Up @@ -40,11 +41,13 @@ default Pray getPrayByIdAndMemberId(Long prayId, String username) throws NotFoun

List<Pray> findByCategoryId(Long categoryId);

default void cancelPray(Pray pray) {
if (pray.getDeleted()) {
default Pray cancelPray(Long prayId, String username) {
Pray pray = getPrayByIdAndMemberId(prayId, username);
if (!Objects.equals(pray.getLastPrayedAt(), LocalDate.now())) {
throw new NotFoundException(ErrorStatus.ALREADY_CANCEL_EXCEPTION,
ErrorStatus.ALREADY_CANCEL_EXCEPTION.getMessage());
}
pray.deleteLastPrayedAt();
return pray;
}
}
5 changes: 1 addition & 4 deletions src/main/java/com/uspray/uspray/service/PrayFacade.java
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,6 @@ public List<PrayListResponseDto> completePray(Long prayId, String username) {

@Transactional
public List<PrayListResponseDto> cancelPray(Long prayId, String username) {
Pray pray = prayRepository.getPrayByIdAndMemberId(prayId, username);
prayRepository.cancelPray(pray);

return getPrayList(username, PrayType.SHARED.stringValue());
return getPrayList(username, prayRepository.cancelPray(prayId, username).getPrayType().stringValue());
}
}

0 comments on commit 768010d

Please sign in to comment.