commit 1a887a3c91d4ea669d28b20c4382ae6f7becd0d1
Author: Lukas Cerny <luc.cerny@gmail.com>
Date:   Thu Jun 6 13:35:15 2019 +0200

    Fixed: user settings, accepting / rejecting vacation, sick day, users, adding and deleting sick days, etc..

diff --git a/server/src/main/java/cz/zcu/yamanager/business/ApiManager.java b/server/src/main/java/cz/zcu/yamanager/business/ApiManager.java
index 1f9fb2c..f5c9d36 100644
--- a/server/src/main/java/cz/zcu/yamanager/business/ApiManager.java
+++ b/server/src/main/java/cz/zcu/yamanager/business/ApiManager.java
@@ -12,7 +12,6 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.dao.DataAccessException;
 import org.springframework.stereotype.Component;
 
-import java.sql.SQLException;
 import java.time.LocalDate;
 import java.util.List;
 import java.util.Optional;
@@ -41,16 +40,17 @@ public class ApiManager implements Manager {
     @Override
     public List<BasicProfileUser> getUsers(Status status) throws RESTFullException {
         try {
-            List<BasicProfileUser> users = status == null ? this.userRepository.getAllBasicUsers() : this.userRepository.getAllBasicUsers(status);
+            List<BasicProfileUser> users = userRepository.getAllBasicUsers(status == null ? Status.ACCEPTED : status);
 
             LocalDate today = LocalDate.now();
             LocalDate weekBefore = today.minusDays(ApiManager.WEEK_LENGTH);
             LocalDate weekAfter = today.plusDays(ApiManager.WEEK_LENGTH);
             for (BasicProfileUser user : users) {
-                user.setCalendar(this.vacationRepository.getVacationDays(user.getId(), weekBefore, weekAfter));
+                user.setCalendar(vacationRepository.getVacationDays(user.getId(), weekBefore, weekAfter));
             }
 
             return users;
+
         } catch (DataAccessException e) {
             log.error(e.getMessage());
             throw new RESTFullException(e.getMessage(), "database.error");
@@ -60,7 +60,7 @@ public class ApiManager implements Manager {
     @Override
     public List<VacationRequest> getVacationRequests(Status status) throws RESTFullException {
         try {
-            return status == null ? this.requestRepository.getAllVacationRequests() : this.requestRepository.getAllVacationRequests(status);
+            return status == null ? requestRepository.getAllVacationRequests() : requestRepository.getAllVacationRequests(status);
         } catch (DataAccessException e) {
             log.error(e.getMessage());
             throw new RESTFullException(e.getMessage(), "database.error");
@@ -70,7 +70,7 @@ public class ApiManager implements Manager {
     @Override
     public List<AuthorizationRequest> getAuthorizationRequests(Status status) throws RESTFullException {
         try {
-            return status == null ? this.requestRepository.getAllAuthorizations() : this.requestRepository.getAllAuthorizations(status);
+            return status == null ? requestRepository.getAllAuthorizations() : requestRepository.getAllAuthorizations(status);
         } catch (DataAccessException e) {
             log.error(e.getMessage());
             throw new RESTFullException(e.getMessage(), "database.error");
@@ -80,7 +80,7 @@ public class ApiManager implements Manager {
     @Override
     public FullUserProfile getUserProfile(Long userId) throws RESTFullException {
         try {
-            return this.userRepository.getFullUser(userId);
+            return userRepository.getFullUser(userId);
         } catch (DataAccessException e) {
             log.error(e.getMessage());
             throw new RESTFullException(e.getMessage(), "database.error");
@@ -90,7 +90,7 @@ public class ApiManager implements Manager {
     @Override
     public DefaultSettings getDefaultSettings() throws RESTFullException {
         try {
-            return this.userRepository.getLastDefaultSettings().orElse(new DefaultSettings());
+            return userRepository.getLastDefaultSettings().orElse(new DefaultSettings());
         } catch (DataAccessException e) {
             log.error(e.getMessage());
             throw new RESTFullException(e.getMessage(), "database.error");
@@ -102,16 +102,17 @@ public class ApiManager implements Manager {
         try {
             List<VacationDay> vacations;
             if (status == null && toDate == null) {
-                vacations = this.vacationRepository.getVacationDays(userId, fromDate);
+                vacations = vacationRepository.getVacationDays(userId, fromDate);
             } else if (status == null) {
-                vacations = this.vacationRepository.getVacationDays(userId, fromDate, toDate);
+                vacations = vacationRepository.getVacationDays(userId, fromDate, toDate);
             } else if (toDate != null) {
-                vacations = this.vacationRepository.getVacationDays(userId, fromDate, toDate, status);
+                vacations = vacationRepository.getVacationDays(userId, fromDate, toDate, status);
             } else {
-                vacations = this.vacationRepository.getVacationDays(userId, fromDate, status);
+                vacations = vacationRepository.getVacationDays(userId, fromDate, status);
             }
 
             return vacations;
+
         } catch (DataAccessException e) {
             log.error(e.getMessage());
             throw new RESTFullException(e.getMessage(), "database.error");
@@ -124,7 +125,7 @@ public class ApiManager implements Manager {
             cz.zcu.yamanager.domain.DefaultSettings defaultSettings = new cz.zcu.yamanager.domain.DefaultSettings();
             defaultSettings.setSickDayCount(settings.getSickDayCount());
             defaultSettings.setNotification(settings.getNotification());
-            this.userRepository.insertSettings(defaultSettings);
+            userRepository.insertSettings(defaultSettings);
         } catch (DataAccessException e) {
             log.error(e.getMessage());
             throw new RESTFullException(e.getMessage(), "database.error");
@@ -134,7 +135,7 @@ public class ApiManager implements Manager {
     @Override
     public void createVacation(Long userId, VacationDay vacationDay) throws RESTFullException {
         try {
-            User user = this.userRepository.getUser(userId);
+            User user = userRepository.getUser(userId);
             vacationDay.setStatus(user.getRole() == UserRole.EMPLOYER ? Status.ACCEPTED : Status.PENDING);
 
             cz.zcu.yamanager.domain.VacationDay vacation = new cz.zcu.yamanager.domain.VacationDay();
@@ -150,28 +151,67 @@ public class ApiManager implements Manager {
                 user.takeSickDay();
             }
 
-            this.vacationRepository.insertVacationDay(userId, vacation);
-            this.userRepository.updateUser(user);
+            vacationRepository.insertVacationDay(userId, vacation);
+            userRepository.updateUser(user);
         } catch (DataAccessException e) {
             log.error(e.getMessage());
             throw new RESTFullException(e.getMessage(), "database.error");
         }
     }
 
+    private void changeSettingsByEmployee(User user, UserSettings settings, DefaultSettings defaultSettings) {
+        if (settings.getNotification() != null && !settings.getNotification().equals(user.getNotification())) {
+            user.setNotification(settings.getNotification());
+        }
+
+        if (user.getTotalSickDayCount().equals(defaultSettings.getSickDayCount())) {
+            user.setTotalSickDayCount(null);
+        }
+    }
+
+    private void changeSettingsByEmployer(User user, UserSettings settings, DefaultSettings defaultSettings) {
+
+        if (settings.getRole() != null && !settings.getRole().equals(user.getRole())) {
+            user.setRole(settings.getRole());
+        }
+
+        if (settings.getSickDayCount() != null) {
+            if (settings.getSickDayCount().equals(defaultSettings.getSickDayCount())) {
+                user.setTotalSickDayCount(null);
+            } else {
+                user.setTotalSickDayCount(settings.getSickDayCount());
+            }
+        } else if (user.getTotalSickDayCount().equals(defaultSettings.getSickDayCount())) {
+            user.setTotalSickDayCount(null);
+        }
+
+        if (settings.getVacationCount() != null) {
+            user.setVacationCount(user.getVacationCount() + settings.getVacationCount());
+        }
+
+        if (settings.getNotification() != null && !settings.getNotification().equals(user.getNotification())) {
+            user.setNotification(settings.getNotification());
+        }
+    }
+
     @Override
     public void changeSettings(Long userId, UserSettings settings) throws RESTFullException {
+
         try {
-            User user = this.userRepository.getUser(userId);
+            UserRole invokedUserPermission = userRepository.getPermission(userId);
+            boolean invokedUserIsAdmin = invokedUserPermission.equals(UserRole.EMPLOYER);
+            DefaultSettings defaultSettings = getDefaultSettings();
 
-            if (settings.getRole() == null && settings.getSickDayCount() == null && settings.getVacationCount() == null) {
-                user.setNotification(settings.getNotification());
+            User userForChange = userRepository.getUser(settings.getId() == null ? userId : settings.getId());
+
+            if (invokedUserIsAdmin) {
+                changeSettingsByEmployer(userForChange, settings, defaultSettings);
             } else {
-                user.addVacationCount(settings.getVacationCount());
-                user.setTotalSickDayCount(settings.getSickDayCount());
-                user.setRole(settings.getRole());
+                changeSettingsByEmployee(userForChange, settings, defaultSettings);
             }
 
-            this.userRepository.updateUserSettings(user);
+            userRepository.updateUserSettings(userForChange);
+
         } catch (DataAccessException e) {
             log.error(e.getMessage());
             throw new RESTFullException(e.getMessage(), "database.error");
@@ -181,15 +221,13 @@ public class ApiManager implements Manager {
     @Override
     public void changeVacation(Long userId, VacationDay vacationDay) throws RESTFullException {
         try {
-            Optional<cz.zcu.yamanager.domain.VacationDay> vacation = this.vacationRepository.getVacationDay(vacationDay.getId());
+            Optional<cz.zcu.yamanager.domain.VacationDay> vacation = vacationRepository.getVacationDay(vacationDay.getId());
             if (vacation.isPresent()) {
                 vacation.get().setDate(vacationDay.getDate());
                 vacation.get().setStatus(vacationDay.getStatus());
                 vacation.get().setType(vacationDay.getType());
                 vacation.get().setTime(vacationDay.getFrom(), vacationDay.getTo());
-                this.vacationRepository.updateVacationDay(vacation.get());
-            } else {
-
+                vacationRepository.updateVacationDay(vacation.get());
             }
         } catch (DataAccessException e) {
             log.error(e.getMessage());
@@ -200,42 +238,76 @@ public class ApiManager implements Manager {
     @Override
     public void changeRequest(RequestType type, BasicRequest request) throws RESTFullException {
         try {
-            if (RequestType.VACATION == type) {
-                Optional<User> user = this.vacationRepository.findUserByVacationID(request.getId());
-                Optional<cz.zcu.yamanager.domain.VacationDay> vacationDay = this.vacationRepository.getVacationDay(request.getId());
-                if (user.isPresent() && request.getStatus() == Status.REJECTED) {
-                    if (vacationDay.get().getType() == VacationType.SICK_DAY) {
-                        user.get().addTakenSickDayCount(-1);
-                    } else {
-                        user.get().addVacationCount(vacationDay.get().getFrom(), vacationDay.get().getTo());
+            switch (type) {
+                case VACATION: {
+
+                    Optional<cz.zcu.yamanager.domain.VacationDay> vacationDayOpt = vacationRepository.getVacationDay(request.getId());
+
+                    if (!vacationDayOpt.isPresent()) {
+                        throw new RESTFullException("", "");
                     }
-                }
 
-                this.requestRepository.updateVacationRequest(request);
-            } else {
-                this.requestRepository.updateAuthorization(request);
+                    cz.zcu.yamanager.domain.VacationDay vacationDay = vacationDayOpt.get();
+
+                    if (request.getStatus().equals(Status.REJECTED)) {
+                        User user = userRepository.getUser(vacationDay.getUserId());
+
+                        switch (vacationDay.getType()) {
+                            case VACATION: {
+                                user.addVacationCount(vacationDay.getFrom(), vacationDay.getTo());
+                                userRepository.updateUserTakenVacation(user);
+                            } break;
+                            case SICK_DAY: {
+                                user.addTakenSickDayCount(-1);
+                                userRepository.updateUserTakenSickDay(user);
+                            } break;
+                        }
+                    }
+
+                    requestRepository.updateVacationRequest(vacationDay.getId(), request.getStatus());
+
+                } break;
+                case AUTHORIZATION: {
+                    requestRepository.updateAuthorization(request);
+                } break;
             }
         } catch (DataAccessException e) {
             log.error(e.getMessage());
             throw new RESTFullException(e.getMessage(), "database.error");
+        } catch (IllegalArgumentException e) {
+            throw new RESTFullException("Cannot create a domain object.", e.getMessage());
         }
     }
 
     @Override
     public void deleteVacation(Long userId, Long vacationId) throws RESTFullException {
         try {
-            User user = this.userRepository.getUser(userId);
-            Optional<cz.zcu.yamanager.domain.VacationDay> vacation = this.vacationRepository.getVacationDay(vacationId);
-            if (vacation.isPresent()) {
-                if (vacation.get().getType() == VacationType.SICK_DAY) {
-                    user.addTakenSickDayCount(-1);
-                } else {
-                    user.addVacationCount(vacation.get().getFrom(), vacation.get().getTo());
-                }
+            User user = userRepository.getUser(userId);
+            Optional<cz.zcu.yamanager.domain.VacationDay> vacation = vacationRepository.getVacationDay(vacationId);
+
+            if (!vacation.isPresent()) {
+                throw new RESTFullException("", "");
             }
 
-            this.userRepository.updateUser(user);
-            this.vacationRepository.deleteVacationDay(vacationId);
+            cz.zcu.yamanager.domain.VacationDay vacationDay = vacation.get();
+
+            if (vacationDay.getDate().isAfter(LocalDate.now())) {
+                if (!vacationDay.getStatus().equals(Status.REJECTED)) {
+                    switch (vacationDay.getType()) {
+                        case VACATION: {
+                            user.addVacationCount(vacationDay.getFrom(), vacationDay.getTo());
+                            userRepository.updateUserTakenVacation(user);
+                        }
+                        break;
+                        case SICK_DAY: {
+                            user.addTakenSickDayCount(-1);
+                            userRepository.updateUserTakenSickDay(user);
+                        }
+                        break;
+                    }
+                }
+                vacationRepository.deleteVacationDay(vacationDay.getId());
+            }
         } catch (DataAccessException e) {
             log.error(e.getMessage());
             throw new RESTFullException(e.getMessage(), "database.error");
diff --git a/server/src/main/java/cz/zcu/yamanager/domain/VacationDay.java b/server/src/main/java/cz/zcu/yamanager/domain/VacationDay.java
index a079dc4..f89275c 100644
--- a/server/src/main/java/cz/zcu/yamanager/domain/VacationDay.java
+++ b/server/src/main/java/cz/zcu/yamanager/domain/VacationDay.java
@@ -5,7 +5,6 @@ import cz.zcu.yamanager.dto.VacationType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import javax.naming.OperationNotSupportedException;
 import java.time.LocalDate;
 import java.time.LocalDateTime;
 import java.time.LocalTime;
@@ -55,6 +54,8 @@ public class VacationDay {
      */
     private VacationType type;
 
+    private Long userId;
+
     /**
      * Returns the ID of this vacation.
      *
@@ -272,6 +273,14 @@ public class VacationDay {
         this.type = type;
     }
 
+    public Long getUserId() {
+        return userId;
+    }
+
+    public void setUserId(Long userId) {
+        this.userId = userId;
+    }
+
     /**
      * Gets a string representation of this vacation. The representation consists of its id, date, starting time, ending time, creation date, status and type.
      *
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 f76b380..14be98b 100644
--- a/server/src/main/java/cz/zcu/yamanager/repository/UserRepository.java
+++ b/server/src/main/java/cz/zcu/yamanager/repository/UserRepository.java
@@ -9,8 +9,6 @@ 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.*;
@@ -19,6 +17,8 @@ import java.util.List;
 import java.util.Map;
 import java.util.Optional;
 
+import static cz.zcu.yamanager.dto.UserRole.getUserRole;
+
 /**
  * An instance of the class UserRepository handles queries which selects and updates users and their settings in a database.
  */
@@ -196,6 +196,12 @@ public class UserRepository {
                 new Object[]{status.name()}, new BasicProfileUserMapper());
     }
 
+    public UserRole getPermission(Long id) {
+        return jdbc.queryForObject("SELECT user_role FROM end_user WHERE id = ?" ,new Object[]{id}, (rs, rowNum) ->
+            getUserRole(rs.getString("user_role"))
+        );
+    }
+
     /**
      *
      * @param id
@@ -216,7 +222,7 @@ public class UserRepository {
         user.setNotification(((Timestamp) resultMap.get("out_alert")).toLocalDateTime());
         user.setEmail((String) resultMap.get("out_email"));
         user.setPhoto((String) resultMap.get("out_photo"));
-        user.setRole(UserRole.getUserRole((String) resultMap.get("out_role")));
+        user.setRole(getUserRole((String) resultMap.get("out_role")));
         user.setStatus(Status.getStatus((String) resultMap.get("out_status")));
         return user;
 
@@ -237,7 +243,7 @@ public class UserRepository {
         user.setNotification(((Timestamp) resultMap.get("out_alert")).toLocalDateTime());
         user.setEmail((String) resultMap.get(("out_email")));
         user.setPhoto((String) resultMap.get("out_photo"));
-        user.setRole(UserRole.getUserRole((String) resultMap.get("out_role")));
+        user.setRole(getUserRole((String) resultMap.get("out_role")));
         user.setStatus(Status.getStatus((String) resultMap.get("out_status")));
         return user;
     }
@@ -262,16 +268,11 @@ public class UserRepository {
         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.setRole(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 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());
@@ -285,4 +286,19 @@ public class UserRepository {
     public void insertSettings(final cz.zcu.yamanager.domain.DefaultSettings settings) {
         this.jdbc.update("INSERT INTO default_settings (no_sick_days, alert) VALUES (?, ?)", settings.getSickDayCount(), settings.getNotification());
     }
+
+    public void updateUserSettings(User user) {
+        jdbc.update("UPDATE end_user SET alert = ?, user_role = ?, no_sick_days = ?, no_vacations = ? WHERE id = ?",
+                user.getNotification(), user.getRole().name(), user.getTotalSickDayCount(), user.getVacationCount(), user.getId());
+    }
+
+    public void updateUserTakenVacation(User user) {
+        jdbc.update("UPDATE end_user SET no_vacations = ? WHERE id = ?",
+                user.getVacationCount(), user.getId());
+    }
+
+    public void updateUserTakenSickDay(User user) {
+        jdbc.update("UPDATE end_user SET taken_sick_days = ? WHERE id = ?",
+                user.getTakenSickDayCount(), user.getId());
+    }
 }
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 62876f7..b6b3600 100644
--- a/server/src/main/java/cz/zcu/yamanager/repository/VacationRepository.java
+++ b/server/src/main/java/cz/zcu/yamanager/repository/VacationRepository.java
@@ -1,10 +1,7 @@
 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;
+import cz.zcu.yamanager.dto.*;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -20,6 +17,9 @@ import java.time.LocalDate;
 import java.util.List;
 import java.util.Optional;
 
+import static cz.zcu.yamanager.dto.Status.getStatus;
+import static java.util.Optional.ofNullable;
+
 @Repository
 public class VacationRepository {
     /**
@@ -55,7 +55,7 @@ public class VacationRepository {
                 item.setTo(timeTo.toLocalTime());
             }
 
-            item.setStatus(Status.getStatus(resultSet.getString("v.status")));
+            item.setStatus(getStatus(resultSet.getString("v.status")));
             item.setType(VacationType.getVacationType(resultSet.getString("v.vacation_type")));
             return item;
         }
@@ -84,7 +84,7 @@ public class VacationRepository {
     }
 
     public List<VacationDay> getVacationDays(final long userId, final LocalDate from) {
-        return this.jdbc.query("SELECT v.id, v.vacation_date, v.time_from, v.time_to, v.status, v.vacation_type " +
+        return jdbc.query("SELECT v.id, v.vacation_date, v.time_from, v.time_to, v.status, v.vacation_type " +
                         "FROM vacation_day v " +
                         "INNER JOIN end_user u ON v.user_id = u.id " +
                         "WHERE v.user_id = ? AND v.vacation_date >= ?",
@@ -92,7 +92,7 @@ public class VacationRepository {
     }
 
     public List<VacationDay> getVacationDays(final long userId, final LocalDate from, final Status status) {
-        return this.jdbc.query("SELECT v.id, v.vacation_date, v.time_from, v.time_to, v.status, v.vacation_type " +
+        return jdbc.query("SELECT v.id, v.vacation_date, v.time_from, v.time_to, v.status, v.vacation_type " +
                         "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 = ?",
@@ -100,7 +100,7 @@ public class VacationRepository {
     }
 
     public List<VacationDay> getVacationDays(final long userId, final LocalDate from, final LocalDate to) {
-        return this.jdbc.query("SELECT v.id, v.vacation_date, v.time_from, v.time_to, v.status, v.vacation_type " +
+        return jdbc.query("SELECT v.id, v.vacation_date, v.time_from, v.time_to, v.status, v.vacation_type " +
                         "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 <= ?",
@@ -109,7 +109,7 @@ public class VacationRepository {
     }
 
     public List<VacationDay> getVacationDays(final long userId, final LocalDate from, final LocalDate to, final Status status) {
-        return this.jdbc.query("SELECT v.id, v.vacation_date, v.time_from, v.time_to, v.status, v.vacation_type " +
+        return jdbc.query("SELECT v.id, v.vacation_date, v.time_from, v.time_to, v.status, v.vacation_type " +
                         "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 = ?",
@@ -117,7 +117,7 @@ public class VacationRepository {
     }
 
     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 " +
+        return ofNullable(jdbc.queryForObject("SELECT id, vacation_date, time_from, time_to, creation_date, status, vacation_type, user_id " +
                         "FROM vacation_day WHERE id = ?", new Object[]{id},
                 (ResultSet rs, int rowNum) -> {
                     cz.zcu.yamanager.domain.VacationDay vacationDay = new cz.zcu.yamanager.domain.VacationDay();
@@ -139,43 +139,49 @@ public class VacationRepository {
                     }
 
                     vacationDay.setCreationDate(rs.getTimestamp("creation_date").toLocalDateTime());
-                    vacationDay.setStatus(Status.getStatus(rs.getString("status")));
+                    vacationDay.setStatus(getStatus(rs.getString("status")));
                     vacationDay.setType(VacationType.getVacationType(rs.getString("vacation_type")));
+                    vacationDay.setUserId(rs.getLong("user_id"));
                     return vacationDay;
                 }));
     }
 
     public void insertVacationDay(final Long userId, final cz.zcu.yamanager.domain.VacationDay day) {
-        this.jdbc.update("INSERT INTO vacation_day (vacation_date, time_from, time_to, status, vacation_type, user_id) VALUES (?,?,?,?,?,?)",
+        jdbc.update("INSERT INTO vacation_day (vacation_date, time_from, time_to, status, vacation_type, user_id) VALUES (?,?,?,?,?,?)",
                 day.getDate(), day.getFrom(), day.getTo(), day.getStatus().name(), day.getType().name(), userId);
     }
 
     public void updateVacationDay(final cz.zcu.yamanager.domain.VacationDay item) {
-        this.jdbc.update("UPDATE vacation_day SET vacation_date=?, time_from=?, time_to=?, status=?, vacation_type=? WHERE id=?",
+        jdbc.update("UPDATE vacation_day SET vacation_date=?, time_from=?, time_to=?, status=?, vacation_type=? WHERE id=?",
                 item.getDate(), item.getFrom(), item.getTo(), item.getStatus().name(), item.getType().name(), item.getId());
     }
 
     public void deleteVacationDay(final long id) {
-        this.jdbc.update("DELETE FROM vacation_day WHERE id=?", id);
+        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)->
+        return ofNullable(jdbc.queryForObject(
+                "SELECT u.id,u.first_name, u.last_name, u.no_vacations," +
+                        "u.no_sick_days, u.taken_sick_days, u.alert, u.token, u.email," +
+                        "u.photo, u.creation_date, u.user_role, u.status " +
+                "FROM vacation_day v INNER JOIN end_user u ON v.user_id = u.id " +
+                "WHERE v.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.setTotalSickDayCount(rs.getInt("u.no_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")));
+            user.setRole(UserRole.getUserRole(rs.getString("u.user_role")));
+            user.setStatus(getStatus(rs.getString("u.status")));
             return user;
         }));
     }
diff --git a/server/src/main/java/cz/zcu/yamanager/ws/rest/ApiController.java b/server/src/main/java/cz/zcu/yamanager/ws/rest/ApiController.java
index fa1788c..bbb6ebc 100644
--- a/server/src/main/java/cz/zcu/yamanager/ws/rest/ApiController.java
+++ b/server/src/main/java/cz/zcu/yamanager/ws/rest/ApiController.java
@@ -214,7 +214,7 @@ public class ApiController {
             @RequestBody UserSettings settings)
     {
         return handle(getLanguage(lang), () ->
-                manager.changeSettings(getUserId(settings.getId()), settings)
+                manager.changeSettings(getUserId("me"), settings)
         );
     }
 
