Revize 88e2ccf3
Přidáno uživatelem Lukas Cerny před téměř 6 roky(ů)
server/src/main/java/cz/zcu/yamanager/business/ApiManager.java | ||
---|---|---|
141 | 141 |
} |
142 | 142 |
|
143 | 143 |
try { |
144 |
|
|
145 |
if (vacationRepository.isExistVacationForUser(userId, vacationDay.getDate())) { |
|
146 |
throw new RESTFullException("Cannot take a double vacation for the same day.", "vacation.double.error"); |
|
147 |
} |
|
148 |
|
|
144 | 149 |
User user = userRepository.getUser(userId); |
145 | 150 |
vacationDay.setStatus(user.getRole() == UserRole.EMPLOYER ? Status.ACCEPTED : Status.PENDING); |
146 | 151 |
|
... | ... | |
159 | 164 |
|
160 | 165 |
vacationRepository.insertVacationDay(userId, vacation); |
161 | 166 |
userRepository.updateUser(user); |
167 |
|
|
162 | 168 |
} catch (DataAccessException e) { |
163 | 169 |
log.error(e.getMessage()); |
164 | 170 |
throw new RESTFullException(e.getMessage(), "database.error"); |
server/src/main/java/cz/zcu/yamanager/repository/VacationRepository.java | ||
---|---|---|
186 | 186 |
return user; |
187 | 187 |
})); |
188 | 188 |
} |
189 |
|
|
190 |
public boolean isExistVacationForUser(Long userId, LocalDate date) { |
|
191 |
return jdbc.queryForObject("SELECT count(id) AS exist FROM vacation_day WHERE vacation_date = ? AND user_id = ?", |
|
192 |
new Object[]{date, userId}, (rs, rowNum) -> rs.getBoolean("exist")); |
|
193 |
} |
|
189 | 194 |
} |
server/src/main/resources/Message_cs.properties | ||
---|---|---|
23 | 23 |
vacation.null.error = Po\u010Det hodin dovolen\u00E9 mus\u00ED b\u00FDt zad\u00E1n. |
24 | 24 |
role.null.error = Role mus\u00ED b\u00FDt zad\u00E1n. |
25 | 25 |
database.error = Vyskytl se probl\u00E9m s datab\u00E1z\u00ED. |
26 |
vacation.past.error = Nelze vybrat volno v minulosti. |
|
26 |
vacation.past.error = Nelze vybrat volno v minulosti. |
|
27 |
vacation.double.error = Nelze vybrat v\u00EDce voln pro stejn\u00FD den. |
server/src/main/resources/Message_en.properties | ||
---|---|---|
23 | 23 |
vacation.null.error = The number of overtime hours has to be filled in. |
24 | 24 |
role.null.error = The role has to be filled in. |
25 | 25 |
database.error = There was a problem with the database. |
26 |
vacation.past.error = You cannot take a vacation in past. |
|
26 |
vacation.past.error = You cannot take a vacation in past. |
|
27 |
vacation.double.error = You cannot take a vacation at the same day. |
Také k dispozici: Unified diff
Fixed a taking vacation for the same day.