Passed
Push — master ( 676f65...74c283 )
by Huu-Phat
02:02 queued 13s
created

convertPostDtoToEntity(PostDto,PostEntity)   A

Complexity

Conditions 1

Size

Total Lines 10
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 10
c 0
b 0
f 0
dl 0
loc 10
rs 9.9
cc 1
1
package com.dawn.jat.illuminati.core.convert;
2
3
import com.dawn.jat.illuminati.post.dto.PostDto;
4
import com.dawn.jat.illuminati.post.entity.PostEntity;
5
6
import java.util.ArrayList;
7
import java.util.List;
8
import java.util.Map;
9
10
import org.springframework.stereotype.Service;
11
12
@Service
13
public class Converter {
14
    private  <T> List<String> convertMapKeysToArray(Map<String, T> map) {
15
        List<String> list = new ArrayList<>();
16
        map.forEach((key, value) -> {
17
            list.add(key);
18
        });
19
        return list;
20
    }
21
22
    /**
23
     * Convert a PostDto to PostEntity.
24
     */
25
    public PostEntity convertPostDtoToEntity(PostDto post, PostEntity postEntity) {
26
        postEntity.setSlug(post.getSlug());
27
        postEntity.setAuthor(post.getAuthor());
28
        postEntity.setBrief(post.getBrief());
29
        postEntity.setTitle(post.getTitle());
30
        postEntity.setTime(post.getTime());
31
        postEntity.setContent(post.getContent());
32
        Map<String, Boolean> tagMap = post.getTag();
33
        postEntity.setTag(convertMapKeysToArray(tagMap));
34
        return postEntity;
35
    }
36
}
37