commit 18b7c801e796f3cbb514a3bfc068676affe832d4
Author: D0miq <dpoch@email.com>
Date:   Thu Jun 6 03:53:17 2019 +0200

    Fixed repositories

diff --git a/server/src/main/java/cz/zcu/yamanager/repository/RequestRepository.java b/server/src/main/java/cz/zcu/yamanager/repository/RequestRepository.java
index 0049e1e..51e7f89 100644
--- a/server/src/main/java/cz/zcu/yamanager/repository/RequestRepository.java
+++ b/server/src/main/java/cz/zcu/yamanager/repository/RequestRepository.java
@@ -5,9 +5,11 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.jdbc.core.RowMapper;
 import org.springframework.stereotype.Repository;
 
 import java.sql.ResultSet;
+import java.sql.SQLException;
 import java.sql.Time;
 import java.util.List;
 
@@ -20,6 +22,72 @@ import java.util.List;
  */
 @Repository
 public class RequestRepository {
+    /**
+     * The mapper maps a row from a result of a query to an AuthorizationRequest.
+     */
+    private class AuthorizationRequestMapper implements RowMapper<AuthorizationRequest> {
+
+        /**
+         * Maps a row from a result of a query to an AuthorizationRequest.
+         * @param resultSet the row from the result
+         * @param i the index of the row
+         * @return the AuthorizationRequest object
+         * @throws SQLException if the columnLabel is not valid; if a database access error occurs or this method is called on a closed result set
+         */
+        @Override
+        public AuthorizationRequest mapRow(ResultSet resultSet, int i) throws SQLException {
+            final AuthorizationRequest request = new AuthorizationRequest();
+            request.setId(resultSet.getLong("id"));
+            request.setFirstName(resultSet.getString("first_name"));
+            request.setLastName(resultSet.getString("last_name"));
+            request.setTimestamp(resultSet.getTimestamp("creation_date").toLocalDateTime());
+            request.setStatus(Status.getStatus(resultSet.getString("status")));
+            return request;
+        }
+    }
+
+    /**
+     * The mapper maps each row from a result of a query to a VacationRequest.
+     */
+    private class VacationRequestMapper implements RowMapper<VacationRequest> {
+
+        /**
+         * Maps a row from a result of a query to an VacationRequest.
+         * @param resultSet the row from the result
+         * @param i the index of the row
+         * @return the VacationRequest object
+         * @throws SQLException if the columnLabel is not valid; if a database access error occurs or this method is called on a closed result set
+         */
+        @Override
+        public VacationRequest mapRow(ResultSet resultSet, int i) throws SQLException {
+            final VacationRequest request = new VacationRequest();
+            request.setId(resultSet.getLong("v.id"));
+            request.setFirstName(resultSet.getString("u.first_name"));
+            request.setLastName(resultSet.getString("u.last_name"));
+            request.setDate(resultSet.getDate("v.vacation_date").toLocalDate());
+
+            /*
+                When a result contains a sick day it doesn't have specified a start and end time because
+                it can be taken only as a whole day. In this case the v.time_from and v.time_to are null.
+                Which must be handled.
+            */
+            final Time timeFrom = resultSet.getTime("v.time_from");
+            if (timeFrom != null) {
+                request.setFrom(timeFrom.toLocalTime());
+            }
+
+            final Time timeTo = resultSet.getTime("v.time_to");
+            if (timeTo != null) {
+                request.setTo(timeTo.toLocalTime());
+            }
+
+            request.setTimestamp(resultSet.getTimestamp("v.creation_date").toLocalDateTime());
+            request.setType(VacationType.getVacationType(resultSet.getString("v.vacation_type")));
+            request.setStatus(Status.getStatus(resultSet.getString("v.status")));
+            return request;
+        }
+    }
+
     /**
      * The logger.
      */
@@ -38,6 +106,7 @@ public class RequestRepository {
     @Autowired
     public RequestRepository(final JdbcTemplate jdbc) {
         RequestRepository.log.trace("Creating a new instance of the class RequestRepository");
+
         this.jdbc = jdbc;
     }
 
@@ -52,16 +121,7 @@ public class RequestRepository {
     public List<AuthorizationRequest> getAllAuthorizations() {
         RequestRepository.log.trace("Selecting all authorization requests from a database.");
 
-        return this.jdbc.query("SELECT id, first_name, last_name, creation_date, status FROM end_user",
-                (ResultSet rs, int rowNum) -> {
-                    final AuthorizationRequest request = new AuthorizationRequest();
-                    request.setId(rs.getLong("id"));
-                    request.setFirstName(rs.getString("first_name"));
-                    request.setLastName(rs.getString("last_name"));
-                    request.setTimestamp(rs.getTimestamp("creation_date").toLocalDateTime());
-                    request.setStatus(Status.getStatus(rs.getString("status")));
-                    return request;
-                });
+        return this.jdbc.query("SELECT id, first_name, last_name, creation_date, status FROM end_user", new AuthorizationRequestMapper());
     }
 
     /**
@@ -77,17 +137,7 @@ public class RequestRepository {
         RequestRepository.log.trace("Selecting all authorization requests from a database with requested status.");
         RequestRepository.log.debug("Status: {}", status);
 
-        return this.jdbc.query("SELECT id, first_name, last_name, creation_date FROM end_user WHERE status = ?",
-                new Object[]{status.name()},
-                (ResultSet rs, int rowNum) -> {
-                    final AuthorizationRequest request = new AuthorizationRequest();
-                    request.setId(rs.getLong("id"));
-                    request.setFirstName(rs.getString("first_name"));
-                    request.setLastName(rs.getString("last_name"));
-                    request.setTimestamp(rs.getTimestamp("creation_date").toLocalDateTime());
-                    request.setStatus(status);
-                    return request;
-                });
+        return this.jdbc.query("SELECT id, first_name, last_name, creation_date, status FROM end_user WHERE status = ?", new Object[]{status.name()}, new AuthorizationRequestMapper());
     }
 
     /**
@@ -124,35 +174,8 @@ public class RequestRepository {
         RequestRepository.log.trace("Selecting all vacation requests from a database.");
 
         return this.jdbc.query("SELECT v.id, v.vacation_date, v.time_from, v.time_to, v.creation_date, v.vacation_type, v.status, u.first_name, u.last_name " +
-                        "FROM vacation_day v " +
-                        "INNER JOIN end_user u ON v.user_id = u.id",
-                (ResultSet rs, int rowNum) -> {
-                    final VacationRequest request = new VacationRequest();
-                    request.setId(rs.getLong("v.id"));
-                    request.setFirstName(rs.getString("u.first_name"));
-                    request.setLastName(rs.getString("u.last_name"));
-                    request.setDate(rs.getDate("v.vacation_date").toLocalDate());
-
-                    /*
-                        When a result contains a sickday it doesn't have specified a start and end time because
-                        it can be taken only as a whole day. In this case the v.time_from and v.time_to are null.
-                        Which must be handled.
-                     */
-                    final Time timeFrom = rs.getTime("v.time_from");
-                    if (timeFrom != null) {
-                        request.setFrom(timeFrom.toLocalTime());
-                    }
-
-                    final Time timeTo = rs.getTime("v.time_to");
-                    if (timeTo != null) {
-                        request.setTo(timeTo.toLocalTime());
-                    }
-
-                    request.setTimestamp(rs.getTimestamp("v.creation_date").toLocalDateTime());
-                    request.setType(VacationType.getVacationType(rs.getString("v.vacation_type")));
-                    request.setStatus(Status.getStatus(rs.getString("v.status")));
-                    return request;
-                });
+                "FROM vacation_day v " +
+                "INNER JOIN end_user u ON v.user_id = u.id", new VacationRequestMapper());
     }
 
     /**
@@ -171,34 +194,7 @@ public class RequestRepository {
                         "FROM vacation_day v " +
                         "INNER JOIN end_user u ON v.user_id = u.id " +
                         "WHERE v.status=?",
-                new Object[]{status.name()},
-                (ResultSet rs, int rowNum) -> {
-                    final VacationRequest request = new VacationRequest();
-                    request.setId(rs.getLong("v.id"));
-                    request.setFirstName(rs.getString("u.first_name"));
-                    request.setLastName(rs.getString("u.last_name"));
-                    request.setDate(rs.getDate("v.vacation_date").toLocalDate());
-
-                     /*
-                        When a result contains a sickday it doesn't have specified start and end time because
-                        it can be taken only as a whole day. In this case the v.time_from and v.time_to are null.
-                        Which must be handled.
-                     */
-                    final Time timeFrom = rs.getTime("v.time_from");
-                    if (timeFrom != null) {
-                        request.setFrom(timeFrom.toLocalTime());
-                    }
-
-                    final Time timeTo = rs.getTime("v.time_to");
-                    if (timeTo != null) {
-                        request.setTo(timeTo.toLocalTime());
-                    }
-
-                    request.setTimestamp(rs.getTimestamp("v.creation_date").toLocalDateTime());
-                    request.setType(VacationType.getVacationType(rs.getString("v.vacation_type")));
-                    request.setStatus(status);
-                    return request;
-                });
+                new Object[]{status.name()}, new VacationRequestMapper());
     }
 
     /**
diff --git a/server/src/main/java/cz/zcu/yamanager/repository/UserRepository.java b/server/src/main/java/cz/zcu/yamanager/repository/UserRepository.java
index 369c41b..f76b380 100644
--- a/server/src/main/java/cz/zcu/yamanager/repository/UserRepository.java
+++ b/server/src/main/java/cz/zcu/yamanager/repository/UserRepository.java
@@ -6,20 +6,69 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.jdbc.core.RowMapper;
 import org.springframework.jdbc.core.SqlOutParameter;
 import org.springframework.jdbc.core.SqlParameter;
+import org.springframework.jdbc.support.GeneratedKeyHolder;
+import org.springframework.jdbc.support.KeyHolder;
 import org.springframework.stereotype.Repository;
 
 import java.sql.*;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
+import java.util.Optional;
 
 /**
  * An instance of the class UserRepository handles queries which selects and updates users and their settings in a database.
  */
 @Repository
 public class UserRepository {
+
+    /**
+     * The mapper maps a row from a result of a query to an BasicProfileUser.
+     */
+    private class BasicProfileUserMapper implements RowMapper<BasicProfileUser> {
+
+        /**
+         * Maps a row from a result of a query to an BasicProfileUser.
+         * @param resultSet the row from the result
+         * @param i the index of the row
+         * @return the BasicProfileUser object
+         * @throws SQLException if the columnLabel is not valid; if a database access error occurs or this method is called on a closed result set
+         */
+        @Override
+        public BasicProfileUser mapRow(ResultSet resultSet, int i) throws SQLException {
+            final BasicProfileUser user = new BasicProfileUser();
+            user.setId(resultSet.getLong("id"));
+            user.setFirstName(resultSet.getString("first_name"));
+            user.setLastName(resultSet.getString("last_name"));
+            user.setPhoto(resultSet.getString("photo"));
+            return user;
+        }
+    }
+
+    /**
+     * The mapper maps a row from a result of a query to an BasicProfileUser.
+     */
+    private class DefaultSettingsMapper implements RowMapper<DefaultSettings> {
+
+        /**
+         * Maps a row from a result of a query to an DefaultSettings.
+         * @param resultSet the row from the result
+         * @param i the index of the row
+         * @return the DefaultSettings object
+         * @throws SQLException if the columnLabel is not valid; if a database access error occurs or this method is called on a closed result set
+         */
+        @Override
+        public DefaultSettings mapRow(ResultSet resultSet, int i) throws SQLException {
+            final DefaultSettings settings = new DefaultSettings();
+            settings.setSickDayCount(resultSet.getInt("no_sick_days"));
+            settings.setNotification(resultSet.getTimestamp("alert").toLocalDateTime());
+            return settings;
+        }
+    }
+
     /**
      * The logger.
      */
@@ -127,14 +176,7 @@ public class UserRepository {
     public List<BasicProfileUser> getAllBasicUsers() {
         UserRepository.log.trace("Selecting basic profiles of all users from a database.");
 
-        return this.jdbc.query("SELECT id, first_name, last_name, photo FROM end_user", (ResultSet rs, int rowNum) -> {
-            final BasicProfileUser user = new BasicProfileUser();
-            user.setId(rs.getLong("id"));
-            user.setFirstName(rs.getString("first_name"));
-            user.setLastName(rs.getString("last_name"));
-            user.setPhoto(rs.getString("photo"));
-            return user;
-        });
+        return this.jdbc.query("SELECT id, first_name, last_name, photo FROM end_user", new BasicProfileUserMapper());
     }
 
     /**
@@ -151,14 +193,7 @@ public class UserRepository {
         UserRepository.log.debug("Status: {}", status);
 
         return this.jdbc.query("SELECT id, first_name, last_name, photo FROM end_user WHERE status = ?",
-                new Object[]{status.name()}, (ResultSet rs, int rowNum) -> {
-                    final BasicProfileUser user = new BasicProfileUser();
-                    user.setId(rs.getLong("id"));
-                    user.setFirstName(rs.getString("first_name"));
-                    user.setLastName(rs.getString("last_name"));
-                    user.setPhoto(rs.getString("photo"));
-                    return user;
-                });
+                new Object[]{status.name()}, new BasicProfileUserMapper());
     }
 
     /**
@@ -207,39 +242,39 @@ public class UserRepository {
         return user;
     }
 
-    public DefaultSettings getLastDefaultSettings() {
-        return this.jdbc.queryForObject("SELECT * FROM default_settings ORDER BY id DESC LIMIT 1", (ResultSet rs, int rowNum) -> {
-            final DefaultSettings settings = new DefaultSettings();
-            settings.setSickDayCount(rs.getInt("no_sick_days"));
-            settings.setNotification(rs.getTimestamp("alert").toLocalDateTime());
-            return settings;
-        });
+    public Optional<DefaultSettings> getLastDefaultSettings() {
+        return Optional.ofNullable(this.jdbc.queryForObject("SELECT * FROM default_settings ORDER BY id DESC LIMIT 1", new DefaultSettingsMapper()));
     }
 
     //---------------------------------- DOMAIN -----------------------------------
 
     public User getUser(final long id) {
         final Map<String, Object> resultMap = this.getUserColumns(id);
-        return new User(
-                id,
-                (String) resultMap.get("out_first_name"),
-                (String) resultMap.get("out_last_name"),
-                ((Double) resultMap.get("out_no_vacations")).floatValue(),
-                (Integer) resultMap.get("out_no_sick_days"),
-                (Integer) resultMap.get("out_taken_sick_days"),
-                ((Timestamp) resultMap.get("out_alert")).toLocalDateTime(),
-                (String) resultMap.get("out_token"),
-                (String) resultMap.get("out_email"),
-                (String) resultMap.get("out_photo"),
-                ((Timestamp) resultMap.get("out_creation_date")).toLocalDateTime(),
-                UserRole.getUserRole((String) resultMap.get("out_role")),
-                Status.getStatus((String) resultMap.get("out_status"))
-        );
+        User user = new User();
+        user.setId((Long) resultMap.get("out_id"));
+        user.setFirstName((String)resultMap.get("out_first_name"));
+        user.setLastName((String)resultMap.get("out_last_name"));
+        user.setVacationCount(((Double)resultMap.get("out_no_vacations")).floatValue());
+        user.setTotalSickDayCount((Integer)resultMap.get("out_no_sick_days"));
+        user.setTakenSickDayCount((Integer)resultMap.get("out_taken_sick_days"));
+        user.setNotification(((Timestamp)resultMap.get("out_alert")).toLocalDateTime());
+        user.setToken((String)resultMap.get("out_token"));
+        user.setEmail((String)resultMap.get("out_email"));
+        user.setPhoto((String)resultMap.get("out_photo"));
+        user.setCreationDate(((Timestamp)resultMap.get("out_creation_date")).toLocalDateTime());
+        user.setRole(UserRole.getUserRole((String)resultMap.get("out_role")));
+        user.setStatus(Status.getStatus((String)resultMap.get("out_status")));
+        return user;
+    }
+
+    public void updateUserSettings(final  User user) {
+        this.jdbc.update("UPDATE end_user SET no_vacations = ?, no_sick_days = ?, alert = ? WHERE id = ?",
+                user.getVacationCount(), user.getTotalSickDayCount(), user.getNotification(), user.getId());
     }
 
-    public void updateUser(final cz.zcu.yamanager.domain.User user) {
-        this.jdbc.update("UPDATE end_user SET first_name = ?, last_name = ?, no_vacations = ?, no_sick_days = ?, taken_sick_days = ?, alert = ?, token = ?, email = ?, photo = ?, user_role = ?, status = ? WHERE id = ?",
-                user.getFirstName(), user.getLastName(), user.getVacationCount(), user.getTotalSickDayCount(), user.getTakenSickDayCount(), user.getNotification(), user.getToken(), user.getEmail(), user.getPhoto(), user.getRole().name(), user.getStatus().name(), user.getId());
+    public void updateUser(final User user) {
+        this.jdbc.update("UPDATE end_user SET first_name = ?, last_name = ?, no_vacations = ?, taken_sick_days = ?, token = ?, email = ?, photo = ?, user_role = ?, status = ? WHERE id = ?",
+                user.getFirstName(), user.getLastName(), user.getVacationCount(), user.getTakenSickDayCount(), user.getToken(), user.getEmail(), user.getPhoto(), user.getRole().name(), user.getStatus().name(), user.getId());
     }
 
     public void insertUser(final User user) {
diff --git a/server/src/main/java/cz/zcu/yamanager/repository/VacationRepository.java b/server/src/main/java/cz/zcu/yamanager/repository/VacationRepository.java
index 9a2f537..62876f7 100644
--- a/server/src/main/java/cz/zcu/yamanager/repository/VacationRepository.java
+++ b/server/src/main/java/cz/zcu/yamanager/repository/VacationRepository.java
@@ -1,6 +1,8 @@
 package cz.zcu.yamanager.repository;
 
+import cz.zcu.yamanager.domain.User;
 import cz.zcu.yamanager.dto.Status;
+import cz.zcu.yamanager.dto.UserRole;
 import cz.zcu.yamanager.dto.VacationDay;
 import cz.zcu.yamanager.dto.VacationType;
 
@@ -8,15 +10,57 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.jdbc.core.RowMapper;
 import org.springframework.stereotype.Repository;
 
 import java.sql.ResultSet;
+import java.sql.SQLException;
 import java.sql.Time;
 import java.time.LocalDate;
 import java.util.List;
+import java.util.Optional;
 
 @Repository
 public class VacationRepository {
+    /**
+     * The mapper maps a row from a result of a query to an VacationDay.
+     */
+    private class VacationDayMapper implements RowMapper<VacationDay> {
+
+        /**
+         * Maps a row from a result of a query to an VacationDay.
+         * @param resultSet the row from the result
+         * @param i the index of the row
+         * @return the VacationDay object
+         * @throws SQLException if the columnLabel is not valid; if a database access error occurs or this method is called on a closed result set
+         */
+        @Override
+        public VacationDay mapRow(ResultSet resultSet, int i) throws SQLException {
+            final VacationDay item = new VacationDay();
+            item.setId(resultSet.getLong("v.id"));
+            item.setDate(resultSet.getDate("v.vacation_date").toLocalDate());
+
+            /*
+                When a result contains a sick day it doesn't have specified a start and end time because
+                it can be taken only as a whole day. In this case the v.time_from and v.time_to are null.
+                Which must be handled.
+            */
+            final Time timeFrom = resultSet.getTime("v.time_from");
+            if (timeFrom != null) {
+                item.setFrom(timeFrom.toLocalTime());
+            }
+
+            final Time timeTo = resultSet.getTime("v.time_to");
+            if (timeTo != null) {
+                item.setTo(timeTo.toLocalTime());
+            }
+
+            item.setStatus(Status.getStatus(resultSet.getString("v.status")));
+            item.setType(VacationType.getVacationType(resultSet.getString("v.vacation_type")));
+            return item;
+        }
+    }
+
     /**
      * The logger.
      */
@@ -35,6 +79,7 @@ public class VacationRepository {
     @Autowired
     public VacationRepository(final JdbcTemplate jdbc) {
         VacationRepository.log.trace("Creating a new instance of the class VacationRepository");
+
         this.jdbc = jdbc;
     }
 
@@ -43,24 +88,7 @@ public class VacationRepository {
                         "FROM vacation_day v " +
                         "INNER JOIN end_user u ON v.user_id = u.id " +
                         "WHERE v.user_id = ? AND v.vacation_date >= ?",
-                new Object[]{userId, from}, (ResultSet rs, int rowNum) -> {
-                    final VacationDay item = new VacationDay();
-                    item.setId(rs.getLong("v.id"));
-                    item.setDate(rs.getDate("v.vacation_date").toLocalDate());
-                    final Time timeFrom = rs.getTime("v.time_from");
-                    if (timeFrom != null) {
-                        item.setFrom(timeFrom.toLocalTime());
-                    }
-
-                    final Time timeTo = rs.getTime("v.time_to");
-                    if (timeTo != null) {
-                        item.setTo(timeTo.toLocalTime());
-                    }
-
-                    item.setStatus(Status.getStatus(rs.getString("v.status")));
-                    item.setType(VacationType.getVacationType(rs.getString("v.vacation_type")));
-                    return item;
-                });
+                new Object[]{userId, from}, new VacationDayMapper());
     }
 
     public List<VacationDay> getVacationDays(final long userId, final LocalDate from, final Status status) {
@@ -68,24 +96,7 @@ public class VacationRepository {
                         "FROM vacation_day v " +
                         "INNER JOIN end_user u ON v.user_id = u.id " +
                         "WHERE v.user_id = ? AND v.vacation_date >= ? AND v.status = ?",
-                new Object[]{userId, from, status.name()}, (ResultSet rs, int rowNum) -> {
-                    final VacationDay item = new VacationDay();
-                    item.setId(rs.getLong("v.id"));
-                    item.setDate(rs.getDate("v.vacation_date").toLocalDate());
-                    final Time timeFrom = rs.getTime("v.time_from");
-                    if (timeFrom != null) {
-                        item.setFrom(timeFrom.toLocalTime());
-                    }
-
-                    final Time timeTo = rs.getTime("v.time_to");
-                    if (timeTo != null) {
-                        item.setTo(timeTo.toLocalTime());
-                    }
-
-                    item.setStatus(Status.getStatus(rs.getString("v.status")));
-                    item.setType(VacationType.getVacationType(rs.getString("v.vacation_type")));
-                    return item;
-                });
+                new Object[]{userId, from, status.name()}, new VacationDayMapper());
     }
 
     public List<VacationDay> getVacationDays(final long userId, final LocalDate from, final LocalDate to) {
@@ -93,24 +104,7 @@ public class VacationRepository {
                         "FROM vacation_day v " +
                         "INNER JOIN end_user u ON v.user_id = u.id " +
                         "WHERE v.user_id=? AND v.vacation_date >= ? AND v.vacation_date <= ?",
-                new Object[]{userId, from, to}, (ResultSet rs, int rowNum) -> {
-                    final VacationDay item = new VacationDay();
-                    item.setId(rs.getLong("v.id"));
-                    item.setDate(rs.getDate("v.vacation_date").toLocalDate());
-                    final Time timeFrom = rs.getTime("v.time_from");
-                    if (timeFrom != null) {
-                        item.setFrom(timeFrom.toLocalTime());
-                    }
-
-                    final Time timeTo = rs.getTime("v.time_to");
-                    if (timeTo != null) {
-                        item.setTo(timeTo.toLocalTime());
-                    }
-
-                    item.setStatus(Status.getStatus(rs.getString("v.status")));
-                    item.setType(VacationType.getVacationType(rs.getString("v.vacation_type")));
-                    return item;
-                });
+                new Object[]{userId, from, to}, new VacationDayMapper());
 
     }
 
