Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/main/java/ua/everybuy/database/entity/Advertisement.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ public class Advertisement {
@Column(name = "is_enabled")
private Boolean isEnabled;

@Column(name = "is_negotiable", nullable = false)
private Boolean isNegotiable = false;

@Column(name = "user_id", nullable = false)
private Long userId;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class AdvertisementDocument {
private Date creationDate;
private Date updateDate;
private Boolean isEnabled;
private Boolean isNegotiable;
private Long userId;
private String mainPhotoUrl;
private Long cityId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class AdvertisementDto {
private Double price;
private LocalDateTime creationDate;
private Boolean isEnabled;
private Boolean isNegotiable;
private Long userId;
private String mainPhotoUrl;
private List<String> photoUrls;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ public record CreateAdvertisementRequest(
@NotNull(message = "Product type is required")
Advertisement.ProductType productType,

@NotNull(message = "Negotiable status is required")
Boolean isNegotiable,

@NotEmpty(message = "Delivery methods are required")
Set<String> deliveryMethods

) implements CategoryRequest {
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ public record UpdateAdvertisementRequest(

@NotNull(message = "Product type is required")
Advertisement.ProductType productType,

@NotNull(message = "Negotiable status is required")
Boolean isNegotiable,

@NotEmpty(message = "Delivery methods are required")
Set<String> deliveryMethods
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package ua.everybuy.routing.dto.response;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.Getter;
import lombok.Setter;
import ua.everybuy.routing.dto.util.PriceSerializer;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Set;
Expand All @@ -21,6 +18,7 @@ public class CreateAdvertisementResponse {
private Double price;
private LocalDateTime creationDate;
private Boolean isEnabled;
private Boolean isNegotiable;
private Long userId;
private String mainPhotoUrl;
private List<String> photoUrls;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class FilteredAdvertisementsResponse {
@JsonSerialize(using = PriceSerializer.class)
private Double price;
private String description;
private Boolean isNegotiable;
private LocalDateTime updateDate;
private City city;
private SubCategoryDto topSubCategory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class UpdateAdvertisementResponse {
private LocalDateTime creationDate;
private LocalDateTime updateDate;
private Boolean isEnabled;
private Boolean isNegotiable;
private Long userId;
private String mainPhotoUrl;
private List<String> photoUrls;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public AdvertisementDocument mapToDocument(Advertisement ad) {
.creationDate(convertToDate(ad.getCreationDate()))
.updateDate(convertToDate(ad.getUpdateDate()))
.isEnabled(ad.getIsEnabled())
.isNegotiable(ad.getIsNegotiable())
.userId(ad.getUserId())
.mainPhotoUrl(ad.getMainPhotoUrl())
.cityId(ad.getCity().getId())
Expand All @@ -61,6 +62,7 @@ public FilteredAdvertisementsResponse mapToFilteredAdvertisementsResponse(Advert
response.setTitle(doc.getTitle());
response.setDescription(doc.getDescription());
response.setPrice(doc.getPrice());
response.setIsNegotiable(doc.getIsNegotiable());
response.setUpdateDate(LocalDateTime.ofInstant(doc.getUpdateDate().toInstant(), ZoneId.systemDefault()));
response.setProductType(Advertisement.ProductType.valueOf(doc.getProductType()));
response.setSection(doc.getSection());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@ Advertisement mapToEntity(CreateAdvertisementRequest request,
@Mapping(source = "request.section", target = "section")
@Mapping(target = "updateDate", expression = "java(java.time.LocalDateTime.now())")
@Mapping(target = "isEnabled", constant = "true")
@Mapping(source = "request.isNegotiable", target = "isNegotiable")
Advertisement mapToEntity(UpdateAdvertisementRequest request, Advertisement advertisement);
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,12 @@
@Service
@RequiredArgsConstructor
public class ElasticAdvertisementReindexingService implements AdvertisementReindexingService {

private static final String INDEX_NAME = "advertisements";
private final AdvertisementRepository advertisementRepository;
private final AdvertisementDocumentMapper mapper;
private final RestHighLevelClient restHighLevelClient;
private final ObjectMapper objectMapper;

private static final String INDEX_NAME = "advertisements";

@Override
public String reindexAllAdvertisements() throws IOException {
createIndexIfNotExists();
Expand Down Expand Up @@ -63,7 +61,8 @@ private void deleteAllDocuments() throws IOException {
restHighLevelClient.deleteByQuery(deleteRequest, RequestOptions.DEFAULT);
}

private BulkRequest createBulkIndexRequest(List<Advertisement> advertisements) throws JsonProcessingException {
private BulkRequest createBulkIndexRequest(List<Advertisement> advertisements)
throws JsonProcessingException {
BulkRequest bulkRequest = new BulkRequest();

for (Advertisement ad : advertisements) {
Expand Down Expand Up @@ -123,6 +122,7 @@ private String getIndexMapping() {
"creationDate": { "type": "date" },
"updateDate": { "type": "date" },
"isEnabled": { "type": "boolean" },
"isNegotiable": { "type": "boolean" },
"userId": { "type": "long" },
"mainPhotoUrl": { "type": "text" },
"cityId": { "type": "long" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import ua.everybuy.routing.dto.request.AdvertisementSearchParametersDto;
import ua.everybuy.routing.dto.response.FilteredAdvertisementsResponse;
import ua.everybuy.routing.mapper.AdvertisementDocumentMapper;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;
Expand All @@ -39,7 +38,9 @@ public AdvertisementSearchResultDto searchAdvertisements(AdvertisementSearchPara

List<FilteredAdvertisementsResponse> advertisements = parseSearchHits(response);
long totalHits = response.getHits().getTotalHits().value;
PriceRangeDto priceRange = elasticSearchPriceAggregationExtractor.extractPriceRange(response.getAggregations());

PriceRangeDto priceRange = elasticSearchPriceAggregationExtractor
.extractPriceRange(response.getAggregations());

return buildSearchResultDto(advertisements, totalHits, size, priceRange);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
ALTER TABLE advertisements
ADD COLUMN is_negotiable BOOLEAN;

UPDATE advertisements
SET is_negotiable = false
WHERE is_negotiable IS NULL;

ALTER TABLE advertisements
ALTER COLUMN is_negotiable SET NOT NULL;
Loading