summaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/blog/web/mappers/ArticleMapper.java
blob: a3642da35f81d3896a16c3ea897c158e7c99463d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package com.blog.web.mappers;

import com.blog.web.dto.ArticleDto;
import com.blog.web.models.Article;

public class ArticleMapper {
    public static Article mapToArticle(ArticleDto articleDto) {
        Article article = Article.builder()
                .id(articleDto.getId())
                .title(articleDto.getTitle())
                .photoUrl(articleDto.getPhotoUrl())
                .content(articleDto.getContent())
                .createdBy(articleDto.getCreatedBy())
                .createdOn(articleDto.getCreatedOn())
                .updatedOn(articleDto.getUpdatedOn())
                .build();
        return article;
    }

    public static ArticleDto mapToArticleDto(Article article) {
        return ArticleDto.builder()
                .id(article.getId())
                .title(article.getTitle())
                .photoUrl(article.getPhotoUrl())
                .content(article.getContent())
                .createdBy(article.getCreatedBy())
                .createdOn(article.getCreatedOn())
                .updatedOn(article.getUpdatedOn())
                .build();
    }
}