-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
musab.bozkurt
committed
Feb 14, 2024
1 parent
ffec9fa
commit a10ac17
Showing
11 changed files
with
144 additions
and
3 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
19 changes: 19 additions & 0 deletions
19
src/main/java/com/mb/livedataservice/api/filter/ApiCarFilter.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,19 @@ | ||
package com.mb.livedataservice.api.filter; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Data | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class ApiCarFilter { | ||
|
||
private String model; | ||
|
||
private Integer yearOfManufacture; | ||
|
||
private String brand; | ||
} |
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
19 changes: 19 additions & 0 deletions
19
src/main/java/com/mb/livedataservice/data/filter/CarFilter.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,19 @@ | ||
package com.mb.livedataservice.data.filter; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Data | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class CarFilter { | ||
|
||
private String model; | ||
|
||
private Integer yearOfManufacture; | ||
|
||
private String brand; | ||
} |
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/mb/livedataservice/mapper/CarMapper.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,16 +1,33 @@ | ||
package com.mb.livedataservice.mapper; | ||
|
||
import co.elastic.clients.elasticsearch.core.SearchResponse; | ||
import co.elastic.clients.elasticsearch.core.search.Hit; | ||
import com.mb.livedataservice.api.filter.ApiCarFilter; | ||
import com.mb.livedataservice.api.request.ApiCarRequest; | ||
import com.mb.livedataservice.api.response.ApiCarResponse; | ||
import com.mb.livedataservice.data.filter.CarFilter; | ||
import com.mb.livedataservice.data.model.elastic.Car; | ||
import org.mapstruct.Mapper; | ||
import org.mapstruct.Mapping; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@Mapper(componentModel = "spring") | ||
public interface CarMapper { | ||
|
||
ApiCarResponse map(Car car); | ||
|
||
@Mapping(target = "id", ignore = true) | ||
Car map(ApiCarRequest apiCarRequest); | ||
|
||
CarFilter map(ApiCarFilter apiCarFilter); | ||
|
||
default List<ApiCarResponse> map(SearchResponse<Car> searchResponse) { | ||
List<ApiCarResponse> carResponses = new ArrayList<>(); | ||
for (Hit<Car> hit : searchResponse.hits().hits()) { | ||
carResponses.add(this.map(hit.source())); | ||
} | ||
return carResponses; | ||
} | ||
} |
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
38 changes: 38 additions & 0 deletions
38
src/main/java/com/mb/livedataservice/util/ElasticSearchUtil.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,38 @@ | ||
package com.mb.livedataservice.util; | ||
|
||
import co.elastic.clients.elasticsearch._types.query_dsl.FuzzyQuery; | ||
import co.elastic.clients.elasticsearch._types.query_dsl.Query; | ||
import com.mb.livedataservice.data.filter.CarFilter; | ||
import lombok.AccessLevel; | ||
import lombok.NoArgsConstructor; | ||
import lombok.val; | ||
import org.apache.commons.lang3.StringUtils; | ||
|
||
import java.util.Objects; | ||
import java.util.function.Supplier; | ||
|
||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
public class ElasticSearchUtil { | ||
|
||
public static Supplier<Query> createSupplierQuery(CarFilter carFilter) { | ||
return () -> Query.of(builder -> builder.fuzzy(createFuzzyQuery(carFilter))); | ||
} | ||
|
||
private static FuzzyQuery createFuzzyQuery(CarFilter carFilter) { | ||
val fuzzyQuery = new FuzzyQuery.Builder(); | ||
|
||
if (StringUtils.isNotBlank(carFilter.getModel())) { | ||
fuzzyQuery.field("model").value(carFilter.getModel()); | ||
} | ||
|
||
if (Objects.nonNull(carFilter.getYearOfManufacture())) { | ||
fuzzyQuery.field("yearOfManufacture").value(carFilter.getYearOfManufacture()); | ||
} | ||
|
||
if (StringUtils.isNotBlank(carFilter.getBrand())) { | ||
fuzzyQuery.field("brand").value(carFilter.getBrand()); | ||
} | ||
|
||
return fuzzyQuery.build(); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...livedataservice/utils/RedisConstants.java → .../livedataservice/util/RedisConstants.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
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