roles) {
for (Role role : roles) {
role.setRolePK(new RolePK(this.getId(), role.getAuthority()));
@@ -100,8 +107,8 @@ public void setAuthorities(String... authorities) {
public String getFullName() {
return getFirstName()
- .concat(" ")
- .concat(getLastName());
+ .concat(" ")
+ .concat(getLastName());
}
@Override
diff --git a/src/main/java/org/siriusxi/htec/fa/domain/dto/request/UpSrtCommentRequest.java b/src/main/java/org/siriusxi/htec/fa/domain/dto/request/UpSrtCommentRequest.java
deleted file mode 100644
index eb1b0d1..0000000
--- a/src/main/java/org/siriusxi/htec/fa/domain/dto/request/UpSrtCommentRequest.java
+++ /dev/null
@@ -1,10 +0,0 @@
-package org.siriusxi.htec.fa.domain.dto.request;
-
-import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
-import com.fasterxml.jackson.annotation.JsonProperty;
-
-import javax.validation.constraints.NotBlank;
-
-@JsonIgnoreProperties(ignoreUnknown = true)
-public record UpSrtCommentRequest(@JsonProperty("comment") @NotBlank String comment) {
-}
diff --git a/src/main/java/org/siriusxi/htec/fa/domain/model/vo/RouteView.java b/src/main/java/org/siriusxi/htec/fa/domain/vo/RouteView.java
similarity index 62%
rename from src/main/java/org/siriusxi/htec/fa/domain/model/vo/RouteView.java
rename to src/main/java/org/siriusxi/htec/fa/domain/vo/RouteView.java
index ccf5029..3d79c16 100644
--- a/src/main/java/org/siriusxi/htec/fa/domain/model/vo/RouteView.java
+++ b/src/main/java/org/siriusxi/htec/fa/domain/vo/RouteView.java
@@ -1,4 +1,4 @@
-package org.siriusxi.htec.fa.domain.model.vo;
+package org.siriusxi.htec.fa.domain.vo;
public record RouteView(String source, String destination, double price) {
}
diff --git a/src/main/java/org/siriusxi/htec/fa/infra/algorithm/distance/DistanceAlgorithm.java b/src/main/java/org/siriusxi/htec/fa/infra/algorithm/distance/DistanceAlgorithm.java
index 3c3fe01..da49baf 100644
--- a/src/main/java/org/siriusxi/htec/fa/infra/algorithm/distance/DistanceAlgorithm.java
+++ b/src/main/java/org/siriusxi/htec/fa/infra/algorithm/distance/DistanceAlgorithm.java
@@ -15,38 +15,6 @@
*/
public sealed interface DistanceAlgorithm permits HaversineAlgorithm, OrthodromicAlgorithm {
- /**
- * Enum to represent the implemented distance calculators algorithms.
- */
- enum Type {
- HAVERSINE,
- ORTHODROMIC
- }
-
- /**
- * The Radius of earth measurements.
- */
- enum MeasureType {
- /**
- * Earth radius in Mile.
- */
- MILE(3_958.0),
- /**
- * Earth radius in Kilometer.
- */
- KILOMETER(6_371.0);
-
- private final double value;
-
- MeasureType(double v) {
- this.value = v;
- }
-
- public double getValue() {
- return value;
- }
- }
-
/**
* A factory method to return the implementation of selected distance calculator algorithm.
*
@@ -80,4 +48,36 @@ static DistanceAlgorithm getAlgorithm(Type type) {
*/
double calculate(Point first, Point second);
+ /**
+ * Enum to represent the implemented distance calculators algorithms.
+ */
+ enum Type {
+ HAVERSINE,
+ ORTHODROMIC
+ }
+
+ /**
+ * The Radius of earth measurements.
+ */
+ enum MeasureType {
+ /**
+ * Earth radius in Mile.
+ */
+ MILE(3_958.0),
+ /**
+ * Earth radius in Kilometer.
+ */
+ KILOMETER(6_371.0);
+
+ private final double value;
+
+ MeasureType(double v) {
+ this.value = v;
+ }
+
+ public double getValue() {
+ return value;
+ }
+ }
+
}
diff --git a/src/main/java/org/siriusxi/htec/fa/infra/algorithm/distance/HaversineAlgorithm.java b/src/main/java/org/siriusxi/htec/fa/infra/algorithm/distance/HaversineAlgorithm.java
index 487552e..d54c27f 100644
--- a/src/main/java/org/siriusxi/htec/fa/infra/algorithm/distance/HaversineAlgorithm.java
+++ b/src/main/java/org/siriusxi/htec/fa/infra/algorithm/distance/HaversineAlgorithm.java
@@ -1,6 +1,11 @@
package org.siriusxi.htec.fa.infra.algorithm.distance;
-import static java.lang.Math.*;
+import static java.lang.Math.asin;
+import static java.lang.Math.cos;
+import static java.lang.Math.pow;
+import static java.lang.Math.sin;
+import static java.lang.Math.sqrt;
+import static java.lang.Math.toRadians;
import static java.util.Objects.requireNonNull;
import static java.util.Objects.requireNonNullElse;
diff --git a/src/main/java/org/siriusxi/htec/fa/infra/algorithm/distance/OrthodromicAlgorithm.java b/src/main/java/org/siriusxi/htec/fa/infra/algorithm/distance/OrthodromicAlgorithm.java
index 292813d..e0f01cd 100644
--- a/src/main/java/org/siriusxi/htec/fa/infra/algorithm/distance/OrthodromicAlgorithm.java
+++ b/src/main/java/org/siriusxi/htec/fa/infra/algorithm/distance/OrthodromicAlgorithm.java
@@ -1,6 +1,11 @@
package org.siriusxi.htec.fa.infra.algorithm.distance;
-import static java.lang.Math.*;
+import static java.lang.Math.asin;
+import static java.lang.Math.cos;
+import static java.lang.Math.pow;
+import static java.lang.Math.sin;
+import static java.lang.Math.sqrt;
+import static java.lang.Math.toRadians;
import static java.util.Objects.requireNonNull;
import static java.util.Objects.requireNonNullElse;
diff --git a/src/main/java/org/siriusxi/htec/fa/infra/config/FileUploadConfig.java b/src/main/java/org/siriusxi/htec/fa/infra/config/FileUploadConfig.java
deleted file mode 100644
index 1b5a601..0000000
--- a/src/main/java/org/siriusxi/htec/fa/infra/config/FileUploadConfig.java
+++ /dev/null
@@ -1,28 +0,0 @@
-package org.siriusxi.htec.fa.infra.config;
-
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.web.multipart.commons.CommonsMultipartResolver;
-
-/**
- * File upload configuration, is to manage the upload of large files.
- *
- * As we cannot use Spring Boot’s default StandardServletMultipartResolver
or
- * CommonsMultipartResolver
, since the server has limited resources (disk space)
- * or memory for buffering.
- * So we need to disable the default MultipartResolver
and define our own
- * MultipartResolver
.
- *
- * @author Mohamed Taman
- */
-
-@Configuration
-public class FileUploadConfig {
-
- @Bean("multipartResolver")
- public CommonsMultipartResolver multipartResolver() {
- var multipartResolver = new CommonsMultipartResolver();
- multipartResolver.setMaxUploadSize(-1);
- return multipartResolver;
- }
-}
diff --git a/src/main/java/org/siriusxi/htec/fa/infra/config/GlobalExceptionHandler.java b/src/main/java/org/siriusxi/htec/fa/infra/config/GlobalExceptionHandler.java
index 1564d94..00aab1d 100644
--- a/src/main/java/org/siriusxi/htec/fa/infra/config/GlobalExceptionHandler.java
+++ b/src/main/java/org/siriusxi/htec/fa/infra/config/GlobalExceptionHandler.java
@@ -1,28 +1,41 @@
package org.siriusxi.htec.fa.infra.config;
import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonRootName;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.validation.ValidationException;
import lombok.extern.log4j.Log4j2;
import org.siriusxi.htec.fa.infra.exception.NotAllowedException;
import org.siriusxi.htec.fa.infra.exception.NotFoundException;
-import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.MissingServletRequestParameterException;
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.method.annotation.MethodArgumentTypeMismatchException;
-import javax.servlet.http.HttpServletRequest;
-import javax.validation.ValidationException;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+
+import static org.springframework.http.HttpStatus.BAD_REQUEST;
+import static org.springframework.http.HttpStatus.FORBIDDEN;
+import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR;
+import static org.springframework.http.HttpStatus.NOT_ACCEPTABLE;
+import static org.springframework.http.HttpStatus.NOT_FOUND;
+import static org.springframework.http.HttpStatus.UNAUTHORIZED;
@Log4j2
@RestControllerAdvice
public class GlobalExceptionHandler {
@ExceptionHandler(NotFoundException.class)
+ @ResponseStatus(NOT_FOUND)
public ResponseEntity> handleNotFoundException(
HttpServletRequest request,
NotFoundException ex) {
@@ -30,11 +43,12 @@ public ResponseEntity> handleNotFoundException(
log.error("NotFoundException {}\n", request.getRequestURI(), ex);
return ResponseEntity
- .status(HttpStatus.NOT_FOUND)
- .body(new ApiCallError<>("Not found", List.of(ex.getMessage())));
+ .status(NOT_FOUND)
+ .body(new ApiCallError<>("Not found", List.of(ex.getMessage())));
}
@ExceptionHandler(NotAllowedException.class)
+ @ResponseStatus(NOT_ACCEPTABLE)
public ResponseEntity>
handleNotAllowedException(HttpServletRequest request,
NotAllowedException ex) {
@@ -42,11 +56,12 @@ public ResponseEntity> handleNotFoundException(
log.error("NotAllowedException {}\n", request.getRequestURI(), ex);
return ResponseEntity
- .status(HttpStatus.NOT_ACCEPTABLE)
- .body(new ApiCallError<>("Not Applicable", List.of(ex.getMessage())));
+ .status(NOT_ACCEPTABLE)
+ .body(new ApiCallError<>("Not Applicable", List.of(ex.getMessage())));
}
@ExceptionHandler(IllegalArgumentException.class)
+ @ResponseStatus(BAD_REQUEST)
public ResponseEntity>
handleIllegalArgumentException(HttpServletRequest request,
IllegalArgumentException ex) {
@@ -55,14 +70,15 @@ public ResponseEntity> handleNotFoundException(
request.getRequestURI(), ex.getMessage());
return ResponseEntity
- .badRequest()
- .body(new ApiCallError<>(
- "Illegal Arguments",
- List.of(ex.getMessage())));
+ .badRequest()
+ .body(new ApiCallError<>(
+ "Illegal Arguments",
+ List.of(ex.getMessage())));
}
@ExceptionHandler(ValidationException.class)
+ @ResponseStatus(BAD_REQUEST)
public ResponseEntity>
handleValidationException(HttpServletRequest request,
ValidationException ex) {
@@ -70,13 +86,14 @@ public ResponseEntity> handleNotFoundException(
log.error("ValidationException {}\n", request.getRequestURI(), ex);
return ResponseEntity
- .badRequest()
- .body(new ApiCallError<>(
- "Validation exception",
- List.of(ex.getMessage())));
+ .badRequest()
+ .body(new ApiCallError<>(
+ "Validation exception",
+ List.of(ex.getMessage())));
}
@ExceptionHandler(MissingServletRequestParameterException.class)
+ @ResponseStatus(BAD_REQUEST)
public ResponseEntity>
handleMissingServletRequestParameterException(HttpServletRequest request,
MissingServletRequestParameterException ex) {
@@ -84,12 +101,13 @@ public ResponseEntity> handleNotFoundException(
log.error("handleMissingServletRequestParameterException {}\n", request.getRequestURI(), ex);
return ResponseEntity
- .badRequest()
- .body(new ApiCallError<>("Missing request parameter",
- List.of(Objects.requireNonNull(ex.getMessage()))));
+ .badRequest()
+ .body(new ApiCallError<>("Missing request parameter",
+ List.of(Objects.requireNonNull(ex.getMessage()))));
}
@ExceptionHandler(MethodArgumentTypeMismatchException.class)
+ @ResponseStatus(BAD_REQUEST)
public ResponseEntity>>
handleMethodArgumentTypeMismatchException(HttpServletRequest request,
MethodArgumentTypeMismatchException ex) {
@@ -102,13 +120,14 @@ public ResponseEntity> handleNotFoundException(
details.put("errorMessage", ex.getMessage());
return ResponseEntity
- .badRequest()
- .body(new ApiCallError<>(
- "Method argument type mismatch",
- List.of(details)));
+ .badRequest()
+ .body(new ApiCallError<>(
+ "Method argument type mismatch",
+ List.of(details)));
}
@ExceptionHandler(MethodArgumentNotValidException.class)
+ @ResponseStatus(BAD_REQUEST)
public ResponseEntity>>
handleMethodArgumentNotValidException(HttpServletRequest request,
MethodArgumentNotValidException ex) {
@@ -128,49 +147,53 @@ public ResponseEntity> handleNotFoundException(
});
return ResponseEntity
- .badRequest()
- .body(new ApiCallError<>(
- "Method argument validation failed",
- details));
+ .badRequest()
+ .body(new ApiCallError<>(
+ "Method argument validation failed",
+ details));
}
@ExceptionHandler(AccessDeniedException.class)
+ @ResponseStatus(FORBIDDEN)
public ResponseEntity>
handleAccessDeniedException(HttpServletRequest request, AccessDeniedException ex) {
log.error("handleAccessDeniedException {}\n", request.getRequestURI(), ex);
return ResponseEntity
- .status(HttpStatus.FORBIDDEN)
- .body(new ApiCallError<>("Access denied!", List.of(ex.getMessage())));
+ .status(FORBIDDEN)
+ .body(new ApiCallError<>("Access denied!", List.of(ex.getMessage())));
}
@ExceptionHandler(HttpClientErrorException.class)
+ @ResponseStatus(UNAUTHORIZED)
public ResponseEntity>
handleUnauthorizedException(HttpServletRequest request, HttpClientErrorException ex) {
log.error("handleUnauthorizedException {}\n", request.getRequestURI(), ex);
return ResponseEntity
- .status(HttpStatus.UNAUTHORIZED)
- .body(new ApiCallError<>("Unauthorized Access, check your credentials!",
- List.of(ex.getMessage() != null ? ex.getMessage() : "")));
+ .status(UNAUTHORIZED)
+ .body(new ApiCallError<>("Unauthorized Access, check your credentials!",
+ List.of(ex.getMessage() != null ? ex.getMessage() : "")));
}
@ExceptionHandler(Exception.class)
+ @ResponseStatus(INTERNAL_SERVER_ERROR)
public ResponseEntity>
handleInternalServerError(HttpServletRequest request, Exception ex) {
log.error("handleInternalServerError {}\n", request.getRequestURI(), ex);
return ResponseEntity
- .status(HttpStatus.INTERNAL_SERVER_ERROR)
- .body(new ApiCallError<>(
- "Internal server error",
- List.of(ex.getMessage())));
+ .status(INTERNAL_SERVER_ERROR)
+ .body(new ApiCallError<>(
+ "Internal server error",
+ List.of(ex.getMessage())));
}
}
+@JsonRootName("ApiError")
record ApiCallError(
@JsonProperty("message") String message,
@JsonProperty("details") List details) {
diff --git a/src/main/java/org/siriusxi/htec/fa/infra/config/SwaggerConfig.java b/src/main/java/org/siriusxi/htec/fa/infra/config/SwaggerConfig.java
index 3465d3b..5280003 100644
--- a/src/main/java/org/siriusxi/htec/fa/infra/config/SwaggerConfig.java
+++ b/src/main/java/org/siriusxi/htec/fa/infra/config/SwaggerConfig.java
@@ -5,27 +5,31 @@
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import io.swagger.v3.oas.models.security.SecurityScheme;
+import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class SwaggerConfig {
+ @Value("${app.version}")
+ private String appVersion;
+
@Bean
public OpenAPI customOpenAPI() {
return new OpenAPI()
- .components(new Components()
- .addSecuritySchemes("bearer-key",
- new SecurityScheme()
- .type(SecurityScheme.Type.HTTP)
- .scheme("bearer")
- .bearerFormat("JWT")))
- .info(new Info()
- .title("REST API for Flight Advisor Service.")
- .version("2.8")
- .license(new License()
- .name("MIT License")
- .url("https://springdoc.org")));
+ .components(new Components()
+ .addSecuritySchemes("bearer-key",
+ new SecurityScheme()
+ .type(SecurityScheme.Type.HTTP)
+ .scheme("bearer")
+ .bearerFormat("JWT")))
+ .info(new Info()
+ .title("REST API for Flight Advisor Service.")
+ .version(appVersion)
+ .license(new License()
+ .name("MIT License")
+ .url("https://springdoc.org")));
}
}
diff --git a/src/main/java/org/siriusxi/htec/fa/domain/mapper/AirportMapper.java b/src/main/java/org/siriusxi/htec/fa/infra/mapper/AirportMapper.java
similarity index 84%
rename from src/main/java/org/siriusxi/htec/fa/domain/mapper/AirportMapper.java
rename to src/main/java/org/siriusxi/htec/fa/infra/mapper/AirportMapper.java
index 2db3f43..9e9d3ea 100644
--- a/src/main/java/org/siriusxi/htec/fa/domain/mapper/AirportMapper.java
+++ b/src/main/java/org/siriusxi/htec/fa/infra/mapper/AirportMapper.java
@@ -1,10 +1,10 @@
-package org.siriusxi.htec.fa.domain.mapper;
+package org.siriusxi.htec.fa.infra.mapper;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
-import org.siriusxi.htec.fa.domain.dto.response.AirportView;
-import org.siriusxi.htec.fa.domain.dto.upload.airport.AirportDto;
-import org.siriusxi.htec.fa.domain.model.Airport;
+import org.siriusxi.htec.fa.api.model.response.AirportView;
+import org.siriusxi.htec.fa.api.model.upload.airport.AirportDto;
+import org.siriusxi.htec.fa.domain.Airport;
import java.util.List;
diff --git a/src/main/java/org/siriusxi/htec/fa/domain/mapper/CityMapper.java b/src/main/java/org/siriusxi/htec/fa/infra/mapper/CityMapper.java
similarity index 79%
rename from src/main/java/org/siriusxi/htec/fa/domain/mapper/CityMapper.java
rename to src/main/java/org/siriusxi/htec/fa/infra/mapper/CityMapper.java
index eb79dbe..d539082 100644
--- a/src/main/java/org/siriusxi/htec/fa/domain/mapper/CityMapper.java
+++ b/src/main/java/org/siriusxi/htec/fa/infra/mapper/CityMapper.java
@@ -1,11 +1,11 @@
-package org.siriusxi.htec.fa.domain.mapper;
+package org.siriusxi.htec.fa.infra.mapper;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
-import org.siriusxi.htec.fa.domain.dto.request.CreateCityRequest;
-import org.siriusxi.htec.fa.domain.dto.response.CityView;
-import org.siriusxi.htec.fa.domain.model.City;
-import org.siriusxi.htec.fa.domain.model.Country;
+import org.siriusxi.htec.fa.api.model.request.CreateCityRequest;
+import org.siriusxi.htec.fa.api.model.response.CityView;
+import org.siriusxi.htec.fa.domain.City;
+import org.siriusxi.htec.fa.domain.Country;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.Collections;
diff --git a/src/main/java/org/siriusxi/htec/fa/domain/mapper/CommentMapper.java b/src/main/java/org/siriusxi/htec/fa/infra/mapper/CommentMapper.java
similarity index 68%
rename from src/main/java/org/siriusxi/htec/fa/domain/mapper/CommentMapper.java
rename to src/main/java/org/siriusxi/htec/fa/infra/mapper/CommentMapper.java
index cae2fe0..4ea6b11 100644
--- a/src/main/java/org/siriusxi/htec/fa/domain/mapper/CommentMapper.java
+++ b/src/main/java/org/siriusxi/htec/fa/infra/mapper/CommentMapper.java
@@ -1,12 +1,12 @@
-package org.siriusxi.htec.fa.domain.mapper;
+package org.siriusxi.htec.fa.infra.mapper;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
-import org.siriusxi.htec.fa.domain.dto.request.UpSrtCommentRequest;
-import org.siriusxi.htec.fa.domain.dto.response.CommentView;
-import org.siriusxi.htec.fa.domain.model.City;
-import org.siriusxi.htec.fa.domain.model.Comment;
-import org.siriusxi.htec.fa.domain.model.User;
+import org.siriusxi.htec.fa.api.model.request.CommentUpSrtRequest;
+import org.siriusxi.htec.fa.api.model.response.CommentView;
+import org.siriusxi.htec.fa.domain.City;
+import org.siriusxi.htec.fa.domain.Comment;
+import org.siriusxi.htec.fa.domain.User;
import java.time.LocalDateTime;
import java.util.List;
@@ -19,14 +19,14 @@ public interface CommentMapper {
@Mapping(target = "createdAt", ignore = true)
@Mapping(target = "user", source = "user")
@Mapping(target = "city", source = "city")
- Comment toNewModel(UpSrtCommentRequest request, User user, City city);
+ Comment toNewModel(CommentUpSrtRequest request, User user, City city);
@Mapping(target = "createdAt", ignore = true)
@Mapping(target = "updatedAt", expression = "java( LocalDateTime.now() )")
@Mapping(target = "user", source = "user")
@Mapping(target = "city", source = "city")
@Mapping(target = "id", source = "commentId")
- Comment toUpdateModel(UpSrtCommentRequest request, int commentId, User user, City city);
+ Comment toUpdateModel(CommentUpSrtRequest request, int commentId, User user, City city);
@Mapping(target = "id", source = "id")
@Mapping(target = "by", source = "user.fullName")
diff --git a/src/main/java/org/siriusxi/htec/fa/domain/mapper/CountryMapper.java b/src/main/java/org/siriusxi/htec/fa/infra/mapper/CountryMapper.java
similarity index 59%
rename from src/main/java/org/siriusxi/htec/fa/domain/mapper/CountryMapper.java
rename to src/main/java/org/siriusxi/htec/fa/infra/mapper/CountryMapper.java
index fe59331..75329e3 100644
--- a/src/main/java/org/siriusxi/htec/fa/domain/mapper/CountryMapper.java
+++ b/src/main/java/org/siriusxi/htec/fa/infra/mapper/CountryMapper.java
@@ -1,8 +1,8 @@
-package org.siriusxi.htec.fa.domain.mapper;
+package org.siriusxi.htec.fa.infra.mapper;
import org.mapstruct.Mapper;
-import org.siriusxi.htec.fa.domain.dto.response.CountryView;
-import org.siriusxi.htec.fa.domain.model.Country;
+import org.siriusxi.htec.fa.api.model.response.CountryView;
+import org.siriusxi.htec.fa.domain.Country;
import java.util.Set;
diff --git a/src/main/java/org/siriusxi/htec/fa/domain/mapper/RouteMapper.java b/src/main/java/org/siriusxi/htec/fa/infra/mapper/RouteMapper.java
similarity index 75%
rename from src/main/java/org/siriusxi/htec/fa/domain/mapper/RouteMapper.java
rename to src/main/java/org/siriusxi/htec/fa/infra/mapper/RouteMapper.java
index 4a7b064..7e722bf 100644
--- a/src/main/java/org/siriusxi/htec/fa/domain/mapper/RouteMapper.java
+++ b/src/main/java/org/siriusxi/htec/fa/infra/mapper/RouteMapper.java
@@ -1,9 +1,9 @@
-package org.siriusxi.htec.fa.domain.mapper;
+package org.siriusxi.htec.fa.infra.mapper;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
-import org.siriusxi.htec.fa.domain.dto.upload.route.RouteDto;
-import org.siriusxi.htec.fa.domain.model.Route;
+import org.siriusxi.htec.fa.api.model.upload.route.RouteDto;
+import org.siriusxi.htec.fa.domain.Route;
@Mapper(componentModel = "spring")
public interface RouteMapper {
diff --git a/src/main/java/org/siriusxi/htec/fa/domain/mapper/UserMapper.java b/src/main/java/org/siriusxi/htec/fa/infra/mapper/UserMapper.java
similarity index 73%
rename from src/main/java/org/siriusxi/htec/fa/domain/mapper/UserMapper.java
rename to src/main/java/org/siriusxi/htec/fa/infra/mapper/UserMapper.java
index 6d069be..df34ad3 100644
--- a/src/main/java/org/siriusxi/htec/fa/domain/mapper/UserMapper.java
+++ b/src/main/java/org/siriusxi/htec/fa/infra/mapper/UserMapper.java
@@ -1,11 +1,11 @@
-package org.siriusxi.htec.fa.domain.mapper;
+package org.siriusxi.htec.fa.infra.mapper;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
-import org.siriusxi.htec.fa.domain.dto.request.CreateUserRequest;
-import org.siriusxi.htec.fa.domain.dto.response.UserView;
-import org.siriusxi.htec.fa.domain.model.Role;
-import org.siriusxi.htec.fa.domain.model.User;
+import org.siriusxi.htec.fa.api.model.request.CreateUserRequest;
+import org.siriusxi.htec.fa.api.model.response.UserView;
+import org.siriusxi.htec.fa.domain.Role;
+import org.siriusxi.htec.fa.domain.User;
import org.siriusxi.htec.fa.infra.Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.password.PasswordEncoder;
@@ -31,8 +31,8 @@ public abstract class UserMapper {
protected String[] map(Set authorities) {
return authorities
- .stream()
- .map(Role::getAuthority)
- .toArray(String[]::new);
+ .stream()
+ .map(Role::getAuthority)
+ .toArray(String[]::new);
}
}
diff --git a/src/main/java/org/siriusxi/htec/fa/infra/security/JwtTokenFilter.java b/src/main/java/org/siriusxi/htec/fa/infra/security/JwtTokenFilter.java
index 9735f2b..59d432c 100644
--- a/src/main/java/org/siriusxi/htec/fa/infra/security/JwtTokenFilter.java
+++ b/src/main/java/org/siriusxi/htec/fa/infra/security/JwtTokenFilter.java
@@ -1,5 +1,9 @@
package org.siriusxi.htec.fa.infra.security;
+import jakarta.servlet.FilterChain;
+import jakarta.servlet.ServletException;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.log4j.Log4j2;
import org.siriusxi.htec.fa.infra.security.jwt.JwtTokenHelper;
import org.siriusxi.htec.fa.repository.UserRepository;
@@ -10,10 +14,6 @@
import org.springframework.stereotype.Component;
import org.springframework.web.filter.OncePerRequestFilter;
-import javax.servlet.FilterChain;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Optional;
@@ -37,7 +37,7 @@ protected void doFilterInternal(HttpServletRequest request,
// Get authorization header and validate
var authToken = getJwtTokenIfValid(request
- .getHeader(HttpHeaders.AUTHORIZATION));
+ .getHeader(HttpHeaders.AUTHORIZATION));
String token;
@@ -48,8 +48,8 @@ protected void doFilterInternal(HttpServletRequest request,
// Get user identity and set it on the spring security context
var userDetails = userRepository
- .findByUsernameIgnoreCase(JwtTokenHelper.getUsername(token))
- .orElse(null);
+ .findByUsernameIgnoreCase(JwtTokenHelper.getUsername(token))
+ .orElse(null);
var authentication = new UsernamePasswordAuthenticationToken(
userDetails, null,
diff --git a/src/main/java/org/siriusxi/htec/fa/infra/security/SecurityConfig.java b/src/main/java/org/siriusxi/htec/fa/infra/security/SecurityConfig.java
index ab971e1..deb0532 100644
--- a/src/main/java/org/siriusxi/htec/fa/infra/security/SecurityConfig.java
+++ b/src/main/java/org/siriusxi/htec/fa/infra/security/SecurityConfig.java
@@ -19,8 +19,8 @@
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
+import static jakarta.servlet.http.HttpServletResponse.SC_UNAUTHORIZED;
import static java.lang.String.format;
-import static javax.servlet.http.HttpServletResponse.SC_UNAUTHORIZED;
import static org.springframework.security.core.context.SecurityContextHolder.MODE_INHERITABLETHREADLOCAL;
import static org.springframework.security.core.context.SecurityContextHolder.setStrategyName;
@@ -35,18 +35,15 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
private final UserRepository userRepository;
private final JwtTokenFilter jwtTokenFilter;
- private final String appVersion;
private final String allowedOrigins;
public SecurityConfig(UserRepository userRepository,
JwtTokenFilter jwtTokenFilter,
- @Value("${app.version:v1}") String appVersion,
@Value("${app.allowedOrigins:*}") String allowedOrigins) {
super();
this.userRepository = userRepository;
this.jwtTokenFilter = jwtTokenFilter;
- this.appVersion = "/".concat(appVersion);
this.allowedOrigins = allowedOrigins;
// Inherit security context in async function calls
@@ -77,9 +74,8 @@ protected void configure(HttpSecurity http) throws Exception {
// List of Swagger URLs
var swaggerAuthList = new String[]{
- appVersion.concat("/api-docs/**"),
- "/webjars/**", "/swagger-ui/**",
- appVersion.concat("/doc/**")};
+ "/api-docs/**", "/webjars/**",
+ "/swagger-ui/**", "/doc/**"};
http
// Enable CORS
diff --git a/src/main/java/org/siriusxi/htec/fa/infra/security/jwt/JwtTokenHelper.java b/src/main/java/org/siriusxi/htec/fa/infra/security/jwt/JwtTokenHelper.java
index eef5ce3..f2c2541 100644
--- a/src/main/java/org/siriusxi/htec/fa/infra/security/jwt/JwtTokenHelper.java
+++ b/src/main/java/org/siriusxi/htec/fa/infra/security/jwt/JwtTokenHelper.java
@@ -1,6 +1,11 @@
package org.siriusxi.htec.fa.infra.security.jwt;
-import io.jsonwebtoken.*;
+import io.jsonwebtoken.Claims;
+import io.jsonwebtoken.ExpiredJwtException;
+import io.jsonwebtoken.Jwts;
+import io.jsonwebtoken.MalformedJwtException;
+import io.jsonwebtoken.SignatureAlgorithm;
+import io.jsonwebtoken.UnsupportedJwtException;
import io.jsonwebtoken.security.Keys;
import lombok.extern.log4j.Log4j2;
@@ -33,16 +38,16 @@ private JwtTokenHelper() {
public static String generateAccessToken(int id, String username) {
var now = System.currentTimeMillis();
return Jwts
- .builder()
- .setId(String.valueOf(id))
- .setSubject(format("%d,%s", id, username))
- .setIssuer(JwtConfig.ISSUER)
- .setIssuedAt(new Date(now))
- .setExpiration(Date.from(ZonedDateTime.now()
- .plusDays(JwtConfig.TOKEN_EXPIRY_DURATION)
- .toInstant()))
- .signWith(JwtConfig.key(), JwtConfig.SIGNATURE_ALGORITHM)
- .compact();
+ .builder()
+ .setId(String.valueOf(id))
+ .setSubject(format("%d,%s", id, username))
+ .setIssuer(JwtConfig.ISSUER)
+ .setIssuedAt(new Date(now))
+ .setExpiration(Date.from(ZonedDateTime.now()
+ .plusDays(JwtConfig.TOKEN_EXPIRY_DURATION)
+ .toInstant()))
+ .signWith(JwtConfig.key(), JwtConfig.SIGNATURE_ALGORITHM)
+ .compact();
}
/**
@@ -53,8 +58,8 @@ public static String generateAccessToken(int id, String username) {
*/
public static int getUserId(String token) {
return Integer.parseInt(getClaims(token)
- .getSubject()
- .split(",")[0]);
+ .getSubject()
+ .split(",")[0]);
}
/**
@@ -65,8 +70,8 @@ public static int getUserId(String token) {
*/
public static String getUsername(String token) {
return getClaims(token)
- .getSubject()
- .split(",")[1];
+ .getSubject()
+ .split(",")[1];
}
/**
@@ -77,7 +82,7 @@ public static String getUsername(String token) {
*/
public static Date tokenExpiredAt(String token) {
return getClaims(token)
- .getExpiration();
+ .getExpiration();
}
/**
@@ -88,11 +93,11 @@ public static Date tokenExpiredAt(String token) {
*/
private static Claims getClaims(String token) {
return Jwts
- .parserBuilder()
- .setSigningKey(JwtConfig.key())
- .build()
- .parseClaimsJws(token.replace(JwtConfig.TOKEN_PREFIX, ""))
- .getBody();
+ .parserBuilder()
+ .setSigningKey(JwtConfig.key())
+ .build()
+ .parseClaimsJws(token.replace(JwtConfig.TOKEN_PREFIX, ""))
+ .getBody();
}
/**
diff --git a/src/main/java/org/siriusxi/htec/fa/infra/security/password/PasswordGenerator.java b/src/main/java/org/siriusxi/htec/fa/infra/security/password/PasswordGenerator.java
index 4031fa9..cf26c3a 100644
--- a/src/main/java/org/siriusxi/htec/fa/infra/security/password/PasswordGenerator.java
+++ b/src/main/java/org/siriusxi/htec/fa/infra/security/password/PasswordGenerator.java
@@ -51,6 +51,6 @@ public static String sha1Random() {
public static String bcrypt(String password) {
return new BCryptPasswordEncoder()
- .encode(password);
+ .encode(password);
}
}
diff --git a/src/main/java/org/siriusxi/htec/fa/repository/AirportRepository.java b/src/main/java/org/siriusxi/htec/fa/repository/AirportRepository.java
index 8a46caa..df0912c 100644
--- a/src/main/java/org/siriusxi/htec/fa/repository/AirportRepository.java
+++ b/src/main/java/org/siriusxi/htec/fa/repository/AirportRepository.java
@@ -1,7 +1,7 @@
package org.siriusxi.htec.fa.repository;
-import org.siriusxi.htec.fa.domain.model.Airport;
-import org.siriusxi.htec.fa.domain.model.City;
+import org.siriusxi.htec.fa.domain.Airport;
+import org.siriusxi.htec.fa.domain.City;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.jpa.repository.Query;
diff --git a/src/main/java/org/siriusxi/htec/fa/repository/CityRepository.java b/src/main/java/org/siriusxi/htec/fa/repository/CityRepository.java
index 00921d0..6a9691b 100644
--- a/src/main/java/org/siriusxi/htec/fa/repository/CityRepository.java
+++ b/src/main/java/org/siriusxi/htec/fa/repository/CityRepository.java
@@ -1,7 +1,7 @@
package org.siriusxi.htec.fa.repository;
-import org.siriusxi.htec.fa.domain.model.City;
-import org.siriusxi.htec.fa.domain.model.Country;
+import org.siriusxi.htec.fa.domain.City;
+import org.siriusxi.htec.fa.domain.Country;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.repository.CrudRepository;
@@ -27,7 +27,7 @@ public interface CityRepository extends CrudRepository {
*/
default City findOrSaveBy(Country country, String name, String description) {
return findByCountryAndNameIgnoreCaseIsLike(country, name.trim())
- .orElseGet(() -> save(new City(name, description, country)));
+ .orElseGet(() -> save(new City(name, description, country)));
}
@Cacheable
diff --git a/src/main/java/org/siriusxi/htec/fa/repository/CommentRepository.java b/src/main/java/org/siriusxi/htec/fa/repository/CommentRepository.java
index 0622111..1dc0975 100644
--- a/src/main/java/org/siriusxi/htec/fa/repository/CommentRepository.java
+++ b/src/main/java/org/siriusxi/htec/fa/repository/CommentRepository.java
@@ -1,8 +1,8 @@
package org.siriusxi.htec.fa.repository;
-import org.siriusxi.htec.fa.domain.model.City;
-import org.siriusxi.htec.fa.domain.model.Comment;
-import org.siriusxi.htec.fa.domain.model.User;
+import org.siriusxi.htec.fa.domain.City;
+import org.siriusxi.htec.fa.domain.Comment;
+import org.siriusxi.htec.fa.domain.User;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
diff --git a/src/main/java/org/siriusxi/htec/fa/repository/CountryRepository.java b/src/main/java/org/siriusxi/htec/fa/repository/CountryRepository.java
index f6cf9d3..198c309 100644
--- a/src/main/java/org/siriusxi/htec/fa/repository/CountryRepository.java
+++ b/src/main/java/org/siriusxi/htec/fa/repository/CountryRepository.java
@@ -1,6 +1,6 @@
package org.siriusxi.htec.fa.repository;
-import org.siriusxi.htec.fa.domain.model.Country;
+import org.siriusxi.htec.fa.domain.Country;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.repository.CrudRepository;
@@ -27,6 +27,6 @@ public interface CountryRepository extends CrudRepository {
@Cacheable
default Country findOrSaveBy(String name) {
return findByNameIgnoreCaseIsLike(name.trim())
- .orElseGet(() -> save(new Country(name)));
+ .orElseGet(() -> save(new Country(name)));
}
}
diff --git a/src/main/java/org/siriusxi/htec/fa/repository/RouteRepository.java b/src/main/java/org/siriusxi/htec/fa/repository/RouteRepository.java
index 0053b00..0090825 100644
--- a/src/main/java/org/siriusxi/htec/fa/repository/RouteRepository.java
+++ b/src/main/java/org/siriusxi/htec/fa/repository/RouteRepository.java
@@ -1,8 +1,8 @@
package org.siriusxi.htec.fa.repository;
-import org.siriusxi.htec.fa.domain.model.Route;
-import org.siriusxi.htec.fa.domain.model.RoutePK;
-import org.siriusxi.htec.fa.domain.model.vo.RouteView;
+import org.siriusxi.htec.fa.domain.Route;
+import org.siriusxi.htec.fa.domain.RoutePK;
+import org.siriusxi.htec.fa.domain.vo.RouteView;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.data.jpa.repository.Query;
@@ -18,7 +18,7 @@
public interface RouteRepository extends CrudRepository {
@Query(value = """
- SELECT new org.siriusxi.htec.fa.domain.model.vo.RouteView
+ SELECT new org.siriusxi.htec.fa.domain.vo.RouteView
(routePK.source, routePK.destination, price)
FROM Route
ORDER BY routePK.source ASC
diff --git a/src/main/java/org/siriusxi/htec/fa/repository/UserRepository.java b/src/main/java/org/siriusxi/htec/fa/repository/UserRepository.java
index 86e3918..4f607c0 100644
--- a/src/main/java/org/siriusxi/htec/fa/repository/UserRepository.java
+++ b/src/main/java/org/siriusxi/htec/fa/repository/UserRepository.java
@@ -1,6 +1,6 @@
package org.siriusxi.htec.fa.repository;
-import org.siriusxi.htec.fa.domain.model.User;
+import org.siriusxi.htec.fa.domain.User;
import org.siriusxi.htec.fa.infra.exception.NotFoundException;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
diff --git a/src/main/java/org/siriusxi/htec/fa/service/CityMgmtService.java b/src/main/java/org/siriusxi/htec/fa/service/CityMgmtService.java
index fd8a54d..5eacfe8 100644
--- a/src/main/java/org/siriusxi/htec/fa/service/CityMgmtService.java
+++ b/src/main/java/org/siriusxi/htec/fa/service/CityMgmtService.java
@@ -1,22 +1,22 @@
package org.siriusxi.htec.fa.service;
import lombok.extern.log4j.Log4j2;
-import org.siriusxi.htec.fa.domain.dto.request.CreateCityRequest;
-import org.siriusxi.htec.fa.domain.dto.request.SearchAirportRequest;
-import org.siriusxi.htec.fa.domain.dto.request.SearchCityRequest;
-import org.siriusxi.htec.fa.domain.dto.request.UpSrtCommentRequest;
-import org.siriusxi.htec.fa.domain.dto.response.AirportView;
-import org.siriusxi.htec.fa.domain.dto.response.CityView;
-import org.siriusxi.htec.fa.domain.dto.response.CommentView;
-import org.siriusxi.htec.fa.domain.mapper.AirportMapper;
-import org.siriusxi.htec.fa.domain.mapper.CityMapper;
-import org.siriusxi.htec.fa.domain.mapper.CommentMapper;
-import org.siriusxi.htec.fa.domain.model.City;
-import org.siriusxi.htec.fa.domain.model.Comment;
-import org.siriusxi.htec.fa.domain.model.Country;
-import org.siriusxi.htec.fa.domain.model.User;
+import org.siriusxi.htec.fa.api.model.request.CommentUpSrtRequest;
+import org.siriusxi.htec.fa.api.model.request.CreateCityRequest;
+import org.siriusxi.htec.fa.api.model.request.SearchAirportRequest;
+import org.siriusxi.htec.fa.api.model.request.SearchCityRequest;
+import org.siriusxi.htec.fa.api.model.response.AirportView;
+import org.siriusxi.htec.fa.api.model.response.CityView;
+import org.siriusxi.htec.fa.api.model.response.CommentView;
+import org.siriusxi.htec.fa.domain.City;
+import org.siriusxi.htec.fa.domain.Comment;
+import org.siriusxi.htec.fa.domain.Country;
+import org.siriusxi.htec.fa.domain.User;
import org.siriusxi.htec.fa.infra.exception.NotAllowedException;
import org.siriusxi.htec.fa.infra.exception.NotFoundException;
+import org.siriusxi.htec.fa.infra.mapper.AirportMapper;
+import org.siriusxi.htec.fa.infra.mapper.CityMapper;
+import org.siriusxi.htec.fa.infra.mapper.CommentMapper;
import org.siriusxi.htec.fa.repository.AirportRepository;
import org.siriusxi.htec.fa.repository.CityRepository;
import org.siriusxi.htec.fa.repository.CommentRepository;
@@ -28,6 +28,8 @@
import java.util.ArrayList;
import java.util.List;
+import static java.util.Objects.isNull;
+
@Log4j2
@Service
public class CityMgmtService {
@@ -83,14 +85,15 @@ public CityView addCity(CreateCityRequest cityRequest) {
@Transactional(readOnly = true)
public List searchCities(SearchCityRequest request, int cLimit) {
-
List cities = new ArrayList<>();
- String searchWord = LIKE.concat(request.name()).concat(LIKE);
- if (cLimit != 0)
+ String searchWord = isNull(request.name()) ? "" : request.name();
+ searchWord = LIKE.concat(searchWord).concat(LIKE);
+
+ if (cLimit > 0)
for (City city : cityRepository.findByNameIgnoreCaseIsLike(searchWord)) {
city.setComments(commentRepository
- .findByCity(city, PageRequest.of(0, cLimit)));
+ .findByCity(city, PageRequest.of(0, cLimit)));
cities.add(city);
}
else
@@ -102,31 +105,33 @@ public List searchCities(SearchCityRequest request, int cLimit) {
// Airport management
public List searchAirports(SearchAirportRequest request, int cityId) {
- String searchWord = LIKE.concat(request.name()).concat(LIKE);
+
+ String searchWord = isNull(request.name()) ? "" : request.name();
+ searchWord = LIKE.concat(searchWord).concat(LIKE);
+
return airportMapper
- .toView(airportRepository
- .findAirportsByCityAndNameIgnoreCaseIsLike(
- new City(cityId),
- searchWord));
+ .toView(airportRepository
+ .findAirportsByCityAndNameIgnoreCaseIsLike(
+ new City(cityId), searchWord));
}
// City Comments management
@Transactional
public CommentView addComment(User user, int cityId,
- UpSrtCommentRequest request) {
+ CommentUpSrtRequest request) {
// Chick if the city is already exists
City city = getCityIfExists(cityId);
return commentMapper
- .toView(commentRepository
- .save(commentMapper
- .toNewModel(request, user, city)));
+ .toView(commentRepository
+ .save(commentMapper
+ .toNewModel(request, user, city)));
}
@Transactional
public void updateComment(User user, int cityId, int commentId,
- UpSrtCommentRequest request) {
+ CommentUpSrtRequest request) {
// Chick if the city is already exists
City city = getCityIfExists(cityId);
@@ -143,9 +148,9 @@ public void updateComment(User user, int cityId, int commentId,
.orElseThrow(() ->
new NotAllowedException(Comment.class, found.getId(), "Update")))
.ifPresent(comment -> commentMapper
- .toView(commentRepository
- .save(commentMapper
- .toUpdateModel(request, comment.getId(), user, city))));
+ .toView(commentRepository
+ .save(commentMapper
+ .toUpdateModel(request, comment.getId(), user, city))));
}
public void deleteComment(User user, int cityId, int commentId) {
@@ -159,14 +164,14 @@ public void deleteComment(User user, int cityId, int commentId) {
.flatMap(comment -> commentRepository.findByIdAndCity(comment.getId(), city))
// If exist check if user is allowed to delete it
.ifPresent(found -> commentRepository.delete(commentRepository
- .findByIdAndCityAndUser(found.getId(), city, user)
- // If user is not allowed throw exception
- .orElseThrow(() -> new NotAllowedException(Comment.class, found.getId(), "Delete"))));
+ .findByIdAndCityAndUser(found.getId(), city, user)
+ // If user is not allowed throw exception
+ .orElseThrow(() -> new NotAllowedException(Comment.class, found.getId(), "Delete"))));
}
private City getCityIfExists(int cityId) {
return cityRepository
- .findById(cityId)
- .orElseThrow(() -> new NotFoundException(City.class, cityId));
+ .findById(cityId)
+ .orElseThrow(() -> new NotFoundException(City.class, cityId));
}
}
diff --git a/src/main/java/org/siriusxi/htec/fa/service/TravelService.java b/src/main/java/org/siriusxi/htec/fa/service/TravelService.java
index 7748a91..8ae102f 100644
--- a/src/main/java/org/siriusxi/htec/fa/service/TravelService.java
+++ b/src/main/java/org/siriusxi/htec/fa/service/TravelService.java
@@ -6,14 +6,14 @@
import es.usc.citius.hipster.graph.GraphSearchProblem;
import es.usc.citius.hipster.model.impl.WeightedNode;
import lombok.extern.log4j.Log4j2;
-import org.siriusxi.htec.fa.domain.dto.response.AirportView;
-import org.siriusxi.htec.fa.domain.dto.response.TripView;
-import org.siriusxi.htec.fa.domain.mapper.AirportMapper;
-import org.siriusxi.htec.fa.domain.model.Airport;
-import org.siriusxi.htec.fa.domain.model.Route;
-import org.siriusxi.htec.fa.domain.model.RoutePK;
+import org.siriusxi.htec.fa.api.model.response.AirportView;
+import org.siriusxi.htec.fa.api.model.response.TripView;
+import org.siriusxi.htec.fa.domain.Airport;
+import org.siriusxi.htec.fa.domain.Route;
+import org.siriusxi.htec.fa.domain.RoutePK;
import org.siriusxi.htec.fa.infra.algorithm.distance.DistanceAlgorithm;
import org.siriusxi.htec.fa.infra.algorithm.distance.Point;
+import org.siriusxi.htec.fa.infra.mapper.AirportMapper;
import org.siriusxi.htec.fa.repository.AirportRepository;
import org.siriusxi.htec.fa.repository.RouteRepository;
import org.springframework.cache.annotation.CacheConfig;
@@ -157,13 +157,13 @@ private List buildFinalTripViews(FinalTrip trip) {
private double calculateDistance(Route route) {
return orthodromicAlgorithm
- .calculate(
- new Point(
- route.getSourceAirport().getLatitude().doubleValue(),
- route.getSourceAirport().getLongitude().doubleValue()),
- new Point(
- route.getDestinationAirport().getLatitude().doubleValue(),
- route.getDestinationAirport().getLongitude().doubleValue()));
+ .calculate(
+ new Point(
+ route.getSourceAirport().getLatitude().doubleValue(),
+ route.getSourceAirport().getLongitude().doubleValue()),
+ new Point(
+ route.getDestinationAirport().getLatitude().doubleValue(),
+ route.getDestinationAirport().getLongitude().doubleValue()));
}
private TripView newTripView(Airport src, Airport dest,
@@ -192,9 +192,9 @@ private FinalTrip findShortestPath(String from, String to) {
// Create the search problem. For graph problems, just use
// the GraphSearchProblem util class to generate the problem with ease.
var problem = GraphSearchProblem
- .startingFrom(from).in(graph)
- .takeCostsFromEdges()
- .build();
+ .startingFrom(from).in(graph)
+ .takeCostsFromEdges()
+ .build();
// Search the shortest path from source to destination
final var result = Hipster.createDijkstra(problem).search(to);
@@ -217,8 +217,8 @@ private GraphBuilder buildGraph(GraphBuilder gra
public List findAirportsForCityOrCountry(String name) {
return airportMapper
- .toView(airportRepository
- .findAirportsByCityOrCountryName(name.toLowerCase()));
+ .toView(airportRepository
+ .findAirportsByCityOrCountryName(name.toLowerCase()));
}
private record FinalTrip(String start,
diff --git a/src/main/java/org/siriusxi/htec/fa/service/UserService.java b/src/main/java/org/siriusxi/htec/fa/service/UserService.java
index 8aad725..2b370a1 100644
--- a/src/main/java/org/siriusxi/htec/fa/service/UserService.java
+++ b/src/main/java/org/siriusxi/htec/fa/service/UserService.java
@@ -1,10 +1,11 @@
package org.siriusxi.htec.fa.service;
+import jakarta.validation.ValidationException;
import lombok.extern.log4j.Log4j2;
-import org.siriusxi.htec.fa.domain.dto.request.CreateUserRequest;
-import org.siriusxi.htec.fa.domain.dto.response.UserView;
-import org.siriusxi.htec.fa.domain.mapper.UserMapper;
-import org.siriusxi.htec.fa.domain.model.User;
+import org.siriusxi.htec.fa.api.model.request.CreateUserRequest;
+import org.siriusxi.htec.fa.api.model.response.UserView;
+import org.siriusxi.htec.fa.domain.User;
+import org.siriusxi.htec.fa.infra.mapper.UserMapper;
import org.siriusxi.htec.fa.repository.UserRepository;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
@@ -12,10 +13,8 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
-import javax.validation.ValidationException;
-
import static java.lang.String.format;
-import static org.siriusxi.htec.fa.domain.model.Role.CLIENT;
+import static org.siriusxi.htec.fa.domain.Role.CLIENT;
@Log4j2
@Service
@@ -57,9 +56,9 @@ public UserView create(CreateUserRequest request) {
@Override
public UserDetails loadUserByUsername(String username) {
return repository
- .findByUsernameIgnoreCase(username)
- .orElseThrow(
- () -> new UsernameNotFoundException(
- format("User with username - %s, not found", username)));
+ .findByUsernameIgnoreCase(username)
+ .orElseThrow(
+ () -> new UsernameNotFoundException(
+ format("User with username - %s, not found", username)));
}
}
diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml
index 7599d0a..7732bd8 100644
--- a/src/main/resources/application.yaml
+++ b/src/main/resources/application.yaml
@@ -1,7 +1,9 @@
# Development profile
## Custom application properties
app:
- version: 'v1'
+ version: @project.version@
+ api:
+ version: 'v1'
# Spring properties
spring:
@@ -10,7 +12,7 @@ spring:
servlet:
multipart:
- enabled: false
+ enabled: true
max-file-size: 10MB
# Database configurations
datasource:
@@ -55,7 +57,7 @@ server:
include-message: always
include-binding-errors: always
servlet:
- context-path: /flight/service/api
+ context-path: /api/${app.api.version}/flight/service
# Application health and information management
management:
@@ -86,7 +88,7 @@ logging.level:
springdoc:
# swagger-ui custom path
swagger-ui:
- path: /${app.version}/doc/index.html
+ path: /doc/index.html
operationsSorter: alpha
tagsSorter: alpha
displayRequestDuration: true
@@ -94,6 +96,6 @@ springdoc:
theme: arta
# /api-docs endpoint custom path
api-docs:
- path: /${app.version}/api-docs
+ path: /api-docs
# to display the actuator endpoints.
show-actuator: false
diff --git a/src/test/java/org/siriusxi/htec/fa/CsvToBeanTests.java b/src/test/java/org/siriusxi/htec/fa/CsvToBeanTests.java
index 0fafbf9..da26a1e 100644
--- a/src/test/java/org/siriusxi/htec/fa/CsvToBeanTests.java
+++ b/src/test/java/org/siriusxi/htec/fa/CsvToBeanTests.java
@@ -2,60 +2,63 @@
import com.opencsv.bean.CsvToBean;
import com.opencsv.bean.CsvToBeanBuilder;
-import lombok.SneakyThrows;
import lombok.extern.log4j.Log4j2;
import org.assertj.core.api.Assertions;
-import org.siriusxi.htec.fa.domain.dto.upload.airport.AirportDto;
-import org.siriusxi.htec.fa.domain.dto.upload.airport.verifer.AirportBeanVerifier;
-import org.siriusxi.htec.fa.domain.dto.upload.route.RouteDto;
-import org.siriusxi.htec.fa.domain.dto.upload.route.verifer.RouteBeanVerifier;
+import org.siriusxi.htec.fa.api.model.upload.airport.AirportDto;
+import org.siriusxi.htec.fa.api.model.upload.airport.verifer.AirportBeanVerifier;
+import org.siriusxi.htec.fa.api.model.upload.route.RouteDto;
+import org.siriusxi.htec.fa.api.model.upload.route.verifer.RouteBeanVerifier;
+import java.io.FileNotFoundException;
import java.io.FileReader;
+import java.io.IOException;
import java.io.Reader;
import java.util.List;
@Log4j2
class CsvToBeanTests {
- @SneakyThrows
//@Test
void parseRoutesCSVFileToBeans() {
try (Reader fileReader = new FileReader("./data/routes.txt")) {
CsvToBean csvToRouteBeans = new CsvToBeanBuilder(fileReader)
- .withType(RouteDto.class)
- .withVerifier(new RouteBeanVerifier())
- .withIgnoreLeadingWhiteSpace(true)
- .build();
+ .withType(RouteDto.class)
+ .withVerifier(new RouteBeanVerifier())
+ .withIgnoreLeadingWhiteSpace(true)
+ .build();
// convert `CsvToBean` object to list of airports
List routes = csvToRouteBeans.parse();
System.out.println(routes.size());
- Assertions.assertThat(routes.size()).isEqualTo(66754);
+ Assertions.assertThat(routes).hasSize(66754);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
}
}
- @SneakyThrows
- // @Test
- void parseAirportsCSVFileToBeans() {
+ // @Test
+ void parseAirportsCSVFileToBeans() throws FileNotFoundException {
try (Reader fileReader = new FileReader("./data/airports.txt")) {
CsvToBean csvToAirportBeans = new CsvToBeanBuilder(fileReader)
- .withType(AirportDto.class)
- .withVerifier(new AirportBeanVerifier())
- .withIgnoreLeadingWhiteSpace(true)
- .build();
+ .withType(AirportDto.class)
+ .withVerifier(new AirportBeanVerifier())
+ .withIgnoreLeadingWhiteSpace(true)
+ .build();
// convert `CsvToBean` object to list of airports
List airports = csvToAirportBeans.parse();
System.out.println(airports.size());
- Assertions.assertThat(airports.size()).isEqualTo(7140);
+ Assertions.assertThat(airports).hasSize(7140);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
}
}
}
diff --git a/src/test/java/org/siriusxi/htec/fa/FlightAdvisorApplicationTests.java b/src/test/java/org/siriusxi/htec/fa/FlightAdvisorApplicationTests.java
index 9c70523..c8df0b6 100644
--- a/src/test/java/org/siriusxi/htec/fa/FlightAdvisorApplicationTests.java
+++ b/src/test/java/org/siriusxi/htec/fa/FlightAdvisorApplicationTests.java
@@ -1,13 +1,21 @@
package org.siriusxi.htec.fa;
import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.ApplicationContext;
+
+import static org.assertj.core.api.Assertions.assertThat;
@SpringBootTest
class FlightAdvisorApplicationTests {
-
- @Test
- void contextLoads() {
- }
-
+
+ @Autowired
+ private ApplicationContext context;
+
+ @Test
+ void contextLoads() {
+ assertThat(context).isNotNull();
+ }
+
}