added image for post
This commit is contained in:
@@ -5,6 +5,9 @@ import com.krylov.refound.dto.PostResponse;
|
||||
import com.krylov.refound.entity.Post;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import com.krylov.refound.entity.Image;
|
||||
import org.mapstruct.Named;
|
||||
import java.util.List;
|
||||
|
||||
@Mapper(componentModel = "spring")
|
||||
public interface PostMapper {
|
||||
@@ -12,5 +15,14 @@ public interface PostMapper {
|
||||
Post toEntity(PostRequest request);
|
||||
|
||||
@Mapping(source = "user.login", target = "userEmail")
|
||||
@Mapping(source = "images", target = "images", qualifiedByName = "imagesToUrls")
|
||||
PostResponse toResponse(Post post);
|
||||
|
||||
@Named("imagesToUrls")
|
||||
default List<String> imagesToUrls(List<Image> images) {
|
||||
if (images == null) return List.of();
|
||||
return images.stream()
|
||||
.map(Image::getUrl)
|
||||
.toList();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user