fix check unique name of grant
This commit is contained in:
parent
a14735699c
commit
2c55293e0e
@ -28,7 +28,7 @@ public interface ConferenceRepository extends JpaRepository<Conference, Integer>
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Query("SELECT title FROM Conference c WHERE (c.title = :name) AND (:id IS NULL OR c.id != :id) ")
|
@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) " +
|
@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)")
|
"AND (u.participation = 'INTRAMURAL') AND (c.beginDate <= CURRENT_DATE) AND (c.endDate >= CURRENT_DATE)")
|
||||||
|
@ -18,7 +18,7 @@ public interface GrantRepository extends JpaRepository<Grant, Integer>, BaseRepo
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Query("SELECT title FROM Grant g WHERE (g.title = :name) AND (:id IS NULL OR g.id != :id) ")
|
@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')")
|
@Query("SELECT g FROM Grant g WHERE (g.status <> 'SKIPPED') AND (g.status <> 'COMPLETED')")
|
||||||
List<Grant> findAllActive();
|
List<Grant> findAllActive();
|
||||||
|
@ -3,5 +3,5 @@ package ru.ulstu.name;
|
|||||||
import org.springframework.data.repository.query.Param;
|
import org.springframework.data.repository.query.Param;
|
||||||
|
|
||||||
public interface BaseRepository {
|
public interface BaseRepository {
|
||||||
String findByNameAndNotId(@Param("name") String name, @Param("id") Integer id);
|
String findFirstByNameAndNotId(@Param("name") String name, @Param("id") Integer id);
|
||||||
}
|
}
|
||||||
|
@ -9,14 +9,14 @@ public abstract class BaseService {
|
|||||||
public BaseRepository baseRepository;
|
public BaseRepository baseRepository;
|
||||||
|
|
||||||
protected void checkUniqueName(NameContainer nameContainer, Errors errors, Integer id, String errorMessage) {
|
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);
|
errors.rejectValue("title", "errorCode", errorMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String checkUniqueName(NameContainer nameContainer, Integer id) {
|
protected String checkUniqueName(NameContainer nameContainer, Integer id) {
|
||||||
if (nameContainer.getName().equals(baseRepository.findByNameAndNotId(nameContainer.getName(), id))) {
|
if (nameContainer.getName().equals(baseRepository.findFirstByNameAndNotId(nameContainer.getName(), id))) {
|
||||||
return baseRepository.findByNameAndNotId(nameContainer.getName(), id);
|
return baseRepository.findFirstByNameAndNotId(nameContainer.getName(), id);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user