#120 add methods for checking unique title and date of grant
This commit is contained in:
parent
bb9f412480
commit
bab621677e
@ -2,8 +2,15 @@ package ru.ulstu.deadline.repository;
|
||||
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import ru.ulstu.deadline.model.Deadline;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public interface DeadlineRepository extends JpaRepository<Deadline, Integer> {
|
||||
|
||||
@Query(
|
||||
value = "SELECT date FROM Deadline d WHERE (d.grant_id = ?1) AND (d.date = ?2)",
|
||||
nativeQuery = true)
|
||||
Date findByGrantIdAndDate(Integer grant_id, Date date);
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import ru.ulstu.deadline.model.Deadline;
|
||||
import ru.ulstu.deadline.repository.DeadlineRepository;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ -46,4 +47,8 @@ public class DeadlineService {
|
||||
public void remove(Integer deadlineId) {
|
||||
deadlineRepository.delete(deadlineId);
|
||||
}
|
||||
|
||||
public Date findByGrantIdAndDate(Integer id, Date date) {
|
||||
return deadlineRepository.findByGrantIdAndDate(id, date);
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,8 @@ public interface GrantRepository extends JpaRepository<Grant, Integer>, BaseRepo
|
||||
|
||||
List<Grant> findByStatus(Grant.GrantStatus status);
|
||||
|
||||
Grant findByTitle(String title);
|
||||
|
||||
@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);
|
||||
|
@ -13,4 +13,11 @@ public abstract class BaseService {
|
||||
errors.rejectValue(checkField, "errorCode", errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
public String checkUniqueName(NameContainer nameContainer, Integer id) {
|
||||
if (nameContainer.getName().equals(baseRepository.findByNameAndNotId(nameContainer.getName(), id))) {
|
||||
return baseRepository.findByNameAndNotId(nameContainer.getName(), id);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user