Skip to content

Commit

Permalink
refactor: getSurveyByTargetId가 항상 최신 Survey를 반환하도록 수정한다
Browse files Browse the repository at this point in the history
  • Loading branch information
devxb committed Mar 6, 2024
1 parent 5232649 commit fba512d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public Optional<Survey> findSurvey(Long surveyId) {

@Override
public Survey getSurveyByTargetId(Long targetId) {
var surveyEntity = surveyFindRepository.findByTargetId(targetId)
var surveyEntity = surveyFindRepository.findFirstByTargetIdOrderByCreatedAtDesc(targetId)
.orElseThrow(() -> new TargetDoesNotHasSurveyException(targetId));

return SurveyEntityMapper.toSurvey(surveyEntity);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package me.nalab.survey.jpa.adaptor.find.repository;

import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;

import me.nalab.core.data.survey.SurveyEntity;
import org.springframework.data.jpa.repository.JpaRepository;

public interface SurveyFindRepository extends JpaRepository<SurveyEntity, Long> {

Optional<SurveyEntity> findByTargetId(Long targetId);
Optional<SurveyEntity> findFirstByTargetIdOrderByCreatedAtDesc(Long targetId);
}

0 comments on commit fba512d

Please sign in to comment.