图片存在性校验
This commit is contained in:
@@ -29,6 +29,7 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -83,6 +84,7 @@ public class ListingServiceImpl extends ServiceImpl<ListingMapper, ListingEntity
|
||||
}
|
||||
|
||||
if (!CollectionUtils.isEmpty(dto.getImages())) {
|
||||
validateImages(dto.getImages());
|
||||
handleImages(listingId, dto.getImages());
|
||||
String cover = extractCover(dto.getImages());
|
||||
if (StringUtils.hasText(cover)) {
|
||||
@@ -213,6 +215,34 @@ public class ListingServiceImpl extends ServiceImpl<ListingMapper, ListingEntity
|
||||
}
|
||||
}
|
||||
|
||||
private void validateImages(List<ListingImageDTO> images) {
|
||||
Set<String> requiredCategories = Set.of(
|
||||
ImageCategoryEnum.COVER.getCode(),
|
||||
ImageCategoryEnum.COVERFROM.getCode(),
|
||||
ImageCategoryEnum.SKETCH.getCode(),
|
||||
ImageCategoryEnum.APPAREL.getCode());
|
||||
|
||||
Set<String> presentCategories = images.stream()
|
||||
.map(ListingImageDTO::getCategory)
|
||||
.filter(StringUtils::hasText)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
for (String category : requiredCategories) {
|
||||
if (!presentCategories.contains(category)) {
|
||||
throw new BusinessException("category [" + category + "] is required");
|
||||
}
|
||||
}
|
||||
|
||||
for (ListingImageDTO img : images) {
|
||||
String category = img.getCategory();
|
||||
if (requiredCategories.contains(category)) {
|
||||
if (!StringUtils.hasText(img.getImageUrl())) {
|
||||
throw new BusinessException(category + " category imageUrl cannot be null or empty");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String extractCover(List<ListingImageDTO> images) {
|
||||
if (CollectionUtils.isEmpty(images)) {
|
||||
return null;
|
||||
@@ -222,12 +252,10 @@ public class ListingServiceImpl extends ServiceImpl<ListingMapper, ListingEntity
|
||||
return img.getImageUrl();
|
||||
}
|
||||
}
|
||||
if (!CollectionUtils.isEmpty(images)) {
|
||||
return images.get(0).getImageUrl();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setPopupReminder(Long sellerId) {
|
||||
String key = "popup:reminder:" + sellerId;
|
||||
|
||||
Reference in New Issue
Block a user