From 2c55293e0ee3a0589065517d70e73d339db7f92f Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Sat, 28 Mar 2020 10:46:35 +0400 Subject: [PATCH] fix check unique name of grant --- .../ulstu/conference/repository/ConferenceRepository.java | 2 +- .../java/ru/ulstu/grant/repository/GrantRepository.java | 2 +- src/main/java/ru/ulstu/name/BaseRepository.java | 2 +- src/main/java/ru/ulstu/name/BaseService.java | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/ru/ulstu/conference/repository/ConferenceRepository.java b/src/main/java/ru/ulstu/conference/repository/ConferenceRepository.java index 8f9e05f..5319e37 100644 --- a/src/main/java/ru/ulstu/conference/repository/ConferenceRepository.java +++ b/src/main/java/ru/ulstu/conference/repository/ConferenceRepository.java @@ -28,7 +28,7 @@ public interface ConferenceRepository extends JpaRepository @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)") diff --git a/src/main/java/ru/ulstu/grant/repository/GrantRepository.java b/src/main/java/ru/ulstu/grant/repository/GrantRepository.java index 50fad13..b370bf3 100644 --- a/src/main/java/ru/ulstu/grant/repository/GrantRepository.java +++ b/src/main/java/ru/ulstu/grant/repository/GrantRepository.java @@ -18,7 +18,7 @@ public interface GrantRepository extends JpaRepository, 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 findAllActive(); diff --git a/src/main/java/ru/ulstu/name/BaseRepository.java b/src/main/java/ru/ulstu/name/BaseRepository.java index b691ea2..d36feec 100644 --- a/src/main/java/ru/ulstu/name/BaseRepository.java +++ b/src/main/java/ru/ulstu/name/BaseRepository.java @@ -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); } diff --git a/src/main/java/ru/ulstu/name/BaseService.java b/src/main/java/ru/ulstu/name/BaseService.java index adcdc74..acad2d9 100644 --- a/src/main/java/ru/ulstu/name/BaseService.java +++ b/src/main/java/ru/ulstu/name/BaseService.java @@ -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; }