fix check unique name of grant

This commit is contained in:
Anton Romanov 2020-03-28 10:46:35 +04:00
parent a14735699c
commit 2c55293e0e
4 changed files with 6 additions and 6 deletions

View File

@ -28,7 +28,7 @@ public interface ConferenceRepository extends JpaRepository<Conference, Integer>
@Override
@Query("SELECT title FROM Conference c WHERE (c.title = :name) AND (:id IS NULL OR c.id != :id) ")
String findByNameAndNotId(@Param("name") String name, @Param("id") Integer id);
String findFirstByNameAndNotId(@Param("name") String name, @Param("id") Integer id);
@Query("SELECT c FROM Conference c LEFT JOIN c.users u WHERE (:user IS NULL OR u.user = :user) " +
"AND (u.participation = 'INTRAMURAL') AND (c.beginDate <= CURRENT_DATE) AND (c.endDate >= CURRENT_DATE)")

View File

@ -18,7 +18,7 @@ public interface GrantRepository extends JpaRepository<Grant, Integer>, BaseRepo
@Override
@Query("SELECT title FROM Grant g WHERE (g.title = :name) AND (:id IS NULL OR g.id != :id) ")
String findByNameAndNotId(@Param("name") String name, @Param("id") Integer id);
String findFirstByNameAndNotId(@Param("name") String name, @Param("id") Integer id);
@Query("SELECT g FROM Grant g WHERE (g.status <> 'SKIPPED') AND (g.status <> 'COMPLETED')")
List<Grant> findAllActive();

View File

@ -3,5 +3,5 @@ package ru.ulstu.name;
import org.springframework.data.repository.query.Param;
public interface BaseRepository {
String findByNameAndNotId(@Param("name") String name, @Param("id") Integer id);
String findFirstByNameAndNotId(@Param("name") String name, @Param("id") Integer id);
}

View File

@ -9,14 +9,14 @@ public abstract class BaseService {
public BaseRepository baseRepository;
protected void checkUniqueName(NameContainer nameContainer, Errors errors, Integer id, String errorMessage) {
if (nameContainer.getName().equals(baseRepository.findByNameAndNotId(nameContainer.getName(), id))) {
if (nameContainer.getName().equals(baseRepository.findFirstByNameAndNotId(nameContainer.getName(), id))) {
errors.rejectValue("title", "errorCode", errorMessage);
}
}
protected String checkUniqueName(NameContainer nameContainer, Integer id) {
if (nameContainer.getName().equals(baseRepository.findByNameAndNotId(nameContainer.getName(), id))) {
return baseRepository.findByNameAndNotId(nameContainer.getName(), id);
if (nameContainer.getName().equals(baseRepository.findFirstByNameAndNotId(nameContainer.getName(), id))) {
return baseRepository.findFirstByNameAndNotId(nameContainer.getName(), id);
}
return null;
}