fixed category in posts
This commit is contained in:
@@ -3,6 +3,7 @@ package com.krylov.refound.mapper;
|
||||
import com.krylov.refound.dto.PostRequest;
|
||||
import com.krylov.refound.dto.PostResponse;
|
||||
import com.krylov.refound.entity.Post;
|
||||
import com.krylov.refound.enums.PostCategory;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import com.krylov.refound.entity.Image;
|
||||
@@ -12,10 +13,12 @@ import java.util.List;
|
||||
@Mapper(componentModel = "spring")
|
||||
public interface PostMapper {
|
||||
|
||||
@Mapping(source = "category", target = "category", qualifiedByName = "stringToPostCategory")
|
||||
Post toEntity(PostRequest request);
|
||||
|
||||
@Mapping(source = "user.login", target = "userEmail")
|
||||
@Mapping(source = "images", target = "images", qualifiedByName = "imagesToUrls")
|
||||
@Mapping(target = "category", expression = "java(post.getCategory().getDisplayName())")
|
||||
PostResponse toResponse(Post post);
|
||||
|
||||
@Named("imagesToUrls")
|
||||
@@ -25,4 +28,10 @@ public interface PostMapper {
|
||||
.map(Image::getUrl)
|
||||
.toList();
|
||||
}
|
||||
|
||||
@Named("stringToPostCategory")
|
||||
default PostCategory stringToPostCategory(String displayName) {
|
||||
if (displayName == null) return null;
|
||||
return PostCategory.fromDisplayName(displayName);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user