├── README.md ├── .mvn └── wrapper │ ├── maven-wrapper.jar │ └── maven-wrapper.properties ├── .gitignore ├── src ├── main │ ├── java │ │ └── com │ │ │ └── tahademiryol │ │ │ └── rentacar │ │ │ ├── business │ │ │ ├── abstracts │ │ │ │ ├── PosService.java │ │ │ │ ├── RentalService.java │ │ │ │ ├── InvoiceService.java │ │ │ │ ├── MaintenanceService.java │ │ │ │ ├── PaymentService.java │ │ │ │ ├── ModelService.java │ │ │ │ ├── BrandService.java │ │ │ │ └── CarService.java │ │ │ ├── dto │ │ │ │ ├── requests │ │ │ │ │ ├── update │ │ │ │ │ │ ├── UpdateBrandRequest.java │ │ │ │ │ │ ├── UpdateModelRequest.java │ │ │ │ │ │ ├── UpdatePaymentRequest.java │ │ │ │ │ │ ├── UpdateRentalRequest.java │ │ │ │ │ │ ├── UpdateCarRequest.java │ │ │ │ │ │ ├── UpdateMaintenanceRequest.java │ │ │ │ │ │ └── UpdateInvoiceRequest.java │ │ │ │ │ ├── create │ │ │ │ │ │ ├── CreateBrandRequest.java │ │ │ │ │ │ ├── CreateModelRequest.java │ │ │ │ │ │ ├── CreateMaintenanceRequest.java │ │ │ │ │ │ ├── CreatePaymentRequest.java │ │ │ │ │ │ ├── CreateRentalRequest.java │ │ │ │ │ │ ├── CreateInvoiceRequest.java │ │ │ │ │ │ └── CreateCarRequest.java │ │ │ │ │ └── PaymentRequest.java │ │ │ │ └── responses │ │ │ │ │ ├── create │ │ │ │ │ ├── CreateBrandResponse.java │ │ │ │ │ ├── CreateModelResponse.java │ │ │ │ │ ├── CreateCarResponse.java │ │ │ │ │ ├── CreateRentalResponse.java │ │ │ │ │ ├── CreatePaymentResponse.java │ │ │ │ │ ├── CreateMaintenanceResponse.java │ │ │ │ │ └── CreateInvoiceResponse.java │ │ │ │ │ ├── update │ │ │ │ │ ├── UpdateBrandResponse.java │ │ │ │ │ ├── UpdateModelResponse.java │ │ │ │ │ ├── UpdateCarResponse.java │ │ │ │ │ ├── UpdateRentalResponse.java │ │ │ │ │ ├── UpdatePaymentResponse.java │ │ │ │ │ ├── UpdateMaintenanceResponse.java │ │ │ │ │ └── UpdateInvoiceResponse.java │ │ │ │ │ └── get │ │ │ │ │ ├── Brand │ │ │ │ │ ├── GetBrandResponse.java │ │ │ │ │ └── GetAllBrandsResponse.java │ │ │ │ │ ├── Model │ │ │ │ │ ├── GetModelResponse.java │ │ │ │ │ └── GetAllModelsResponse.java │ │ │ │ │ ├── Payment │ │ │ │ │ ├── GetPaymentResponse.java │ │ │ │ │ └── GetAllPaymentsResponse.java │ │ │ │ │ ├── Rental │ │ │ │ │ ├── GetAllRentalsResponse.java │ │ │ │ │ └── GetRentalResponse.java │ │ │ │ │ ├── Maintenance │ │ │ │ │ ├── GetMaintenanceResponse.java │ │ │ │ │ └── GetAllMaintenanceResponse.java │ │ │ │ │ ├── Car │ │ │ │ │ ├── GetCarResponse.java │ │ │ │ │ └── GetAllCarsResponse.java │ │ │ │ │ └── Invoice │ │ │ │ │ ├── GetInvoiceResponse.java │ │ │ │ │ └── GetAllInvoicesResponse.java │ │ │ ├── rules │ │ │ │ ├── CarBusinessRules.java │ │ │ │ ├── InvoiceBusinessRules.java │ │ │ │ ├── BrandBusinessRules.java │ │ │ │ ├── ModelBusinessRules.java │ │ │ │ ├── RentalBusinessRules.java │ │ │ │ ├── MaintenanceBusinessRules.java │ │ │ │ └── PaymentBusinessRules.java │ │ │ └── concretes │ │ │ │ ├── InvoiceManager.java │ │ │ │ ├── ModelManager.java │ │ │ │ ├── PaymentManager.java │ │ │ │ ├── BrandManager.java │ │ │ │ ├── CarManager.java │ │ │ │ ├── MaintenanceManager.java │ │ │ │ └── RentalManager.java │ │ │ ├── entities │ │ │ ├── enums │ │ │ │ └── State.java │ │ │ └── concretes │ │ │ │ ├── Payment.java │ │ │ │ ├── Brand.java │ │ │ │ ├── Model.java │ │ │ │ ├── Rental.java │ │ │ │ ├── Maintenance.java │ │ │ │ ├── Invoice.java │ │ │ │ └── Car.java │ │ │ ├── core │ │ │ ├── exceptions │ │ │ │ └── BusinessException.java │ │ │ ├── utils │ │ │ │ └── results │ │ │ │ │ └── ExceptionResult.java │ │ │ └── configuration │ │ │ │ └── exceptions │ │ │ │ └── RestExceptionHandler.java │ │ │ ├── common │ │ │ ├── constants │ │ │ │ ├── Regex.java │ │ │ │ ├── ExceptionTypes.java │ │ │ │ └── Messages.java │ │ │ ├── dto │ │ │ │ └── CreateRentalPaymentRequest.java │ │ │ └── utils │ │ │ │ └── annotations │ │ │ │ ├── NotFutureYearValidator.java │ │ │ │ └── NotFutureYear.java │ │ │ ├── repository │ │ │ └── abstracts │ │ │ │ ├── RentalRepository.java │ │ │ │ ├── InvoiceRepository.java │ │ │ │ ├── ModelRepository.java │ │ │ │ ├── BrandRepository.java │ │ │ │ ├── CarRepository.java │ │ │ │ ├── MaintenanceRepository.java │ │ │ │ └── PaymentRepository.java │ │ │ ├── configuration │ │ │ └── mapper │ │ │ │ └── ModelMapperConfig.java │ │ │ ├── adapters │ │ │ └── FakePosServiceAdapter.java │ │ │ ├── RentACarApplication.java │ │ │ └── api │ │ │ └── controllers │ │ │ ├── InvoicesController.java │ │ │ ├── PaymentsController.java │ │ │ ├── RentalsController.java │ │ │ ├── ModelsController.java │ │ │ ├── BrandsController.java │ │ │ ├── MaintenancesController.java │ │ │ └── CarsController.java │ └── resources │ │ └── application.properties └── test │ └── java │ └── com │ └── tahademiryol │ └── rentacar │ └── RentACarApplicationTests.java ├── pom.xml ├── mvnw.cmd └── mvnw /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MuhammetTahaDemiryol/rent-a-car/HEAD/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | .idea 7 | *.iws 8 | *.iml 9 | *.ipr 10 | 11 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/business/abstracts/PosService.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.business.abstracts; 2 | 3 | public interface PosService { 4 | void pay(); 5 | } 6 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/entities/enums/State.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.entities.enums; 2 | 3 | public enum State { 4 | AVAILABLE, 5 | RENTED, 6 | MAINTENANCE 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/core/exceptions/BusinessException.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.core.exceptions; 2 | 3 | public class BusinessException extends RuntimeException { 4 | public BusinessException(String message) { 5 | super(message); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/test/java/com/tahademiryol/rentacar/RentACarApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class RentACarApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/common/constants/Regex.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.common.constants; 2 | 3 | public class Regex { 4 | public final static String Plate2 = "^(0[1-9]|[1-7][0-9]|8[01])\\s[A-Z]{1,3}\\s(\\d{2,4}|[1-9]\\d{3})$"; 5 | public final static String Plate = "^(0[1-9]|[1-7][0-9]|8[01]) [A-Z]{1,3} \\d{3,4}$"; 6 | } 7 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/repository/abstracts/RentalRepository.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.repository.abstracts; 2 | 3 | import com.tahademiryol.rentacar.entities.concretes.Rental; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | 6 | public interface RentalRepository extends JpaRepository { 7 | } 8 | -------------------------------------------------------------------------------- /src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect 2 | spring.jpa.hibernate.ddl-auto=update 3 | spring.datasource.url=jdbc:postgresql://localhost:5432/turkcell-rentacardb 4 | spring.datasource.username=postgres 5 | spring.datasource.password=12345 6 | spring.jpa.properties.javax.persistence.validation.mode=none 7 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/business/dto/requests/update/UpdateBrandRequest.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.business.dto.requests.update; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Getter; 5 | import lombok.NoArgsConstructor; 6 | import lombok.Setter; 7 | 8 | @AllArgsConstructor 9 | @NoArgsConstructor 10 | @Getter 11 | @Setter 12 | public class UpdateBrandRequest { 13 | private String name; 14 | } -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/repository/abstracts/InvoiceRepository.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.repository.abstracts; 2 | 3 | import com.tahademiryol.rentacar.entities.concretes.Invoice; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | 6 | public interface InvoiceRepository extends JpaRepository { 7 | // @Transactional 8 | // void deleteByRentalId(int rentalId); 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/business/dto/requests/create/CreateBrandRequest.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.business.dto.requests.create; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Getter; 5 | import lombok.NoArgsConstructor; 6 | import lombok.Setter; 7 | 8 | @AllArgsConstructor 9 | @NoArgsConstructor 10 | @Getter 11 | @Setter 12 | public class CreateBrandRequest { 13 | private String name; 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/repository/abstracts/ModelRepository.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.repository.abstracts; 2 | 3 | import com.tahademiryol.rentacar.entities.concretes.Model; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | 6 | 7 | public interface ModelRepository extends JpaRepository { 8 | 9 | //custom queries 10 | boolean existsByNameIgnoreCase(String name); 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/business/dto/requests/create/CreateModelRequest.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.business.dto.requests.create; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Getter; 5 | import lombok.NoArgsConstructor; 6 | import lombok.Setter; 7 | 8 | @AllArgsConstructor 9 | @NoArgsConstructor 10 | @Getter 11 | @Setter 12 | public class CreateModelRequest { 13 | private int brandId; 14 | private String name; 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/business/dto/requests/update/UpdateModelRequest.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.business.dto.requests.update; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Getter; 5 | import lombok.NoArgsConstructor; 6 | import lombok.Setter; 7 | 8 | @AllArgsConstructor 9 | @NoArgsConstructor 10 | @Getter 11 | @Setter 12 | public class UpdateModelRequest { 13 | private int brandId; 14 | private String name; 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/business/dto/responses/create/CreateBrandResponse.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.business.dto.responses.create; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Getter; 5 | import lombok.NoArgsConstructor; 6 | import lombok.Setter; 7 | 8 | @AllArgsConstructor 9 | @NoArgsConstructor 10 | @Getter 11 | @Setter 12 | public class CreateBrandResponse { 13 | private int id; 14 | private String name; 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/business/dto/responses/update/UpdateBrandResponse.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.business.dto.responses.update; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Getter; 5 | import lombok.NoArgsConstructor; 6 | import lombok.Setter; 7 | 8 | @AllArgsConstructor 9 | @NoArgsConstructor 10 | @Getter 11 | @Setter 12 | public class UpdateBrandResponse { 13 | private int id; 14 | private String name; 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/business/dto/responses/get/Brand/GetBrandResponse.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.business.dto.responses.get.Brand; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Getter; 5 | import lombok.NoArgsConstructor; 6 | import lombok.Setter; 7 | 8 | @AllArgsConstructor 9 | @NoArgsConstructor 10 | @Getter 11 | @Setter 12 | public class GetBrandResponse { 13 | private int id; 14 | private String name; 15 | } 16 | 17 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/configuration/mapper/ModelMapperConfig.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.configuration.mapper; 2 | 3 | import org.modelmapper.ModelMapper; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | 7 | @Configuration 8 | public class ModelMapperConfig { 9 | @Bean 10 | public ModelMapper getModelMapper() { 11 | return new ModelMapper(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/business/dto/requests/create/CreateMaintenanceRequest.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.business.dto.requests.create; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Getter; 5 | import lombok.NoArgsConstructor; 6 | import lombok.Setter; 7 | 8 | @AllArgsConstructor 9 | @NoArgsConstructor 10 | @Getter 11 | @Setter 12 | public class CreateMaintenanceRequest { 13 | private int carId; 14 | private String information; 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/business/dto/responses/get/Brand/GetAllBrandsResponse.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.business.dto.responses.get.Brand; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Getter; 5 | import lombok.NoArgsConstructor; 6 | import lombok.Setter; 7 | 8 | @AllArgsConstructor 9 | @NoArgsConstructor 10 | @Getter 11 | @Setter 12 | public class GetAllBrandsResponse { 13 | private int id; 14 | private String name; 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/repository/abstracts/BrandRepository.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.repository.abstracts; 2 | 3 | import com.tahademiryol.rentacar.entities.concretes.Brand; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | 6 | //CRUD operations, manages the database 7 | public interface BrandRepository extends JpaRepository { 8 | 9 | //custom queries 10 | boolean existsByNameIgnoreCase(String name); 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/business/dto/responses/create/CreateModelResponse.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.business.dto.responses.create; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Getter; 5 | import lombok.NoArgsConstructor; 6 | import lombok.Setter; 7 | 8 | @AllArgsConstructor 9 | @NoArgsConstructor 10 | @Getter 11 | @Setter 12 | public class CreateModelResponse { 13 | private int id; 14 | private int brandId; 15 | private String name; 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/business/dto/responses/update/UpdateModelResponse.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.business.dto.responses.update; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Getter; 5 | import lombok.NoArgsConstructor; 6 | import lombok.Setter; 7 | 8 | @AllArgsConstructor 9 | @NoArgsConstructor 10 | @Getter 11 | @Setter 12 | public class UpdateModelResponse { 13 | private int id; 14 | private int brandId; 15 | private String name; 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/repository/abstracts/CarRepository.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.repository.abstracts; 2 | 3 | import com.tahademiryol.rentacar.entities.concretes.Car; 4 | import com.tahademiryol.rentacar.entities.enums.State; 5 | import org.springframework.data.jpa.repository.JpaRepository; 6 | 7 | import java.util.List; 8 | 9 | 10 | public interface CarRepository extends JpaRepository { 11 | List findAllByStateIsNot(State state); 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/business/dto/responses/get/Model/GetModelResponse.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.business.dto.responses.get.Model; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Getter; 5 | import lombok.NoArgsConstructor; 6 | import lombok.Setter; 7 | 8 | @AllArgsConstructor 9 | @NoArgsConstructor 10 | @Getter 11 | @Setter 12 | public class GetModelResponse { 13 | private int id; 14 | private int brandId; 15 | private String name; 16 | } 17 | 18 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/business/dto/responses/get/Model/GetAllModelsResponse.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.business.dto.responses.get.Model; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Getter; 5 | import lombok.NoArgsConstructor; 6 | import lombok.Setter; 7 | 8 | @AllArgsConstructor 9 | @NoArgsConstructor 10 | @Getter 11 | @Setter 12 | public class GetAllModelsResponse { 13 | private int id; 14 | private int brandId; 15 | private String name; 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/common/constants/ExceptionTypes.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.common.constants; 2 | 3 | public class ExceptionTypes { 4 | public static class Exception { 5 | public static final String Validation = "VALIDATION_EXCEPTION"; 6 | public static final String Business = "BUSINESS_EXCEPTION"; 7 | public static final String Runtime = "RUNTIME_EXCEPTION"; 8 | public static final String DataIntegrityViolation = "DATA_INTEGRITY_VIOLATION_EXCEPTION"; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/business/dto/requests/update/UpdatePaymentRequest.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.business.dto.requests.update; 2 | 3 | import jakarta.validation.constraints.Min; 4 | import jakarta.validation.constraints.NotNull; 5 | import lombok.AllArgsConstructor; 6 | import lombok.Getter; 7 | import lombok.NoArgsConstructor; 8 | import lombok.Setter; 9 | 10 | @Getter 11 | @Setter 12 | @NoArgsConstructor 13 | @AllArgsConstructor 14 | public class UpdatePaymentRequest { 15 | @NotNull 16 | @Min(value = 1) 17 | private double balance; 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/repository/abstracts/MaintenanceRepository.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.repository.abstracts; 2 | 3 | import com.tahademiryol.rentacar.entities.concretes.Maintenance; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | 6 | public interface MaintenanceRepository extends JpaRepository { 7 | // @Nonnull 8 | // Maintenance findById(int id); 9 | Maintenance findMaintenanceByCarIdAndIsCompletedFalse(int carId); 10 | 11 | boolean existsByCarIdAndIsCompletedFalse(int carId); 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/core/utils/results/ExceptionResult.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.core.utils.results; 2 | 3 | import lombok.Getter; 4 | import lombok.Setter; 5 | 6 | import java.time.LocalDateTime; 7 | 8 | @Setter 9 | @Getter 10 | public class ExceptionResult { 11 | private LocalDateTime timestamp; 12 | private String type; 13 | private T message; 14 | 15 | public ExceptionResult(String type, T message) { 16 | this.timestamp = LocalDateTime.now(); 17 | this.type = type; 18 | this.message = message; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/business/dto/requests/update/UpdateRentalRequest.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.business.dto.requests.update; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Getter; 5 | import lombok.NoArgsConstructor; 6 | import lombok.Setter; 7 | 8 | import java.time.LocalDateTime; 9 | 10 | @AllArgsConstructor 11 | @NoArgsConstructor 12 | @Getter 13 | @Setter 14 | public class UpdateRentalRequest { 15 | private int carId; 16 | private int rentedForDays; 17 | private double dailyPrice; 18 | private LocalDateTime startDate; 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/common/dto/CreateRentalPaymentRequest.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.common.dto; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Getter; 5 | import lombok.NoArgsConstructor; 6 | import lombok.Setter; 7 | 8 | @Setter 9 | @Getter 10 | @NoArgsConstructor 11 | @AllArgsConstructor 12 | public class CreateRentalPaymentRequest { 13 | private int cardExpirationMonth; 14 | private int cardExpirationYear; 15 | private String cardNumber; 16 | private String cardholder; 17 | private String cardCvv; 18 | private double price; 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/business/dto/requests/create/CreatePaymentRequest.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.business.dto.requests.create; 2 | 3 | import com.tahademiryol.rentacar.business.dto.requests.PaymentRequest; 4 | import jakarta.validation.constraints.Min; 5 | import lombok.AllArgsConstructor; 6 | import lombok.Getter; 7 | import lombok.NoArgsConstructor; 8 | import lombok.Setter; 9 | 10 | @Getter 11 | @Setter 12 | @NoArgsConstructor 13 | @AllArgsConstructor 14 | public class CreatePaymentRequest extends PaymentRequest { 15 | @Min(value = 1) 16 | private double balance; 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/business/dto/requests/update/UpdateCarRequest.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.business.dto.requests.update; 2 | 3 | import com.tahademiryol.rentacar.entities.enums.State; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Getter; 6 | import lombok.NoArgsConstructor; 7 | import lombok.Setter; 8 | 9 | @AllArgsConstructor 10 | @NoArgsConstructor 11 | @Getter 12 | @Setter 13 | public class UpdateCarRequest { 14 | private int modelId; 15 | private double dailyPrice; 16 | private int modelYear; 17 | private String plate; 18 | private State state; 19 | } -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/common/utils/annotations/NotFutureYearValidator.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.common.utils.annotations; 2 | 3 | import jakarta.validation.ConstraintValidator; 4 | import jakarta.validation.ConstraintValidatorContext; 5 | 6 | import java.time.Year; 7 | 8 | public class NotFutureYearValidator implements ConstraintValidator { 9 | 10 | 11 | @Override 12 | public boolean isValid(Integer value, ConstraintValidatorContext context) { 13 | int currentYear = Year.now().getValue(); 14 | return value <= currentYear; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/business/dto/requests/create/CreateRentalRequest.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.business.dto.requests.create; 2 | 3 | import com.tahademiryol.rentacar.business.dto.requests.PaymentRequest; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Getter; 6 | import lombok.NoArgsConstructor; 7 | import lombok.Setter; 8 | 9 | @AllArgsConstructor 10 | @NoArgsConstructor 11 | @Getter 12 | @Setter 13 | public class CreateRentalRequest { 14 | private int carId; 15 | private int rentedForDays; 16 | private double dailyPrice; 17 | 18 | private PaymentRequest paymentRequest; 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/business/dto/requests/update/UpdateMaintenanceRequest.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.business.dto.requests.update; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Getter; 5 | import lombok.NoArgsConstructor; 6 | import lombok.Setter; 7 | 8 | import java.time.LocalDateTime; 9 | 10 | @AllArgsConstructor 11 | @NoArgsConstructor 12 | @Getter 13 | @Setter 14 | public class UpdateMaintenanceRequest { 15 | private int carId; 16 | private String information; 17 | private boolean isCompleted; 18 | private LocalDateTime startDate; 19 | private LocalDateTime endDate; 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/business/dto/responses/create/CreateCarResponse.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.business.dto.responses.create; 2 | 3 | import com.tahademiryol.rentacar.entities.enums.State; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Getter; 6 | import lombok.NoArgsConstructor; 7 | import lombok.Setter; 8 | 9 | @AllArgsConstructor 10 | @NoArgsConstructor 11 | @Getter 12 | @Setter 13 | public class CreateCarResponse { 14 | private int id; 15 | private int modelId; 16 | private double dailyPrice; 17 | private int modelYear; 18 | private String plate; 19 | private State state; 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/business/dto/responses/update/UpdateCarResponse.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.business.dto.responses.update; 2 | 3 | import com.tahademiryol.rentacar.entities.enums.State; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Getter; 6 | import lombok.NoArgsConstructor; 7 | import lombok.Setter; 8 | 9 | @AllArgsConstructor 10 | @NoArgsConstructor 11 | @Getter 12 | @Setter 13 | public class UpdateCarResponse { 14 | private int id; 15 | private int modelId; 16 | private double dailyPrice; 17 | private int modelYear; 18 | private String plate; 19 | private State state; 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/business/dto/responses/update/UpdateRentalResponse.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.business.dto.responses.update; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Getter; 5 | import lombok.NoArgsConstructor; 6 | import lombok.Setter; 7 | 8 | import java.time.LocalDateTime; 9 | 10 | @AllArgsConstructor 11 | @NoArgsConstructor 12 | @Getter 13 | @Setter 14 | public class UpdateRentalResponse { 15 | private int id; 16 | private int carId; 17 | private int rentedForDays; 18 | private double dailyPrice; 19 | private double totalPrice; 20 | private LocalDateTime startDate; 21 | } -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/business/dto/responses/create/CreateRentalResponse.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.business.dto.responses.create; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Getter; 5 | import lombok.NoArgsConstructor; 6 | import lombok.Setter; 7 | 8 | import java.time.LocalDateTime; 9 | 10 | @AllArgsConstructor 11 | @NoArgsConstructor 12 | @Getter 13 | @Setter 14 | public class CreateRentalResponse { 15 | private int id; 16 | private int carId; 17 | private int rentedForDays; 18 | private double dailyPrice; 19 | private double totalPrice; 20 | private LocalDateTime startDate; 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/business/dto/responses/create/CreatePaymentResponse.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.business.dto.responses.create; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Getter; 5 | import lombok.NoArgsConstructor; 6 | import lombok.Setter; 7 | 8 | @Getter 9 | @Setter 10 | @NoArgsConstructor 11 | @AllArgsConstructor 12 | public class CreatePaymentResponse { 13 | private int id; 14 | private int cardExpirationMonth; 15 | private int cardExpirationYear; 16 | private String cardNumber; 17 | private String cardHolder; 18 | private String cardCvv; 19 | private double balance; 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/business/dto/responses/update/UpdatePaymentResponse.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.business.dto.responses.update; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Getter; 5 | import lombok.NoArgsConstructor; 6 | import lombok.Setter; 7 | 8 | @Getter 9 | @Setter 10 | @NoArgsConstructor 11 | @AllArgsConstructor 12 | public class UpdatePaymentResponse { 13 | private int id; 14 | private int cardExpirationMonth; 15 | private int cardExpirationYear; 16 | private String cardNumber; 17 | private String cardHolder; 18 | private String cardCvv; 19 | private double balance; 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/business/dto/responses/get/Payment/GetPaymentResponse.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.business.dto.responses.get.Payment; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Getter; 5 | import lombok.NoArgsConstructor; 6 | import lombok.Setter; 7 | 8 | @Getter 9 | @Setter 10 | @NoArgsConstructor 11 | @AllArgsConstructor 12 | public class GetPaymentResponse { 13 | private int id; 14 | private int cardExpirationMonth; 15 | private int cardExpirationYear; 16 | private String cardNumber; 17 | private String cardHolder; 18 | private String cardCvv; 19 | private double balance; 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/business/dto/responses/get/Rental/GetAllRentalsResponse.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.business.dto.responses.get.Rental; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Getter; 5 | import lombok.NoArgsConstructor; 6 | import lombok.Setter; 7 | 8 | import java.time.LocalDateTime; 9 | 10 | @AllArgsConstructor 11 | @NoArgsConstructor 12 | @Getter 13 | @Setter 14 | public class GetAllRentalsResponse { 15 | private int id; 16 | private int carId; 17 | private int rentedForDays; 18 | private double dailyPrice; 19 | private double totalPrice; 20 | private LocalDateTime startDate; 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/business/dto/responses/get/Payment/GetAllPaymentsResponse.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.business.dto.responses.get.Payment; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Getter; 5 | import lombok.NoArgsConstructor; 6 | import lombok.Setter; 7 | 8 | @Getter 9 | @Setter 10 | @NoArgsConstructor 11 | @AllArgsConstructor 12 | public class GetAllPaymentsResponse { 13 | private int id; 14 | private int cardExpirationMonth; 15 | private int cardExpirationYear; 16 | private String cardNumber; 17 | private String cardHolder; 18 | private String cardCvv; 19 | private double balance; 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/business/dto/responses/create/CreateMaintenanceResponse.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.business.dto.responses.create; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Getter; 5 | import lombok.NoArgsConstructor; 6 | import lombok.Setter; 7 | 8 | import java.time.LocalDateTime; 9 | 10 | @AllArgsConstructor 11 | @NoArgsConstructor 12 | @Getter 13 | @Setter 14 | public class CreateMaintenanceResponse { 15 | private int id; 16 | private int carId; 17 | private String information; 18 | private boolean isCompleted; 19 | private LocalDateTime startDate; 20 | private LocalDateTime endDate; 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/business/dto/responses/get/Rental/GetRentalResponse.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.business.dto.responses.get.Rental; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Getter; 5 | import lombok.NoArgsConstructor; 6 | import lombok.Setter; 7 | 8 | import java.time.LocalDateTime; 9 | 10 | @AllArgsConstructor 11 | @NoArgsConstructor 12 | @Getter 13 | @Setter 14 | public class GetRentalResponse { 15 | private int id; 16 | private int carId; 17 | private int rentedForDays; 18 | private double dailyPrice; 19 | private double totalPrice; 20 | private LocalDateTime startDate; 21 | } 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/business/dto/responses/update/UpdateMaintenanceResponse.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.business.dto.responses.update; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Getter; 5 | import lombok.NoArgsConstructor; 6 | import lombok.Setter; 7 | 8 | import java.time.LocalDateTime; 9 | 10 | @AllArgsConstructor 11 | @NoArgsConstructor 12 | @Getter 13 | @Setter 14 | public class UpdateMaintenanceResponse { 15 | private int id; 16 | private int carId; 17 | private String information; 18 | private boolean isCompleted; 19 | private LocalDateTime startDate; 20 | private LocalDateTime endDate; 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/business/dto/responses/get/Maintenance/GetMaintenanceResponse.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.business.dto.responses.get.Maintenance; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Getter; 5 | import lombok.NoArgsConstructor; 6 | import lombok.Setter; 7 | 8 | import java.time.LocalDateTime; 9 | 10 | @AllArgsConstructor 11 | @NoArgsConstructor 12 | @Getter 13 | @Setter 14 | public class GetMaintenanceResponse { 15 | private int id; 16 | private int carId; 17 | private String information; 18 | private boolean isCompleted; 19 | private LocalDateTime startDate; 20 | private LocalDateTime endDate; 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/business/dto/responses/get/Maintenance/GetAllMaintenanceResponse.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.business.dto.responses.get.Maintenance; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Getter; 5 | import lombok.NoArgsConstructor; 6 | import lombok.Setter; 7 | 8 | import java.time.LocalDateTime; 9 | 10 | @AllArgsConstructor 11 | @NoArgsConstructor 12 | @Getter 13 | @Setter 14 | public class GetAllMaintenanceResponse { 15 | private int id; 16 | private int carId; 17 | private String information; 18 | private boolean isCompleted; 19 | private LocalDateTime startDate; 20 | private LocalDateTime endDate; 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/business/dto/responses/get/Car/GetCarResponse.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.business.dto.responses.get.Car; 2 | 3 | import com.tahademiryol.rentacar.entities.enums.State; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Getter; 6 | import lombok.NoArgsConstructor; 7 | import lombok.Setter; 8 | 9 | @AllArgsConstructor 10 | @NoArgsConstructor 11 | @Getter 12 | @Setter 13 | public class GetCarResponse { 14 | private int id; 15 | private int modelId; 16 | private double dailyPrice; 17 | private int modelYear; 18 | private String plate; 19 | private State state; 20 | 21 | private String modelName; 22 | private String modelBrandName; 23 | } 24 | 25 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/adapters/FakePosServiceAdapter.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.adapters; 2 | 3 | import com.tahademiryol.rentacar.business.abstracts.PosService; 4 | import com.tahademiryol.rentacar.common.constants.Messages; 5 | import com.tahademiryol.rentacar.core.exceptions.BusinessException; 6 | import org.springframework.stereotype.Service; 7 | 8 | import java.util.Random; 9 | 10 | @Service 11 | public class FakePosServiceAdapter implements PosService { 12 | @Override 13 | public void pay() { 14 | boolean isPaymentSuccessful = new Random().nextBoolean(); 15 | if (!isPaymentSuccessful) 16 | throw new BusinessException(Messages.Payment.Failed); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/RentACarApplication.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cache.annotation.EnableCaching; 6 | 7 | 8 | @EnableCaching 9 | @SpringBootApplication 10 | public class RentACarApplication { 11 | 12 | public static void main(String[] args) { 13 | SpringApplication.run(RentACarApplication.class, args); 14 | } 15 | 16 | // ApplicationContext apc = SpringApplication.run(RentACarApplication.class, args); 17 | // for (String s : apc.getBeanDefinitionNames()) { 18 | // System.out.println(s); 19 | // } 20 | 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/business/dto/responses/get/Car/GetAllCarsResponse.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.business.dto.responses.get.Car; 2 | 3 | import com.tahademiryol.rentacar.entities.enums.State; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Getter; 6 | import lombok.NoArgsConstructor; 7 | import lombok.Setter; 8 | 9 | @AllArgsConstructor 10 | @NoArgsConstructor 11 | @Getter 12 | @Setter 13 | public class GetAllCarsResponse { 14 | private int id; 15 | private int modelId; 16 | private double dailyPrice; 17 | private int modelYear; 18 | private String plate; 19 | private State state; 20 | 21 | // private String modelName; 22 | // private String modelBrandName; 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/business/dto/requests/create/CreateInvoiceRequest.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.business.dto.requests.create; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Getter; 5 | import lombok.NoArgsConstructor; 6 | import lombok.Setter; 7 | 8 | import java.time.LocalDateTime; 9 | 10 | @Setter 11 | @Getter 12 | @NoArgsConstructor 13 | @AllArgsConstructor 14 | public class CreateInvoiceRequest { 15 | 16 | private String cardHolder; 17 | private String modelName; 18 | private String brandName; 19 | private String plate; 20 | private int modelYear; 21 | private double dailyPrice; 22 | private int rentedForDays; 23 | private LocalDateTime rentedAt; 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/business/dto/requests/update/UpdateInvoiceRequest.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.business.dto.requests.update; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Getter; 5 | import lombok.NoArgsConstructor; 6 | import lombok.Setter; 7 | 8 | import java.time.LocalDateTime; 9 | 10 | @Setter 11 | @Getter 12 | @NoArgsConstructor 13 | @AllArgsConstructor 14 | public class UpdateInvoiceRequest { 15 | 16 | private String cardHolder; 17 | private String modelName; 18 | private String brandName; 19 | private String plate; 20 | private int modelYear; 21 | private double dailyPrice; 22 | private int rentedForDays; 23 | private LocalDateTime rentedAt; 24 | 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/business/rules/CarBusinessRules.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.business.rules; 2 | 3 | import com.tahademiryol.rentacar.common.constants.Messages; 4 | import com.tahademiryol.rentacar.core.exceptions.BusinessException; 5 | import com.tahademiryol.rentacar.repository.abstracts.CarRepository; 6 | import lombok.AllArgsConstructor; 7 | import org.springframework.stereotype.Service; 8 | 9 | @Service 10 | @AllArgsConstructor 11 | public class CarBusinessRules { 12 | private final CarRepository repository; 13 | 14 | // Business rules 15 | public void checkIfCarExists(int id) { 16 | if (!repository.existsById(id)) throw new BusinessException(Messages.Car.NotExists); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/business/rules/InvoiceBusinessRules.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.business.rules; 2 | 3 | import com.tahademiryol.rentacar.common.constants.Messages; 4 | import com.tahademiryol.rentacar.core.exceptions.BusinessException; 5 | import com.tahademiryol.rentacar.repository.abstracts.InvoiceRepository; 6 | import lombok.AllArgsConstructor; 7 | import org.springframework.stereotype.Service; 8 | 9 | @Service 10 | @AllArgsConstructor 11 | public class InvoiceBusinessRules { 12 | private final InvoiceRepository repository; 13 | 14 | // Business rules 15 | public void checkIfInvoiceExist(int id) { 16 | if (!repository.existsById(id)) throw new BusinessException(Messages.Invoice.NotFound); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/entities/concretes/Payment.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.entities.concretes; 2 | 3 | import jakarta.persistence.*; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Getter; 6 | import lombok.NoArgsConstructor; 7 | import lombok.Setter; 8 | 9 | @Getter 10 | @Setter 11 | @Entity 12 | @NoArgsConstructor 13 | @AllArgsConstructor 14 | @Table(name = "payments") 15 | public class Payment { 16 | @Id 17 | @GeneratedValue(strategy = GenerationType.IDENTITY) 18 | private int id; 19 | private int cardExpirationMonth; 20 | private int cardExpirationYear; 21 | private String cardNumber; 22 | private String cardHolder; 23 | private String cardCvv; 24 | private double balance; 25 | 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/entities/concretes/Brand.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.entities.concretes; 2 | 3 | import jakarta.persistence.*; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Getter; 6 | import lombok.NoArgsConstructor; 7 | import lombok.Setter; 8 | 9 | import java.util.List; 10 | 11 | // code first 12 | @Entity // not needed but it's useful for reviewing 13 | @Setter 14 | @Getter 15 | @NoArgsConstructor 16 | @AllArgsConstructor 17 | @Table(name = "brands") 18 | public class Brand { 19 | @Id // Primary Key -> PK 20 | @GeneratedValue(strategy = GenerationType.IDENTITY) 21 | private int id; 22 | private String name; 23 | 24 | // @JsonBackReference 25 | @OneToMany(mappedBy = "brand") 26 | private List models; 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/business/dto/responses/get/Invoice/GetInvoiceResponse.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.business.dto.responses.get.Invoice; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Getter; 5 | import lombok.NoArgsConstructor; 6 | import lombok.Setter; 7 | 8 | import java.time.LocalDateTime; 9 | 10 | @Setter 11 | @Getter 12 | @NoArgsConstructor 13 | @AllArgsConstructor 14 | public class GetInvoiceResponse { 15 | private int id; 16 | private String cardHolder; 17 | private String modelName; 18 | private String brandName; 19 | private String plate; 20 | private int modelYear; 21 | private double dailyPrice; 22 | private double totalPrice; 23 | private int rentedForDays; 24 | private LocalDateTime rentedAt; 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/business/dto/responses/create/CreateInvoiceResponse.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.business.dto.responses.create; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Getter; 5 | import lombok.NoArgsConstructor; 6 | import lombok.Setter; 7 | 8 | import java.time.LocalDateTime; 9 | 10 | @Setter 11 | @Getter 12 | @NoArgsConstructor 13 | @AllArgsConstructor 14 | public class CreateInvoiceResponse { 15 | 16 | private int id; 17 | private String cardHolder; 18 | private String modelName; 19 | private String brandName; 20 | private String plate; 21 | private int modelYear; 22 | private double dailyPrice; 23 | private double totalPrice; 24 | private int rentedForDays; 25 | private LocalDateTime rentedAt; 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/business/dto/responses/update/UpdateInvoiceResponse.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.business.dto.responses.update; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Getter; 5 | import lombok.NoArgsConstructor; 6 | import lombok.Setter; 7 | 8 | import java.time.LocalDateTime; 9 | 10 | @Setter 11 | @Getter 12 | @NoArgsConstructor 13 | @AllArgsConstructor 14 | public class UpdateInvoiceResponse { 15 | private int id; 16 | private String cardHolder; 17 | private String modelName; 18 | private String brandName; 19 | private String plate; 20 | private int modelYear; 21 | private double dailyPrice; 22 | private double totalPrice; 23 | private int rentedForDays; 24 | private LocalDateTime rentedAt; 25 | 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/business/dto/responses/get/Invoice/GetAllInvoicesResponse.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.business.dto.responses.get.Invoice; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Getter; 5 | import lombok.NoArgsConstructor; 6 | import lombok.Setter; 7 | 8 | import java.time.LocalDateTime; 9 | 10 | @Setter 11 | @Getter 12 | @NoArgsConstructor 13 | @AllArgsConstructor 14 | public class GetAllInvoicesResponse { 15 | private int id; 16 | private String cardHolder; 17 | private String modelName; 18 | private String brandName; 19 | private String plate; 20 | private int modelYear; 21 | private double dailyPrice; 22 | private double totalPrice; 23 | private int rentedForDays; 24 | private LocalDateTime rentedAt; 25 | 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/entities/concretes/Model.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.entities.concretes; 2 | 3 | import jakarta.persistence.*; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Getter; 6 | import lombok.NoArgsConstructor; 7 | import lombok.Setter; 8 | 9 | import java.util.List; 10 | 11 | @Entity 12 | @Setter 13 | @Getter 14 | @NoArgsConstructor 15 | @AllArgsConstructor 16 | @Table(name = "models") 17 | public class Model { 18 | @Id 19 | @GeneratedValue(strategy = GenerationType.IDENTITY) 20 | private int id; 21 | private String name; 22 | 23 | @ManyToOne 24 | // @JsonManagedReference 25 | @JoinColumn(name = "brand_id") 26 | private Brand brand; 27 | 28 | @OneToMany(mappedBy = "model") 29 | // @JsonBackReference 30 | private List cars; 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/entities/concretes/Rental.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.entities.concretes; 2 | 3 | import jakarta.persistence.*; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Getter; 6 | import lombok.NoArgsConstructor; 7 | import lombok.Setter; 8 | 9 | import java.time.LocalDateTime; 10 | 11 | @Entity 12 | @AllArgsConstructor 13 | @NoArgsConstructor 14 | @Setter 15 | @Getter 16 | @Table(name = "rentals") 17 | public class Rental { 18 | @Id 19 | @GeneratedValue(strategy = GenerationType.IDENTITY) 20 | private int id; 21 | 22 | private int rentedForDays; 23 | private double dailyPrice; 24 | private double totalPrice; //read-only 25 | private LocalDateTime startDate; 26 | 27 | @ManyToOne 28 | @JoinColumn(name = "car_id") 29 | private Car car; 30 | 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/entities/concretes/Maintenance.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.entities.concretes; 2 | 3 | import jakarta.persistence.*; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Getter; 6 | import lombok.NoArgsConstructor; 7 | import lombok.Setter; 8 | 9 | import java.time.LocalDateTime; 10 | 11 | 12 | @Entity 13 | @Setter 14 | @Getter 15 | @NoArgsConstructor 16 | @AllArgsConstructor 17 | @Table(name = "maintenances") 18 | public class Maintenance { 19 | @Id 20 | @GeneratedValue(strategy = GenerationType.IDENTITY) 21 | private int id; 22 | 23 | private String information; 24 | private boolean isCompleted; 25 | private LocalDateTime startDate; 26 | private LocalDateTime endDate; 27 | 28 | @ManyToOne 29 | @JoinColumn(name = "car_id") 30 | private Car car; 31 | 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/entities/concretes/Invoice.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.entities.concretes; 2 | 3 | import jakarta.persistence.*; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Getter; 6 | import lombok.NoArgsConstructor; 7 | import lombok.Setter; 8 | 9 | import java.time.LocalDateTime; 10 | 11 | @Entity 12 | @Setter 13 | @Getter 14 | @NoArgsConstructor 15 | @AllArgsConstructor 16 | @Table(name = "invoices") 17 | public class Invoice { 18 | 19 | @Id 20 | @GeneratedValue(strategy = GenerationType.IDENTITY) 21 | private int id; 22 | private String cardHolder; 23 | private String modelName; 24 | private String brandName; 25 | private String plate; 26 | private int modelYear; 27 | private double dailyPrice; 28 | private double totalPrice; 29 | private int rentedForDays; 30 | private LocalDateTime rentedAt; 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/business/rules/BrandBusinessRules.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.business.rules; 2 | 3 | import com.tahademiryol.rentacar.common.constants.Messages; 4 | import com.tahademiryol.rentacar.core.exceptions.BusinessException; 5 | import com.tahademiryol.rentacar.repository.abstracts.BrandRepository; 6 | import lombok.AllArgsConstructor; 7 | import org.springframework.stereotype.Service; 8 | 9 | @Service 10 | @AllArgsConstructor 11 | public class BrandBusinessRules { 12 | private final BrandRepository repository; 13 | 14 | // Business rules 15 | public void checkIfBrandExists(int id) { 16 | if (!repository.existsById(id)) throw new BusinessException(Messages.Brand.NotExists); 17 | } 18 | 19 | public void checkIfBrandExistsByName(String name) { 20 | if (repository.existsByNameIgnoreCase(name)) throw new BusinessException(Messages.Brand.Exists); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/business/rules/ModelBusinessRules.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.business.rules; 2 | 3 | import com.tahademiryol.rentacar.common.constants.Messages; 4 | import com.tahademiryol.rentacar.core.exceptions.BusinessException; 5 | import com.tahademiryol.rentacar.repository.abstracts.ModelRepository; 6 | import lombok.AllArgsConstructor; 7 | import org.springframework.stereotype.Service; 8 | 9 | @Service 10 | @AllArgsConstructor 11 | public class ModelBusinessRules { 12 | private final ModelRepository repository; 13 | 14 | // Business rules 15 | public void checkIfModelExists(int id) { 16 | if (!repository.existsById(id)) throw new BusinessException(Messages.Model.NotExists); 17 | } 18 | 19 | public void checkIfModelExistsByName(String name) { 20 | if (repository.existsByNameIgnoreCase(name)) throw new BusinessException(Messages.Model.Exists); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/business/dto/requests/create/CreateCarRequest.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.business.dto.requests.create; 2 | 3 | import com.tahademiryol.rentacar.common.constants.Regex; 4 | import com.tahademiryol.rentacar.common.utils.annotations.NotFutureYear; 5 | import jakarta.validation.constraints.Min; 6 | import jakarta.validation.constraints.Pattern; 7 | import lombok.AllArgsConstructor; 8 | import lombok.Getter; 9 | import lombok.NoArgsConstructor; 10 | import lombok.Setter; 11 | 12 | @Setter 13 | @Getter 14 | @NoArgsConstructor 15 | @AllArgsConstructor 16 | public class CreateCarRequest { 17 | private int modelId; 18 | @Min(1998) 19 | @NotFutureYear 20 | private int modelYear; 21 | @Min(1) 22 | private double dailyPrice; 23 | 24 | // 01-81, A-AA-AAA, 0000 25 | @Pattern(regexp = Regex.Plate, message = "Invalid Licence Plate Code") 26 | private String plate; 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/common/utils/annotations/NotFutureYear.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.common.utils.annotations; 2 | 3 | import jakarta.validation.Constraint; 4 | import jakarta.validation.Payload; 5 | 6 | import java.lang.annotation.ElementType; 7 | import java.lang.annotation.Retention; 8 | import java.lang.annotation.RetentionPolicy; 9 | import java.lang.annotation.Target; 10 | 11 | @Target({ElementType.FIELD, ElementType.PARAMETER}) 12 | @Retention(RetentionPolicy.RUNTIME) 13 | @Constraint(validatedBy = NotFutureYearValidator.class) 14 | public @interface NotFutureYear { 15 | String message() default "The year value cannot be in the future"; 16 | 17 | //? Different user groups can have different rules and features 18 | Class[] groups() default {}; 19 | 20 | //? used in data transfer objects for carrying messages for different user groups 21 | Class[] payload() default {}; 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/business/abstracts/RentalService.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.business.abstracts; 2 | 3 | import com.tahademiryol.rentacar.business.dto.requests.create.CreateRentalRequest; 4 | import com.tahademiryol.rentacar.business.dto.requests.update.UpdateRentalRequest; 5 | import com.tahademiryol.rentacar.business.dto.responses.create.CreateRentalResponse; 6 | import com.tahademiryol.rentacar.business.dto.responses.get.Rental.GetAllRentalsResponse; 7 | import com.tahademiryol.rentacar.business.dto.responses.get.Rental.GetRentalResponse; 8 | import com.tahademiryol.rentacar.business.dto.responses.update.UpdateRentalResponse; 9 | 10 | import java.util.List; 11 | 12 | public interface RentalService { 13 | List getAll(); 14 | 15 | GetRentalResponse getById(int id); 16 | 17 | CreateRentalResponse add(CreateRentalRequest request); 18 | 19 | UpdateRentalResponse update(int id, UpdateRentalRequest request); 20 | 21 | void delete(int id); 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/business/abstracts/InvoiceService.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.business.abstracts; 2 | 3 | import com.tahademiryol.rentacar.business.dto.requests.create.CreateInvoiceRequest; 4 | import com.tahademiryol.rentacar.business.dto.requests.update.UpdateInvoiceRequest; 5 | import com.tahademiryol.rentacar.business.dto.responses.create.CreateInvoiceResponse; 6 | import com.tahademiryol.rentacar.business.dto.responses.get.Invoice.GetAllInvoicesResponse; 7 | import com.tahademiryol.rentacar.business.dto.responses.get.Invoice.GetInvoiceResponse; 8 | import com.tahademiryol.rentacar.business.dto.responses.update.UpdateInvoiceResponse; 9 | 10 | import java.util.List; 11 | 12 | public interface InvoiceService { 13 | List getAll(); 14 | 15 | GetInvoiceResponse getById(int id); 16 | 17 | CreateInvoiceResponse add(CreateInvoiceRequest request); 18 | 19 | UpdateInvoiceResponse update(int id, UpdateInvoiceRequest request); 20 | 21 | void delete(int id); 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/business/rules/RentalBusinessRules.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.business.rules; 2 | 3 | import com.tahademiryol.rentacar.common.constants.Messages; 4 | import com.tahademiryol.rentacar.core.exceptions.BusinessException; 5 | import com.tahademiryol.rentacar.entities.enums.State; 6 | import com.tahademiryol.rentacar.repository.abstracts.RentalRepository; 7 | import lombok.AllArgsConstructor; 8 | import org.springframework.stereotype.Service; 9 | 10 | @Service 11 | @AllArgsConstructor 12 | public class RentalBusinessRules { 13 | private final RentalRepository repository; 14 | 15 | // Business rules 16 | public void checkIfRentalExists(int id) { 17 | if (!repository.existsById(id)) 18 | throw new BusinessException(Messages.Rental.NotExists); 19 | } 20 | 21 | public void checkIfCarAvailable(State state) { 22 | if (!state.equals(State.AVAILABLE)) { 23 | throw new BusinessException(Messages.Car.NotAvailable); 24 | } 25 | 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # https://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.7/apache-maven-3.8.7-bin.zip 18 | wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar 19 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/entities/concretes/Car.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.entities.concretes; 2 | 3 | import com.tahademiryol.rentacar.entities.enums.State; 4 | import jakarta.persistence.*; 5 | import lombok.AllArgsConstructor; 6 | import lombok.Getter; 7 | import lombok.NoArgsConstructor; 8 | import lombok.Setter; 9 | 10 | import java.util.List; 11 | 12 | 13 | @Getter 14 | @Setter 15 | @Entity 16 | @NoArgsConstructor 17 | @AllArgsConstructor 18 | @Table(name = "cars") 19 | public class Car { 20 | @Id 21 | @GeneratedValue(strategy = GenerationType.IDENTITY) 22 | private int id; 23 | private int modelYear; 24 | private String plate; 25 | private double dailyPrice; 26 | @Enumerated(EnumType.STRING) 27 | private State state; // Available, Rented, Maintenance 28 | 29 | @ManyToOne 30 | // @JsonManagedReference 31 | @JoinColumn(name = "model_id") 32 | private Model model; 33 | 34 | @OneToMany(mappedBy = "car") 35 | private List maintenances; 36 | 37 | @OneToMany(mappedBy = "car") 38 | private List rentals; 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/business/abstracts/MaintenanceService.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.business.abstracts; 2 | 3 | import com.tahademiryol.rentacar.business.dto.requests.create.CreateMaintenanceRequest; 4 | import com.tahademiryol.rentacar.business.dto.requests.update.UpdateMaintenanceRequest; 5 | import com.tahademiryol.rentacar.business.dto.responses.create.CreateMaintenanceResponse; 6 | import com.tahademiryol.rentacar.business.dto.responses.get.Maintenance.GetAllMaintenanceResponse; 7 | import com.tahademiryol.rentacar.business.dto.responses.get.Maintenance.GetMaintenanceResponse; 8 | import com.tahademiryol.rentacar.business.dto.responses.update.UpdateMaintenanceResponse; 9 | 10 | import java.util.List; 11 | 12 | public interface MaintenanceService { 13 | List getAll(); 14 | 15 | GetMaintenanceResponse getById(int id); 16 | 17 | GetMaintenanceResponse returnCarFromMaintenance(int carId); 18 | 19 | CreateMaintenanceResponse add(CreateMaintenanceRequest request); 20 | 21 | UpdateMaintenanceResponse update(int id, UpdateMaintenanceRequest request); 22 | 23 | void delete(int id); 24 | 25 | } -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/business/dto/requests/PaymentRequest.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.business.dto.requests; 2 | 3 | import jakarta.validation.constraints.Max; 4 | import jakarta.validation.constraints.Min; 5 | import jakarta.validation.constraints.NotBlank; 6 | import jakarta.validation.constraints.NotNull; 7 | import lombok.AllArgsConstructor; 8 | import lombok.Getter; 9 | import lombok.NoArgsConstructor; 10 | import lombok.Setter; 11 | import org.hibernate.validator.constraints.Length; 12 | 13 | @Getter 14 | @Setter 15 | @NoArgsConstructor 16 | @AllArgsConstructor 17 | public class PaymentRequest { 18 | 19 | @Min(value = 2023) 20 | private int cardExpirationYear; 21 | 22 | 23 | @Max(value = 12) 24 | @Min(value = 1) 25 | private int cardExpirationMonth; 26 | 27 | @NotBlank(message = "Card Number is not validated.") 28 | @Length(min = 16, max = 16, message = "Must be 16 characters long.") 29 | private String cardNumber; 30 | 31 | @NotBlank 32 | @Length(min = 5) 33 | private String cardHolder; 34 | 35 | @NotNull 36 | @NotBlank 37 | @Length(min = 3, max = 3) 38 | private String cardCvv; 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/business/abstracts/PaymentService.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.business.abstracts; 2 | 3 | import com.tahademiryol.rentacar.business.dto.requests.create.CreatePaymentRequest; 4 | import com.tahademiryol.rentacar.business.dto.requests.update.UpdatePaymentRequest; 5 | import com.tahademiryol.rentacar.business.dto.responses.create.CreatePaymentResponse; 6 | import com.tahademiryol.rentacar.business.dto.responses.get.Payment.GetAllPaymentsResponse; 7 | import com.tahademiryol.rentacar.business.dto.responses.get.Payment.GetPaymentResponse; 8 | import com.tahademiryol.rentacar.business.dto.responses.update.UpdatePaymentResponse; 9 | import com.tahademiryol.rentacar.common.dto.CreateRentalPaymentRequest; 10 | 11 | import java.util.List; 12 | 13 | public interface PaymentService { 14 | List getAll(); 15 | 16 | GetPaymentResponse getById(int id); 17 | 18 | CreatePaymentResponse add(CreatePaymentRequest request); 19 | 20 | UpdatePaymentResponse update(int id, UpdatePaymentRequest request); 21 | 22 | void delete(int id); 23 | 24 | void processRentalPayment(CreateRentalPaymentRequest request); 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/business/abstracts/ModelService.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.business.abstracts; 2 | 3 | import com.tahademiryol.rentacar.business.dto.requests.create.CreateModelRequest; 4 | import com.tahademiryol.rentacar.business.dto.requests.update.UpdateModelRequest; 5 | import com.tahademiryol.rentacar.business.dto.responses.create.CreateModelResponse; 6 | import com.tahademiryol.rentacar.business.dto.responses.get.Car.GetAllCarsResponse; 7 | import com.tahademiryol.rentacar.business.dto.responses.get.Model.GetAllModelsResponse; 8 | import com.tahademiryol.rentacar.business.dto.responses.get.Model.GetModelResponse; 9 | import com.tahademiryol.rentacar.business.dto.responses.update.UpdateModelResponse; 10 | 11 | import java.util.List; 12 | 13 | public interface ModelService { 14 | List getAll(); 15 | 16 | GetModelResponse getById(int id); 17 | 18 | CreateModelResponse add(CreateModelRequest request); 19 | 20 | UpdateModelResponse update(int id, UpdateModelRequest request); 21 | 22 | void delete(int id); 23 | 24 | List showCars(int id); 25 | 26 | //@Configuration 27 | //@Service 28 | //@Repository 29 | //@Component 30 | 31 | // @Bean -- method 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/business/abstracts/BrandService.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.business.abstracts; 2 | 3 | import com.tahademiryol.rentacar.business.dto.requests.create.CreateBrandRequest; 4 | import com.tahademiryol.rentacar.business.dto.requests.update.UpdateBrandRequest; 5 | import com.tahademiryol.rentacar.business.dto.responses.create.CreateBrandResponse; 6 | import com.tahademiryol.rentacar.business.dto.responses.get.Brand.GetAllBrandsResponse; 7 | import com.tahademiryol.rentacar.business.dto.responses.get.Brand.GetBrandResponse; 8 | import com.tahademiryol.rentacar.business.dto.responses.get.Model.GetAllModelsResponse; 9 | import com.tahademiryol.rentacar.business.dto.responses.update.UpdateBrandResponse; 10 | 11 | import java.util.List; 12 | 13 | public interface BrandService { 14 | List getAll(); 15 | 16 | GetBrandResponse getById(int id); 17 | 18 | CreateBrandResponse add(CreateBrandRequest request); 19 | 20 | UpdateBrandResponse update(int id, UpdateBrandRequest request); 21 | 22 | void delete(int id); 23 | 24 | List showModels(int id); 25 | 26 | //@Configuration 27 | //@Service 28 | //@Repository 29 | //@Component 30 | 31 | // @Bean -- method 32 | } 33 | 34 | 35 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/business/abstracts/CarService.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.business.abstracts; 2 | 3 | import com.tahademiryol.rentacar.business.dto.requests.create.CreateCarRequest; 4 | import com.tahademiryol.rentacar.business.dto.requests.update.UpdateCarRequest; 5 | import com.tahademiryol.rentacar.business.dto.responses.create.CreateCarResponse; 6 | import com.tahademiryol.rentacar.business.dto.responses.get.Car.GetAllCarsResponse; 7 | import com.tahademiryol.rentacar.business.dto.responses.get.Car.GetCarResponse; 8 | import com.tahademiryol.rentacar.business.dto.responses.get.Maintenance.GetAllMaintenanceResponse; 9 | import com.tahademiryol.rentacar.business.dto.responses.update.UpdateCarResponse; 10 | import com.tahademiryol.rentacar.entities.enums.State; 11 | 12 | import java.util.List; 13 | 14 | public interface CarService { 15 | List getAll(boolean includeMaintenance); 16 | 17 | GetCarResponse getById(int id); 18 | 19 | CreateCarResponse add(CreateCarRequest request); 20 | 21 | UpdateCarResponse update(int id, UpdateCarRequest request); 22 | 23 | void delete(int id); 24 | 25 | public void changeState(int carId, State state); 26 | 27 | List showMaintenances(int id); 28 | 29 | 30 | //@Configuration 31 | //@Service 32 | //@Repository 33 | //@Component 34 | 35 | // @Bean -- method 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/repository/abstracts/PaymentRepository.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.repository.abstracts; 2 | 3 | import com.tahademiryol.rentacar.entities.concretes.Payment; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | 6 | public interface PaymentRepository extends JpaRepository { 7 | Payment findByCardNumber(String cardNumber); 8 | 9 | boolean existsByCardNumber(String cardNumber); 10 | 11 | boolean existsByCardNumberAndCardHolderAndCardExpirationYearAndCardExpirationMonthAndCardCvv( 12 | String cardNumber, String cardHolder, int cardExpirationYear, 13 | int cardExpirationMonth, String cardCvv); 14 | 15 | 16 | // SPeL -> Spring Expression language 17 | //Custom query 18 | // @Query("SELECT CASE WHEN COUNT (p) > 0 THEN true ELSE false END" + 19 | // " FROM Payment p Where p.cardNumber = :#{#paymentRequest.cardNumber} " + 20 | // " AND p.cardHolder = :#{#paymentRequest.cardHolder} " + 21 | // " AND p.cardExpirationYear = :#{#paymentRequest.cardExpirationYear} " + 22 | // " AND p.cardExpirationMonth = :#{#paymentRequest.cardExpirationMonth}" + 23 | // " AND p.cardCvv = :#{#paymentRequest.cardCvv}") 24 | // boolean existsByCardNumberAndCardHolderAndCardExpirationYearAndCardExpirationMonthAndCardCvv( 25 | // @Param("paymentRequest") PaymentRequest paymentRequest); 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/business/rules/MaintenanceBusinessRules.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.business.rules; 2 | 3 | import com.tahademiryol.rentacar.common.constants.Messages; 4 | import com.tahademiryol.rentacar.core.exceptions.BusinessException; 5 | import com.tahademiryol.rentacar.entities.enums.State; 6 | import com.tahademiryol.rentacar.repository.abstracts.MaintenanceRepository; 7 | import lombok.AllArgsConstructor; 8 | import org.springframework.stereotype.Service; 9 | 10 | @Service 11 | @AllArgsConstructor 12 | public class MaintenanceBusinessRules { 13 | private final MaintenanceRepository repository; 14 | // Business rules 15 | 16 | public void checkIfMaintenanceExist(int id) { 17 | if (!repository.existsById(id)) throw new BusinessException(Messages.Maintenance.NotExists); 18 | } 19 | 20 | 21 | public void checkIfCarUnderMaintenance(int carId) { 22 | if (repository.existsByCarIdAndIsCompletedFalse(carId)) { 23 | throw new BusinessException(Messages.Maintenance.CarExists); 24 | } 25 | 26 | } 27 | 28 | public void checkIfCarIsNotUnderMaintenance(int carId) { 29 | if (!repository.existsByCarIdAndIsCompletedFalse(carId)) { 30 | throw new BusinessException(Messages.Maintenance.CarNotExists); 31 | } 32 | } 33 | 34 | public void checkCarAvailabilityForMaintenance(State state) { 35 | if (state.equals(State.RENTED)) { 36 | throw new BusinessException(Messages.Maintenance.CarIsRented); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/api/controllers/InvoicesController.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.api.controllers; 2 | 3 | import com.tahademiryol.rentacar.business.abstracts.InvoiceService; 4 | import com.tahademiryol.rentacar.business.dto.requests.create.CreateInvoiceRequest; 5 | import com.tahademiryol.rentacar.business.dto.requests.update.UpdateInvoiceRequest; 6 | import com.tahademiryol.rentacar.business.dto.responses.create.CreateInvoiceResponse; 7 | import com.tahademiryol.rentacar.business.dto.responses.get.Invoice.GetAllInvoicesResponse; 8 | import com.tahademiryol.rentacar.business.dto.responses.get.Invoice.GetInvoiceResponse; 9 | import com.tahademiryol.rentacar.business.dto.responses.update.UpdateInvoiceResponse; 10 | import lombok.AllArgsConstructor; 11 | import org.springframework.web.bind.annotation.*; 12 | 13 | import java.util.List; 14 | 15 | @RestController 16 | @AllArgsConstructor 17 | @RequestMapping("/api/invoices") 18 | public class InvoicesController { 19 | private final InvoiceService service; 20 | 21 | @GetMapping 22 | public List getAll() { 23 | return service.getAll(); 24 | } 25 | 26 | @GetMapping("/{id}") 27 | public GetInvoiceResponse getById(@PathVariable int id) { 28 | return service.getById(id); 29 | } 30 | 31 | @PostMapping 32 | public CreateInvoiceResponse add(@RequestBody CreateInvoiceRequest request) { 33 | return service.add(request); 34 | } 35 | 36 | @PutMapping("/{id}") 37 | public UpdateInvoiceResponse update(@PathVariable int id, @RequestBody UpdateInvoiceRequest request) { 38 | return service.update(id, request); 39 | } 40 | 41 | @DeleteMapping("/{id}") 42 | public void delete(@PathVariable int id) { 43 | service.delete(id); 44 | } 45 | } -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/api/controllers/PaymentsController.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.api.controllers; 2 | 3 | import com.tahademiryol.rentacar.business.abstracts.PaymentService; 4 | import com.tahademiryol.rentacar.business.dto.requests.create.CreatePaymentRequest; 5 | import com.tahademiryol.rentacar.business.dto.requests.update.UpdatePaymentRequest; 6 | import com.tahademiryol.rentacar.business.dto.responses.create.CreatePaymentResponse; 7 | import com.tahademiryol.rentacar.business.dto.responses.get.Payment.GetAllPaymentsResponse; 8 | import com.tahademiryol.rentacar.business.dto.responses.get.Payment.GetPaymentResponse; 9 | import com.tahademiryol.rentacar.business.dto.responses.update.UpdatePaymentResponse; 10 | import jakarta.validation.Valid; 11 | import lombok.AllArgsConstructor; 12 | import org.springframework.web.bind.annotation.*; 13 | 14 | import java.util.List; 15 | 16 | @RestController 17 | @AllArgsConstructor 18 | @RequestMapping("/api/payments") 19 | public class PaymentsController { 20 | private final PaymentService service; 21 | 22 | @GetMapping 23 | public List getAll() { 24 | return service.getAll(); 25 | } 26 | 27 | @GetMapping("/{id}") 28 | public GetPaymentResponse getById(@PathVariable int id) { 29 | return service.getById(id); 30 | } 31 | 32 | @PostMapping 33 | public CreatePaymentResponse add(@Valid @RequestBody CreatePaymentRequest request) { 34 | return service.add(request); 35 | } 36 | 37 | @PutMapping("/{id}") 38 | public UpdatePaymentResponse update(@PathVariable int id, @Valid @RequestBody UpdatePaymentRequest request) { 39 | return service.update(id, request); 40 | } 41 | 42 | @DeleteMapping("/{id}") 43 | public void delete(@PathVariable int id) { 44 | service.delete(id); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/business/rules/PaymentBusinessRules.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.business.rules; 2 | 3 | import com.tahademiryol.rentacar.common.constants.Messages; 4 | import com.tahademiryol.rentacar.common.dto.CreateRentalPaymentRequest; 5 | import com.tahademiryol.rentacar.core.exceptions.BusinessException; 6 | import com.tahademiryol.rentacar.repository.abstracts.PaymentRepository; 7 | import lombok.AllArgsConstructor; 8 | import org.springframework.stereotype.Service; 9 | 10 | @Service 11 | @AllArgsConstructor 12 | public class PaymentBusinessRules { 13 | private final PaymentRepository repository; 14 | 15 | // Business rules 16 | public void checkIfPaymentIsValid(CreateRentalPaymentRequest request) { 17 | if (!repository.existsByCardNumberAndCardHolderAndCardExpirationYearAndCardExpirationMonthAndCardCvv( 18 | request.getCardNumber(), 19 | request.getCardholder(), 20 | request.getCardExpirationYear(), 21 | request.getCardExpirationMonth(), 22 | request.getCardCvv() 23 | )) { 24 | throw new BusinessException(Messages.Payment.NotAValidPayment); 25 | } 26 | } 27 | 28 | public void checkIfCardExists(String cardNumber) { 29 | if (repository.existsByCardNumber(cardNumber)) { 30 | throw new BusinessException(Messages.Payment.CardNumberAlreadyExists); 31 | } 32 | } 33 | 34 | public void checkIfPaymentExists(int id) { 35 | if (repository.existsById(id)) { 36 | throw new BusinessException(Messages.Payment.NotFound); 37 | } 38 | } 39 | 40 | public void checkIfBalanceIsEnough(double price, double balance) { 41 | if (balance < price) { 42 | throw new BusinessException(Messages.Payment.NotEnoughMoney); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/common/constants/Messages.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.common.constants; 2 | 3 | public class Messages { 4 | public static class Car { 5 | public static final String NotExists = "CAR_NOT_EXISTS"; 6 | public static final String Exists = "CAR_ALREADY_EXISTS"; 7 | public static final String NotAvailable = "CAR_NOT_AVAILABLE"; 8 | } 9 | 10 | public static class Model { 11 | public static final String NotExists = "MODEL_NOT_EXISTS"; 12 | public static final String Exists = "MODEL_ALREADY_EXISTS"; 13 | } 14 | 15 | public static class Brand { 16 | public static final String NotExists = "BRAND_NOT_EXISTS"; 17 | public static final String Exists = "BRAND_ALREADY_EXISTS"; 18 | } 19 | 20 | public static class Maintenance { 21 | public static final String NotExists = "MAINTENANCE_NOT_EXISTS"; 22 | public static final String CarExists = "CAR_IS_CURRENTLY_UNDER_MAINTENANCE"; 23 | public static final String CarNotExists = "CAR_NOT_REGISTERED_FOR_MAINTENANCE"; 24 | public static final String CarIsRented = "CAR_IS_CURRENTLY_RENTED_AND_CANNOT_BE_SERVICED_FOR_MAINTENANCE"; 25 | } 26 | 27 | public static class Rental { 28 | public static final String NotExists = "RENTAL_NOT_EXISTS"; 29 | } 30 | 31 | public static class Payment { 32 | public static final String NotFound = "PAYMENT_NOT_FOUND"; 33 | public static final String CardNumberAlreadyExists = "CARD_NUMBER_ALREADY_EXISTS"; 34 | public static final String NotEnoughMoney = "NOT_ENOUGH_MONEY"; 35 | public static final String NotAValidPayment = "NOT_A_VALID_PAYMENT"; 36 | public static final String Failed = "PAYMENT_FAILED"; 37 | } 38 | 39 | public static class Invoice { 40 | public static final String NotFound = "INVOICE_NOT_FOUND"; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/api/controllers/RentalsController.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.api.controllers; 2 | 3 | 4 | import com.tahademiryol.rentacar.business.abstracts.RentalService; 5 | import com.tahademiryol.rentacar.business.dto.requests.create.CreateRentalRequest; 6 | import com.tahademiryol.rentacar.business.dto.requests.update.UpdateRentalRequest; 7 | import com.tahademiryol.rentacar.business.dto.responses.create.CreateRentalResponse; 8 | import com.tahademiryol.rentacar.business.dto.responses.get.Rental.GetAllRentalsResponse; 9 | import com.tahademiryol.rentacar.business.dto.responses.get.Rental.GetRentalResponse; 10 | import com.tahademiryol.rentacar.business.dto.responses.update.UpdateRentalResponse; 11 | import lombok.AllArgsConstructor; 12 | import org.springframework.http.HttpStatus; 13 | import org.springframework.web.bind.annotation.*; 14 | 15 | import java.util.List; 16 | 17 | @RestController 18 | @AllArgsConstructor 19 | @RequestMapping("/api/rentals") 20 | public class RentalsController { 21 | private final RentalService service; 22 | 23 | @GetMapping 24 | public List getAll() { 25 | return service.getAll(); 26 | } 27 | 28 | @GetMapping("/{id}") 29 | public GetRentalResponse getById(@PathVariable int id) { 30 | return service.getById(id); 31 | } 32 | 33 | @PostMapping 34 | @ResponseStatus(HttpStatus.CREATED) 35 | public CreateRentalResponse add(@RequestBody CreateRentalRequest request) { 36 | return service.add(request); 37 | } 38 | 39 | @PutMapping("/{id}") 40 | public UpdateRentalResponse update(@PathVariable int id, @RequestBody UpdateRentalRequest request) { 41 | return service.update(id, request); 42 | } 43 | 44 | @DeleteMapping("/{id}") 45 | @ResponseStatus(HttpStatus.NO_CONTENT) 46 | public void delete(@PathVariable int id) { 47 | service.delete(id); 48 | } 49 | } 50 | 51 | 52 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/api/controllers/ModelsController.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.api.controllers; 2 | 3 | import com.tahademiryol.rentacar.business.abstracts.ModelService; 4 | import com.tahademiryol.rentacar.business.dto.requests.create.CreateModelRequest; 5 | import com.tahademiryol.rentacar.business.dto.requests.update.UpdateModelRequest; 6 | import com.tahademiryol.rentacar.business.dto.responses.create.CreateModelResponse; 7 | import com.tahademiryol.rentacar.business.dto.responses.get.Car.GetAllCarsResponse; 8 | import com.tahademiryol.rentacar.business.dto.responses.get.Model.GetAllModelsResponse; 9 | import com.tahademiryol.rentacar.business.dto.responses.get.Model.GetModelResponse; 10 | import com.tahademiryol.rentacar.business.dto.responses.update.UpdateModelResponse; 11 | import lombok.AllArgsConstructor; 12 | import org.springframework.http.HttpStatus; 13 | import org.springframework.web.bind.annotation.*; 14 | 15 | import java.util.List; 16 | 17 | @RestController 18 | @AllArgsConstructor 19 | @RequestMapping("/api/models") 20 | public class ModelsController { 21 | private final ModelService service; 22 | 23 | @GetMapping 24 | public List getAll() { 25 | return service.getAll(); 26 | } 27 | 28 | @GetMapping("/{id}") 29 | public GetModelResponse getById(@PathVariable int id) { 30 | return service.getById(id); 31 | } 32 | 33 | @PostMapping 34 | @ResponseStatus(HttpStatus.CREATED) 35 | public CreateModelResponse add(@RequestBody CreateModelRequest request) { 36 | return service.add(request); 37 | } 38 | 39 | @PutMapping("/{id}") 40 | public UpdateModelResponse update(@PathVariable int id, @RequestBody UpdateModelRequest request) { 41 | return service.update(id, request); 42 | } 43 | 44 | @DeleteMapping("/{id}") 45 | @ResponseStatus(HttpStatus.NO_CONTENT) 46 | public void delete(@PathVariable int id) { 47 | service.delete(id); 48 | } 49 | 50 | @GetMapping("/cars-of-{id}") 51 | public List getModels(@PathVariable int id) { 52 | return service.showCars(id); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/api/controllers/BrandsController.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.api.controllers; 2 | 3 | import com.tahademiryol.rentacar.business.abstracts.BrandService; 4 | import com.tahademiryol.rentacar.business.dto.requests.create.CreateBrandRequest; 5 | import com.tahademiryol.rentacar.business.dto.requests.update.UpdateBrandRequest; 6 | import com.tahademiryol.rentacar.business.dto.responses.create.CreateBrandResponse; 7 | import com.tahademiryol.rentacar.business.dto.responses.get.Brand.GetAllBrandsResponse; 8 | import com.tahademiryol.rentacar.business.dto.responses.get.Brand.GetBrandResponse; 9 | import com.tahademiryol.rentacar.business.dto.responses.get.Model.GetAllModelsResponse; 10 | import com.tahademiryol.rentacar.business.dto.responses.update.UpdateBrandResponse; 11 | import lombok.AllArgsConstructor; 12 | import org.springframework.http.HttpStatus; 13 | import org.springframework.web.bind.annotation.*; 14 | 15 | import java.util.List; 16 | 17 | @RestController 18 | @AllArgsConstructor 19 | @RequestMapping("/api/brands") 20 | public class BrandsController { 21 | private final BrandService service; 22 | 23 | @GetMapping 24 | public List getAll() { 25 | return service.getAll(); 26 | } 27 | 28 | @GetMapping("/{id}") 29 | public GetBrandResponse getById(@PathVariable int id) { 30 | return service.getById(id); 31 | } 32 | 33 | @PostMapping 34 | @ResponseStatus(HttpStatus.CREATED) 35 | public CreateBrandResponse add(@RequestBody CreateBrandRequest request) { 36 | return service.add(request); 37 | } 38 | 39 | @PutMapping("/{id}") 40 | public UpdateBrandResponse update(@PathVariable int id, @RequestBody UpdateBrandRequest request) { 41 | return service.update(id, request); 42 | } 43 | 44 | @DeleteMapping("/{id}") 45 | @ResponseStatus(HttpStatus.NO_CONTENT) 46 | public void delete(@PathVariable int id) { 47 | service.delete(id); 48 | } 49 | 50 | @GetMapping("/models-of-{id}") 51 | public List getModels(@PathVariable int id) { 52 | return service.showModels(id); 53 | } 54 | 55 | 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/api/controllers/MaintenancesController.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.api.controllers; 2 | 3 | 4 | import com.tahademiryol.rentacar.business.abstracts.MaintenanceService; 5 | import com.tahademiryol.rentacar.business.dto.requests.create.CreateMaintenanceRequest; 6 | import com.tahademiryol.rentacar.business.dto.requests.update.UpdateMaintenanceRequest; 7 | import com.tahademiryol.rentacar.business.dto.responses.create.CreateMaintenanceResponse; 8 | import com.tahademiryol.rentacar.business.dto.responses.get.Maintenance.GetAllMaintenanceResponse; 9 | import com.tahademiryol.rentacar.business.dto.responses.get.Maintenance.GetMaintenanceResponse; 10 | import com.tahademiryol.rentacar.business.dto.responses.update.UpdateMaintenanceResponse; 11 | import lombok.AllArgsConstructor; 12 | import org.springframework.http.HttpStatus; 13 | import org.springframework.web.bind.annotation.*; 14 | 15 | import java.util.List; 16 | 17 | @RestController 18 | @AllArgsConstructor 19 | @RequestMapping("/api/maintenances") 20 | public class MaintenancesController { 21 | private final MaintenanceService service; 22 | 23 | @GetMapping 24 | public List getAll() { 25 | return service.getAll(); 26 | } 27 | 28 | @GetMapping("/{id}") 29 | public GetMaintenanceResponse getById(@PathVariable int id) { 30 | return service.getById(id); 31 | } 32 | 33 | @PostMapping 34 | @ResponseStatus(HttpStatus.CREATED) 35 | public CreateMaintenanceResponse add(@RequestBody CreateMaintenanceRequest request) { 36 | return service.add(request); 37 | } 38 | 39 | @PutMapping("/return") 40 | public GetMaintenanceResponse returnCarFromMaintenance(@RequestParam int carId) { 41 | return service.returnCarFromMaintenance(carId); 42 | } 43 | 44 | @PutMapping("/{id}") 45 | public UpdateMaintenanceResponse update(@PathVariable int id, @RequestBody UpdateMaintenanceRequest request) { 46 | return service.update(id, request); 47 | } 48 | 49 | @DeleteMapping("/{id}") 50 | @ResponseStatus(HttpStatus.NO_CONTENT) 51 | public void delete(@PathVariable int id) { 52 | service.delete(id); 53 | } 54 | } 55 | 56 | 57 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/api/controllers/CarsController.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.api.controllers; 2 | 3 | import com.tahademiryol.rentacar.business.abstracts.CarService; 4 | import com.tahademiryol.rentacar.business.dto.requests.create.CreateCarRequest; 5 | import com.tahademiryol.rentacar.business.dto.requests.update.UpdateCarRequest; 6 | import com.tahademiryol.rentacar.business.dto.responses.create.CreateCarResponse; 7 | import com.tahademiryol.rentacar.business.dto.responses.get.Car.GetAllCarsResponse; 8 | import com.tahademiryol.rentacar.business.dto.responses.get.Car.GetCarResponse; 9 | import com.tahademiryol.rentacar.business.dto.responses.get.Maintenance.GetAllMaintenanceResponse; 10 | import com.tahademiryol.rentacar.business.dto.responses.update.UpdateCarResponse; 11 | import jakarta.validation.Valid; 12 | import lombok.AllArgsConstructor; 13 | import org.springframework.http.HttpStatus; 14 | import org.springframework.web.bind.annotation.*; 15 | 16 | import java.util.List; 17 | 18 | @RestController 19 | @AllArgsConstructor 20 | @RequestMapping("/api/cars") 21 | public class CarsController { 22 | private final CarService service; 23 | 24 | @GetMapping 25 | public List getAll(@RequestParam(defaultValue = "false") boolean includeMaintenance) { 26 | return service.getAll(includeMaintenance); 27 | } 28 | 29 | @GetMapping("/{id}") 30 | public GetCarResponse getById(@PathVariable int id) { 31 | return service.getById(id); 32 | } 33 | 34 | @PostMapping 35 | @ResponseStatus(HttpStatus.CREATED) 36 | public CreateCarResponse add(@Valid @RequestBody CreateCarRequest request) { 37 | return service.add(request); 38 | } 39 | 40 | @PutMapping("/{id}") 41 | public UpdateCarResponse update(@PathVariable int id, @Valid @RequestBody UpdateCarRequest request) { 42 | return service.update(id, request); 43 | } 44 | 45 | @DeleteMapping("/{id}") 46 | @ResponseStatus(HttpStatus.NO_CONTENT) 47 | public void delete(@PathVariable int id) { 48 | service.delete(id); 49 | } 50 | 51 | @GetMapping("/maintenances-of-{id}") 52 | public List getModels(@PathVariable int id) { 53 | return service.showMaintenances(id); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/core/configuration/exceptions/RestExceptionHandler.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.core.configuration.exceptions; 2 | 3 | import com.tahademiryol.rentacar.common.constants.ExceptionTypes; 4 | import com.tahademiryol.rentacar.core.exceptions.BusinessException; 5 | import com.tahademiryol.rentacar.core.utils.results.ExceptionResult; 6 | import jakarta.validation.ValidationException; 7 | import org.springframework.dao.DataIntegrityViolationException; 8 | import org.springframework.http.HttpStatus; 9 | import org.springframework.web.bind.MethodArgumentNotValidException; 10 | import org.springframework.web.bind.annotation.ExceptionHandler; 11 | import org.springframework.web.bind.annotation.ResponseStatus; 12 | import org.springframework.web.bind.annotation.RestControllerAdvice; 13 | 14 | import java.util.Map; 15 | 16 | @RestControllerAdvice 17 | public class RestExceptionHandler { 18 | 19 | @ExceptionHandler 20 | @ResponseStatus(HttpStatus.BAD_REQUEST) // 400 21 | public ExceptionResult handleMethodArgumentNotValidException(MethodArgumentNotValidException exception) { 22 | Map validationErrors = exception.getBindingResult().getFieldErrors().stream() 23 | .collect( 24 | java.util.stream.Collectors.toMap( 25 | fieldError -> fieldError.getField(), 26 | fieldError -> fieldError.getDefaultMessage() 27 | ) 28 | ); 29 | return new ExceptionResult<>(ExceptionTypes.Exception.Validation, validationErrors); 30 | } 31 | 32 | @ExceptionHandler 33 | @ResponseStatus(HttpStatus.UNPROCESSABLE_ENTITY) // 422 34 | public ExceptionResult handleValidationException(ValidationException exception) { 35 | return new ExceptionResult<>(ExceptionTypes.Exception.Validation, exception.getMessage()); 36 | } 37 | 38 | @ExceptionHandler 39 | @ResponseStatus(HttpStatus.UNPROCESSABLE_ENTITY) // 422 40 | public ExceptionResult handleBusinessException(BusinessException exception) { 41 | return new ExceptionResult<>(ExceptionTypes.Exception.Business, exception.getMessage()); 42 | } 43 | 44 | @ExceptionHandler 45 | @ResponseStatus(HttpStatus.CONFLICT) // 409 46 | public ExceptionResult handleDataIntegrityViolationException(DataIntegrityViolationException exception) { 47 | return new ExceptionResult<>(ExceptionTypes.Exception.DataIntegrityViolation, exception.getMessage()); 48 | } 49 | 50 | @ExceptionHandler 51 | @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) // 500 52 | public ExceptionResult handleRuntimeException(RuntimeException exception) { 53 | return new ExceptionResult<>(ExceptionTypes.Exception.Runtime, exception.getMessage()); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/business/concretes/InvoiceManager.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.business.concretes; 2 | 3 | import com.tahademiryol.rentacar.business.abstracts.InvoiceService; 4 | import com.tahademiryol.rentacar.business.dto.requests.create.CreateInvoiceRequest; 5 | import com.tahademiryol.rentacar.business.dto.requests.update.UpdateInvoiceRequest; 6 | import com.tahademiryol.rentacar.business.dto.responses.create.CreateInvoiceResponse; 7 | import com.tahademiryol.rentacar.business.dto.responses.get.Invoice.GetAllInvoicesResponse; 8 | import com.tahademiryol.rentacar.business.dto.responses.get.Invoice.GetInvoiceResponse; 9 | import com.tahademiryol.rentacar.business.dto.responses.update.UpdateInvoiceResponse; 10 | import com.tahademiryol.rentacar.business.rules.InvoiceBusinessRules; 11 | import com.tahademiryol.rentacar.entities.concretes.Invoice; 12 | import com.tahademiryol.rentacar.repository.abstracts.InvoiceRepository; 13 | import lombok.AllArgsConstructor; 14 | import org.modelmapper.ModelMapper; 15 | import org.springframework.stereotype.Service; 16 | 17 | import java.util.List; 18 | 19 | @Service 20 | @AllArgsConstructor 21 | public class InvoiceManager implements InvoiceService { 22 | private final InvoiceRepository repository; 23 | private final ModelMapper mapper; 24 | private final InvoiceBusinessRules rules; 25 | 26 | @Override 27 | public List getAll() { 28 | 29 | return repository.findAll().stream() 30 | .map(invoice -> mapper.map(invoice, GetAllInvoicesResponse.class)) 31 | .toList(); 32 | } 33 | 34 | @Override 35 | public GetInvoiceResponse getById(int id) { 36 | Invoice invoice = repository.findById(id).orElseThrow(); 37 | return mapper.map(invoice, GetInvoiceResponse.class); 38 | } 39 | 40 | @Override 41 | public CreateInvoiceResponse add(CreateInvoiceRequest request) { 42 | Invoice invoice = mapper.map(request, Invoice.class); 43 | invoice.setId(0); 44 | invoice.setTotalPrice(getTotalPrice(invoice)); 45 | repository.save(invoice); 46 | return mapper.map(invoice, CreateInvoiceResponse.class); 47 | } 48 | 49 | @Override 50 | public UpdateInvoiceResponse update(int id, UpdateInvoiceRequest request) { 51 | rules.checkIfInvoiceExist(id); 52 | Invoice invoice = mapper.map(request, Invoice.class); 53 | invoice.setId(id); 54 | repository.save(invoice); 55 | 56 | return mapper.map(invoice, UpdateInvoiceResponse.class); 57 | } 58 | 59 | @Override 60 | public void delete(int id) { 61 | rules.checkIfInvoiceExist(id); 62 | ; 63 | repository.deleteById(id); 64 | 65 | } 66 | 67 | 68 | private double getTotalPrice(Invoice invoice) { 69 | return invoice.getDailyPrice() * invoice.getRentedForDays(); 70 | } 71 | 72 | 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/business/concretes/ModelManager.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.business.concretes; 2 | 3 | import com.tahademiryol.rentacar.business.abstracts.ModelService; 4 | import com.tahademiryol.rentacar.business.dto.requests.create.CreateModelRequest; 5 | import com.tahademiryol.rentacar.business.dto.requests.update.UpdateModelRequest; 6 | import com.tahademiryol.rentacar.business.dto.responses.create.CreateModelResponse; 7 | import com.tahademiryol.rentacar.business.dto.responses.get.Car.GetAllCarsResponse; 8 | import com.tahademiryol.rentacar.business.dto.responses.get.Model.GetAllModelsResponse; 9 | import com.tahademiryol.rentacar.business.dto.responses.get.Model.GetModelResponse; 10 | import com.tahademiryol.rentacar.business.dto.responses.update.UpdateModelResponse; 11 | import com.tahademiryol.rentacar.business.rules.ModelBusinessRules; 12 | import com.tahademiryol.rentacar.entities.concretes.Model; 13 | import com.tahademiryol.rentacar.repository.abstracts.ModelRepository; 14 | import lombok.AllArgsConstructor; 15 | import org.modelmapper.ModelMapper; 16 | import org.springframework.stereotype.Service; 17 | 18 | import java.util.List; 19 | 20 | 21 | @Service 22 | @AllArgsConstructor 23 | public class ModelManager implements ModelService { 24 | private final ModelRepository repository; 25 | private final ModelMapper mapper; 26 | private final ModelBusinessRules rules; 27 | 28 | @Override 29 | public List getAll() { 30 | List models = repository.findAll(); 31 | 32 | return models 33 | .stream() 34 | .map(model -> mapper.map(model, GetAllModelsResponse.class)) 35 | .toList(); 36 | } 37 | 38 | @Override 39 | public GetModelResponse getById(int id) { 40 | rules.checkIfModelExists(id); 41 | Model model = repository.findById(id).orElseThrow(); 42 | return mapper.map(model, GetModelResponse.class); 43 | } 44 | 45 | @Override 46 | public CreateModelResponse add(CreateModelRequest request) { 47 | rules.checkIfModelExistsByName(request.getName()); 48 | Model model = mapper.map(request, Model.class); 49 | model.setId(0); 50 | repository.save(model); 51 | return mapper.map(model, CreateModelResponse.class); 52 | } 53 | 54 | @Override 55 | public UpdateModelResponse update(int id, UpdateModelRequest request) { 56 | rules.checkIfModelExists(id); 57 | Model model = mapper.map(request, Model.class); 58 | model.setId(id); 59 | repository.save(model); 60 | return mapper.map(model, UpdateModelResponse.class); 61 | 62 | } 63 | 64 | 65 | @Override 66 | public void delete(int id) { 67 | rules.checkIfModelExists(id); 68 | repository.deleteById(id); 69 | } 70 | 71 | @Override 72 | public List showCars(int id) { 73 | Model model = repository.findById(id).orElseThrow(); 74 | return model.getCars().stream() 75 | .map(car -> mapper.map(car, GetAllCarsResponse.class)).toList(); 76 | } 77 | 78 | 79 | } 80 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/business/concretes/PaymentManager.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.business.concretes; 2 | 3 | import com.tahademiryol.rentacar.adapters.FakePosServiceAdapter; 4 | import com.tahademiryol.rentacar.business.abstracts.PaymentService; 5 | import com.tahademiryol.rentacar.business.dto.requests.create.CreatePaymentRequest; 6 | import com.tahademiryol.rentacar.business.dto.requests.update.UpdatePaymentRequest; 7 | import com.tahademiryol.rentacar.business.dto.responses.create.CreatePaymentResponse; 8 | import com.tahademiryol.rentacar.business.dto.responses.get.Payment.GetAllPaymentsResponse; 9 | import com.tahademiryol.rentacar.business.dto.responses.get.Payment.GetPaymentResponse; 10 | import com.tahademiryol.rentacar.business.dto.responses.update.UpdatePaymentResponse; 11 | import com.tahademiryol.rentacar.business.rules.PaymentBusinessRules; 12 | import com.tahademiryol.rentacar.common.dto.CreateRentalPaymentRequest; 13 | import com.tahademiryol.rentacar.entities.concretes.Payment; 14 | import com.tahademiryol.rentacar.repository.abstracts.PaymentRepository; 15 | import lombok.AllArgsConstructor; 16 | import org.modelmapper.ModelMapper; 17 | import org.springframework.stereotype.Service; 18 | 19 | import java.util.List; 20 | 21 | @Service 22 | @AllArgsConstructor 23 | public class PaymentManager implements PaymentService { 24 | private final PaymentRepository repository; 25 | private final ModelMapper mapper; 26 | private final FakePosServiceAdapter fakePosServiceAdapter; 27 | private final PaymentBusinessRules rules; 28 | 29 | @Override 30 | public List getAll() { 31 | List payments = repository.findAll(); 32 | return payments.stream().map(payment -> mapper.map(payment, GetAllPaymentsResponse.class)).toList(); 33 | } 34 | 35 | @Override 36 | public GetPaymentResponse getById(int id) { 37 | Payment payment = repository.findById(id).orElseThrow(); 38 | return mapper.map(payment, GetPaymentResponse.class); 39 | 40 | } 41 | 42 | @Override 43 | public CreatePaymentResponse add(CreatePaymentRequest request) { 44 | rules.checkIfCardExists(request.getCardNumber()); 45 | Payment payment = mapper.map(request, Payment.class); 46 | payment.setId(0); 47 | repository.save(payment); 48 | return mapper.map(payment, CreatePaymentResponse.class); 49 | } 50 | 51 | @Override 52 | public UpdatePaymentResponse update(int id, UpdatePaymentRequest request) { 53 | Payment payment = mapper.map(request, Payment.class); 54 | payment.setId(id); 55 | repository.save(payment); 56 | return mapper.map(payment, UpdatePaymentResponse.class); 57 | } 58 | 59 | @Override 60 | public void delete(int id) { 61 | rules.checkIfPaymentExists(id); 62 | repository.deleteById(id); 63 | } 64 | 65 | @Override 66 | public void processRentalPayment(CreateRentalPaymentRequest request) { 67 | rules.checkIfPaymentIsValid(request); 68 | Payment payment = repository.findByCardNumber(request.getCardNumber()); 69 | rules.checkIfBalanceIsEnough(request.getPrice(), payment.getBalance()); 70 | //fake pos service 71 | fakePosServiceAdapter.pay(); 72 | payment.setBalance(payment.getBalance() - request.getPrice()); 73 | repository.save(payment); 74 | } 75 | 76 | 77 | } 78 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/business/concretes/BrandManager.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.business.concretes; 2 | 3 | import com.tahademiryol.rentacar.business.abstracts.BrandService; 4 | import com.tahademiryol.rentacar.business.dto.requests.create.CreateBrandRequest; 5 | import com.tahademiryol.rentacar.business.dto.requests.update.UpdateBrandRequest; 6 | import com.tahademiryol.rentacar.business.dto.responses.create.CreateBrandResponse; 7 | import com.tahademiryol.rentacar.business.dto.responses.get.Brand.GetAllBrandsResponse; 8 | import com.tahademiryol.rentacar.business.dto.responses.get.Brand.GetBrandResponse; 9 | import com.tahademiryol.rentacar.business.dto.responses.get.Model.GetAllModelsResponse; 10 | import com.tahademiryol.rentacar.business.dto.responses.update.UpdateBrandResponse; 11 | import com.tahademiryol.rentacar.business.rules.BrandBusinessRules; 12 | import com.tahademiryol.rentacar.entities.concretes.Brand; 13 | import com.tahademiryol.rentacar.repository.abstracts.BrandRepository; 14 | import lombok.AllArgsConstructor; 15 | import org.modelmapper.ModelMapper; 16 | import org.springframework.cache.annotation.CacheEvict; 17 | import org.springframework.cache.annotation.Cacheable; 18 | import org.springframework.stereotype.Service; 19 | 20 | import java.util.List; 21 | 22 | 23 | @Service 24 | @AllArgsConstructor 25 | public class BrandManager implements BrandService { 26 | private final BrandRepository repository; 27 | private final ModelMapper mapper; 28 | private final BrandBusinessRules rules; 29 | 30 | @Override 31 | @Cacheable(value = "brand_list") 32 | public List getAll() { 33 | List brands = repository.findAll(); 34 | 35 | return brands.stream().map(brand -> mapper.map(brand, GetAllBrandsResponse.class)).toList(); 36 | } 37 | 38 | @Override 39 | public GetBrandResponse getById(int id) { 40 | rules.checkIfBrandExists(id); 41 | Brand brand = repository.findById(id).orElseThrow(); 42 | return mapper.map(brand, GetBrandResponse.class); 43 | } 44 | 45 | @Override 46 | @CacheEvict(value = "brand_list", allEntries = true) 47 | public CreateBrandResponse add(CreateBrandRequest request) { 48 | rules.checkIfBrandExistsByName(request.getName()); 49 | // Brand brand = new Brand(); 50 | // brand.setName(requests.getName()); 51 | // repository.save(brand); 52 | // 53 | // CreateBrandResponse responses = new CreateBrandResponse(); 54 | // responses.setId(brand.getId()); 55 | // responses.setName(brand.getName()); 56 | // 57 | // return responses; 58 | Brand brand = mapper.map(request, Brand.class); 59 | brand.setId(0); 60 | repository.save(brand); 61 | return mapper.map(brand, CreateBrandResponse.class); 62 | } 63 | 64 | @Override 65 | public UpdateBrandResponse update(int id, UpdateBrandRequest request) { 66 | rules.checkIfBrandExists(id); 67 | Brand brand = mapper.map(request, Brand.class); 68 | brand.setId(id); 69 | repository.save(brand); 70 | return mapper.map(brand, UpdateBrandResponse.class); 71 | } 72 | 73 | @Override 74 | public void delete(int id) { 75 | rules.checkIfBrandExists(id); 76 | repository.deleteById(id); 77 | } 78 | 79 | 80 | @Override 81 | public List showModels(int id) { 82 | Brand brand = repository.findById(id).orElseThrow(); 83 | return brand.getModels().stream().map(model -> mapper.map(model, GetAllModelsResponse.class)).toList(); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 3.0.4 9 | 10 | 11 | com.tahademiryol 12 | rent-a-car 13 | 0.0.1-SNAPSHOT 14 | rent-a-car 15 | rent-a-car 16 | 17 | 17 18 | 19 | 20 | 21 | org.springframework.boot 22 | spring-boot-starter-data-jpa 23 | 24 | 25 | org.springframework.boot 26 | spring-boot-starter-validation 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter-web 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-devtools 35 | runtime 36 | true 37 | 38 | 39 | org.postgresql 40 | postgresql 41 | runtime 42 | 43 | 44 | org.projectlombok 45 | lombok 46 | true 47 | 48 | 49 | org.springframework.boot 50 | spring-boot-starter-test 51 | test 52 | 53 | 54 | org.springdoc 55 | springdoc-openapi-starter-webmvc-ui 56 | 2.0.4 57 | 58 | 59 | org.modelmapper 60 | modelmapper 61 | 3.1.1 62 | 63 | 64 | 65 | jakarta.validation 66 | jakarta.validation-api 67 | 3.0.2 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | org.springframework.boot 77 | spring-boot-maven-plugin 78 | 79 | 80 | 81 | org.projectlombok 82 | lombok 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/business/concretes/CarManager.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.business.concretes; 2 | 3 | import com.tahademiryol.rentacar.business.abstracts.CarService; 4 | import com.tahademiryol.rentacar.business.dto.requests.create.CreateCarRequest; 5 | import com.tahademiryol.rentacar.business.dto.requests.update.UpdateCarRequest; 6 | import com.tahademiryol.rentacar.business.dto.responses.create.CreateCarResponse; 7 | import com.tahademiryol.rentacar.business.dto.responses.get.Car.GetAllCarsResponse; 8 | import com.tahademiryol.rentacar.business.dto.responses.get.Car.GetCarResponse; 9 | import com.tahademiryol.rentacar.business.dto.responses.get.Maintenance.GetAllMaintenanceResponse; 10 | import com.tahademiryol.rentacar.business.dto.responses.update.UpdateCarResponse; 11 | import com.tahademiryol.rentacar.business.rules.CarBusinessRules; 12 | import com.tahademiryol.rentacar.entities.concretes.Car; 13 | import com.tahademiryol.rentacar.entities.enums.State; 14 | import com.tahademiryol.rentacar.repository.abstracts.CarRepository; 15 | import lombok.AllArgsConstructor; 16 | import org.modelmapper.ModelMapper; 17 | import org.springframework.stereotype.Service; 18 | 19 | import java.util.List; 20 | 21 | 22 | @Service 23 | @AllArgsConstructor 24 | public class CarManager implements CarService { 25 | private final CarRepository repository; 26 | private final ModelMapper mapper; 27 | private final CarBusinessRules rules; 28 | 29 | 30 | @Override 31 | public List getAll(boolean includeMaintenance) { 32 | List cars = filterCarsByMaintenanceState(includeMaintenance); 33 | 34 | return cars 35 | .stream() 36 | .map(car -> mapper.map(car, GetAllCarsResponse.class)) 37 | .toList(); 38 | } 39 | 40 | @Override 41 | public GetCarResponse getById(int id) { 42 | rules.checkIfCarExists(id); 43 | Car car = repository.findById(id).orElseThrow(); 44 | return mapper.map(car, GetCarResponse.class); 45 | } 46 | 47 | @Override 48 | public CreateCarResponse add(CreateCarRequest request) { 49 | Car car = mapper.map(request, Car.class); 50 | car.setId(0); 51 | car.setState(State.AVAILABLE); 52 | repository.save(car); 53 | return mapper.map(car, CreateCarResponse.class); 54 | } 55 | 56 | @Override 57 | public UpdateCarResponse update(int id, UpdateCarRequest request) { 58 | rules.checkIfCarExists(id); 59 | Car car = mapper.map(request, Car.class); 60 | car.setId(id); 61 | repository.save(car); 62 | return mapper.map(car, UpdateCarResponse.class); 63 | 64 | } 65 | 66 | @Override 67 | public void delete(int id) { 68 | rules.checkIfCarExists(id); 69 | repository.deleteById(id); 70 | } 71 | 72 | 73 | @Override 74 | public List showMaintenances(int id) { 75 | Car car = repository.findById(id).orElseThrow(); 76 | return car.getMaintenances().stream() 77 | .map(maintenance -> mapper.map(maintenance, GetAllMaintenanceResponse.class)).toList(); 78 | } 79 | 80 | 81 | @Override 82 | public void changeState(int carId, State state) { 83 | Car car = repository.findById(carId).orElseThrow(); 84 | car.setState(state); 85 | repository.save(car); 86 | } 87 | 88 | 89 | private List filterCarsByMaintenanceState(boolean includeMaintenance) { 90 | if (includeMaintenance) 91 | return repository.findAll(); 92 | return repository.findAllByStateIsNot(State.MAINTENANCE); 93 | } 94 | 95 | } 96 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/business/concretes/MaintenanceManager.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.business.concretes; 2 | 3 | import com.tahademiryol.rentacar.business.abstracts.CarService; 4 | import com.tahademiryol.rentacar.business.abstracts.MaintenanceService; 5 | import com.tahademiryol.rentacar.business.dto.requests.create.CreateMaintenanceRequest; 6 | import com.tahademiryol.rentacar.business.dto.requests.update.UpdateMaintenanceRequest; 7 | import com.tahademiryol.rentacar.business.dto.responses.create.CreateMaintenanceResponse; 8 | import com.tahademiryol.rentacar.business.dto.responses.get.Maintenance.GetAllMaintenanceResponse; 9 | import com.tahademiryol.rentacar.business.dto.responses.get.Maintenance.GetMaintenanceResponse; 10 | import com.tahademiryol.rentacar.business.dto.responses.update.UpdateMaintenanceResponse; 11 | import com.tahademiryol.rentacar.business.rules.MaintenanceBusinessRules; 12 | import com.tahademiryol.rentacar.entities.concretes.Maintenance; 13 | import com.tahademiryol.rentacar.entities.enums.State; 14 | import com.tahademiryol.rentacar.repository.abstracts.MaintenanceRepository; 15 | import lombok.AllArgsConstructor; 16 | import org.modelmapper.ModelMapper; 17 | import org.springframework.stereotype.Service; 18 | 19 | import java.time.LocalDateTime; 20 | import java.util.List; 21 | 22 | @Service 23 | @AllArgsConstructor 24 | public class MaintenanceManager implements MaintenanceService { 25 | private final MaintenanceRepository repository; 26 | private final ModelMapper mapper; 27 | private final CarService carService; 28 | private final MaintenanceBusinessRules rules; 29 | 30 | @Override 31 | public List getAll() { 32 | List maintenances = repository.findAll(); 33 | return maintenances 34 | .stream() 35 | .map(maintenance -> mapper.map(maintenance, GetAllMaintenanceResponse.class)) 36 | .toList(); 37 | } 38 | 39 | @Override 40 | public GetMaintenanceResponse getById(int id) { 41 | rules.checkIfMaintenanceExist(id); 42 | Maintenance maintenance = repository.findById(id).orElseThrow(); 43 | return mapper.map(maintenance, GetMaintenanceResponse.class); 44 | } 45 | 46 | @Override 47 | public GetMaintenanceResponse returnCarFromMaintenance(int carId) { 48 | rules.checkIfCarIsNotUnderMaintenance(carId); 49 | Maintenance maintenance = repository.findMaintenanceByCarIdAndIsCompletedFalse(carId); 50 | maintenance.setCompleted(true); 51 | maintenance.setEndDate(LocalDateTime.now()); 52 | repository.save(maintenance); 53 | carService.changeState(carId, State.AVAILABLE); 54 | 55 | return mapper.map(maintenance, GetMaintenanceResponse.class); 56 | } 57 | 58 | @Override 59 | public CreateMaintenanceResponse add(CreateMaintenanceRequest request) { 60 | rules.checkCarAvailabilityForMaintenance(carService.getById(request.getCarId()).getState()); 61 | rules.checkIfCarUnderMaintenance(request.getCarId()); 62 | Maintenance maintenance = mapper.map(request, Maintenance.class); 63 | maintenance.setId(0); 64 | maintenance.setCompleted(false); 65 | maintenance.setStartDate(LocalDateTime.now()); 66 | maintenance.setEndDate(null); 67 | 68 | carService.changeState(request.getCarId(), State.MAINTENANCE); 69 | repository.save(maintenance); 70 | 71 | return mapper.map(maintenance, CreateMaintenanceResponse.class); 72 | } 73 | 74 | @Override 75 | public UpdateMaintenanceResponse update(int id, UpdateMaintenanceRequest request) { 76 | rules.checkIfMaintenanceExist(id); 77 | Maintenance maintenance = mapper.map(request, Maintenance.class); 78 | maintenance.setId(id); 79 | repository.save(maintenance); 80 | 81 | return mapper.map(maintenance, UpdateMaintenanceResponse.class); 82 | } 83 | 84 | @Override 85 | public void delete(int id) { 86 | rules.checkIfMaintenanceExist(id); 87 | makeCarAvailableIfIsCompletedFalse(id); 88 | repository.deleteById(id); 89 | 90 | } 91 | 92 | 93 | private void makeCarAvailableIfIsCompletedFalse(int id) { 94 | int carId = repository.findById(id).get().getCar().getId(); 95 | if (repository.existsByCarIdAndIsCompletedFalse(carId)) 96 | carService.changeState(carId, State.AVAILABLE); 97 | } 98 | } 99 | 100 | -------------------------------------------------------------------------------- /src/main/java/com/tahademiryol/rentacar/business/concretes/RentalManager.java: -------------------------------------------------------------------------------- 1 | package com.tahademiryol.rentacar.business.concretes; 2 | 3 | import com.tahademiryol.rentacar.business.abstracts.CarService; 4 | import com.tahademiryol.rentacar.business.abstracts.InvoiceService; 5 | import com.tahademiryol.rentacar.business.abstracts.PaymentService; 6 | import com.tahademiryol.rentacar.business.abstracts.RentalService; 7 | import com.tahademiryol.rentacar.business.dto.requests.create.CreateInvoiceRequest; 8 | import com.tahademiryol.rentacar.business.dto.requests.create.CreateRentalRequest; 9 | import com.tahademiryol.rentacar.business.dto.requests.update.UpdateRentalRequest; 10 | import com.tahademiryol.rentacar.business.dto.responses.create.CreateRentalResponse; 11 | import com.tahademiryol.rentacar.business.dto.responses.get.Car.GetCarResponse; 12 | import com.tahademiryol.rentacar.business.dto.responses.get.Rental.GetAllRentalsResponse; 13 | import com.tahademiryol.rentacar.business.dto.responses.get.Rental.GetRentalResponse; 14 | import com.tahademiryol.rentacar.business.dto.responses.update.UpdateRentalResponse; 15 | import com.tahademiryol.rentacar.business.rules.RentalBusinessRules; 16 | import com.tahademiryol.rentacar.common.dto.CreateRentalPaymentRequest; 17 | import com.tahademiryol.rentacar.entities.concretes.Rental; 18 | import com.tahademiryol.rentacar.entities.enums.State; 19 | import com.tahademiryol.rentacar.repository.abstracts.RentalRepository; 20 | import lombok.AllArgsConstructor; 21 | import org.modelmapper.ModelMapper; 22 | import org.springframework.stereotype.Service; 23 | 24 | import java.time.LocalDateTime; 25 | import java.util.List; 26 | 27 | @Service 28 | @AllArgsConstructor 29 | public class RentalManager implements RentalService { 30 | private final RentalRepository repository; 31 | private final ModelMapper mapper; 32 | private final CarService carService; 33 | private final PaymentService paymentService; 34 | private final InvoiceService invoiceService; 35 | private final RentalBusinessRules rules; 36 | 37 | @Override 38 | public List getAll() { 39 | List rentals = repository.findAll(); 40 | 41 | return rentals 42 | .stream() 43 | .map(rental -> mapper.map(rental, GetAllRentalsResponse.class)) 44 | .toList(); 45 | } 46 | 47 | @Override 48 | public GetRentalResponse getById(int id) { 49 | rules.checkIfRentalExists(id); 50 | Rental rental = repository.findById(id).orElseThrow(); 51 | 52 | return mapper.map(rental, GetRentalResponse.class); 53 | } 54 | 55 | @Override 56 | public CreateRentalResponse add(CreateRentalRequest request) { 57 | rules.checkIfCarAvailable(carService.getById(request.getCarId()).getState()); 58 | Rental rental = mapper.map(request, Rental.class); 59 | rental.setId(0); 60 | rental.setTotalPrice(getTotalPrice(rental)); 61 | rental.setStartDate(LocalDateTime.now()); 62 | 63 | //Payment Create 64 | CreateRentalPaymentRequest paymentRequest = new CreateRentalPaymentRequest(); 65 | mapper.map(request.getPaymentRequest(), paymentRequest); 66 | paymentRequest.setPrice(getTotalPrice(rental)); 67 | paymentService.processRentalPayment(paymentRequest); 68 | 69 | repository.save(rental); 70 | carService.changeState(rental.getCar().getId(), State.RENTED); 71 | 72 | //Invoice Create 73 | CreateInvoiceRequest invoiceRequest = new CreateInvoiceRequest(); 74 | createInvoiceRequest(request, invoiceRequest, rental); 75 | invoiceService.add(invoiceRequest); 76 | 77 | return mapper.map(rental, CreateRentalResponse.class); 78 | } 79 | 80 | 81 | @Override 82 | public UpdateRentalResponse update(int id, UpdateRentalRequest request) { 83 | rules.checkIfRentalExists(id); 84 | Rental rental = mapper.map(request, Rental.class); 85 | rental.setId(id); 86 | rental.setTotalPrice(getTotalPrice(rental)); 87 | repository.save(rental); 88 | return mapper.map(rental, UpdateRentalResponse.class); 89 | } 90 | 91 | @Override 92 | public void delete(int id) { 93 | rules.checkIfRentalExists(id); 94 | int carId = repository.findById(id).get().getCar().getId(); 95 | carService.changeState(carId, State.AVAILABLE); 96 | repository.deleteById(id); 97 | } 98 | 99 | 100 | public double getTotalPrice(Rental rental) { 101 | return rental.getDailyPrice() * rental.getRentedForDays(); 102 | } 103 | 104 | private void createInvoiceRequest(CreateRentalRequest request, CreateInvoiceRequest invoiceRequest, Rental rental) { 105 | GetCarResponse car = carService.getById(request.getCarId()); 106 | 107 | invoiceRequest.setRentedAt(rental.getStartDate()); 108 | invoiceRequest.setModelName(car.getModelName()); 109 | invoiceRequest.setBrandName(car.getModelBrandName()); 110 | invoiceRequest.setDailyPrice(request.getDailyPrice()); 111 | invoiceRequest.setPlate(car.getPlate()); 112 | invoiceRequest.setCardHolder(request.getPaymentRequest().getCardHolder()); 113 | invoiceRequest.setModelYear(car.getModelYear()); 114 | invoiceRequest.setRentedForDays(request.getRentedForDays()); 115 | } 116 | 117 | 118 | } 119 | -------------------------------------------------------------------------------- /mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM https://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM set title of command window 39 | title %0 40 | @REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' 41 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 42 | 43 | @REM set %HOME% to equivalent of $HOME 44 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 45 | 46 | @REM Execute a user defined script before this one 47 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 48 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 49 | if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %* 50 | if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %* 51 | :skipRcPre 52 | 53 | @setlocal 54 | 55 | set ERROR_CODE=0 56 | 57 | @REM To isolate internal variables from possible post scripts, we use another setlocal 58 | @setlocal 59 | 60 | @REM ==== START VALIDATION ==== 61 | if not "%JAVA_HOME%" == "" goto OkJHome 62 | 63 | echo. 64 | echo Error: JAVA_HOME not found in your environment. >&2 65 | echo Please set the JAVA_HOME variable in your environment to match the >&2 66 | echo location of your Java installation. >&2 67 | echo. 68 | goto error 69 | 70 | :OkJHome 71 | if exist "%JAVA_HOME%\bin\java.exe" goto init 72 | 73 | echo. 74 | echo Error: JAVA_HOME is set to an invalid directory. >&2 75 | echo JAVA_HOME = "%JAVA_HOME%" >&2 76 | echo Please set the JAVA_HOME variable in your environment to match the >&2 77 | echo location of your Java installation. >&2 78 | echo. 79 | goto error 80 | 81 | @REM ==== END VALIDATION ==== 82 | 83 | :init 84 | 85 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 86 | @REM Fallback to current working directory if not found. 87 | 88 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 89 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 90 | 91 | set EXEC_DIR=%CD% 92 | set WDIR=%EXEC_DIR% 93 | :findBaseDir 94 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 95 | cd .. 96 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 97 | set WDIR=%CD% 98 | goto findBaseDir 99 | 100 | :baseDirFound 101 | set MAVEN_PROJECTBASEDIR=%WDIR% 102 | cd "%EXEC_DIR%" 103 | goto endDetectBaseDir 104 | 105 | :baseDirNotFound 106 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 107 | cd "%EXEC_DIR%" 108 | 109 | :endDetectBaseDir 110 | 111 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 112 | 113 | @setlocal EnableExtensions EnableDelayedExpansion 114 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 115 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 116 | 117 | :endReadAdditionalConfig 118 | 119 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 120 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 121 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 122 | 123 | set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" 124 | 125 | FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( 126 | IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B 127 | ) 128 | 129 | @REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 130 | @REM This allows using the maven wrapper in projects that prohibit checking in binary data. 131 | if exist %WRAPPER_JAR% ( 132 | if "%MVNW_VERBOSE%" == "true" ( 133 | echo Found %WRAPPER_JAR% 134 | ) 135 | ) else ( 136 | if not "%MVNW_REPOURL%" == "" ( 137 | SET DOWNLOAD_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" 138 | ) 139 | if "%MVNW_VERBOSE%" == "true" ( 140 | echo Couldn't find %WRAPPER_JAR%, downloading it ... 141 | echo Downloading from: %DOWNLOAD_URL% 142 | ) 143 | 144 | powershell -Command "&{"^ 145 | "$webclient = new-object System.Net.WebClient;"^ 146 | "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ 147 | "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ 148 | "}"^ 149 | "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ 150 | "}" 151 | if "%MVNW_VERBOSE%" == "true" ( 152 | echo Finished downloading %WRAPPER_JAR% 153 | ) 154 | ) 155 | @REM End of extension 156 | 157 | @REM Provide a "standardized" way to retrieve the CLI args that will 158 | @REM work with both Windows and non-Windows executions. 159 | set MAVEN_CMD_LINE_ARGS=%* 160 | 161 | %MAVEN_JAVA_EXE% ^ 162 | %JVM_CONFIG_MAVEN_PROPS% ^ 163 | %MAVEN_OPTS% ^ 164 | %MAVEN_DEBUG_OPTS% ^ 165 | -classpath %WRAPPER_JAR% ^ 166 | "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^ 167 | %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 168 | if ERRORLEVEL 1 goto error 169 | goto end 170 | 171 | :error 172 | set ERROR_CODE=1 173 | 174 | :end 175 | @endlocal & set ERROR_CODE=%ERROR_CODE% 176 | 177 | if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost 178 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 179 | if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat" 180 | if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd" 181 | :skipRcPost 182 | 183 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 184 | if "%MAVEN_BATCH_PAUSE%"=="on" pause 185 | 186 | if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE% 187 | 188 | cmd /C exit /B %ERROR_CODE% 189 | -------------------------------------------------------------------------------- /mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # https://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Maven Start Up Batch script 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # M2_HOME - location of maven2's installed home dir 31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 32 | # e.g. to debug Maven itself, use 33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 35 | # ---------------------------------------------------------------------------- 36 | 37 | if [ -z "$MAVEN_SKIP_RC" ] ; then 38 | 39 | if [ -f /usr/local/etc/mavenrc ] ; then 40 | . /usr/local/etc/mavenrc 41 | fi 42 | 43 | if [ -f /etc/mavenrc ] ; then 44 | . /etc/mavenrc 45 | fi 46 | 47 | if [ -f "$HOME/.mavenrc" ] ; then 48 | . "$HOME/.mavenrc" 49 | fi 50 | 51 | fi 52 | 53 | # OS specific support. $var _must_ be set to either true or false. 54 | cygwin=false; 55 | darwin=false; 56 | mingw=false 57 | case "`uname`" in 58 | CYGWIN*) cygwin=true ;; 59 | MINGW*) mingw=true;; 60 | Darwin*) darwin=true 61 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home 62 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html 63 | if [ -z "$JAVA_HOME" ]; then 64 | if [ -x "/usr/libexec/java_home" ]; then 65 | export JAVA_HOME="`/usr/libexec/java_home`" 66 | else 67 | export JAVA_HOME="/Library/Java/Home" 68 | fi 69 | fi 70 | ;; 71 | esac 72 | 73 | if [ -z "$JAVA_HOME" ] ; then 74 | if [ -r /etc/gentoo-release ] ; then 75 | JAVA_HOME=`java-config --jre-home` 76 | fi 77 | fi 78 | 79 | if [ -z "$M2_HOME" ] ; then 80 | ## resolve links - $0 may be a link to maven's home 81 | PRG="$0" 82 | 83 | # need this for relative symlinks 84 | while [ -h "$PRG" ] ; do 85 | ls=`ls -ld "$PRG"` 86 | link=`expr "$ls" : '.*-> \(.*\)$'` 87 | if expr "$link" : '/.*' > /dev/null; then 88 | PRG="$link" 89 | else 90 | PRG="`dirname "$PRG"`/$link" 91 | fi 92 | done 93 | 94 | saveddir=`pwd` 95 | 96 | M2_HOME=`dirname "$PRG"`/.. 97 | 98 | # make it fully qualified 99 | M2_HOME=`cd "$M2_HOME" && pwd` 100 | 101 | cd "$saveddir" 102 | # echo Using m2 at $M2_HOME 103 | fi 104 | 105 | # For Cygwin, ensure paths are in UNIX format before anything is touched 106 | if $cygwin ; then 107 | [ -n "$M2_HOME" ] && 108 | M2_HOME=`cygpath --unix "$M2_HOME"` 109 | [ -n "$JAVA_HOME" ] && 110 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 111 | [ -n "$CLASSPATH" ] && 112 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 113 | fi 114 | 115 | # For Mingw, ensure paths are in UNIX format before anything is touched 116 | if $mingw ; then 117 | [ -n "$M2_HOME" ] && 118 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 119 | [ -n "$JAVA_HOME" ] && 120 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 121 | fi 122 | 123 | if [ -z "$JAVA_HOME" ]; then 124 | javaExecutable="`which javac`" 125 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 126 | # readlink(1) is not available as standard on Solaris 10. 127 | readLink=`which readlink` 128 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 129 | if $darwin ; then 130 | javaHome="`dirname \"$javaExecutable\"`" 131 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 132 | else 133 | javaExecutable="`readlink -f \"$javaExecutable\"`" 134 | fi 135 | javaHome="`dirname \"$javaExecutable\"`" 136 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 137 | JAVA_HOME="$javaHome" 138 | export JAVA_HOME 139 | fi 140 | fi 141 | fi 142 | 143 | if [ -z "$JAVACMD" ] ; then 144 | if [ -n "$JAVA_HOME" ] ; then 145 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 146 | # IBM's JDK on AIX uses strange locations for the executables 147 | JAVACMD="$JAVA_HOME/jre/sh/java" 148 | else 149 | JAVACMD="$JAVA_HOME/bin/java" 150 | fi 151 | else 152 | JAVACMD="`\\unset -f command; \\command -v java`" 153 | fi 154 | fi 155 | 156 | if [ ! -x "$JAVACMD" ] ; then 157 | echo "Error: JAVA_HOME is not defined correctly." >&2 158 | echo " We cannot execute $JAVACMD" >&2 159 | exit 1 160 | fi 161 | 162 | if [ -z "$JAVA_HOME" ] ; then 163 | echo "Warning: JAVA_HOME environment variable is not set." 164 | fi 165 | 166 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 167 | 168 | # traverses directory structure from process work directory to filesystem root 169 | # first directory with .mvn subdirectory is considered project base directory 170 | find_maven_basedir() { 171 | 172 | if [ -z "$1" ] 173 | then 174 | echo "Path not specified to find_maven_basedir" 175 | return 1 176 | fi 177 | 178 | basedir="$1" 179 | wdir="$1" 180 | while [ "$wdir" != '/' ] ; do 181 | if [ -d "$wdir"/.mvn ] ; then 182 | basedir=$wdir 183 | break 184 | fi 185 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 186 | if [ -d "${wdir}" ]; then 187 | wdir=`cd "$wdir/.."; pwd` 188 | fi 189 | # end of workaround 190 | done 191 | echo "${basedir}" 192 | } 193 | 194 | # concatenates all lines of a file 195 | concat_lines() { 196 | if [ -f "$1" ]; then 197 | echo "$(tr -s '\n' ' ' < "$1")" 198 | fi 199 | } 200 | 201 | BASE_DIR=`find_maven_basedir "$(pwd)"` 202 | if [ -z "$BASE_DIR" ]; then 203 | exit 1; 204 | fi 205 | 206 | ########################################################################################## 207 | # Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 208 | # This allows using the maven wrapper in projects that prohibit checking in binary data. 209 | ########################################################################################## 210 | if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then 211 | if [ "$MVNW_VERBOSE" = true ]; then 212 | echo "Found .mvn/wrapper/maven-wrapper.jar" 213 | fi 214 | else 215 | if [ "$MVNW_VERBOSE" = true ]; then 216 | echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." 217 | fi 218 | if [ -n "$MVNW_REPOURL" ]; then 219 | jarUrl="$MVNW_REPOURL/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" 220 | else 221 | jarUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" 222 | fi 223 | while IFS="=" read key value; do 224 | case "$key" in (wrapperUrl) jarUrl="$value"; break ;; 225 | esac 226 | done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" 227 | if [ "$MVNW_VERBOSE" = true ]; then 228 | echo "Downloading from: $jarUrl" 229 | fi 230 | wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" 231 | if $cygwin; then 232 | wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` 233 | fi 234 | 235 | if command -v wget > /dev/null; then 236 | if [ "$MVNW_VERBOSE" = true ]; then 237 | echo "Found wget ... using wget" 238 | fi 239 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then 240 | wget "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" 241 | else 242 | wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" 243 | fi 244 | elif command -v curl > /dev/null; then 245 | if [ "$MVNW_VERBOSE" = true ]; then 246 | echo "Found curl ... using curl" 247 | fi 248 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then 249 | curl -o "$wrapperJarPath" "$jarUrl" -f 250 | else 251 | curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f 252 | fi 253 | 254 | else 255 | if [ "$MVNW_VERBOSE" = true ]; then 256 | echo "Falling back to using Java to download" 257 | fi 258 | javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" 259 | # For Cygwin, switch paths to Windows format before running javac 260 | if $cygwin; then 261 | javaClass=`cygpath --path --windows "$javaClass"` 262 | fi 263 | if [ -e "$javaClass" ]; then 264 | if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 265 | if [ "$MVNW_VERBOSE" = true ]; then 266 | echo " - Compiling MavenWrapperDownloader.java ..." 267 | fi 268 | # Compiling the Java class 269 | ("$JAVA_HOME/bin/javac" "$javaClass") 270 | fi 271 | if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 272 | # Running the downloader 273 | if [ "$MVNW_VERBOSE" = true ]; then 274 | echo " - Running MavenWrapperDownloader.java ..." 275 | fi 276 | ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") 277 | fi 278 | fi 279 | fi 280 | fi 281 | ########################################################################################## 282 | # End of extension 283 | ########################################################################################## 284 | 285 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} 286 | if [ "$MVNW_VERBOSE" = true ]; then 287 | echo $MAVEN_PROJECTBASEDIR 288 | fi 289 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 290 | 291 | # For Cygwin, switch paths to Windows format before running java 292 | if $cygwin; then 293 | [ -n "$M2_HOME" ] && 294 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 295 | [ -n "$JAVA_HOME" ] && 296 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 297 | [ -n "$CLASSPATH" ] && 298 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 299 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 300 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` 301 | fi 302 | 303 | # Provide a "standardized" way to retrieve the CLI args that will 304 | # work with both Windows and non-Windows executions. 305 | MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" 306 | export MAVEN_CMD_LINE_ARGS 307 | 308 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 309 | 310 | exec "$JAVACMD" \ 311 | $MAVEN_OPTS \ 312 | $MAVEN_DEBUG_OPTS \ 313 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 314 | "-Dmaven.home=${M2_HOME}" \ 315 | "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 316 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 317 | --------------------------------------------------------------------------------