From e92a4dfd314fc14d18ec591114c44d5480702ee7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Diana=20Gul=C4=8D=C3=ADkov=C3=A1?= <xgulcik@fi.muni.cz>
Date: Mon, 17 Apr 2023 00:26:09 +0200
Subject: [PATCH] checkstyle fix

---
 .../exception/RestExceptionHandler.java       | 26 ++++++++++++++++---
 .../muni/pa165/race/service/RaceService.java  | 15 +++++------
 2 files changed, 28 insertions(+), 13 deletions(-)

diff --git a/common_library/src/main/java/cz/muni/pa165/common_library/exception/RestExceptionHandler.java b/common_library/src/main/java/cz/muni/pa165/common_library/exception/RestExceptionHandler.java
index bfe65b08..c7f84bf9 100644
--- a/common_library/src/main/java/cz/muni/pa165/common_library/exception/RestExceptionHandler.java
+++ b/common_library/src/main/java/cz/muni/pa165/common_library/exception/RestExceptionHandler.java
@@ -12,7 +12,6 @@ import org.springframework.web.bind.MethodArgumentNotValidException;
 import org.springframework.web.bind.annotation.ExceptionHandler;
 import org.springframework.web.bind.annotation.ResponseStatus;
 import org.springframework.web.bind.annotation.RestControllerAdvice;
-import org.springframework.web.client.HttpClientErrorException;
 import org.springframework.web.client.HttpServerErrorException;
 import org.springframework.web.servlet.NoHandlerFoundException;
 
@@ -91,7 +90,7 @@ public class RestExceptionHandler {
       for (ObjectError error : validationErrors) {
         var errorField = (FieldError) error;
         var errorMessage = errorField.getDefaultMessage();
-        var fieldName =  errorField.getField();
+        var fieldName = errorField.getField();
 
         validtionMessage.append(" field ").append(fieldName).append(": ")
             .append(errorMessage).append(",");
@@ -106,24 +105,43 @@ public class RestExceptionHandler {
         new ExError(message), new HttpHeaders(), HttpStatus.BAD_REQUEST);
   }
 
+  /**
+   * Handler for server error exception.
+   *
+   * @param ex thrown exception.
+   * @return Message with datetime.
+   */
   @ExceptionHandler(HttpServerErrorException.class)
   public ResponseEntity<ExError> handleServerException(HttpServerErrorException ex) {
     return new ResponseEntity<>(
         new ExError(ex.getMessage()), new HttpHeaders(), HttpStatus.INTERNAL_SERVER_ERROR);
   }
 
+  /**
+   * Handler for server error exception.
+   *
+   * @param ex thrown exception.
+   * @return Message with datetime.
+   */
   @ExceptionHandler(HttpServerErrorException.InternalServerError.class)
-  public ResponseEntity<ExError> handleServerException(HttpServerErrorException.InternalServerError ex) {
+  public ResponseEntity<ExError> handleServerException(
+      HttpServerErrorException.InternalServerError ex) {
     return new ResponseEntity<>(
         new ExError(ex.getMessage()), new HttpHeaders(), HttpStatus.INTERNAL_SERVER_ERROR);
   }
 
+  /**
+   * Handler for server error exception.
+   *
+   * @param ex thrown exception.
+   * @return Message with datetime.
+   */
   @ExceptionHandler(HttpHostConnectException.class)
   public ResponseEntity<ExError> handleServerException(HttpHostConnectException ex) {
     var message = "";
     if (ex.getMessage().contains("8083")) {
       message = "Failed to connect to the driver service";
-    } else if (ex.getMessage().contains("8082")){
+    } else if (ex.getMessage().contains("8082")) {
       message = "Failed to connect to the car service";
     }
     return new ResponseEntity<>(
diff --git a/race/src/main/java/cz/muni/pa165/race/service/RaceService.java b/race/src/main/java/cz/muni/pa165/race/service/RaceService.java
index 3a3de0a5..5d6dc7af 100644
--- a/race/src/main/java/cz/muni/pa165/race/service/RaceService.java
+++ b/race/src/main/java/cz/muni/pa165/race/service/RaceService.java
@@ -1,7 +1,5 @@
 package cz.muni.pa165.race.service;
 
-import cz.muni.pa165.common_library.dtos.CarResponseDto;
-import cz.muni.pa165.common_library.dtos.DriverDto;
 import cz.muni.pa165.common_library.dtos.Location;
 import cz.muni.pa165.common_library.dtos.RaceDriverCarDto;
 import cz.muni.pa165.common_library.dtos.RaceDto;
@@ -19,7 +17,6 @@ import java.util.Set;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
-import org.springframework.web.client.RestTemplate;
 
 /**
  * Service for managing races.
@@ -49,11 +46,11 @@ public class RaceService implements RaceServiceI {
   public RaceDto postRace(RaceDto raceDto) {
     raceDto.setId(null);
 
-    if ((raceDto.getDriverOne() != null ) &&
-        (raceDto.getDriverTwo() != null)) {
+    if ((raceDto.getDriverOne() != null)
+        && (raceDto.getDriverTwo() != null)) {
 
-      if (raceDto.getDriverOne().getDriverId() != null &&  raceDto.getDriverTwo().getDriverId() != null)
-      {
+      if (raceDto.getDriverOne().getDriverId() != null
+          && raceDto.getDriverTwo().getDriverId() != null) {
         if (Objects.equals(raceDto.getDriverOne().getCarId(),
             raceDto.getDriverTwo().getCarId())) {
           throw new DatabaseException("Cant assign same car to both drivers");
@@ -172,7 +169,7 @@ public class RaceService implements RaceServiceI {
   /**
    * Assigns positions for driver number two.
    *
-   * @param raceId race id.
+   * @param raceId   race id.
    * @param position position of driver two.
    * @return updated race.
    */
@@ -187,7 +184,7 @@ public class RaceService implements RaceServiceI {
   /**
    * Assigns positions for driver number one.
    *
-   * @param raceId race id.
+   * @param raceId   race id.
    * @param position position of driver one.
    * @return updated race.
    */
-- 
GitLab