Небольшой рефакторинг репозиториев для MR

This commit is contained in:
Struchkov Mark 2022-12-21 20:55:07 +03:00
parent 4877a45c67
commit 295da29cd6
Signed by: upagge
GPG Key ID: D3018BE7BA428CA6
4 changed files with 12 additions and 19 deletions

View File

@ -22,8 +22,6 @@ public interface MergeRequestRepository {
List<MergeRequest> findAllById(Set<Long> mergeRequestIds);
void deleteByIds(Set<Long> mergeRequestIds);
List<MergeRequest> findAllByReviewerId(Long personId);
void deleteByStates(Set<MergeRequestState> states);

View File

@ -10,6 +10,7 @@ import dev.struchkov.bot.gitlab.data.jpa.MergeRequestJpaRepository;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.Optional;
@ -23,41 +24,43 @@ public class MergeRequestRepositoryImpl implements MergeRequestRepository {
private final MergeRequestForDiscussionJpaRepository forDiscussionJpaRepository;
@Override
@Transactional(readOnly = true)
public Set<IdAndStatusPr> findAllIdByStateIn(@NonNull Set<MergeRequestState> statuses) {
return jpaRepository.findAllIdByStateIn(statuses);
}
@Override
@Transactional
public MergeRequest save(MergeRequest mergeRequest) {
return jpaRepository.save(mergeRequest);
}
@Override
@Transactional(readOnly = true)
public Optional<MergeRequest> findById(Long mergeRequestId) {
return jpaRepository.findById(mergeRequestId);
}
@Override
@Transactional(readOnly = true)
public List<MergeRequestForDiscussion> findAllForDiscussion() {
return forDiscussionJpaRepository.findAll();
}
@Override
@Transactional(readOnly = true)
public List<MergeRequest> findAllById(Set<Long> mergeRequestIds) {
return jpaRepository.findAllById(mergeRequestIds);
}
@Override
public void deleteByIds(Set<Long> mergeRequestIds) {
jpaRepository.deleteAllByIdIn(mergeRequestIds);
}
@Override
@Transactional(readOnly = true)
public List<MergeRequest> findAllByReviewerId(Long personId) {
return jpaRepository.findAllByReviewersIn(personId);
}
@Override
@Transactional
public void deleteByStates(Set<MergeRequestState> states) {
jpaRepository.deleteAllByStateIn(states);
}

View File

@ -7,9 +7,7 @@ import org.springframework.data.jpa.repository.Query;
import org.springframework.data.jpa.repository.support.JpaRepositoryImplementation;
import org.springframework.data.repository.query.Param;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.Set;
/**
@ -18,19 +16,9 @@ import java.util.Set;
public interface MergeRequestJpaRepository extends JpaRepositoryImplementation<MergeRequest, Long> {
void deleteAllByIdIn(Collection<Long> id);
@Query("SELECT new dev.struchkov.bot.gitlab.context.domain.IdAndStatusPr(p.id, p.twoId, p.projectId, p.state) FROM MergeRequest p WHERE p.state IN :states")
Set<IdAndStatusPr> findAllIdByStateIn(@Param("states") Set<MergeRequestState> states);
@Query("SELECT p.id FROM MergeRequest p")
Set<Long> findAllIds();
@Query("SELECT p.author.id FROM MergeRequest p WHERE p.id = :id")
Optional<String> findAuthorById(@Param("id") Long id);
List<MergeRequest> findAllByAssigneeId(Long userId);
@Query("SELECT mr FROM MergeRequest mr LEFT JOIN mr.reviewers r WHERE r.id = :reviewerId")
List<MergeRequest> findAllByReviewersIn(@Param("reviewerId") Long reviewerId);

View File

@ -56,6 +56,10 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
</dependencies>
<build>