NemesLaszlo/Forum

View on GitHub
src/main/java/com/forum/mapper/CommentMapper.java

Summary

Maintainability
A
0 mins
Test Coverage
package com.forum.mapper;

import com.forum.dto.CommentsDto;
import com.forum.model.Comment;
import com.forum.model.Post;
import com.forum.model.User;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;

@Mapper(componentModel = "spring")
public interface CommentMapper {

    @Mapping(target = "id", ignore = true)
    @Mapping(target = "text", source = "commentsDto.text")
    @Mapping(target = "createdDate", expression = "java(java.time.Instant.now())")
    @Mapping(target = "post", source = "post")
    @Mapping(target = "user", source = "user")
    Comment map(CommentsDto commentsDto, Post post, User user);

    @Mapping(target = "postId", expression = "java(comment.getPost().getPostId())")
    @Mapping(target = "userName", expression = "java(comment.getUser().getUsername())")
    CommentsDto mapToDto(Comment comment);
}