@@ -119,41 +113,36 @@ public class VacationRepository {
                         "FROM vacation_day v " +
                         "INNER JOIN end_user u ON v.user_id = u.id " +
                         "WHERE v.user_id=? AND v.vacation_date >= ? AND v.vacation_date <= ? AND v.status = ?",
-                new Object[]{userId, from, to, status.name()}, (ResultSet rs, int rowNum) -> {
-                    final VacationDay item = new VacationDay();
-                    item.setId(rs.getLong("v.id"));
-                    item.setDate(rs.getDate("v.vacation_date").toLocalDate());
+                new Object[]{userId, from, to, status.name()}, new VacationDayMapper());
+    }
 
-                    final Time timeFrom = rs.getTime("v.time_from");
+    public Optional<cz.zcu.yamanager.domain.VacationDay> getVacationDay(final long id) {
+        return Optional.ofNullable(this.jdbc.queryForObject("SELECT id, vacation_date, time_from, time_to, creation_date, status, vacation_type " +
+                        "FROM vacation_day WHERE id = ?", new Object[]{id},
+                (ResultSet rs, int rowNum) -> {
+                    cz.zcu.yamanager.domain.VacationDay vacationDay = new cz.zcu.yamanager.domain.VacationDay();
+                    vacationDay.setId(rs.getLong("id"));
+                    vacationDay.setDate(rs.getDate("vacation_date").toLocalDate());
+                    /*
+                        When a result contains a sick day it doesn't have specified a start and end time because
+                        it can be taken only as a whole day. In this case the v.time_from and v.time_to are null.
+                        Which must be handled.
+                    */
+                    final Time timeFrom = rs.getTime("time_from");
                     if (timeFrom != null) {
-                        item.setFrom(timeFrom.toLocalTime());
+                        vacationDay.setFrom(timeFrom.toLocalTime());
                     }
 
-                    final Time timeTo = rs.getTime("v.time_to");
+                    final Time timeTo = rs.getTime("time_to");
                     if (timeTo != null) {
-                        item.setTo(timeTo.toLocalTime());
+                        vacationDay.setTo(timeTo.toLocalTime());
                     }
 
-                    item.setStatus(Status.getStatus(rs.getString("v.status")));
-                    item.setType(VacationType.getVacationType(rs.getString("v.vacation_type")));
-                    return item;
-                });
-    }
-
-    public cz.zcu.yamanager.domain.VacationDay getVacationDay(final long id) {
-        return this.jdbc.queryForObject("SELECT id, vacation_date, time_from, time_to, creation_date, status, vacation_type" +
-                        "FROM vacation_day " +
-                        "WHERE id = ?", new Object[]{id},
-                (ResultSet rs, int rowNum) ->
-                    new cz.zcu.yamanager.domain.VacationDay(
-                            rs.getLong("id"),
-                            rs.getDate("vacation_date").toLocalDate(),
-                            rs.getTime("time_from").toLocalTime(),
-                            rs.getTime("time_to").toLocalTime(),
-                            rs.getTimestamp("creation_date").toLocalDateTime(),
-                            Status.getStatus(rs.getString("status")),
-                            VacationType.getVacationType(rs.getString("v.vacation_type")))
-                );
+                    vacationDay.setCreationDate(rs.getTimestamp("creation_date").toLocalDateTime());
+                    vacationDay.setStatus(Status.getStatus(rs.getString("status")));
+                    vacationDay.setType(VacationType.getVacationType(rs.getString("vacation_type")));
+                    return vacationDay;
+                }));
     }
 
     public void insertVacationDay(final Long userId, final cz.zcu.yamanager.domain.VacationDay day) {
@@ -169,4 +158,25 @@ public class VacationRepository {
     public void deleteVacationDay(final long id) {
         this.jdbc.update("DELETE FROM vacation_day WHERE id=?", id);
     }
+
+    public Optional<User> findUserByVacationID(final long id) {
+        return Optional.ofNullable(this.jdbc.queryForObject("SELECT u.* FROM vacation_day v INNER JOIN end_user u ON v.user_id = u.id WHERE v.user_id = ?", new Object[]{id}, (ResultSet rs, int rowNum)->
+        {
+            User user = new User();
+            user.setId(rs.getLong("u.id"));
+            user.setFirstName(rs.getString("u.first_name"));
+            user.setLastName(rs.getString("u.last_name"));
+            user.setVacationCount(rs.getFloat("u.no_vacations"));
+            user.setTotalSickDayCount(rs.getInt("u.total_sick_days"));
+            user.setTakenSickDayCount(rs.getInt("u.taken_sick_days"));
+            user.setNotification(rs.getTimestamp("u.alert").toLocalDateTime());
+            user.setToken(rs.getString("u.token"));
+            user.setEmail(rs.getString("u.email"));
+            user.setPhoto(rs.getString("u.photo"));
+            user.setCreationDate(rs.getTimestamp("u.creation_date").toLocalDateTime());
+            user.setRole(UserRole.getUserRole(rs.getString("u.role")));
+            user.setStatus(Status.getStatus(rs.getString("u.status")));
+            return user;
+        }));
+    }
 }
