Skip to content
This repository has been archived by the owner on Jul 26, 2024. It is now read-only.

Commit

Permalink
introduce mapper for configs
Browse files Browse the repository at this point in the history
  • Loading branch information
Ralf Ueberfuhr committed Dec 21, 2023
1 parent edc950c commit fab77b2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package de.sample.schulung.spring.blog.domain;

import de.sample.schulung.spring.blog.domain.config.BlogPostConfigMapper;
import de.sample.schulung.spring.blog.domain.config.BlogPostInitializationConfig;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Profile;
Expand All @@ -14,21 +15,15 @@ public class BlogPostInitializer {

private final BlogPostService service;
private final BlogPostInitializationConfig config;
private final BlogPostConfigMapper mapper;

@EventListener(ContextRefreshedEvent.class)
void initBlogPosts() {
if(service.count() == 0 && config.isEnabled()) {
config.getBlogposts()
.forEach(
blogPostConfig -> {
var blogpost = BlogPost
.builder()
.title(blogPostConfig.getTitle())
.content(blogPostConfig.getContent())
.build();
service.create(blogpost);
}
);
.stream()
.map(this.mapper::map)
.forEach(service::create);
}

}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package de.sample.schulung.spring.blog.domain.config;

import de.sample.schulung.spring.blog.domain.BlogPost;
import org.mapstruct.Mapper;

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

BlogPost map(BlogPostConfig source);

}

0 comments on commit fab77b2

Please sign in to comment.