-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
resolved all of conflicts and updated the branch for implementing pay…
…ment features
- Loading branch information
Showing
36 changed files
with
519 additions
and
371 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
src/main/java/com/project/carsharingapp/dto/rental/RentalSearchParametersDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.project.carsharingapp.dto.rental; | ||
|
||
public record RentalSearchParametersDto( | ||
String[] userId, | ||
String[] isActive | ||
) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/main/java/com/project/carsharingapp/mapper/RentalMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.project.carsharingapp.mapper; | ||
|
||
import com.project.carsharingapp.config.MapperConfig; | ||
import com.project.carsharingapp.dto.rental.CreateRentalRequestDto; | ||
import com.project.carsharingapp.dto.rental.RentalDto; | ||
import com.project.carsharingapp.model.Rental; | ||
import org.mapstruct.Mapper; | ||
import org.mapstruct.Mapping; | ||
|
||
@Mapper(config = MapperConfig.class) | ||
public interface RentalMapper { | ||
Rental toEntity(CreateRentalRequestDto requestDto); | ||
|
||
@Mapping(source = "user.id", target = "userId") | ||
@Mapping(source = "car.id", target = "carId") | ||
RentalDto toDto(Rental rental); | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/project/carsharingapp/mapper/UserMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.project.carsharingapp.mapper; | ||
|
||
import com.project.carsharingapp.config.MapperConfig; | ||
import com.project.carsharingapp.dto.user.UserDto; | ||
import com.project.carsharingapp.model.User; | ||
import org.mapstruct.Mapper; | ||
|
||
@Mapper(config = MapperConfig.class) | ||
public interface UserMapper { | ||
UserDto toDto(User user); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
2 changes: 2 additions & 0 deletions
2
src/main/java/com/project/carsharingapp/repository/RoleRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
package com.project.carsharingapp.repository; | ||
|
||
import com.project.carsharingapp.model.Role; | ||
import java.util.Optional; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface RoleRepository extends JpaRepository<Role, Long> { | ||
Optional<Role> findByRoleName(Role.RoleName name); | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/com/project/carsharingapp/repository/SpecificationBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.project.carsharingapp.repository; | ||
|
||
import com.project.carsharingapp.dto.rental.RentalSearchParametersDto; | ||
import org.springframework.data.jpa.domain.Specification; | ||
|
||
public interface SpecificationBuilder<T> { | ||
Specification<T> build(RentalSearchParametersDto searchParametersDto); | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/project/carsharingapp/repository/SpecificationProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.project.carsharingapp.repository; | ||
|
||
import com.project.carsharingapp.model.Rental; | ||
import org.springframework.data.jpa.domain.Specification; | ||
|
||
public interface SpecificationProvider<T> { | ||
String getKey(); | ||
|
||
Specification<Rental> getSpecification(String[] params); | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/java/com/project/carsharingapp/repository/SpecificationProviderManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.project.carsharingapp.repository; | ||
|
||
public interface SpecificationProviderManager<T> { | ||
SpecificationProvider<T> getSpecificationProvider(String key); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 7 additions & 1 deletion
8
...aringapp/repository/RentalRepository.java → .../repository/rentals/RentalRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,18 @@ | ||
package com.project.carsharingapp.repository; | ||
package com.project.carsharingapp.repository.rentals; | ||
|
||
import com.project.carsharingapp.model.Rental; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface RentalRepository extends JpaRepository<Rental, Long> { | ||
@Query("FROM Rental r LEFT JOIN FETCH r.car " | ||
+ "LEFT JOIN FETCH r.user WHERE r.id = :id") | ||
Optional<Rental> findById(Long id); | ||
|
||
@Query("FROM Rental r WHERE r.user.id = :userId AND r.isActive = :isActive") | ||
List<Rental> findRentalsByUserIdAndActiveStatus(Long userId, boolean isActive); | ||
} |
36 changes: 36 additions & 0 deletions
36
src/main/java/com/project/carsharingapp/repository/rentals/RentalSpecificationBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.project.carsharingapp.repository.rentals; | ||
|
||
import com.project.carsharingapp.dto.rental.RentalSearchParametersDto; | ||
import com.project.carsharingapp.model.Rental; | ||
import com.project.carsharingapp.repository.SpecificationBuilder; | ||
import com.project.carsharingapp.repository.SpecificationProviderManager; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.jpa.domain.Specification; | ||
import org.springframework.stereotype.Component; | ||
|
||
@RequiredArgsConstructor | ||
@Component | ||
public class RentalSpecificationBuilder implements SpecificationBuilder<Rental> { | ||
public static final String USER_ID_KEY = "userId"; | ||
public static final String IS_ACTIVE_KEY = "isActive"; | ||
|
||
private final SpecificationProviderManager<Rental> rentalSpecificationProviderManager; | ||
|
||
@Override | ||
public Specification<Rental> build(RentalSearchParametersDto searchParametersDto) { | ||
Specification<Rental> spec = Specification.where(null); | ||
spec = getRentalSpecification(searchParametersDto.userId(), spec, USER_ID_KEY); | ||
spec = getRentalSpecification(searchParametersDto.isActive(), spec, IS_ACTIVE_KEY); | ||
return spec; | ||
} | ||
|
||
private Specification<Rental> getRentalSpecification(String[] searchParametersDto, | ||
Specification<Rental> spec, | ||
String key) { | ||
if (searchParametersDto != null && searchParametersDto.length > 0) { | ||
spec = spec.and(rentalSpecificationProviderManager.getSpecificationProvider(key) | ||
.getSpecification(searchParametersDto)); | ||
} | ||
return spec; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...java/com/project/carsharingapp/repository/rentals/RentalSpecificationProviderManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.project.carsharingapp.repository.rentals; | ||
|
||
import com.project.carsharingapp.model.Rental; | ||
import com.project.carsharingapp.repository.SpecificationProvider; | ||
import com.project.carsharingapp.repository.SpecificationProviderManager; | ||
import java.util.List; | ||
import java.util.NoSuchElementException; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
|
||
@RequiredArgsConstructor | ||
@Component | ||
public class RentalSpecificationProviderManager implements SpecificationProviderManager<Rental> { | ||
private final List<SpecificationProvider<Rental>> rentalSpecificationProviders; | ||
|
||
@Override | ||
public SpecificationProvider<Rental> getSpecificationProvider(String key) { | ||
return rentalSpecificationProviders | ||
.stream() | ||
.filter(p -> p.getKey().equals(key)) | ||
.findFirst() | ||
.orElseThrow(() -> new NoSuchElementException( | ||
"Can't find correct specification provider for key: " + key)); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
.../com/project/carsharingapp/repository/rentals/spec/ActiveStatusSpecificationProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.project.carsharingapp.repository.rentals.spec; | ||
|
||
import static com.project.carsharingapp.repository.rentals.RentalSpecificationBuilder.IS_ACTIVE_KEY; | ||
|
||
import com.project.carsharingapp.model.Rental; | ||
import com.project.carsharingapp.repository.SpecificationProvider; | ||
import java.util.Arrays; | ||
import org.springframework.data.jpa.domain.Specification; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class ActiveStatusSpecificationProvider implements SpecificationProvider<Rental> { | ||
@Override | ||
public String getKey() { | ||
return IS_ACTIVE_KEY; | ||
} | ||
|
||
public Specification<Rental> getSpecification(String[] params) { | ||
return (root, query, criteriaBuilder) -> root.get(IS_ACTIVE_KEY) | ||
.in(Arrays.stream(params).toArray()); | ||
} | ||
} |
Oops, something went wrong.