Skip to content

Commit

Permalink
#7 - Feat: 1번 회원이 1번 해시태그 키워드를 선택하여 도서 1, 2번 글을 도서로 등록하는 Product Init…
Browse files Browse the repository at this point in the history
…Data 추가
  • Loading branch information
ahah525 committed Oct 24, 2022
1 parent 2c488dc commit 42a73d6
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.example.mutbooks.app.member.service.MemberService;
import com.example.mutbooks.app.post.service.PostService;
import com.example.mutbooks.app.product.service.ProductService;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand All @@ -11,9 +12,9 @@
@Profile("dev")
public class DevInitData implements InitDataBefore {
@Bean
CommandLineRunner initData(MemberService memberService, PostService postService) {
CommandLineRunner initData(MemberService memberService, PostService postService, ProductService productService) {
return args -> {
before(memberService, postService);
before(memberService, postService, productService);
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,21 @@
import com.example.mutbooks.app.member.service.MemberService;
import com.example.mutbooks.app.post.form.WriteForm;
import com.example.mutbooks.app.post.service.PostService;
import com.example.mutbooks.app.product.form.ProductForm;
import com.example.mutbooks.app.product.service.ProductService;

public interface InitDataBefore {
default void before(MemberService memberService, PostService postService) {
default void before(MemberService memberService, PostService postService, ProductService productService) {
// 작가 회원
Member member1 = memberService.join(new JoinForm("user1", "1234", "작가", "[email protected]"));
// 일반 회원
Member member2 = memberService.join(new JoinForm("user2", "1234", null, "[email protected]"));

// 글 작성
postService.write(member1, new WriteForm("제목1", "안녕하세요1", "<ul><li><p>안녕하세요1</p></li></ul>","#판타지 #소설 #판타지 #SF"));
postService.write(member1, new WriteForm("제목2", "안녕하세요2", "<ul><li><p>안녕하세요2</p></li></ul>", null));
postService.write(member1, new WriteForm("제목2", "안녕하세요2", "<ul><li><p>안녕하세요2</p></li></ul>", "#판타지 #로맨스"));

// 1번 회원이 1번(판타지) 글 키워드 선택 -> 1, 2번 글 도서 등록
productService.create(member1, new ProductForm("해리포터", "판타지 소설입니다.", 10000, 1L, "#판타지 #소설"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.example.mutbooks.app.member.service.MemberService;
import com.example.mutbooks.app.post.service.PostService;
import com.example.mutbooks.app.product.service.ProductService;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand All @@ -11,9 +12,9 @@
@Profile("test")
public class TestInitData implements InitDataBefore {
@Bean
CommandLineRunner initData(MemberService memberService, PostService postService) {
CommandLineRunner initData(MemberService memberService, PostService postService, ProductService productService) {
return args -> {
before(memberService, postService);
before(memberService, postService, productService);
};
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.mutbooks.app.product.form;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;

Expand All @@ -8,6 +9,7 @@

@Getter
@Setter
@AllArgsConstructor
public class ProductForm {
@NotEmpty(message = "도서명을 입력해주세요.")
private String subject;
Expand Down

0 comments on commit 42a73d6

Please sign in to comment.